Updated tests to match refactor

This commit is contained in:
Samuel Hawksby-Robinson 2021-02-15 15:03:18 +00:00 committed by Andrea Maria Piana
parent 3a1349141a
commit a50048e290
1 changed files with 8 additions and 19 deletions

View File

@ -2595,8 +2595,8 @@ func (s *MessengerSuite) TestEncryptDecryptIdentityImagesWithContactPubKeys() {
s.m.allContacts.Store(contact.ID, contact) s.m.allContacts.Store(contact.ID, contact)
} }
// Test encryptIdentityImagesWithContactPubKeys // Test EncryptIdentityImagesWithContactPubKeys
err := s.m.encryptIdentityImagesWithContactPubKeys(ci.Images) err := EncryptIdentityImagesWithContactPubKeys(ci.Images, s.m)
s.Require().NoError(err) s.Require().NoError(err)
for _, ii := range ci.Images { for _, ii := range ci.Images {
@ -2607,12 +2607,8 @@ func (s *MessengerSuite) TestEncryptDecryptIdentityImagesWithContactPubKeys() {
s.Require().True(ci.Images["small"].Encrypted) s.Require().True(ci.Images["small"].Encrypted)
s.Require().True(ci.Images["large"].Encrypted) s.Require().True(ci.Images["large"].Encrypted)
// Switch messenger identities // Test DecryptIdentityImagesWithIdentityPrivateKey
sender := s.m.identity err = DecryptIdentityImagesWithIdentityPrivateKey(ci.Images, contactKeys[2], &s.m.identity.PublicKey)
s.m.identity = contactKeys[2]
// Test decryptIdentityImagesWithIdentityPrivateKey
err = s.m.decryptIdentityImagesWithIdentityPrivateKey(ci.Images, &sender.PublicKey)
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(smPayload, string(ci.Images["small"].Payload)) s.Require().Equal(smPayload, string(ci.Images["small"].Payload))
@ -2621,13 +2617,12 @@ func (s *MessengerSuite) TestEncryptDecryptIdentityImagesWithContactPubKeys() {
s.Require().False(ci.Images["large"].Encrypted) s.Require().False(ci.Images["large"].Encrypted)
// RESET Messenger identity, Contacts and IdentityImage.EncryptionKeys // RESET Messenger identity, Contacts and IdentityImage.EncryptionKeys
s.m.identity = sender
s.m.allContacts = nil s.m.allContacts = nil
ci.Images["small"].EncryptionKeys = nil ci.Images["small"].EncryptionKeys = nil
ci.Images["large"].EncryptionKeys = nil ci.Images["large"].EncryptionKeys = nil
// Test encryptIdentityImagesWithContactPubKeys with no contacts // Test EncryptIdentityImagesWithContactPubKeys with no contacts
err = s.m.encryptIdentityImagesWithContactPubKeys(ci.Images) err = EncryptIdentityImagesWithContactPubKeys(ci.Images, s.m)
s.Require().NoError(err) s.Require().NoError(err)
for _, ii := range ci.Images { for _, ii := range ci.Images {
@ -2638,18 +2633,12 @@ func (s *MessengerSuite) TestEncryptDecryptIdentityImagesWithContactPubKeys() {
s.Require().True(ci.Images["small"].Encrypted) s.Require().True(ci.Images["small"].Encrypted)
s.Require().True(ci.Images["large"].Encrypted) s.Require().True(ci.Images["large"].Encrypted)
// Switch messenger identities // Test DecryptIdentityImagesWithIdentityPrivateKey with no valid identity
s.m.identity = contactKeys[2] err = DecryptIdentityImagesWithIdentityPrivateKey(ci.Images, contactKeys[2], &s.m.identity.PublicKey)
// Test decryptIdentityImagesWithIdentityPrivateKey with no valid identity
err = s.m.decryptIdentityImagesWithIdentityPrivateKey(ci.Images, &sender.PublicKey)
s.Require().NoError(err) s.Require().NoError(err)
s.Require().NotEqual([]byte(smPayload), ci.Images["small"].Payload) s.Require().NotEqual([]byte(smPayload), ci.Images["small"].Payload)
s.Require().NotEqual([]byte(lgPayload), ci.Images["large"].Payload) s.Require().NotEqual([]byte(lgPayload), ci.Images["large"].Payload)
s.Require().True(ci.Images["small"].Encrypted) s.Require().True(ci.Images["small"].Encrypted)
s.Require().True(ci.Images["large"].Encrypted) s.Require().True(ci.Images["large"].Encrypted)
// RESET Messenger identity
s.m.identity = sender
} }