2023-02-21 12:35:26 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
|
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2023-05-16 10:50:04 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2023-02-21 12:35:26 +00:00
|
|
|
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
|
|
|
"github.com/status-im/status-go/protocol/tt"
|
|
|
|
"github.com/status-im/status-go/waku"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMessengerSyncKeycardChangeSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(MessengerSyncKeycardChangeSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessengerSyncKeycardChangeSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
main *Messenger // main instance of Messenger paired with `other`
|
|
|
|
other *Messenger
|
|
|
|
privateKey *ecdsa.PrivateKey // private key for the main instance of Messenger
|
|
|
|
|
|
|
|
// If one wants to send messages between different instances of Messenger,
|
|
|
|
// a single Waku service should be shared.
|
|
|
|
shh types.Waku
|
|
|
|
|
|
|
|
logger *zap.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) SetupTest() {
|
|
|
|
s.logger = tt.MustCreateTestLogger()
|
|
|
|
|
|
|
|
config := waku.DefaultConfig
|
|
|
|
config.MinimumAcceptedPoW = 0
|
|
|
|
shh := waku.New(&config, s.logger)
|
|
|
|
s.shh = gethbridge.NewGethWakuWrapper(shh)
|
|
|
|
s.Require().NoError(shh.Start())
|
|
|
|
|
|
|
|
s.main = s.newMessenger(s.shh)
|
|
|
|
s.privateKey = s.main.identity
|
|
|
|
|
2024-02-26 09:12:37 +00:00
|
|
|
var err error
|
2023-02-21 12:35:26 +00:00
|
|
|
// Create new device and add main account to
|
|
|
|
s.other, err = newMessengerWithKey(s.shh, s.main.identity, s.logger, nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Pair devices (main and other)
|
|
|
|
imOther := &multidevice.InstallationMetadata{
|
|
|
|
Name: "other-device",
|
|
|
|
DeviceType: "other-device-type",
|
|
|
|
}
|
|
|
|
err = s.other.SetInstallationMetadata(s.other.installationID, imOther)
|
|
|
|
s.Require().NoError(err)
|
2023-02-28 12:32:45 +00:00
|
|
|
response, err := s.other.SendPairInstallation(context.Background(), nil)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
// Wait for the message to reach its destination
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
s.main,
|
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 },
|
2023-02-21 12:35:26 +00:00
|
|
|
"installation not received",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
err = s.main.EnableInstallation(s.other.installationID)
|
|
|
|
s.Require().NoError(err)
|
2023-05-16 10:50:04 +00:00
|
|
|
|
|
|
|
// Pre-condition - both sides have to know about keypairs migrated to a keycards
|
2023-05-24 14:40:40 +00:00
|
|
|
kp1 := accounts.GetProfileKeypairForTest(true, true, true)
|
2023-05-16 10:50:04 +00:00
|
|
|
kp2 := accounts.GetSeedImportedKeypair1ForTest()
|
|
|
|
// kp3 := accounts.GetSeedImportedKeypair2ForTest()
|
2023-07-05 12:41:58 +00:00
|
|
|
kp1.Clock = 1
|
|
|
|
kp2.Clock = 1
|
|
|
|
// kp3.Clock = 1
|
2023-05-16 10:50:04 +00:00
|
|
|
|
|
|
|
err = s.main.settings.SaveOrUpdateKeypair(kp1)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
err = s.main.settings.SaveOrUpdateKeypair(kp2)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
// err = s.main.settings.SaveOrUpdateKeypair(kp3)
|
|
|
|
// s.Require().NoError(err)
|
2023-07-25 15:17:17 +00:00
|
|
|
dbKeypairs, err := s.main.settings.GetActiveKeypairs()
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(2, len(dbKeypairs))
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
kp1.Clock = 0
|
|
|
|
kp2.Clock = 0
|
|
|
|
// kp3.Clock = 0
|
|
|
|
|
|
|
|
err = s.other.settings.SaveOrUpdateKeypair(kp1)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
err = s.other.settings.SaveOrUpdateKeypair(kp2)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
// err = s.other.settings.SaveOrUpdateKeypair(kp3)
|
2023-05-16 10:50:04 +00:00
|
|
|
// s.Require().NoError(err)
|
2023-07-25 15:17:17 +00:00
|
|
|
dbKeypairs, err = s.other.settings.GetActiveKeypairs()
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(2, len(dbKeypairs))
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TearDownTest() {
|
2023-11-27 17:01:13 +00:00
|
|
|
TearDownMessenger(&s.Suite, s.other)
|
|
|
|
TearDownMessenger(&s.Suite, s.main)
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) 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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TestAddingNewKeycards() {
|
|
|
|
dbOnReceiver := s.other.settings
|
|
|
|
|
|
|
|
// Add key cards on sender
|
2023-05-16 10:50:04 +00:00
|
|
|
keycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
|
|
|
|
keycard2 := accounts.GetKeycardForSeedImportedKeypair1ForTest()
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
err := s.main.SaveOrUpdateKeycard(context.Background(), keycard1)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
err = s.main.SaveOrUpdateKeycard(context.Background(), keycard2)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-21 12:35:26 +00:00
|
|
|
|
|
|
|
// Wait for the response
|
2023-05-16 10:50:04 +00:00
|
|
|
_, err = WaitOnMessengerResponse(
|
2023-02-21 12:35:26 +00:00
|
|
|
s.other,
|
|
|
|
func(r *MessengerResponse) bool {
|
2023-07-05 12:41:58 +00:00
|
|
|
return len(r.Keypairs) == 2
|
2023-02-21 12:35:26 +00:00
|
|
|
},
|
|
|
|
"expected to receive keycard activities",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
senderKeycards, err := s.main.settings.GetAllKnownKeycards()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(2, len(senderKeycards))
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.Contains(senderKeycards, keycard1, accounts.SameKeycards))
|
|
|
|
s.Require().True(accounts.Contains(senderKeycards, keycard2, accounts.SameKeycards))
|
2023-05-16 10:50:04 +00:00
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
syncedKeycards, err := dbOnReceiver.GetAllKnownKeycards()
|
|
|
|
s.Require().NoError(err)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().Equal(2, len(syncedKeycards))
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.Contains(syncedKeycards, keycard1, accounts.SameKeycards))
|
|
|
|
s.Require().True(accounts.Contains(syncedKeycards, keycard2, accounts.SameKeycards))
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TestAddingAccountsToKeycard() {
|
|
|
|
senderDb := s.main.settings
|
|
|
|
dbOnReceiver := s.other.settings
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
keycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
|
|
|
|
keycard2 := accounts.GetKeycardForSeedImportedKeypair1ForTest()
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
// Add keycard on sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err := senderDb.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Add the same keycard on receiver
|
2023-07-05 12:41:58 +00:00
|
|
|
err = dbOnReceiver.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Add additional accounts to sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err = s.main.SaveOrUpdateKeycard(context.Background(), keycard2)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for the response
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
s.other,
|
|
|
|
func(r *MessengerResponse) bool {
|
2023-07-05 12:41:58 +00:00
|
|
|
return len(r.Keypairs) == 1
|
2023-02-21 12:35:26 +00:00
|
|
|
},
|
|
|
|
"expected to receive keycard activities",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
senderKeycards, err := senderDb.GetAllKnownKeycards()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(2, len(senderKeycards))
|
|
|
|
s.Require().True(contains(senderKeycards, keycard1, accounts.SameKeycards))
|
|
|
|
s.Require().True(contains(senderKeycards, keycard2, accounts.SameKeycards))
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
syncedKeycards, err := dbOnReceiver.GetAllKnownKeycards()
|
|
|
|
s.Require().NoError(err)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().Equal(2, len(syncedKeycards))
|
|
|
|
s.Require().True(contains(syncedKeycards, keycard1, accounts.SameKeycards))
|
|
|
|
s.Require().True(contains(syncedKeycards, keycard2, accounts.SameKeycards))
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TestRemovingAccountsFromKeycard() {
|
|
|
|
senderDb := s.main.settings
|
|
|
|
dbOnReceiver := s.other.settings
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
keycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
// Add keycard on sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err := senderDb.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Add the same keycard on receiver
|
2023-07-05 12:41:58 +00:00
|
|
|
err = dbOnReceiver.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
// Prepare expected keycard for comparison
|
|
|
|
updatedKeycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
updatedKeycard1.AccountsAddresses = updatedKeycard1.AccountsAddresses[2:]
|
2023-02-21 12:35:26 +00:00
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
// Remove accounts from sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err = s.main.DeleteKeycardAccounts(context.Background(), keycard1.KeycardUID, keycard1.AccountsAddresses[:2])
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for the response
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
s.other,
|
|
|
|
func(r *MessengerResponse) bool {
|
2023-07-05 12:41:58 +00:00
|
|
|
return len(r.Keypairs) == 1
|
2023-02-21 12:35:26 +00:00
|
|
|
},
|
|
|
|
"expected to receive keycard activities",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
senderKeycards, err := senderDb.GetAllKnownKeycards()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(1, len(senderKeycards))
|
|
|
|
s.Require().True(contains(senderKeycards, updatedKeycard1, accounts.SameKeycards))
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
syncedKeycards, err := dbOnReceiver.GetAllKnownKeycards()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(1, len(syncedKeycards))
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().True(contains(syncedKeycards, updatedKeycard1, accounts.SameKeycards))
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TestRemovingAllAccountsForKeyUID() {
|
2023-02-21 12:35:26 +00:00
|
|
|
senderDb := s.main.settings
|
|
|
|
dbOnReceiver := s.other.settings
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
keycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
// Add keycard on sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err := senderDb.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Add the same keycard on receiver
|
2023-07-05 12:41:58 +00:00
|
|
|
err = dbOnReceiver.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
// Remove all accounts from sender for KeyUID
|
|
|
|
err = s.main.DeleteAllKeycardsWithKeyUID(context.Background(), keycard1.KeyUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for the response
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
s.other,
|
|
|
|
func(r *MessengerResponse) bool {
|
2023-07-05 12:41:58 +00:00
|
|
|
return len(r.Keypairs) == 1
|
2023-02-21 12:35:26 +00:00
|
|
|
},
|
|
|
|
"expected to receive keycard activities",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
senderKeycards, err := senderDb.GetKeycardsWithSameKeyUID(keycard1.KeyUID)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(0, len(senderKeycards))
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
syncedKeycards, err := dbOnReceiver.GetKeycardsWithSameKeyUID(keycard1.KeyUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(0, len(syncedKeycards))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TestDeleteKeycard() {
|
|
|
|
senderDb := s.main.settings
|
|
|
|
dbOnReceiver := s.other.settings
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
keycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
// Add keycard on sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err := senderDb.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Add the same keycard on receiver
|
2023-07-05 12:41:58 +00:00
|
|
|
err = dbOnReceiver.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Remove keycard from sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err = s.main.DeleteKeycard(context.Background(), keycard1.KeycardUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for the response
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
s.other,
|
|
|
|
func(r *MessengerResponse) bool {
|
2023-07-05 12:41:58 +00:00
|
|
|
return len(r.Keypairs) == 1
|
2023-02-21 12:35:26 +00:00
|
|
|
},
|
|
|
|
"expected to receive keycard activities",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
senderKeycard, err := senderDb.GetKeycardByKeycardUID(keycard1.KeycardUID)
|
|
|
|
s.Require().Error(err)
|
|
|
|
s.Require().True(err == accounts.ErrNoKeycardForPassedKeycardUID)
|
|
|
|
s.Require().Nil(senderKeycard)
|
2023-05-16 10:50:04 +00:00
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
syncedKeycard, err := dbOnReceiver.GetKeycardByKeycardUID(keycard1.KeycardUID)
|
|
|
|
s.Require().Error(err)
|
|
|
|
s.Require().True(err == accounts.ErrNoKeycardForPassedKeycardUID)
|
|
|
|
s.Require().Nil(syncedKeycard)
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TestSettingKeycardName() {
|
|
|
|
senderDb := s.main.settings
|
|
|
|
dbOnReceiver := s.other.settings
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
keycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
// Add keycard on sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err := senderDb.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Add the same keycard on receiver
|
2023-07-05 12:41:58 +00:00
|
|
|
err = dbOnReceiver.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
// Prepare expected keycard for comparison
|
|
|
|
updatedKeycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
updatedKeycard1.KeycardName = "New Keycard Name"
|
2023-02-21 12:35:26 +00:00
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
// Set new keycard name to sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err = s.main.SetKeycardName(context.Background(), updatedKeycard1.KeycardUID, updatedKeycard1.KeycardName)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for the response
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
s.other,
|
|
|
|
func(r *MessengerResponse) bool {
|
2023-07-05 12:41:58 +00:00
|
|
|
return len(r.Keypairs) == 1
|
2023-02-21 12:35:26 +00:00
|
|
|
},
|
|
|
|
"expected to receive keycard activities",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
senderKeycard, err := senderDb.GetKeycardByKeycardUID(updatedKeycard1.KeycardUID)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.SameKeycards(updatedKeycard1, senderKeycard))
|
2023-05-16 10:50:04 +00:00
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
syncedKeycard, err := dbOnReceiver.GetKeycardByKeycardUID(updatedKeycard1.KeycardUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.SameKeycards(updatedKeycard1, syncedKeycard))
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TestSettingKeycardLocked() {
|
|
|
|
senderDb := s.main.settings
|
|
|
|
dbOnReceiver := s.other.settings
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
keycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
// Add keycard on sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err := senderDb.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Add the same keycard on receiver
|
2023-07-05 12:41:58 +00:00
|
|
|
err = dbOnReceiver.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
// Prepare expected keycard for comparison
|
|
|
|
updatedKeycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
updatedKeycard1.KeycardLocked = true
|
2023-02-21 12:35:26 +00:00
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
err = s.main.KeycardLocked(context.Background(), updatedKeycard1.KeycardUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for the response
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
s.other,
|
|
|
|
func(r *MessengerResponse) bool {
|
2023-07-05 12:41:58 +00:00
|
|
|
return len(r.Keypairs) == 1
|
2023-02-21 12:35:26 +00:00
|
|
|
},
|
|
|
|
"expected to receive keycard activities",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
senderKeycard, err := senderDb.GetKeycardByKeycardUID(updatedKeycard1.KeycardUID)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.SameKeycards(updatedKeycard1, senderKeycard))
|
2023-05-16 10:50:04 +00:00
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
syncedKeycard, err := dbOnReceiver.GetKeycardByKeycardUID(updatedKeycard1.KeycardUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.SameKeycards(updatedKeycard1, syncedKeycard))
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TestSettingKeycardUnlocked() {
|
|
|
|
senderDb := s.main.settings
|
|
|
|
dbOnReceiver := s.other.settings
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
keycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
keycard1.KeycardLocked = true
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
// Add keycard on sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err := senderDb.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Add the same keycard on receiver
|
2023-07-05 12:41:58 +00:00
|
|
|
err = dbOnReceiver.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
// Prepare expected keycard for comparison
|
|
|
|
updatedKeycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
updatedKeycard1.KeycardLocked = false
|
2023-02-21 12:35:26 +00:00
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
err = s.main.KeycardUnlocked(context.Background(), updatedKeycard1.KeycardUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for the response
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
s.other,
|
|
|
|
func(r *MessengerResponse) bool {
|
2023-07-05 12:41:58 +00:00
|
|
|
return len(r.Keypairs) == 1
|
2023-02-21 12:35:26 +00:00
|
|
|
},
|
|
|
|
"expected to receive keycard activities",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
senderKeycard, err := senderDb.GetKeycardByKeycardUID(updatedKeycard1.KeycardUID)
|
2023-05-16 10:50:04 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.SameKeycards(updatedKeycard1, senderKeycard))
|
2023-05-16 10:50:04 +00:00
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
syncedKeycard, err := dbOnReceiver.GetKeycardByKeycardUID(updatedKeycard1.KeycardUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.SameKeycards(updatedKeycard1, syncedKeycard))
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerSyncKeycardChangeSuite) TestUpdatingKeycardUid() {
|
|
|
|
senderDb := s.main.settings
|
|
|
|
dbOnReceiver := s.other.settings
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
keycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
|
2023-02-21 12:35:26 +00:00
|
|
|
// Add keycard on sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err := senderDb.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Add the same keycard on receiver
|
2023-07-05 12:41:58 +00:00
|
|
|
err = dbOnReceiver.SaveOrUpdateKeycard(*keycard1, 0, false)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
// Prepare expected keycard for comparison
|
|
|
|
updatedKeycard1 := accounts.GetProfileKeycardForTest()
|
|
|
|
updatedKeycard1.KeycardUID = "00000000000000000000000000000000"
|
2023-02-21 12:35:26 +00:00
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
// Update keycard uid on sender
|
2023-07-05 12:41:58 +00:00
|
|
|
err = s.main.UpdateKeycardUID(context.Background(), keycard1.KeycardUID, updatedKeycard1.KeycardUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for the response
|
|
|
|
_, err = WaitOnMessengerResponse(
|
|
|
|
s.other,
|
|
|
|
func(r *MessengerResponse) bool {
|
2023-07-05 12:41:58 +00:00
|
|
|
return len(r.Keypairs) == 1
|
2023-02-21 12:35:26 +00:00
|
|
|
},
|
|
|
|
"expected to receive keycard activities",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
senderKeycard, err := senderDb.GetKeycardByKeycardUID(updatedKeycard1.KeycardUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.SameKeycards(updatedKeycard1, senderKeycard))
|
2023-02-21 12:35:26 +00:00
|
|
|
|
2023-07-05 12:41:58 +00:00
|
|
|
syncedKeycard, err := dbOnReceiver.GetKeycardByKeycardUID(updatedKeycard1.KeycardUID)
|
2023-02-21 12:35:26 +00:00
|
|
|
s.Require().NoError(err)
|
2023-07-05 12:41:58 +00:00
|
|
|
s.Require().True(accounts.SameKeycards(updatedKeycard1, syncedKeycard))
|
2023-02-21 12:35:26 +00:00
|
|
|
}
|