status-go/protocol/messenger_contact_verificat...

819 lines
37 KiB
Go
Raw Normal View History

package protocol
import (
"context"
"testing"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/protocol/verification"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/eth-node/types"
)
func TestMessengerVerificationRequests(t *testing.T) { // nolint: deadcode,unused
suite.Run(t, new(MessengerVerificationRequests))
}
type MessengerVerificationRequests struct {
MessengerBaseTestSuite
}
func (s *MessengerVerificationRequests) mutualContact(theirMessenger *Messenger) {
messageText := "hello!"
contactID := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
request := &requests.SendContactRequest{
2022-10-14 08:50:36 +00:00
ID: contactID,
Message: messageText,
}
// Send contact request
resp, err := s.m.SendContactRequest(context.Background(), request)
s.Require().NoError(err)
s.Require().NotNil(resp)
s.Require().Len(resp.Messages(), 2)
// Make sure it's not returned as coming from us
contactRequests, _, err := s.m.PendingContactRequests("", 10)
s.Require().NoError(err)
s.Require().Len(contactRequests, 0)
// Make sure contact is added on the sender side
contacts := s.m.AddedContacts()
s.Require().Len(contacts, 1)
2023-01-20 14:28:30 +00:00
s.Require().Equal(ContactRequestStateSent, contacts[0].ContactRequestLocalState)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
theirMessenger,
func(r *MessengerResponse) bool {
return len(r.Contacts) > 0 && len(r.Messages()) > 0 && len(r.ActivityCenterNotifications()) > 0
},
"no messages",
)
// Check contact request has been received
s.Require().NoError(err)
// Check activity center notification is of the right type
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(ActivityCenterNotificationTypeContactRequest, resp.ActivityCenterNotifications()[0].Type)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].Message)
s.Require().Equal(common.ContactRequestStatePending, resp.ActivityCenterNotifications()[0].Message.ContactRequestState)
// Check the contact state is correctly set
s.Require().Len(resp.Contacts, 1)
2023-01-20 14:28:30 +00:00
s.Require().Equal(ContactRequestStateReceived, resp.Contacts[0].ContactRequestRemoteState)
// Make sure it's the pending contact requests
contactRequests, _, err = theirMessenger.PendingContactRequests("", 10)
s.Require().NoError(err)
s.Require().Len(contactRequests, 1)
s.Require().Equal(contactRequests[0].ContactRequestState, common.ContactRequestStatePending)
// Accept contact request, receiver side
resp, err = theirMessenger.AcceptContactRequest(context.Background(), &requests.AcceptContactRequest{ID: types.Hex2Bytes(contactRequests[0].ID)})
s.Require().NoError(err)
// Make sure the message is updated
s.Require().NotNil(resp)
s.Require().Len(resp.Messages(), 2)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), contactRequests[0].ID)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].Message)
s.Require().Equal(common.ContactRequestStateAccepted, resp.ActivityCenterNotifications()[0].Message.ContactRequestState)
// Check the contact state is correctly set
s.Require().Len(resp.Contacts, 1)
2023-01-20 14:28:30 +00:00
s.Require().True(resp.Contacts[0].mutual())
// Make sure the sender is added to our contacts
contacts = theirMessenger.AddedContacts()
s.Require().Len(contacts, 1)
// Make sure we consider them a mutual contact, receiver side
mutualContacts := theirMessenger.MutualContacts()
s.Require().Len(mutualContacts, 1)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
s.m,
func(r *MessengerResponse) bool {
return len(r.Contacts) == 1 && len(r.Messages()) == 2 && len(r.ActivityCenterNotifications()) == 1
},
"no messages",
)
s.Require().NoError(err)
// Check activity center notification is of the right type
s.Require().Equal(ActivityCenterNotificationTypeContactRequest, resp.ActivityCenterNotifications()[0].Type)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].Message)
s.Require().Equal(common.ContactRequestStateAccepted, resp.ActivityCenterNotifications()[0].Message.ContactRequestState)
// Make sure the message is updated, sender side
s.Require().NotNil(resp)
s.Require().Len(resp.Messages(), 2)
// Make sure we consider them a mutual contact, sender side
mutualContacts = s.m.MutualContacts()
s.Require().Len(mutualContacts, 1)
// Check the contact state is correctly set
s.Require().Len(resp.Contacts, 1)
2023-01-20 14:28:30 +00:00
s.Require().True(resp.Contacts[0].mutual())
}
2022-10-24 11:33:47 +00:00
func (s *MessengerVerificationRequests) TestAcceptVerificationRequests() {
theirMessenger := s.newMessenger(s.shh)
defer TearDownMessenger(&s.Suite, theirMessenger)
s.mutualContact(theirMessenger)
theirPk := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
challenge := "challenge"
resp, err := s.m.SendContactVerificationRequest(context.Background(), theirPk, challenge)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
verificationRequestID := resp.VerificationRequests()[0].ID
s.Require().Len(resp.Messages(), 1)
s.Require().NotEmpty(resp.Messages()[0].OutgoingStatus)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
theirMessenger,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1 && len(r.ActivityCenterNotifications()) == 1
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Type, ActivityCenterNotificationTypeContactVerification)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusPENDING)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].Message)
s.Require().Equal(challenge, resp.ActivityCenterNotifications()[0].Message.Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 1)
s.Require().Empty(resp.Messages()[0].OutgoingStatus)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
resp, err = theirMessenger.AcceptContactVerificationRequest(context.Background(), verificationRequestID, "hello back")
s.Require().NoError(err)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.VerificationRequests()[0].RequestStatus, verification.RequestStatusACCEPTED)
s.Require().NotEmpty(resp.VerificationRequests()[0].RepliedAt)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusACCEPTED)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().Equal(common.ContactVerificationStateAccepted, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 2)
s.Require().Equal(common.ContactVerificationStateAccepted, resp.Messages()[0].ContactVerificationState)
2022-10-28 09:51:54 +00:00
s.Require().NotNil(resp.ActivityCenterNotifications()[0].ReplyMessage)
s.Require().NotEmpty(resp.ActivityCenterNotifications()[0].ReplyMessage.OutgoingStatus)
s.Require().Equal("hello back", resp.ActivityCenterNotifications()[0].ReplyMessage.Text)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
s.m,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
messages := resp.Messages()
2022-10-28 09:51:54 +00:00
s.Require().Len(messages, 2)
var originalMessage *common.Message
var replyMessage *common.Message
if messages[0].ID == resp.VerificationRequests()[0].ID {
originalMessage = messages[0]
replyMessage = messages[1]
} else {
originalMessage = messages[1]
replyMessage = messages[0]
}
s.Require().Equal(common.ContactVerificationStateAccepted, originalMessage.ContactVerificationState)
// Not sure this is the right state for this, it should probably be pendingtrustedverification or something
s.Require().Equal(common.ContactVerificationStateAccepted, replyMessage.ContactVerificationState)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusACCEPTED)
s.Require().Equal(common.ContactVerificationStateAccepted, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].ReplyMessage)
s.Require().Empty(resp.ActivityCenterNotifications()[0].ReplyMessage.OutgoingStatus)
s.Require().Equal("hello back", resp.ActivityCenterNotifications()[0].ReplyMessage.Text)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
// Mark as tusted
resp, err = s.m.VerifiedTrusted(context.Background(), &requests.VerifiedTrusted{ID: types.FromHex(verificationRequestID)})
s.Require().NoError(err)
s.Require().NotNil(resp)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusTRUSTED)
s.Require().Equal(common.ContactVerificationStateTrusted, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(common.ContactVerificationStateTrusted, resp.Messages()[0].ContactVerificationState)
s.Require().Len(resp.Contacts, 1)
s.Require().Equal(resp.Contacts[0].ID, theirPk)
s.Require().Equal(resp.Contacts[0].VerificationStatus, VerificationStatusVERIFIED)
}
func (s *MessengerVerificationRequests) TestTrustedVerificationRequests() {
theirMessenger := s.newMessenger(s.shh)
defer TearDownMessenger(&s.Suite, theirMessenger)
s.mutualContact(theirMessenger)
theirPk := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
challenge := "challenge"
resp, err := s.m.SendContactVerificationRequest(context.Background(), theirPk, challenge)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
verificationRequestID := resp.VerificationRequests()[0].ID
s.Require().Len(resp.Messages(), 1)
s.Require().NotEmpty(resp.Messages()[0].OutgoingStatus)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
theirMessenger,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1 && len(r.ActivityCenterNotifications()) == 1
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Type, ActivityCenterNotificationTypeContactVerification)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusPENDING)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].Message)
s.Require().Equal(challenge, resp.ActivityCenterNotifications()[0].Message.Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 1)
s.Require().Empty(resp.Messages()[0].OutgoingStatus)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
resp, err = theirMessenger.AcceptContactVerificationRequest(context.Background(), verificationRequestID, "hello back")
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.VerificationRequests()[0].RequestStatus, verification.RequestStatusACCEPTED)
s.Require().NotEmpty(resp.VerificationRequests()[0].RepliedAt)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusACCEPTED)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().Equal(common.ContactVerificationStateAccepted, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 2)
s.Require().Equal(common.ContactVerificationStateAccepted, resp.Messages()[0].ContactVerificationState)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].ReplyMessage)
s.Require().NotEmpty(resp.ActivityCenterNotifications()[0].ReplyMessage.OutgoingStatus)
s.Require().Equal("hello back", resp.ActivityCenterNotifications()[0].ReplyMessage.Text)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
s.m,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
messages := resp.Messages()
s.Require().Len(messages, 2)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusACCEPTED)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().Equal(common.ContactVerificationStateAccepted, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].ReplyMessage)
s.Require().Empty(resp.ActivityCenterNotifications()[0].ReplyMessage.OutgoingStatus)
s.Require().Equal("hello back", resp.ActivityCenterNotifications()[0].ReplyMessage.Text)
resp, err = s.m.VerifiedTrusted(context.Background(), &requests.VerifiedTrusted{ID: types.FromHex(verificationRequestID)})
s.Require().NoError(err)
s.Require().NotNil(resp)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusTRUSTED)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().Equal(common.ContactVerificationStateTrusted, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(common.ContactVerificationStateTrusted, resp.Messages()[0].ContactVerificationState)
}
func (s *MessengerVerificationRequests) TestUnthrustworthyVerificationRequests() {
theirMessenger := s.newMessenger(s.shh)
defer TearDownMessenger(&s.Suite, theirMessenger)
s.mutualContact(theirMessenger)
theirPk := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
challenge := "challenge"
resp, err := s.m.SendContactVerificationRequest(context.Background(), theirPk, challenge)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
verificationRequestID := resp.VerificationRequests()[0].ID
s.Require().Len(resp.Messages(), 1)
s.Require().NotEmpty(resp.Messages()[0].OutgoingStatus)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
theirMessenger,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1 && len(r.ActivityCenterNotifications()) == 1
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Type, ActivityCenterNotificationTypeContactVerification)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusPENDING)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].Message)
s.Require().Equal(challenge, resp.ActivityCenterNotifications()[0].Message.Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 1)
s.Require().Empty(resp.Messages()[0].OutgoingStatus)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
2022-10-28 09:51:54 +00:00
resp, err = theirMessenger.AcceptContactVerificationRequest(context.Background(), verificationRequestID, "hello back")
s.Require().NoError(err)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.VerificationRequests()[0].RequestStatus, verification.RequestStatusACCEPTED)
s.Require().NotEmpty(resp.VerificationRequests()[0].RepliedAt)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusACCEPTED)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().Equal(common.ContactVerificationStateAccepted, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 2)
s.Require().Equal(common.ContactVerificationStateAccepted, resp.Messages()[0].ContactVerificationState)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].ReplyMessage)
s.Require().NotEmpty(resp.ActivityCenterNotifications()[0].ReplyMessage.OutgoingStatus)
s.Require().Equal("hello back", resp.ActivityCenterNotifications()[0].ReplyMessage.Text)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
s.m,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
messages := resp.Messages()
s.Require().Len(messages, 2)
var originalMessage *common.Message
var replyMessage *common.Message
if messages[0].ID == resp.VerificationRequests()[0].ID {
originalMessage = messages[0]
replyMessage = messages[1]
} else {
originalMessage = messages[1]
replyMessage = messages[0]
}
2022-10-28 09:51:54 +00:00
s.Require().Equal(common.ContactVerificationStateAccepted, originalMessage.ContactVerificationState)
// Not sure this is the right state for this, it should probably be pendingtrustedverification or something
2022-10-28 09:51:54 +00:00
s.Require().Equal(common.ContactVerificationStateAccepted, replyMessage.ContactVerificationState)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusACCEPTED)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().Equal(common.ContactVerificationStateAccepted, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
2022-10-28 09:51:54 +00:00
s.Require().NotNil(resp.ActivityCenterNotifications()[0].ReplyMessage)
s.Require().Empty(resp.ActivityCenterNotifications()[0].ReplyMessage.OutgoingStatus)
s.Require().Equal("hello back", resp.ActivityCenterNotifications()[0].ReplyMessage.Text)
resp, err = s.m.VerifiedUntrustworthy(context.Background(), &requests.VerifiedUntrustworthy{ID: types.FromHex(verificationRequestID)})
s.Require().NoError(err)
s.Require().NotNil(resp)
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusUNTRUSTWORTHY)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().Equal(common.ContactVerificationStateUntrustworthy, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(common.ContactVerificationStateUntrustworthy, resp.Messages()[0].ContactVerificationState)
}
func (s *MessengerVerificationRequests) TestRemoveTrustVerificationStatus() {
// GIVEN
theirMessenger := s.newMessenger(s.shh)
defer TearDownMessenger(&s.Suite, theirMessenger)
s.mutualContact(theirMessenger)
theirPk := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
challenge := "challenge"
resp, err := s.m.SendContactVerificationRequest(context.Background(), theirPk, challenge)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
verificationRequestID := resp.VerificationRequests()[0].ID
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
theirMessenger,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1 && len(r.ActivityCenterNotifications()) == 1
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
resp, err = theirMessenger.AcceptContactVerificationRequest(context.Background(), verificationRequestID, "hello back")
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
// Wait for the message to reach its destination
_, err = WaitOnMessengerResponse(
s.m,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1
},
"no messages",
)
s.Require().NoError(err)
// Mark as trusted
_, err = s.m.VerifiedTrusted(context.Background(), &requests.VerifiedTrusted{ID: types.FromHex(verificationRequestID)})
s.Require().NoError(err)
// WHEN
_, err = s.m.RemoveTrustVerificationStatus(context.Background(), theirPk)
s.Require().NoError(err)
// THEN
trustStatus, err := s.m.GetTrustStatus(theirPk)
s.Require().NoError(err)
s.Require().Equal(verification.TrustStatusUNKNOWN, trustStatus)
contact, _ := s.m.allContacts.Load(theirPk)
s.Require().NotNil(contact)
s.Require().Equal(VerificationStatusUNVERIFIED, contact.VerificationStatus)
s.Require().Equal(verification.TrustStatusUNKNOWN, contact.TrustStatus)
}
2022-10-24 11:33:47 +00:00
func (s *MessengerVerificationRequests) TestDeclineVerificationRequests() {
theirMessenger := s.newMessenger(s.shh)
defer TearDownMessenger(&s.Suite, theirMessenger)
2022-10-24 11:33:47 +00:00
s.mutualContact(theirMessenger)
theirPk := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
challenge := "challenge"
resp, err := s.m.SendContactVerificationRequest(context.Background(), theirPk, challenge)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
verificationRequestID := resp.VerificationRequests()[0].ID
2022-10-24 11:33:47 +00:00
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
theirMessenger,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1 && len(r.ActivityCenterNotifications()) == 1
2022-10-24 11:33:47 +00:00
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
2022-10-24 11:33:47 +00:00
s.Require().Equal(resp.ActivityCenterNotifications()[0].Type, ActivityCenterNotificationTypeContactVerification)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusPENDING)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
2022-10-24 11:33:47 +00:00
s.Require().NotNil(resp.ActivityCenterNotifications()[0].Message)
s.Require().Equal(challenge, resp.ActivityCenterNotifications()[0].Message.Text)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Message.ContactVerificationState, common.ContactVerificationStatePending)
2022-10-24 11:33:47 +00:00
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(resp.Messages()[0].ContactVerificationState, common.ContactVerificationStatePending)
2022-10-24 11:33:47 +00:00
// Make sure it's stored and retrieved correctly
notification, err := theirMessenger.ActivityCenterNotification(types.FromHex(verificationRequestID))
2022-10-24 11:33:47 +00:00
s.Require().NoError(err)
s.Require().NotNil(notification)
s.Require().Equal(notification.ContactVerificationStatus, verification.RequestStatusPENDING)
s.Require().Equal(notification.Message.ContactVerificationState, common.ContactVerificationStatePending)
s.Require().Equal(notification.Read, false)
s.Require().Equal(notification.Accepted, false)
s.Require().Equal(notification.Dismissed, false)
2022-10-24 11:33:47 +00:00
resp, err = theirMessenger.DeclineContactVerificationRequest(context.Background(), verificationRequestID)
s.Require().NoError(err)
s.Require().NotNil(resp)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.VerificationRequests()[0].RequestStatus, verification.RequestStatusDECLINED)
s.Require().NotEmpty(resp.VerificationRequests()[0].RepliedAt)
2022-10-24 11:33:47 +00:00
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusDECLINED)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Message.ContactVerificationState, common.ContactVerificationStateDeclined)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, true)
2022-10-24 11:33:47 +00:00
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(resp.Messages()[0].ContactVerificationState, common.ContactVerificationStateDeclined)
2022-10-24 11:33:47 +00:00
// Make sure it's stored and retrieved correctly
notification, err = theirMessenger.ActivityCenterNotification(types.FromHex(verificationRequestID))
2022-10-24 11:33:47 +00:00
s.Require().NoError(err)
s.Require().NotNil(notification)
s.Require().Equal(notification.ContactVerificationStatus, verification.RequestStatusDECLINED)
s.Require().Equal(notification.Message.ContactVerificationState, common.ContactVerificationStateDeclined)
s.Require().Equal(notification.Read, true)
s.Require().Equal(notification.Accepted, false)
s.Require().Equal(notification.Dismissed, true)
2022-10-24 11:33:47 +00:00
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
s.m,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1
2022-10-24 11:33:47 +00:00
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
2022-10-24 11:33:47 +00:00
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(resp.Messages()[0].ContactVerificationState, common.ContactVerificationStateDeclined)
2022-10-24 11:33:47 +00:00
s.Require().Len(resp.Contacts, 1)
s.Require().Equal(resp.Contacts[0].ID, theirPk)
s.Require().Equal(resp.Contacts[0].VerificationStatus, VerificationStatusUNVERIFIED)
2022-10-24 11:33:47 +00:00
s.Require().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusDECLINED)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Message.ContactVerificationState, common.ContactVerificationStateDeclined)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, true)
}
func (s *MessengerVerificationRequests) TestCancelVerificationRequest() {
theirMessenger := s.newMessenger(s.shh)
defer TearDownMessenger(&s.Suite, theirMessenger)
s.mutualContact(theirMessenger)
theirPk := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
challenge := "challenge"
resp, err := s.m.SendContactVerificationRequest(context.Background(), theirPk, challenge)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
verificationRequestID := resp.VerificationRequests()[0].ID
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
// Wait for the message to reach its destination
resp, err = WaitOnMessengerResponse(
theirMessenger,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1 && len(r.ActivityCenterNotifications()) == 1
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Type, ActivityCenterNotificationTypeContactVerification)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusPENDING)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].Message)
s.Require().Equal(challenge, resp.ActivityCenterNotifications()[0].Message.Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.ActivityCenterNotifications()[0].Message.ContactVerificationState)
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
// Make sure it's stored and retrieved correctly
notifications, err := theirMessenger.ActivityCenterNotifications(
ActivityCenterNotificationsRequest{
Cursor: "",
Limit: 4,
ActivityTypes: []ActivityCenterType{ActivityCenterNotificationTypeContactVerification},
ReadType: ActivityCenterQueryParamsReadUnread,
},
)
s.Require().NoError(err)
s.Require().Greater(len(notifications.Notifications), 0)
s.Require().Equal(notifications.Notifications[0].ContactVerificationStatus, verification.RequestStatusPENDING)
s.Require().Equal(common.ContactVerificationStatePending, notifications.Notifications[0].Message.ContactVerificationState)
resp, err = s.m.CancelVerificationRequest(context.Background(), verificationRequestID)
s.Require().NoError(err)
s.Require().NotNil(resp)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.VerificationRequests()[0].RequestStatus, verification.RequestStatusCANCELED)
s.Require().Len(resp.Contacts, 1)
s.Require().Equal(resp.Contacts[0].ID, theirPk)
s.Require().Equal(resp.Contacts[0].VerificationStatus, VerificationStatusUNVERIFIED)
// Check canceled state on the receiver's side
resp, err = WaitOnMessengerResponse(
theirMessenger,
func(r *MessengerResponse) bool {
return len(r.VerificationRequests()) == 1 && len(r.ActivityCenterNotifications()) == 1
},
"no messages",
)
s.Require().NoError(err)
s.Require().Len(resp.VerificationRequests(), 1)
s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Type, ActivityCenterNotificationTypeContactVerification)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusCANCELED)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Read, true)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false)
s.Require().NotNil(resp.ActivityCenterNotifications()[0].Message)
s.Require().Equal(challenge, resp.ActivityCenterNotifications()[0].Message.Text)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Message.ContactVerificationState, common.ContactVerificationStateCanceled)
s.Require().Len(resp.Messages(), 1)
s.Require().Equal(challenge, resp.Messages()[0].Text)
s.Require().Equal(resp.Messages()[0].ContactVerificationState, common.ContactVerificationStateCanceled)
2022-10-24 11:33:47 +00:00
}
func (s *MessengerVerificationRequests) newMessenger(shh types.Waku) *Messenger {
privateKey, err := crypto.GenerateKey()
s.Require().NoError(err)
messenger, err := newMessengerWithKey(s.shh, privateKey, s.logger, nil)
s.Require().NoError(err)
return messenger
}
test_: Code Migration from status-cli-tests author shashankshampi <shashank.sanket1995@gmail.com> 1729780155 +0530 committer shashankshampi <shashank.sanket1995@gmail.com> 1730274350 +0530 test: Code Migration from status-cli-tests fix_: functional tests (#5979) * fix_: generate on test-functional * chore(test)_: fix functional test assertion --------- Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com> feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977) * feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766) The original GH issue https://github.com/status-im/status-mobile/issues/21113 came from a request from the Legal team. We must show to Status v1 users the new terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2 from the stores. The solution we use is to create a flag in the accounts table, named hasAcceptedTerms. The flag will be set to true on the first account ever created in v2 and we provide a native call in mobile/status.go#AcceptTerms, which allows the client to persist the user's choice in case they are upgrading (from v1 -> v2, or from a v2 older than this PR). This solution is not the best because we should store the setting in a separate table, not in the accounts table. Related Mobile PR https://github.com/status-im/status-mobile/pull/21124 * fix(test)_: Compare addresses using uppercased strings --------- Co-authored-by: Icaro Motta <icaro.ldm@gmail.com> test_: restore account (#5960) feat_: `LogOnPanic` linter (#5969) * feat_: LogOnPanic linter * fix_: add missing defer LogOnPanic * chore_: make vendor * fix_: tests, address pr comments * fix_: address pr comments fix(ci)_: remove workspace and tmp dir This ensures we do not encounter weird errors like: ``` + ln -s /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907 /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go ln: failed to create symbolic link '/home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go': File exists script returned exit code 1 ``` Signed-off-by: Jakub Sokołowski <jakub@status.im> chore_: enable windows and macos CI build (#5840) - Added support for Windows and macOS in CI pipelines - Added missing dependencies for Windows and x86-64-darwin - Resolved macOS SDK version compatibility for darwin-x86_64 The `mkShell` override was necessary to ensure compatibility with the newer macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures because of the missing libs and frameworks. OverrideSDK creates a mapping from the default SDK in all package categories to the requested SDK (11.0). fix(contacts)_: fix trust status not being saved to cache when changed (#5965) Fixes https://github.com/status-im/status-desktop/issues/16392 cleanup added logger and cleanup review comments changes fix_: functional tests (#5979) * fix_: generate on test-functional * chore(test)_: fix functional test assertion --------- Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com> feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977) * feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766) The original GH issue https://github.com/status-im/status-mobile/issues/21113 came from a request from the Legal team. We must show to Status v1 users the new terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2 from the stores. The solution we use is to create a flag in the accounts table, named hasAcceptedTerms. The flag will be set to true on the first account ever created in v2 and we provide a native call in mobile/status.go#AcceptTerms, which allows the client to persist the user's choice in case they are upgrading (from v1 -> v2, or from a v2 older than this PR). This solution is not the best because we should store the setting in a separate table, not in the accounts table. Related Mobile PR https://github.com/status-im/status-mobile/pull/21124 * fix(test)_: Compare addresses using uppercased strings --------- Co-authored-by: Icaro Motta <icaro.ldm@gmail.com> test_: restore account (#5960) feat_: `LogOnPanic` linter (#5969) * feat_: LogOnPanic linter * fix_: add missing defer LogOnPanic * chore_: make vendor * fix_: tests, address pr comments * fix_: address pr comments chore_: enable windows and macos CI build (#5840) - Added support for Windows and macOS in CI pipelines - Added missing dependencies for Windows and x86-64-darwin - Resolved macOS SDK version compatibility for darwin-x86_64 The `mkShell` override was necessary to ensure compatibility with the newer macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures because of the missing libs and frameworks. OverrideSDK creates a mapping from the default SDK in all package categories to the requested SDK (11.0). fix(contacts)_: fix trust status not being saved to cache when changed (#5965) Fixes https://github.com/status-im/status-desktop/issues/16392 test_: remove port bind chore(wallet)_: move route execution code to separate module chore_: replace geth logger with zap logger (#5962) closes: #6002 feat(telemetry)_: add metrics for message reliability (#5899) * feat(telemetry)_: track message reliability Add metrics for dial errors, missed messages, missed relevant messages, and confirmed delivery. * fix_: handle error from json marshal chore_: use zap logger as request logger iterates: status-im/status-desktop#16536 test_: unique project per run test_: use docker compose v2, more concrete project name fix(codecov)_: ignore folders without tests Otherwise Codecov reports incorrect numbers when making changes. https://docs.codecov.com/docs/ignoring-paths Signed-off-by: Jakub Sokołowski <jakub@status.im> test_: verify schema of signals during init; fix schema verification warnings (#5947) fix_: update defaultGorushURL (#6011) fix(tests)_: use non-standard port to avoid conflicts We have observed `nimbus-eth2` build failures reporting this port: ```json { "lvl": "NTC", "ts": "2024-10-28 13:51:32.308+00:00", "msg": "REST HTTP server could not be started", "topics": "beacnde", "address": "127.0.0.1:5432", "reason": "(98) Address already in use" } ``` https://ci.status.im/job/nimbus-eth2/job/platforms/job/linux/job/x86_64/job/main/job/PR-6683/3/ Signed-off-by: Jakub Sokołowski <jakub@status.im> fix_: create request logger ad-hoc in tests Fixes `TestCall` failing when run concurrently. chore_: configure codecov (#6005) * chore_: configure codecov * fix_: after_n_builds
2024-10-24 14:29:15 +00:00
func (s *MessengerVerificationRequests) TestTrustStatus() {
theirMessenger := s.newMessenger(s.shh)
defer TearDownMessenger(&s.Suite, theirMessenger)
s.mutualContact(theirMessenger)
theirPk := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey))
// Test Mark as Trusted
err := s.m.MarkAsTrusted(context.Background(), theirPk)
s.Require().NoError(err)
contactFromCache, ok := s.m.allContacts.Load(theirPk)
s.Require().True(ok)
s.Require().Equal(verification.TrustStatusTRUSTED, contactFromCache.TrustStatus)
trustStatusFromDb, err := s.m.GetTrustStatus(theirPk)
s.Require().NoError(err)
s.Require().Equal(verification.TrustStatusTRUSTED, trustStatusFromDb)
// Test Remove Trust Mark
err = s.m.RemoveTrustStatus(context.Background(), theirPk)
s.Require().NoError(err)
contactFromCache, ok = s.m.allContacts.Load(theirPk)
s.Require().True(ok)
s.Require().Equal(verification.TrustStatusUNKNOWN, contactFromCache.TrustStatus)
trustStatusFromDb, err = s.m.GetTrustStatus(theirPk)
s.Require().NoError(err)
s.Require().Equal(verification.TrustStatusUNKNOWN, trustStatusFromDb)
// Test Mark as Untrustoworthy
err = s.m.MarkAsUntrustworthy(context.Background(), theirPk)
s.Require().NoError(err)
contactFromCache, ok = s.m.allContacts.Load(theirPk)
s.Require().True(ok)
s.Require().Equal(verification.TrustStatusUNTRUSTWORTHY, contactFromCache.TrustStatus)
trustStatusFromDb, err = s.m.GetTrustStatus(theirPk)
s.Require().NoError(err)
s.Require().Equal(verification.TrustStatusUNTRUSTWORTHY, trustStatusFromDb)
// Test calling with an unknown contact
err = s.m.MarkAsTrusted(context.Background(), "0x00000123")
s.Require().Error(err)
s.Require().Equal("contact not found", err.Error())
}