validate token type
This commit is contained in:
parent
52da9de0c6
commit
6ed7f705b9
|
@ -8,5 +8,6 @@ var ErrMalformedPushNotificationRegistrationInstallationID = errors.New("invalid
|
||||||
var ErrEmptyPushNotificationRegistrationPublicKey = errors.New("no public key")
|
var ErrEmptyPushNotificationRegistrationPublicKey = errors.New("no public key")
|
||||||
var ErrCouldNotUnmarshalPushNotificationRegistration = errors.New("could not unmarshal preferences")
|
var ErrCouldNotUnmarshalPushNotificationRegistration = errors.New("could not unmarshal preferences")
|
||||||
var ErrInvalidCiphertextLength = errors.New("invalid cyphertext length")
|
var ErrInvalidCiphertextLength = errors.New("invalid cyphertext length")
|
||||||
var ErrMalformedPushNotificationRegistrationAccessToken = errors.New("invalid access token")
|
|
||||||
var ErrMalformedPushNotificationRegistrationDeviceToken = errors.New("invalid device token")
|
var ErrMalformedPushNotificationRegistrationDeviceToken = errors.New("invalid device token")
|
||||||
|
var ErrMalformedPushNotificationRegistrationAccessToken = errors.New("invalid access token")
|
||||||
|
var ErrUnknownPushNotificationRegistrationTokenType = errors.New("invalid token type")
|
||||||
|
|
|
@ -112,6 +112,10 @@ func (p *Server) ValidateRegistration(publicKey *ecdsa.PublicKey, payload []byte
|
||||||
return nil, ErrMalformedPushNotificationRegistrationDeviceToken
|
return nil, ErrMalformedPushNotificationRegistrationDeviceToken
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if registration.TokenType == protobuf.PushNotificationRegistration_UNKNOWN_TOKEN_TYPE {
|
||||||
|
return nil, ErrUnknownPushNotificationRegistrationTokenType
|
||||||
|
}
|
||||||
|
|
||||||
return registration, nil
|
return registration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
// Missing installationID
|
// Missing installationID
|
||||||
payload, err := proto.Marshal(&protobuf.PushNotificationRegistration{
|
payload, err := proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -113,6 +114,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
// Malformed installationID
|
// Malformed installationID
|
||||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: "abc",
|
InstallationId: "abc",
|
||||||
Version: 1,
|
Version: 1,
|
||||||
})
|
})
|
||||||
|
@ -124,6 +126,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
// Version set to 0
|
// Version set to 0
|
||||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -136,6 +139,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
// Version lower than previous one
|
// Version lower than previous one
|
||||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
})
|
})
|
||||||
|
@ -147,6 +151,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
// Setup persistence
|
// Setup persistence
|
||||||
s.Require().NoError(s.persistence.SavePushNotificationRegistration(&s.key.PublicKey, &protobuf.PushNotificationRegistration{
|
s.Require().NoError(s.persistence.SavePushNotificationRegistration(&s.key.PublicKey, &protobuf.PushNotificationRegistration{
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
Version: 2}))
|
Version: 2}))
|
||||||
|
|
||||||
|
@ -158,6 +163,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
|
|
||||||
// Unregistering message
|
// Unregistering message
|
||||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
Unregister: true,
|
Unregister: true,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
|
@ -172,6 +178,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
// Missing access token
|
// Missing access token
|
||||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
})
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -184,6 +191,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
// Invalid access token
|
// Invalid access token
|
||||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
AccessToken: "bc",
|
AccessToken: "bc",
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
})
|
})
|
||||||
|
@ -197,6 +205,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
// Missing device token
|
// Missing device token
|
||||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
})
|
})
|
||||||
|
@ -207,10 +216,25 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||||
s.Require().Equal(ErrMalformedPushNotificationRegistrationDeviceToken, err)
|
s.Require().Equal(ErrMalformedPushNotificationRegistrationDeviceToken, err)
|
||||||
|
|
||||||
|
// Missing token type
|
||||||
|
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
|
AccessToken: s.accessToken,
|
||||||
|
Token: "device-token",
|
||||||
|
InstallationId: s.installationID,
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
cyphertext, err = encrypt(payload, s.sharedKey, rand.Reader)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||||
|
s.Require().Equal(ErrUnknownPushNotificationRegistrationTokenType, err)
|
||||||
|
|
||||||
// Successful
|
// Successful
|
||||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||||
Token: "abc",
|
Token: "abc",
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
})
|
})
|
||||||
|
@ -383,6 +407,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
||||||
registration := &protobuf.PushNotificationRegistration{
|
registration := &protobuf.PushNotificationRegistration{
|
||||||
Token: "abc",
|
Token: "abc",
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
}
|
}
|
||||||
|
@ -433,6 +458,7 @@ func (s *ServerSuite) TestHandlePushNotificationQueryNoFiltering() {
|
||||||
registration := &protobuf.PushNotificationRegistration{
|
registration := &protobuf.PushNotificationRegistration{
|
||||||
Token: "abc",
|
Token: "abc",
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
}
|
}
|
||||||
|
@ -467,6 +493,7 @@ func (s *ServerSuite) TestHandlePushNotificationQueryWithFiltering() {
|
||||||
registration := &protobuf.PushNotificationRegistration{
|
registration := &protobuf.PushNotificationRegistration{
|
||||||
Token: "abc",
|
Token: "abc",
|
||||||
AccessToken: s.accessToken,
|
AccessToken: s.accessToken,
|
||||||
|
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||||
InstallationId: s.installationID,
|
InstallationId: s.installationID,
|
||||||
AllowedUserList: allowedUserList,
|
AllowedUserList: allowedUserList,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
|
|
Loading…
Reference in New Issue