fix version check

This commit is contained in:
Andrea Maria Piana 2020-07-31 10:56:26 +02:00
parent 46aef6f3df
commit be8e64fe8d
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 13 additions and 12 deletions

View File

@ -60,15 +60,16 @@ func (p *SQLitePersistence) GetPushNotificationRegistrationByPublicKeyAndInstall
} }
func (p *SQLitePersistence) GetPushNotificationRegistrationVersion(publicKey []byte, installationID string) (uint64, error) { func (p *SQLitePersistence) GetPushNotificationRegistrationVersion(publicKey []byte, installationID string) (uint64, error) {
registration, err := p.GetPushNotificationRegistrationByPublicKeyAndInstallationID(publicKey, installationID) var version uint64
if err != nil { err := p.db.QueryRow(`SELECT version FROM push_notification_server_registrations WHERE public_key = ? AND installation_id = ?`, publicKey, installationID).Scan(&version)
if err == sql.ErrNoRows {
return 0, nil
} else if err != nil {
return 0, err return 0, err
} }
if registration == nil { return version, nil
return 0, nil
}
return registration.Version, nil
} }
type PushNotificationIDAndRegistration struct { type PushNotificationIDAndRegistration struct {

View File

@ -500,16 +500,16 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext) response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
s.Require().NotNil(response) s.Require().NotNil(response)
s.Require().True(response.Success) s.Require().True(response.Success)
s.Require().Equal(common.Shake256(cyphertext), response.RequestId)
// Check is gone from the db // Check is gone from the db
retrievedRegistration, err = s.persistence.GetPushNotificationRegistrationByPublicKeyAndInstallationID(common.HashPublicKey(&s.key.PublicKey), s.installationID) retrievedRegistration, err = s.persistence.GetPushNotificationRegistrationByPublicKeyAndInstallationID(common.HashPublicKey(&s.key.PublicKey), s.installationID)
s.Require().NoError(err) s.Require().NoError(err)
s.Require().NotNil(retrievedRegistration) s.Require().Nil(retrievedRegistration)
s.Require().Empty(retrievedRegistration.AccessToken) // Check version is mantained
s.Require().Empty(retrievedRegistration.DeviceToken) version, err := s.persistence.GetPushNotificationRegistrationVersion(common.HashPublicKey(&s.key.PublicKey), s.installationID)
s.Require().Equal(uint64(2), retrievedRegistration.Version) s.Require().NoError(err)
s.Require().Equal(s.installationID, retrievedRegistration.InstallationId) s.Require().Equal(uint64(2), version)
s.Require().Equal(common.Shake256(cyphertext), response.RequestId)
} }
func (s *ServerSuite) TestbuildPushNotificationQueryResponseNoFiltering() { func (s *ServerSuite) TestbuildPushNotificationQueryResponseNoFiltering() {