Skip to content

Commit

Permalink
Finalised e2e test for send/receive ii
Browse files Browse the repository at this point in the history
  • Loading branch information
Samyoul committed Sep 24, 2021
1 parent 143b45e commit ed3d376
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 58 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.89.0
0.90.0
50 changes: 25 additions & 25 deletions appdatabase/migrations/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions protocol/common/message_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ func (s *MessageSender) SendPublic(
chatName string,
rawMessage RawMessage,
) ([]byte, error) {
s.logger.Debug("SendPublic fired")
// Set sender
if rawMessage.Sender == nil {
rawMessage.Sender = s.identity
Expand Down Expand Up @@ -444,12 +443,10 @@ func (s *MessageSender) SendPublic(
// notify before dispatching
s.notifyOnScheduledMessage(&rawMessage)

s.logger.Debug("before s.transport.SendPublic")
hash, err := s.transport.SendPublic(ctx, newMessage, chatName)
if err != nil {
return nil, err
}
s.logger.Debug("after s.transport.SendPublic")

sentMessage := &SentMessage{
Spec: messageSpec,
Expand Down
15 changes: 2 additions & 13 deletions protocol/messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,10 @@ func (m *Messenger) publishContactCode() error {
m.logger.Error("could not build contact code advertisement", zap.Error(err))
}

m.logger.Debug("initing cca if not set")
if contactCodeAdvertisement == nil {
m.logger.Debug("cca was not set, setting to empty default")
contactCodeAdvertisement = &protobuf.ContactCodeAdvertisement{}
}

m.logger.Debug("before attachChatIdentity")
err = m.attachChatIdentity(contactCodeAdvertisement)
if err != nil {
return err
Expand Down Expand Up @@ -652,24 +649,20 @@ func (m *Messenger) publishContactCode() error {
func (m *Messenger) attachChatIdentity(cca *protobuf.ContactCodeAdvertisement) error {
contactCodeTopic := transport.ContactCodeTopic(&m.identity.PublicKey)

m.logger.Debug("before shouldPublishChatIdentity")
shouldPublish, err := m.shouldPublishChatIdentity(contactCodeTopic)

if err != nil {
return err
}
m.logger.Debug("after shouldPublishChatIdentity",
zap.Bool("shouldPublish", shouldPublish))

if !shouldPublish {
return nil
}

m.logger.Debug("before createChatIdentity")
cca.ChatIdentity, err = m.createChatIdentity(privateChat)
if err != nil {
return err
}
m.logger.Debug("after createChatIdentity")

img, err := m.multiAccounts.GetIdentityImage(m.account.KeyUID, userimage.SmallDimName)
if err != nil {
Expand Down Expand Up @@ -759,15 +752,11 @@ func (m *Messenger) shouldPublishChatIdentity(chatID string) (bool, error) {
return false, err
}

m.logger.Debug("output from GetWhenChatIdentityLastPublished",
zap.Int64("last published", lp),
zap.Any("hash", hash))

if !bytes.Equal(hash, img.Hash()) {
return true, nil
}

// TODO if Alice does not add bob as a contact she will not update her contact code with images
// Note: If Alice does not add bob as a contact she will not update her contact code with images
return lp == 0 || time.Now().Unix()-lp > 24*60*60, nil
}

Expand Down
8 changes: 0 additions & 8 deletions protocol/messenger_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,21 +1324,18 @@ func (m *Messenger) HandleChatIdentity(state *ReceivedMessageState, ci protobuf.
// Or if there are images and visibility is set to from contacts only, check if message is allowed
// otherwise process the images without checking if the message is allowed
if len(ci.Images) == 0 || (len(ci.Images) > 0 && (viewFromContacts)) {
m.logger.Debug("checking if isMessageAllowedFrom")
allowed, err := m.isMessageAllowedFrom(state.CurrentMessageState.Contact.ID, nil)
if err != nil {
return err
}

m.logger.Debug("result", zap.Bool("isMessageAllowedFrom", allowed))
if !allowed {
return ErrMessageNotAllowed
}
}
contact := state.CurrentMessageState.Contact

err = DecryptIdentityImagesWithIdentityPrivateKey(ci.Images, m.identity, state.CurrentMessageState.PublicKey)
m.logger.Debug("DecryptIdentityImagesWithIdentityPrivateKey", zap.Error(err))
if err != nil {
return err
}
Expand All @@ -1351,11 +1348,6 @@ func (m *Messenger) HandleChatIdentity(state *ReceivedMessageState, ci protobuf.
}

newImages, err := m.persistence.SaveContactChatIdentity(contact.ID, &ci)
m.logger.Debug("m.persistence.SaveContactChatIdentity",
zap.String("contact.ID", contact.ID),
zap.Any("ci", ci),
zap.Bool("newImages", newImages),
)
if err != nil {
return err
}
Expand Down
33 changes: 25 additions & 8 deletions protocol/messenger_identity_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,7 @@ func (s *MessengerProfilePictureHandlerSuite) TestE2eSendingReceivingProfilePict
privateChat,
}

// TODO Set option for testing between private and public chat types
// private types need to send and received Contact Code message with attached chat identity
// private types send large and thumbnail image payloads

// TODO see if possible to push each test scenario into a go routine

for _, cc := range chatContexts {
for sn, ss := range profilePicShowSettings {
for vn, vs := range profilePicViewSettings {
Expand Down Expand Up @@ -440,19 +435,41 @@ func (s *MessengerProfilePictureHandlerSuite) TestE2eSendingReceivingProfilePict

s.logger.Debug("checked alice's contact info all good")

// Check Alice's profile picture(s)
// Check that Bob now has Alice's profile picture(s)
switch cc {
case publicChat:
s.Require().Len(contact.Images, 1)
// In public chat context we only need the images.SmallDimName, but also may have the large
s.Require().GreaterOrEqual(len(contact.Images), 1)

// Check if the result matches expectation
smImg, ok := contact.Images[images.SmallDimName]
s.Require().True(ok, "contact images must contain the images.SmallDimName")

for _, ii := range iis {
if ii.Name == images.SmallDimName {
s.Require().Equal(ii.Payload, contact.Images[images.SmallDimName].Payload)
s.Require().Equal(ii.Payload, smImg.Payload)
}
}
case privateChat:
s.Require().Equal(len(contact.Images), 2)
s.logger.Info("private chat chat images", zap.Any("iis", iis))

// Check if the result matches expectation
smImg, ok := contact.Images[images.SmallDimName]
s.Require().True(ok, "contact images must contain the images.SmallDimName")

lgImg, ok := contact.Images[images.LargeDimName]
s.Require().True(ok, "contact images must contain the images.LargeDimName")

for _, ii := range iis {
switch ii.Name {
case images.SmallDimName:
s.Require().Equal(ii.Payload, smImg.Payload)
case images.LargeDimName:
s.Require().Equal(ii.Payload, lgImg.Payload)
}
}

}

s.logger.Info("Completed testing with criteria:",
Expand Down

0 comments on commit ed3d376

Please sign in to comment.