status-go/protocol/messenger_installations_tes...

428 lines
13 KiB
Go
Raw Normal View History

package protocol
import (
"context"
"errors"
"image"
"image/png"
"os"
"runtime"
"testing"
userimage "github.com/status-im/status-go/images"
"github.com/status-im/status-go/server"
2022-01-17 03:42:11 +00:00
"github.com/status-im/status-go/services/browsers"
2020-01-15 11:36:49 +00:00
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
multiaccountscommon "github.com/status-im/status-go/multiaccounts/common"
"github.com/status-im/status-go/protocol/encryption/multidevice"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/protocol/tt"
)
2020-07-22 07:41:40 +00:00
const statusChatID = "status"
2021-10-05 17:26:02 +00:00
const removedChatID = "deactivated"
2020-07-22 07:41:40 +00:00
func TestMessengerInstallationSuite(t *testing.T) {
suite.Run(t, new(MessengerInstallationSuite))
}
type MessengerInstallationSuite struct {
2023-07-13 10:28:34 +00:00
MessengerBaseTestSuite
}
func (s *MessengerInstallationSuite) TestReceiveInstallation() {
2020-12-21 11:57:47 +00:00
theirMessenger, err := newMessengerWithKey(s.shh, s.privateKey, s.logger, nil)
s.Require().NoError(err)
2020-12-21 11:57:47 +00:00
err = theirMessenger.SetInstallationMetadata(theirMessenger.installationID, &multidevice.InstallationMetadata{
Name: "their-name",
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err := theirMessenger.SendPairInstallation(context.Background(), nil)
s.Require().NoError(err)
s.Require().NotNil(response)
2021-01-11 10:32:51 +00:00
s.Require().Len(response.Chats(), 1)
s.Require().False(response.Chats()[0].Active)
// Wait for the message to reach its destination
response, err = WaitOnMessengerResponse(
s.m,
feat(pairing)_: Fallback pairing seed (#5614) (#5627) * feat(pairing)!: Add extra parameters and remove v2 compatibility This commit includes the following changes: I have added a flag to maintain 2.29 compatibility. Breaking change in connection string The local pairing code that was parsing the connection string had a few non-upgradable features: It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking. It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect. The code has been changed so that: Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow. I have also removed version from the payload, since it wasn't used. This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one). https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy Changed MessengerResponse to use internally a map of installations rather than an array (minor) Just moving towards maps as arrays tend to lead to subtle bugs. Moved pairing methods to messenger_pairing.go Just moved some methods Added 2 new methods for the fallback flow FinishPairingThroughSeedPhraseProcess https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29 EnableAndSyncInstallation https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18 Flow for clients Client A1 is logged in Client A2 is logged out Client A1 shows a QR code Client A2 scans a QR code If connection fails on A2, the user will be prompted to enter a seed phrase. If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device. Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow. Current issues Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further. * test_: add more test for connection string parser * fix_: fix panic when parse old connection string * test_: add comments for TestMessengerPairAfterSeedPhrase * fix_: correct error description * feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair * fix_: delete leftover * fix_: add UniqueKey method * fix_: unify the response for InputConnectionStringForBootstrapping * fix_: remove fields installationID and keyUID in GethStatusBackend * fix_: rename messenger_pairing to messenger_pairing_and_syncing --------- Co-authored-by: frank <lovefree103@gmail.com> Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
func(r *MessengerResponse) bool { return len(r.Installations()) > 0 },
"installation not received",
)
s.Require().NoError(err)
feat(pairing)_: Fallback pairing seed (#5614) (#5627) * feat(pairing)!: Add extra parameters and remove v2 compatibility This commit includes the following changes: I have added a flag to maintain 2.29 compatibility. Breaking change in connection string The local pairing code that was parsing the connection string had a few non-upgradable features: It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking. It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect. The code has been changed so that: Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow. I have also removed version from the payload, since it wasn't used. This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one). https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy Changed MessengerResponse to use internally a map of installations rather than an array (minor) Just moving towards maps as arrays tend to lead to subtle bugs. Moved pairing methods to messenger_pairing.go Just moved some methods Added 2 new methods for the fallback flow FinishPairingThroughSeedPhraseProcess https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29 EnableAndSyncInstallation https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18 Flow for clients Client A1 is logged in Client A2 is logged out Client A1 shows a QR code Client A2 scans a QR code If connection fails on A2, the user will be prompted to enter a seed phrase. If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device. Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow. Current issues Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further. * test_: add more test for connection string parser * fix_: fix panic when parse old connection string * test_: add comments for TestMessengerPairAfterSeedPhrase * fix_: correct error description * feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair * fix_: delete leftover * fix_: add UniqueKey method * fix_: unify the response for InputConnectionStringForBootstrapping * fix_: remove fields installationID and keyUID in GethStatusBackend * fix_: rename messenger_pairing to messenger_pairing_and_syncing --------- Co-authored-by: frank <lovefree103@gmail.com> Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
actualInstallation := response.Installations()[0]
s.Require().Equal(theirMessenger.installationID, actualInstallation.ID)
s.Require().NotNil(actualInstallation.InstallationMetadata)
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
err = s.m.EnableInstallation(theirMessenger.installationID)
s.Require().NoError(err)
contactKey, err := crypto.GenerateKey()
s.Require().NoError(err)
2021-03-25 15:15:22 +00:00
contact, err := BuildContactFromPublicKey(&contactKey.PublicKey)
s.Require().NoError(err)
response, err = s.m.AddContact(context.Background(), &requests.AddContact{ID: contact.ID, CustomizationColor: string(multiaccountscommon.CustomizationColorRed)})
s.Require().NoError(err)
2023-02-14 17:44:00 +00:00
s.Require().Len(response.Contacts, 1)
s.Require().Equal(response.Contacts[0].ID, contact.ID)
s.Require().Equal(response.Contacts[0].CustomizationColor, multiaccountscommon.CustomizationColorRed)
2023-02-14 17:44:00 +00:00
// Wait for the message to reach its destination
response, err = WaitOnMessengerResponse(
theirMessenger,
2023-02-14 17:44:00 +00:00
func(r *MessengerResponse) bool { return len(r.Contacts) == 1 && r.Contacts[0].ID == contact.ID },
"contact not received",
)
s.Require().NoError(err)
actualContact := response.Contacts[0]
s.Require().Equal(contact.ID, actualContact.ID)
2023-01-20 14:28:30 +00:00
s.Require().True(actualContact.added())
2023-02-14 17:44:00 +00:00
// Simulate update from contact
contact.LastUpdated = 10
contact.DisplayName = "display-name"
contact.CustomizationColor = multiaccountscommon.CustomizationColorRed
2023-02-14 17:44:00 +00:00
s.Require().NoError(s.m.persistence.SaveContacts([]*Contact{contact}))
// Trigger syncing of contact
err = s.m.syncContact(context.Background(), contact, s.m.dispatchMessage)
s.Require().NoError(err)
// Wait for the message to reach its destination
2023-04-27 16:39:59 +00:00
_, err = WaitOnMessengerResponse(
2023-02-14 17:44:00 +00:00
theirMessenger,
2023-04-27 16:39:59 +00:00
func(r *MessengerResponse) bool {
return len(r.Contacts) == 1 &&
r.Contacts[0].ID == contact.ID &&
// Make sure lastupdated is **not** synced
actualContact.LastUpdated == 0 &&
r.Contacts[0].DisplayName == "display-name" &&
r.Contacts[0].CustomizationColor == multiaccountscommon.CustomizationColorRed
2023-04-27 16:39:59 +00:00
},
2023-02-14 17:44:00 +00:00
"contact not received",
)
s.Require().NoError(err)
2020-07-22 07:41:40 +00:00
chat := CreatePublicChat(statusChatID, s.m.transport)
2021-01-11 10:32:51 +00:00
err = s.m.SaveChat(chat)
s.Require().NoError(err)
response, err = WaitOnMessengerResponse(
theirMessenger,
2021-01-11 10:32:51 +00:00
func(r *MessengerResponse) bool { return len(r.Chats()) > 0 },
"sync chat not received",
)
s.Require().NoError(err)
2021-01-11 10:32:51 +00:00
actualChat := response.Chats()[0]
2020-07-22 07:41:40 +00:00
s.Require().Equal(statusChatID, actualChat.ID)
s.Require().True(actualChat.Active)
2020-07-31 09:46:38 +00:00
s.Require().NoError(theirMessenger.Shutdown())
}
func (s *MessengerInstallationSuite) TestSyncInstallation() {
// add contact
contactKey, err := crypto.GenerateKey()
s.Require().NoError(err)
2021-03-25 15:15:22 +00:00
contact, err := BuildContactFromPublicKey(&contactKey.PublicKey)
s.Require().NoError(err)
// mock added as mutual contact
contact.LastUpdated = 1
2023-01-20 14:28:30 +00:00
contact.ContactRequestReceived(1)
s.m.allContacts.Store(contact.ID, contact)
2020-08-20 14:06:38 +00:00
contact.LocalNickname = "Test Nickname"
_, err = s.m.AddContact(context.Background(), &requests.AddContact{ID: contact.ID, CustomizationColor: string(multiaccountscommon.CustomizationColorRed)})
s.Require().NoError(err)
2021-10-27 10:59:43 +00:00
_, err = s.m.SetContactLocalNickname(&requests.SetContactLocalNickname{ID: types.Hex2Bytes(contact.ID), Nickname: contact.LocalNickname})
s.Require().NoError(err)
2022-01-17 03:42:11 +00:00
//add bookmark
bookmark := browsers.Bookmark{
Name: "status official site",
URL: "https://status.im",
Removed: false,
}
_, err = s.m.browserDatabase.StoreBookmark(bookmark)
s.Require().NoError(err)
// add chat
2020-07-22 07:41:40 +00:00
chat := CreatePublicChat(statusChatID, s.m.transport)
2021-01-11 10:32:51 +00:00
err = s.m.SaveChat(chat)
s.Require().NoError(err)
// Create group chat
response, err := s.m.CreateGroupChatWithMembers(context.Background(), "group", []string{})
s.NoError(err)
s.Require().Len(response.Chats(), 1)
ourGroupChat := response.Chats()[0]
err = s.m.SaveChat(ourGroupChat)
s.NoError(err)
// Generate test image bigger than BannerDim
testImage := image.NewRGBA(image.Rect(0, 0, 20, 10))
tmpTestFilePath := s.T().TempDir() + "/test.png"
file, err := os.Create(tmpTestFilePath)
s.NoError(err)
defer file.Close()
err = png.Encode(file, testImage)
s.Require().NoError(err)
groupImg := userimage.CroppedImage{
ImagePath: tmpTestFilePath,
X: 1,
Y: 1,
Width: 10,
Height: 5,
}
// Add image to chat
response, err = s.m.EditGroupChat(context.Background(), ourGroupChat.ID, "test_admin_group", "#FF00FF", groupImg)
s.Require().NoError(err)
s.Require().Len(response.Chats(), 1)
s.Require().Equal("test_admin_group", response.Chats()[0].Name)
s.Require().Equal("#FF00FF", response.Chats()[0].Color)
ourGroupChat = response.Chats()[0]
// Create second group chat and deactivate it
response, err = s.m.CreateGroupChatWithMembers(context.Background(), "deactivated-group", []string{})
s.NoError(err)
s.Require().Len(response.Chats(), 1)
ourDeactivatedGroupChat := response.Chats()[0]
err = s.m.SaveChat(ourDeactivatedGroupChat)
s.NoError(err)
_, err = s.m.deactivateChat(ourDeactivatedGroupChat.ID, 0, true, true)
s.NoError(err)
// Create Alice for the 1-1 chat
alice := s.newMessenger()
defer TearDownMessenger(&s.Suite, alice)
// Create 1-1 chat
ourOneOneChat := CreateOneToOneChat("Our 1TO1", &alice.identity.PublicKey, alice.transport)
err = s.m.SaveChat(ourOneOneChat)
s.Require().NoError(err)
2021-10-05 17:26:02 +00:00
// add and deactivate chat
chat2 := CreatePublicChat(removedChatID, s.m.transport)
chat2.DeletedAtClockValue = 1
2021-10-05 17:26:02 +00:00
err = s.m.SaveChat(chat2)
s.Require().NoError(err)
_, err = s.m.deactivateChat(removedChatID, 0, true, true)
2021-10-05 17:26:02 +00:00
s.Require().NoError(err)
// pair
2020-12-21 11:57:47 +00:00
theirMessenger, err := newMessengerWithKey(s.shh, s.privateKey, s.logger, nil)
s.Require().NoError(err)
2021-10-05 17:26:02 +00:00
err = theirMessenger.SaveChat(chat2)
s.Require().NoError(err)
err = theirMessenger.SetInstallationMetadata(theirMessenger.installationID, &multidevice.InstallationMetadata{
Name: "their-name",
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err = theirMessenger.SendPairInstallation(context.Background(), nil)
s.Require().NoError(err)
s.Require().NotNil(response)
2021-01-11 10:32:51 +00:00
s.Require().Len(response.Chats(), 1)
s.Require().False(response.Chats()[0].Active)
// Wait for the message to reach its destination
response, err = WaitOnMessengerResponse(
s.m,
feat(pairing)_: Fallback pairing seed (#5614) (#5627) * feat(pairing)!: Add extra parameters and remove v2 compatibility This commit includes the following changes: I have added a flag to maintain 2.29 compatibility. Breaking change in connection string The local pairing code that was parsing the connection string had a few non-upgradable features: It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking. It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect. The code has been changed so that: Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow. I have also removed version from the payload, since it wasn't used. This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one). https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy Changed MessengerResponse to use internally a map of installations rather than an array (minor) Just moving towards maps as arrays tend to lead to subtle bugs. Moved pairing methods to messenger_pairing.go Just moved some methods Added 2 new methods for the fallback flow FinishPairingThroughSeedPhraseProcess https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29 EnableAndSyncInstallation https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18 Flow for clients Client A1 is logged in Client A2 is logged out Client A1 shows a QR code Client A2 scans a QR code If connection fails on A2, the user will be prompted to enter a seed phrase. If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device. Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow. Current issues Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further. * test_: add more test for connection string parser * fix_: fix panic when parse old connection string * test_: add comments for TestMessengerPairAfterSeedPhrase * fix_: correct error description * feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair * fix_: delete leftover * fix_: add UniqueKey method * fix_: unify the response for InputConnectionStringForBootstrapping * fix_: remove fields installationID and keyUID in GethStatusBackend * fix_: rename messenger_pairing to messenger_pairing_and_syncing --------- Co-authored-by: frank <lovefree103@gmail.com> Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
func(r *MessengerResponse) bool { return len(r.Installations()) > 0 },
"installation not received",
)
s.Require().NoError(err)
feat(pairing)_: Fallback pairing seed (#5614) (#5627) * feat(pairing)!: Add extra parameters and remove v2 compatibility This commit includes the following changes: I have added a flag to maintain 2.29 compatibility. Breaking change in connection string The local pairing code that was parsing the connection string had a few non-upgradable features: It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking. It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect. The code has been changed so that: Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow. I have also removed version from the payload, since it wasn't used. This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one). https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy Changed MessengerResponse to use internally a map of installations rather than an array (minor) Just moving towards maps as arrays tend to lead to subtle bugs. Moved pairing methods to messenger_pairing.go Just moved some methods Added 2 new methods for the fallback flow FinishPairingThroughSeedPhraseProcess https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29 EnableAndSyncInstallation https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18 Flow for clients Client A1 is logged in Client A2 is logged out Client A1 shows a QR code Client A2 scans a QR code If connection fails on A2, the user will be prompted to enter a seed phrase. If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device. Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow. Current issues Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further. * test_: add more test for connection string parser * fix_: fix panic when parse old connection string * test_: add comments for TestMessengerPairAfterSeedPhrase * fix_: correct error description * feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair * fix_: delete leftover * fix_: add UniqueKey method * fix_: unify the response for InputConnectionStringForBootstrapping * fix_: remove fields installationID and keyUID in GethStatusBackend * fix_: rename messenger_pairing to messenger_pairing_and_syncing --------- Co-authored-by: frank <lovefree103@gmail.com> Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
actualInstallation := response.Installations()[0]
s.Require().Equal(theirMessenger.installationID, actualInstallation.ID)
s.Require().NotNil(actualInstallation.InstallationMetadata)
s.Require().Equal("their-name", actualInstallation.InstallationMetadata.Name)
s.Require().Equal("their-device-type", actualInstallation.InstallationMetadata.DeviceType)
err = s.m.EnableInstallation(theirMessenger.installationID)
s.Require().NoError(err)
// sync
err = s.m.SyncDevices(context.Background(), "ens-name", "profile-image", nil)
s.Require().NoError(err)
var allChats []*Chat
var actualContact *Contact
var bookmarks []*browsers.Bookmark
// Wait for the message to reach its destination
err = tt.RetryWithBackOff(func() error {
var err error
response, err = theirMessenger.RetrieveAll()
if err != nil {
return err
}
2021-01-11 10:32:51 +00:00
allChats = append(allChats, response.Chats()...)
for _, c := range response.Contacts {
if c.LocalNickname == contact.LocalNickname {
actualContact = c
break
}
}
bookmarks = append(bookmarks, response.GetBookmarks()...)
if len(allChats) >= 5 && actualContact != nil && len(bookmarks) >= 1 {
return nil
}
return errors.New("not received all chats & contacts & bookmarks yet")
})
s.Require().NoError(err)
var statusChat *Chat
var groupChat *Chat
var removedGroupChat *Chat
var oneToOneChat *Chat
2021-10-05 17:26:02 +00:00
var removedChat *Chat
for _, c := range allChats {
2020-07-22 07:41:40 +00:00
if c.ID == statusChatID {
statusChat = c
}
if c.ID == ourGroupChat.ID {
groupChat = c
}
if c.ID == ourDeactivatedGroupChat.ID {
removedGroupChat = c
}
if c.ID == ourOneOneChat.ID {
oneToOneChat = c
}
2021-10-05 17:26:02 +00:00
if c.ID == removedChatID {
removedChat = c
}
}
s.Require().NotNil(statusChat)
s.Require().NotNil(groupChat)
s.Require().NotNil(removedGroupChat)
s.Require().NotNil(oneToOneChat)
s.Require().Equal(ourGroupChat.Name, groupChat.Name)
s.Require().True(ourGroupChat.Active)
s.Require().Equal(ourDeactivatedGroupChat.Name, removedGroupChat.Name)
s.Require().False(removedGroupChat.Active)
s.Require().Equal("", oneToOneChat.Name) // We set 1-1 chat names to "" because the name is not good
s.Require().True(oneToOneChat.Active)
2023-01-20 14:28:30 +00:00
s.Require().True(actualContact.added())
2020-08-20 14:06:38 +00:00
s.Require().Equal("Test Nickname", actualContact.LocalNickname)
s.Require().Equal(multiaccountscommon.CustomizationColorRed, actualContact.CustomizationColor)
2023-01-20 14:28:30 +00:00
s.Require().True(actualContact.hasAddedUs())
s.Require().True(actualContact.mutual())
2022-01-17 03:42:11 +00:00
bookmarks, err = theirMessenger.browserDatabase.GetBookmarks()
2022-01-17 03:42:11 +00:00
s.Require().NoError(err)
s.Require().Equal(1, len(bookmarks))
2020-07-31 09:46:38 +00:00
s.Require().NoError(theirMessenger.Shutdown())
2021-10-05 17:26:02 +00:00
s.Require().NotNil(removedChat)
s.Require().False(removedChat.Active)
2022-01-17 03:42:11 +00:00
}
2020-07-28 13:22:22 +00:00
func (s *MessengerInstallationSuite) TestSyncInstallationNewMessages() {
bob1 := s.m
// pair
2020-12-21 11:57:47 +00:00
bob2, err := newMessengerWithKey(s.shh, s.privateKey, s.logger, nil)
s.Require().NoError(err)
2023-07-13 10:44:09 +00:00
alice := s.newMessenger()
2020-07-28 13:22:22 +00:00
2020-12-21 11:57:47 +00:00
err = bob2.SetInstallationMetadata(bob2.installationID, &multidevice.InstallationMetadata{
2020-07-28 13:22:22 +00:00
Name: "their-name",
DeviceType: "their-device-type",
})
s.Require().NoError(err)
response, err := bob2.SendPairInstallation(context.Background(), nil)
2020-07-28 13:22:22 +00:00
s.Require().NoError(err)
s.Require().NotNil(response)
2021-01-11 10:32:51 +00:00
s.Require().Len(response.Chats(), 1)
s.Require().False(response.Chats()[0].Active)
2020-07-28 13:22:22 +00:00
// Wait for the message to reach its destination
response, err = WaitOnMessengerResponse(
bob1,
feat(pairing)_: Fallback pairing seed (#5614) (#5627) * feat(pairing)!: Add extra parameters and remove v2 compatibility This commit includes the following changes: I have added a flag to maintain 2.29 compatibility. Breaking change in connection string The local pairing code that was parsing the connection string had a few non-upgradable features: It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking. It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect. The code has been changed so that: Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow. I have also removed version from the payload, since it wasn't used. This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one). https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy Changed MessengerResponse to use internally a map of installations rather than an array (minor) Just moving towards maps as arrays tend to lead to subtle bugs. Moved pairing methods to messenger_pairing.go Just moved some methods Added 2 new methods for the fallback flow FinishPairingThroughSeedPhraseProcess https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29 EnableAndSyncInstallation https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18 Flow for clients Client A1 is logged in Client A2 is logged out Client A1 shows a QR code Client A2 scans a QR code If connection fails on A2, the user will be prompted to enter a seed phrase. If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device. Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow. Current issues Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further. * test_: add more test for connection string parser * fix_: fix panic when parse old connection string * test_: add comments for TestMessengerPairAfterSeedPhrase * fix_: correct error description * feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair * fix_: delete leftover * fix_: add UniqueKey method * fix_: unify the response for InputConnectionStringForBootstrapping * fix_: remove fields installationID and keyUID in GethStatusBackend * fix_: rename messenger_pairing to messenger_pairing_and_syncing --------- Co-authored-by: frank <lovefree103@gmail.com> Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
func(r *MessengerResponse) bool { return len(r.Installations()) > 0 },
2020-07-28 13:22:22 +00:00
"installation not received",
)
s.Require().NoError(err)
feat(pairing)_: Fallback pairing seed (#5614) (#5627) * feat(pairing)!: Add extra parameters and remove v2 compatibility This commit includes the following changes: I have added a flag to maintain 2.29 compatibility. Breaking change in connection string The local pairing code that was parsing the connection string had a few non-upgradable features: It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking. It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect. The code has been changed so that: Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow. I have also removed version from the payload, since it wasn't used. This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one). https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy Changed MessengerResponse to use internally a map of installations rather than an array (minor) Just moving towards maps as arrays tend to lead to subtle bugs. Moved pairing methods to messenger_pairing.go Just moved some methods Added 2 new methods for the fallback flow FinishPairingThroughSeedPhraseProcess https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29 EnableAndSyncInstallation https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18 Flow for clients Client A1 is logged in Client A2 is logged out Client A1 shows a QR code Client A2 scans a QR code If connection fails on A2, the user will be prompted to enter a seed phrase. If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device. Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow. Current issues Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further. * test_: add more test for connection string parser * fix_: fix panic when parse old connection string * test_: add comments for TestMessengerPairAfterSeedPhrase * fix_: correct error description * feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair * fix_: delete leftover * fix_: add UniqueKey method * fix_: unify the response for InputConnectionStringForBootstrapping * fix_: remove fields installationID and keyUID in GethStatusBackend * fix_: rename messenger_pairing to messenger_pairing_and_syncing --------- Co-authored-by: frank <lovefree103@gmail.com> Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
actualInstallation := response.Installations()[0]
2020-07-28 13:22:22 +00:00
s.Require().Equal(bob2.installationID, actualInstallation.ID)
err = bob1.EnableInstallation(bob2.installationID)
s.Require().NoError(err)
// send a message from bob1 to alice, it should be received on both bob1 and bob2
alicePkString := types.EncodeHex(crypto.FromECDSAPub(&alice.identity.PublicKey))
chat := CreateOneToOneChat(alicePkString, &alice.identity.PublicKey, bob1.transport)
2021-01-11 10:32:51 +00:00
s.Require().NoError(bob1.SaveChat(chat))
2020-07-28 13:22:22 +00:00
2021-01-11 10:32:51 +00:00
inputMessage := buildTestMessage(*chat)
2020-07-28 13:22:22 +00:00
_, err = s.m.SendChatMessage(context.Background(), inputMessage)
s.Require().NoError(err)
// Wait for the message to reach its destination
_, err = WaitOnMessengerResponse(
bob2,
2021-06-03 13:11:55 +00:00
func(r *MessengerResponse) bool { return len(r.Messages()) > 0 },
2020-07-28 13:22:22 +00:00
"message not received",
)
s.Require().NoError(err)
2020-07-31 09:46:38 +00:00
s.Require().NoError(bob2.Shutdown())
s.Require().NoError(alice.Shutdown())
2020-07-28 13:22:22 +00:00
}
func (s *MessengerInstallationSuite) TestInitInstallations() {
m, err := newMessengerWithKey(s.shh, s.privateKey, s.logger, nil)
s.Require().NoError(err)
// m.InitInstallations is already called when we set-up the messenger for
// testing, thus this test has no act phase.
// err = m.InitInstallations()
// We get one installation when the messenger initializes installations
// correctly.
s.Require().Equal(1, m.allInstallations.Len())
deviceName, err := server.GetDeviceName()
s.Require().NoError(err)
installation, ok := m.allInstallations.Load(m.installationID)
s.Require().True(ok)
s.Require().Equal(deviceName+" ", installation.InstallationMetadata.Name)
s.Require().Equal(runtime.GOOS, installation.InstallationMetadata.DeviceType)
}