2023-01-06 12:21:14 +00:00
|
|
|
package pairing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2024-02-19 18:00:44 +00:00
|
|
|
"errors"
|
2023-08-18 08:51:16 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2023-01-06 12:21:14 +00:00
|
|
|
"path/filepath"
|
2024-02-17 18:07:20 +00:00
|
|
|
"reflect"
|
2023-08-18 08:51:16 +00:00
|
|
|
"strings"
|
2023-01-06 12:21:14 +00:00
|
|
|
"testing"
|
2023-05-12 08:31:34 +00:00
|
|
|
"time"
|
2023-04-19 22:59:09 +00:00
|
|
|
|
2023-07-12 09:46:56 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2023-10-02 09:28:42 +00:00
|
|
|
"github.com/status-im/status-go/common/dbsetup"
|
2023-07-12 09:46:56 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
2024-02-17 18:07:20 +00:00
|
|
|
"github.com/status-im/status-go/protocol"
|
2024-02-19 18:00:44 +00:00
|
|
|
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
2023-07-12 09:46:56 +00:00
|
|
|
"github.com/status-im/status-go/protocol/tt"
|
|
|
|
|
2023-01-06 12:21:14 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/api"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2023-05-12 08:31:34 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2023-08-18 08:51:16 +00:00
|
|
|
accservice "github.com/status-im/status-go/services/accounts"
|
2023-01-06 12:21:14 +00:00
|
|
|
"github.com/status-im/status-go/services/browsers"
|
|
|
|
)
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
const (
|
2024-02-19 18:00:44 +00:00
|
|
|
pathWalletRoot = "m/44'/60'/0'/0"
|
|
|
|
pathEIP1581 = "m/43'/60'/1581'"
|
|
|
|
pathDefaultChat = pathEIP1581 + "/0'/0"
|
|
|
|
pathDefaultWallet = pathWalletRoot + "/0"
|
|
|
|
currentNetwork = "mainnet_rpc"
|
|
|
|
socialLinkURL = "https://github.com/status-im"
|
|
|
|
ensUsername = "bob.stateofus.eth"
|
|
|
|
ensChainID = 1
|
|
|
|
publicChatID = "localpairtest"
|
|
|
|
profileKeypairMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon"
|
|
|
|
seedKeypairMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
|
|
|
profileKeypairMnemonic1 = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about about"
|
|
|
|
seedKeypairMnemonic1 = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about abandon"
|
|
|
|
path0 = "m/44'/60'/0'/0/0"
|
|
|
|
path1 = "m/44'/60'/0'/0/1"
|
|
|
|
expectedKDFIterations = 1024
|
2023-03-23 11:44:15 +00:00
|
|
|
)
|
2023-01-06 12:21:14 +00:00
|
|
|
|
|
|
|
func TestSyncDeviceSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(SyncDeviceSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type SyncDeviceSuite struct {
|
|
|
|
suite.Suite
|
2024-03-26 13:47:12 +00:00
|
|
|
logger *zap.Logger
|
|
|
|
password string
|
|
|
|
tmpdir string
|
2023-01-06 12:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) SetupTest() {
|
2023-07-12 09:46:56 +00:00
|
|
|
s.logger = tt.MustCreateTestLogger()
|
2023-01-06 12:21:14 +00:00
|
|
|
s.password = "password"
|
2024-03-26 13:47:12 +00:00
|
|
|
s.tmpdir = s.T().TempDir()
|
2023-01-06 12:21:14 +00:00
|
|
|
}
|
|
|
|
|
2023-08-18 08:51:16 +00:00
|
|
|
func (s *SyncDeviceSuite) prepareBackendWithAccount(mnemonic, tmpdir string) *api.GethStatusBackend {
|
2023-01-06 12:21:14 +00:00
|
|
|
backend := s.prepareBackendWithoutAccount(tmpdir)
|
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
displayName, err := common.RandomAlphabeticalString(8)
|
|
|
|
s.Require().NoError(err)
|
2023-01-12 03:00:24 +00:00
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
deviceName, err := common.RandomAlphanumericString(8)
|
|
|
|
s.Require().NoError(err)
|
2023-01-06 12:21:14 +00:00
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
createAccount := requests.CreateAccount{
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
KdfIterations: dbsetup.ReducedKDFIterationsNumber,
|
|
|
|
DisplayName: displayName,
|
|
|
|
DeviceName: deviceName,
|
|
|
|
Password: s.password,
|
|
|
|
CustomizationColor: "primary",
|
2023-01-06 12:21:14 +00:00
|
|
|
}
|
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
if mnemonic == "" {
|
|
|
|
_, err = backend.CreateAccountAndLogin(&createAccount)
|
|
|
|
} else {
|
|
|
|
_, err = backend.RestoreAccountAndLogin(&requests.RestoreAccount{
|
|
|
|
Mnemonic: mnemonic,
|
|
|
|
FetchBackup: false,
|
|
|
|
CreateAccount: createAccount,
|
|
|
|
})
|
2023-01-06 12:21:14 +00:00
|
|
|
}
|
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
accs, err := backend.GetAccounts()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotEmpty(accs[0].ColorHash)
|
2023-02-28 12:32:45 +00:00
|
|
|
|
2023-01-06 12:21:14 +00:00
|
|
|
return backend
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) prepareBackendWithoutAccount(tmpdir string) *api.GethStatusBackend {
|
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
|
|
|
backend := api.NewGethStatusBackend(s.logger)
|
2023-01-06 12:21:14 +00:00
|
|
|
backend.UpdateRootDataDir(tmpdir)
|
|
|
|
return backend
|
|
|
|
}
|
|
|
|
|
2023-07-12 09:46:56 +00:00
|
|
|
func (s *SyncDeviceSuite) pairAccounts(serverBackend *api.GethStatusBackend, serverDir string,
|
|
|
|
clientBackend *api.GethStatusBackend, clientDir string) {
|
|
|
|
|
|
|
|
// Start sender server
|
|
|
|
|
|
|
|
serverActiveAccount, err := serverBackend.GetActiveAccount()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
serverKeystorePath := filepath.Join(serverDir, api.DefaultKeystoreRelativePath, serverActiveAccount.KeyUID)
|
2023-07-12 09:46:56 +00:00
|
|
|
serverConfig := &SenderServerConfig{
|
|
|
|
SenderConfig: &SenderConfig{
|
|
|
|
KeystorePath: serverKeystorePath,
|
|
|
|
DeviceType: "desktop",
|
|
|
|
KeyUID: serverActiveAccount.KeyUID,
|
|
|
|
Password: s.password,
|
|
|
|
},
|
|
|
|
ServerConfig: new(ServerConfig),
|
|
|
|
}
|
|
|
|
|
|
|
|
configBytes, err := json.Marshal(serverConfig)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
connectionString, err := StartUpSenderServer(serverBackend, string(configBytes))
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
// Start receiving client
|
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
err = clientBackend.AccountManager().InitKeystore(filepath.Join(clientDir, api.DefaultKeystoreRelativePath))
|
2023-07-12 09:46:56 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
err = clientBackend.OpenAccounts()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
clientPayloadSourceConfig := ReceiverClientConfig{
|
|
|
|
ReceiverConfig: &ReceiverConfig{
|
2024-08-14 20:10:19 +00:00
|
|
|
CreateAccount: &requests.CreateAccount{
|
|
|
|
RootDataDir: clientDir,
|
|
|
|
KdfIterations: expectedKDFIterations,
|
|
|
|
},
|
2023-07-12 09:46:56 +00:00
|
|
|
},
|
|
|
|
ClientConfig: new(ClientConfig),
|
|
|
|
}
|
|
|
|
|
|
|
|
clientConfigBytes, err := json.Marshal(clientPayloadSourceConfig)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
err = StartUpReceivingClient(clientBackend, connectionString, string(clientConfigBytes))
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
require.True(s.T(), serverBackend.Messenger().HasPairedDevices())
|
|
|
|
require.True(s.T(), clientBackend.Messenger().HasPairedDevices())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) sendContactRequest(request *requests.SendContactRequest, messenger *protocol.Messenger) {
|
|
|
|
senderPublicKey := common.PubkeyToHex(messenger.IdentityPublicKey())
|
|
|
|
s.logger.Info("sendContactRequest", zap.String("sender", senderPublicKey), zap.String("receiver", request.ID))
|
|
|
|
|
|
|
|
resp, err := messenger.SendContactRequest(context.Background(), request)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) receiveContactRequest(messageText string, messenger *protocol.Messenger) *common.Message {
|
|
|
|
receiverPublicKey := types.EncodeHex(crypto.FromECDSAPub(messenger.IdentityPublicKey()))
|
|
|
|
s.logger.Info("receiveContactRequest", zap.String("receiver", receiverPublicKey))
|
|
|
|
|
|
|
|
// Wait for the message to reach its destination
|
|
|
|
resp, err := protocol.WaitOnMessengerResponse(
|
|
|
|
messenger,
|
|
|
|
func(r *protocol.MessengerResponse) bool {
|
|
|
|
return len(r.Contacts) == 1 && len(r.Messages()) == 2 && len(r.ActivityCenterNotifications()) == 1
|
|
|
|
},
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(resp)
|
|
|
|
|
|
|
|
contactRequest := protocol.FindFirstByContentType(resp.Messages(), protobuf.ChatMessage_CONTACT_REQUEST)
|
|
|
|
s.Require().NotNil(contactRequest)
|
|
|
|
|
|
|
|
return contactRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) acceptContactRequest(contactRequest *common.Message, sender *protocol.Messenger, receiver *protocol.Messenger) {
|
|
|
|
senderPublicKey := types.EncodeHex(crypto.FromECDSAPub(sender.IdentityPublicKey()))
|
|
|
|
receiverPublicKey := types.EncodeHex(crypto.FromECDSAPub(receiver.IdentityPublicKey()))
|
|
|
|
s.logger.Info("acceptContactRequest", zap.String("sender", senderPublicKey), zap.String("receiver", receiverPublicKey))
|
|
|
|
|
|
|
|
_, err := receiver.AcceptContactRequest(context.Background(), &requests.AcceptContactRequest{ID: types.Hex2Bytes(contactRequest.ID)})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for the message to reach its destination
|
|
|
|
resp, err := protocol.WaitOnMessengerResponse(
|
|
|
|
sender,
|
|
|
|
func(r *protocol.MessengerResponse) bool {
|
|
|
|
return len(r.Contacts) == 1 && len(r.Messages()) == 2 && len(r.ActivityCenterNotifications()) == 1
|
|
|
|
},
|
|
|
|
"no messages",
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) checkMutualContact(backend *api.GethStatusBackend, contactPublicKey string) {
|
|
|
|
messenger := backend.Messenger()
|
|
|
|
contacts := messenger.MutualContacts()
|
|
|
|
s.Require().Len(contacts, 1)
|
|
|
|
contact := contacts[0]
|
|
|
|
s.Require().Equal(contactPublicKey, contact.ID)
|
|
|
|
s.Require().Equal(protocol.ContactRequestStateSent, contact.ContactRequestLocalState)
|
|
|
|
s.Require().Equal(protocol.ContactRequestStateReceived, contact.ContactRequestRemoteState)
|
|
|
|
s.Require().NotNil(contact.DisplayName)
|
|
|
|
}
|
|
|
|
|
2023-01-06 12:21:14 +00:00
|
|
|
func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsSender() {
|
2024-03-26 13:47:12 +00:00
|
|
|
clientTmpDir := filepath.Join(s.tmpdir, "client")
|
2023-08-18 08:51:16 +00:00
|
|
|
clientBackend := s.prepareBackendWithAccount("", clientTmpDir)
|
2024-03-26 13:47:12 +00:00
|
|
|
serverTmpDir := filepath.Join(s.tmpdir, "server")
|
2023-01-06 12:21:14 +00:00
|
|
|
serverBackend := s.prepareBackendWithoutAccount(serverTmpDir)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(s.T(), serverBackend.Logout())
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), clientBackend.Logout())
|
2023-01-06 12:21:14 +00:00
|
|
|
}()
|
2023-05-12 08:31:34 +00:00
|
|
|
ctx := context.TODO()
|
2023-01-06 12:21:14 +00:00
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
err := serverBackend.AccountManager().InitKeystore(filepath.Join(serverTmpDir, api.DefaultKeystoreRelativePath))
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
err = serverBackend.OpenAccounts()
|
|
|
|
require.NoError(s.T(), err)
|
2024-08-14 20:10:19 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
serverPayloadSourceConfig := &ReceiverServerConfig{
|
|
|
|
ReceiverConfig: &ReceiverConfig{
|
2024-08-14 20:10:19 +00:00
|
|
|
CreateAccount: &requests.CreateAccount{
|
|
|
|
RootDataDir: serverTmpDir,
|
|
|
|
KdfIterations: expectedKDFIterations,
|
|
|
|
},
|
2023-02-17 13:02:42 +00:00
|
|
|
},
|
2023-03-23 11:44:15 +00:00
|
|
|
ServerConfig: new(ServerConfig),
|
2023-02-17 13:02:42 +00:00
|
|
|
}
|
2024-08-14 20:10:19 +00:00
|
|
|
|
2023-02-17 13:02:42 +00:00
|
|
|
serverConfigBytes, err := json.Marshal(serverPayloadSourceConfig)
|
|
|
|
require.NoError(s.T(), err)
|
2023-03-21 13:08:28 +00:00
|
|
|
cs, err := StartUpReceiverServer(serverBackend, string(serverConfigBytes))
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
// generate some data for the client
|
2023-05-12 08:31:34 +00:00
|
|
|
// generate bookmark
|
2023-01-06 12:21:14 +00:00
|
|
|
clientBrowserAPI := clientBackend.StatusNode().BrowserService().APIs()[0].Service.(*browsers.API)
|
2023-05-12 08:31:34 +00:00
|
|
|
_, err = clientBrowserAPI.StoreBookmark(ctx, browsers.Bookmark{
|
2023-01-06 12:21:14 +00:00
|
|
|
Name: "status.im",
|
|
|
|
URL: "https://status.im",
|
|
|
|
})
|
|
|
|
require.NoError(s.T(), err)
|
2024-05-24 08:35:34 +00:00
|
|
|
|
2023-05-12 08:31:34 +00:00
|
|
|
// generate ens username
|
|
|
|
err = clientBackend.StatusNode().EnsService().API().Add(ctx, ensChainID, ensUsername)
|
2023-04-26 15:37:18 +00:00
|
|
|
require.NoError(s.T(), err)
|
2024-02-17 18:07:20 +00:00
|
|
|
// generate profile showcase preferences
|
2024-02-22 08:08:58 +00:00
|
|
|
profileShowcasePreferences := protocol.DummyProfileShowcasePreferences(false)
|
2024-02-17 18:07:20 +00:00
|
|
|
err = clientBackend.Messenger().SetProfileShowcasePreferences(profileShowcasePreferences, false)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
// startup sending client
|
2023-01-12 03:00:24 +00:00
|
|
|
clientActiveAccount, err := clientBackend.GetActiveAccount()
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
2024-08-14 20:10:19 +00:00
|
|
|
clientKeystorePath := filepath.Join(clientTmpDir, api.DefaultKeystoreRelativePath, clientActiveAccount.KeyUID)
|
2023-03-23 11:44:15 +00:00
|
|
|
clientPayloadSourceConfig := SenderClientConfig{
|
|
|
|
SenderConfig: &SenderConfig{
|
|
|
|
KeystorePath: clientKeystorePath,
|
|
|
|
DeviceType: "android",
|
|
|
|
KeyUID: clientActiveAccount.KeyUID,
|
|
|
|
Password: s.password,
|
2023-02-17 13:02:42 +00:00
|
|
|
},
|
2023-03-23 11:44:15 +00:00
|
|
|
ClientConfig: new(ClientConfig),
|
2023-01-06 12:21:14 +00:00
|
|
|
}
|
2023-02-17 13:02:42 +00:00
|
|
|
clientConfigBytes, err := json.Marshal(clientPayloadSourceConfig)
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
2023-03-23 11:44:15 +00:00
|
|
|
err = StartUpSendingClient(clientBackend, cs, string(clientConfigBytes))
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
2023-04-19 22:59:09 +00:00
|
|
|
// check that the server has the same data as the client
|
2023-01-06 12:21:14 +00:00
|
|
|
serverBrowserAPI := serverBackend.StatusNode().BrowserService().APIs()[0].Service.(*browsers.API)
|
2024-05-24 08:35:34 +00:00
|
|
|
|
2023-05-12 08:31:34 +00:00
|
|
|
bookmarks, err := serverBrowserAPI.GetBookmarks(ctx)
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.Equal(s.T(), 1, len(bookmarks))
|
|
|
|
require.Equal(s.T(), "status.im", bookmarks[0].Name)
|
2024-05-24 08:35:34 +00:00
|
|
|
|
2023-05-12 08:31:34 +00:00
|
|
|
uds, err := serverBackend.StatusNode().EnsService().API().GetEnsUsernames(ctx)
|
2023-04-26 15:37:18 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.Equal(s.T(), 1, len(uds))
|
|
|
|
require.Equal(s.T(), ensUsername, uds[0].Username)
|
|
|
|
require.Equal(s.T(), uint64(ensChainID), uds[0].ChainID)
|
|
|
|
require.False(s.T(), uds[0].Removed)
|
|
|
|
require.Greater(s.T(), uds[0].Clock, uint64(0))
|
2024-05-24 08:35:34 +00:00
|
|
|
|
2024-02-17 18:07:20 +00:00
|
|
|
serverProfileShowcasePreferences, err := serverBackend.Messenger().GetProfileShowcasePreferences()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.True(s.T(), reflect.DeepEqual(profileShowcasePreferences, serverProfileShowcasePreferences))
|
2023-01-12 03:00:24 +00:00
|
|
|
|
|
|
|
serverActiveAccount, err := serverBackend.GetActiveAccount()
|
|
|
|
require.NoError(s.T(), err)
|
2024-08-14 20:10:19 +00:00
|
|
|
require.Equal(s.T(), clientActiveAccount.Name, serverActiveAccount.Name)
|
|
|
|
require.Equal(s.T(), expectedKDFIterations, serverActiveAccount.KDFIterations)
|
2023-02-28 12:32:45 +00:00
|
|
|
|
|
|
|
serverMessenger := serverBackend.Messenger()
|
|
|
|
clientMessenger := clientBackend.Messenger()
|
|
|
|
require.True(s.T(), serverMessenger.HasPairedDevices())
|
|
|
|
require.True(s.T(), clientMessenger.HasPairedDevices())
|
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
serverNodeConfig, err := serverBackend.GetNodeConfig()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-02-28 12:32:45 +00:00
|
|
|
err = clientMessenger.DisableInstallation(serverNodeConfig.ShhextConfig.InstallationID)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.False(s.T(), clientMessenger.HasPairedDevices())
|
2024-05-24 08:35:34 +00:00
|
|
|
|
2023-02-28 12:32:45 +00:00
|
|
|
clientNodeConfig, err := clientBackend.GetNodeConfig()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
err = serverMessenger.DisableInstallation(clientNodeConfig.ShhextConfig.InstallationID)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.False(s.T(), serverMessenger.HasPairedDevices())
|
|
|
|
|
|
|
|
// repeat local pairing, we should expect no error after receiver logged in
|
2023-03-21 13:08:28 +00:00
|
|
|
cs, err = StartUpReceiverServer(serverBackend, string(serverConfigBytes))
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), err)
|
2023-03-23 11:44:15 +00:00
|
|
|
err = StartUpSendingClient(clientBackend, cs, string(clientConfigBytes))
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.True(s.T(), clientMessenger.HasPairedDevices())
|
|
|
|
require.True(s.T(), serverMessenger.HasPairedDevices())
|
|
|
|
|
|
|
|
// test if it's okay when account already exist but not logged in
|
|
|
|
require.NoError(s.T(), serverBackend.Logout())
|
2023-03-21 13:08:28 +00:00
|
|
|
cs, err = StartUpReceiverServer(serverBackend, string(serverConfigBytes))
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), err)
|
2023-03-23 11:44:15 +00:00
|
|
|
err = StartUpSendingClient(clientBackend, cs, string(clientConfigBytes))
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), err)
|
2023-01-06 12:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsReceiver() {
|
2024-03-26 13:47:12 +00:00
|
|
|
clientTmpDir := filepath.Join(s.tmpdir, "client")
|
2023-01-06 12:21:14 +00:00
|
|
|
clientBackend := s.prepareBackendWithoutAccount(clientTmpDir)
|
2023-05-12 08:31:34 +00:00
|
|
|
ctx := context.TODO()
|
2023-01-06 12:21:14 +00:00
|
|
|
|
2024-03-26 13:47:12 +00:00
|
|
|
serverTmpDir := filepath.Join(s.tmpdir, "server")
|
2023-08-18 08:51:16 +00:00
|
|
|
serverBackend := s.prepareBackendWithAccount("", serverTmpDir)
|
2023-01-06 12:21:14 +00:00
|
|
|
defer func() {
|
|
|
|
require.NoError(s.T(), clientBackend.Logout())
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), serverBackend.Logout())
|
2023-01-06 12:21:14 +00:00
|
|
|
}()
|
|
|
|
|
2023-01-12 03:00:24 +00:00
|
|
|
serverActiveAccount, err := serverBackend.GetActiveAccount()
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
2024-08-14 20:10:19 +00:00
|
|
|
serverKeystorePath := filepath.Join(serverTmpDir, api.DefaultKeystoreRelativePath, serverActiveAccount.KeyUID)
|
2023-03-23 11:44:15 +00:00
|
|
|
var config = &SenderServerConfig{
|
|
|
|
SenderConfig: &SenderConfig{
|
|
|
|
KeystorePath: serverKeystorePath,
|
|
|
|
DeviceType: "desktop",
|
|
|
|
KeyUID: serverActiveAccount.KeyUID,
|
|
|
|
Password: s.password,
|
2023-02-17 13:02:42 +00:00
|
|
|
},
|
2023-03-23 11:44:15 +00:00
|
|
|
ServerConfig: new(ServerConfig),
|
2023-01-06 12:21:14 +00:00
|
|
|
}
|
|
|
|
configBytes, err := json.Marshal(config)
|
|
|
|
require.NoError(s.T(), err)
|
2023-03-21 13:08:28 +00:00
|
|
|
cs, err := StartUpSenderServer(serverBackend, string(configBytes))
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
// generate some data for the server
|
2023-05-12 08:31:34 +00:00
|
|
|
// generate bookmark
|
2023-01-06 12:21:14 +00:00
|
|
|
serverBrowserAPI := serverBackend.StatusNode().BrowserService().APIs()[0].Service.(*browsers.API)
|
2023-05-12 08:31:34 +00:00
|
|
|
_, err = serverBrowserAPI.StoreBookmark(ctx, browsers.Bookmark{
|
2023-01-06 12:21:14 +00:00
|
|
|
Name: "status.im",
|
|
|
|
URL: "https://status.im",
|
|
|
|
})
|
|
|
|
require.NoError(s.T(), err)
|
2023-05-12 08:31:34 +00:00
|
|
|
|
|
|
|
serverMessenger := serverBackend.Messenger()
|
2024-05-24 08:35:34 +00:00
|
|
|
|
2023-05-12 08:31:34 +00:00
|
|
|
// generate ens username
|
|
|
|
err = serverBackend.StatusNode().EnsService().API().Add(ctx, ensChainID, ensUsername)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
2024-02-26 13:53:40 +00:00
|
|
|
// generate profile showcase preferences
|
|
|
|
profileShowcasePreferences := protocol.DummyProfileShowcasePreferences(false)
|
|
|
|
err = serverMessenger.SetProfileShowcasePreferences(profileShowcasePreferences, false)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
2023-05-12 08:31:34 +00:00
|
|
|
// generate local deleted message
|
|
|
|
_, err = serverMessenger.CreatePublicChat(&requests.CreatePublicChat{ID: publicChatID})
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
serverChat := serverMessenger.Chat(publicChatID)
|
|
|
|
serverMessage := buildTestMessage(serverChat)
|
|
|
|
serverMessengerResponse, err := serverMessenger.SendChatMessage(ctx, serverMessage)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.Equal(s.T(), 1, len(serverMessengerResponse.Messages()))
|
|
|
|
serverMessageID := serverMessengerResponse.Messages()[0].ID
|
|
|
|
_, err = serverMessenger.DeleteMessageForMeAndSync(ctx, publicChatID, serverMessageID)
|
2023-04-26 15:37:18 +00:00
|
|
|
require.NoError(s.T(), err)
|
2023-01-06 12:21:14 +00:00
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
err = clientBackend.AccountManager().InitKeystore(filepath.Join(clientTmpDir, api.DefaultKeystoreRelativePath))
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
err = clientBackend.OpenAccounts()
|
|
|
|
require.NoError(s.T(), err)
|
2024-08-14 20:10:19 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
clientPayloadSourceConfig := ReceiverClientConfig{
|
|
|
|
ReceiverConfig: &ReceiverConfig{
|
2024-08-14 20:10:19 +00:00
|
|
|
CreateAccount: &requests.CreateAccount{
|
|
|
|
RootDataDir: clientTmpDir,
|
|
|
|
KdfIterations: expectedKDFIterations,
|
|
|
|
DeviceName: "device-1",
|
|
|
|
},
|
2023-02-17 13:02:42 +00:00
|
|
|
},
|
2023-03-23 11:44:15 +00:00
|
|
|
ClientConfig: new(ClientConfig),
|
2023-02-17 13:02:42 +00:00
|
|
|
}
|
|
|
|
clientConfigBytes, err := json.Marshal(clientPayloadSourceConfig)
|
|
|
|
require.NoError(s.T(), err)
|
2023-03-23 11:44:15 +00:00
|
|
|
err = StartUpReceivingClient(clientBackend, cs, string(clientConfigBytes))
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
2023-04-19 22:59:09 +00:00
|
|
|
// check that the client has the same data as the server
|
2023-05-12 08:31:34 +00:00
|
|
|
clientMessenger := clientBackend.Messenger()
|
2023-01-06 12:21:14 +00:00
|
|
|
clientBrowserAPI := clientBackend.StatusNode().BrowserService().APIs()[0].Service.(*browsers.API)
|
2023-05-12 08:31:34 +00:00
|
|
|
bookmarks, err := clientBrowserAPI.GetBookmarks(ctx)
|
2023-01-06 12:21:14 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.Equal(s.T(), 1, len(bookmarks))
|
|
|
|
require.Equal(s.T(), "status.im", bookmarks[0].Name)
|
2024-02-26 13:53:40 +00:00
|
|
|
|
|
|
|
clientProfileShowcasePreferences, err := clientMessenger.GetProfileShowcasePreferences()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.True(s.T(), reflect.DeepEqual(profileShowcasePreferences, clientProfileShowcasePreferences))
|
|
|
|
|
2023-05-12 08:31:34 +00:00
|
|
|
uds, err := clientBackend.StatusNode().EnsService().API().GetEnsUsernames(ctx)
|
2023-04-26 15:37:18 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.Equal(s.T(), 1, len(uds))
|
|
|
|
require.Equal(s.T(), ensUsername, uds[0].Username)
|
|
|
|
require.Equal(s.T(), uint64(ensChainID), uds[0].ChainID)
|
2023-05-12 08:31:34 +00:00
|
|
|
deleteForMeMessages, err := clientMessenger.GetDeleteForMeMessages()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.Equal(s.T(), 1, len(deleteForMeMessages))
|
2023-01-12 03:00:24 +00:00
|
|
|
|
|
|
|
clientActiveAccount, err := clientBackend.GetActiveAccount()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.Equal(s.T(), serverActiveAccount.Name, clientActiveAccount.Name)
|
2023-02-17 13:02:42 +00:00
|
|
|
require.Equal(s.T(), clientActiveAccount.KDFIterations, expectedKDFIterations)
|
2023-02-28 12:32:45 +00:00
|
|
|
|
|
|
|
require.True(s.T(), serverMessenger.HasPairedDevices())
|
|
|
|
require.True(s.T(), clientMessenger.HasPairedDevices())
|
|
|
|
|
2024-08-14 20:10:19 +00:00
|
|
|
clientNodeConfig, err := clientBackend.GetNodeConfig()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-02-28 12:32:45 +00:00
|
|
|
err = serverMessenger.DisableInstallation(clientNodeConfig.ShhextConfig.InstallationID)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.False(s.T(), serverMessenger.HasPairedDevices())
|
2024-08-14 20:10:19 +00:00
|
|
|
|
2023-02-28 12:32:45 +00:00
|
|
|
serverNodeConfig, err := serverBackend.GetNodeConfig()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
err = clientMessenger.DisableInstallation(serverNodeConfig.ShhextConfig.InstallationID)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.False(s.T(), clientMessenger.HasPairedDevices())
|
|
|
|
|
|
|
|
// repeat local pairing, we should expect no error after receiver logged in
|
2023-03-21 13:08:28 +00:00
|
|
|
cs, err = StartUpSenderServer(serverBackend, string(configBytes))
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), err)
|
2023-03-23 11:44:15 +00:00
|
|
|
err = StartUpReceivingClient(clientBackend, cs, string(clientConfigBytes))
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.True(s.T(), serverMessenger.HasPairedDevices())
|
|
|
|
require.True(s.T(), clientMessenger.HasPairedDevices())
|
|
|
|
|
|
|
|
// test if it's okay when account already exist but not logged in
|
|
|
|
require.NoError(s.T(), clientBackend.Logout())
|
2023-03-21 13:08:28 +00:00
|
|
|
cs, err = StartUpSenderServer(serverBackend, string(configBytes))
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), err)
|
2023-03-23 11:44:15 +00:00
|
|
|
err = StartUpReceivingClient(clientBackend, cs, string(clientConfigBytes))
|
2023-02-28 12:32:45 +00:00
|
|
|
require.NoError(s.T(), err)
|
2023-01-06 12:21:14 +00:00
|
|
|
}
|
|
|
|
|
2023-07-12 09:46:56 +00:00
|
|
|
func (s *SyncDeviceSuite) TestPairingThreeDevices() {
|
2024-03-26 13:47:12 +00:00
|
|
|
bobTmpDir := filepath.Join(s.tmpdir, "bob")
|
2023-08-18 08:51:16 +00:00
|
|
|
bobBackend := s.prepareBackendWithAccount("", bobTmpDir)
|
2023-07-12 09:46:56 +00:00
|
|
|
bobMessenger := bobBackend.Messenger()
|
|
|
|
_, err := bobMessenger.Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2024-03-26 13:47:12 +00:00
|
|
|
alice1TmpDir := filepath.Join(s.tmpdir, "alice1")
|
2023-08-18 08:51:16 +00:00
|
|
|
alice1Backend := s.prepareBackendWithAccount("", alice1TmpDir)
|
2023-07-12 09:46:56 +00:00
|
|
|
alice1Messenger := alice1Backend.Messenger()
|
|
|
|
_, err = alice1Messenger.Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2024-03-26 13:47:12 +00:00
|
|
|
alice2TmpDir := filepath.Join(s.tmpdir, "alice2")
|
2023-07-12 09:46:56 +00:00
|
|
|
alice2Backend := s.prepareBackendWithoutAccount(alice2TmpDir)
|
|
|
|
|
2024-03-26 13:47:12 +00:00
|
|
|
alice3TmpDir := filepath.Join(s.tmpdir, "alice3")
|
2023-09-21 00:32:16 +00:00
|
|
|
alice3Backend := s.prepareBackendWithoutAccount(alice3TmpDir)
|
2023-07-12 09:46:56 +00:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
require.NoError(s.T(), bobBackend.Logout())
|
|
|
|
require.NoError(s.T(), alice1Backend.Logout())
|
|
|
|
require.NoError(s.T(), alice2Backend.Logout())
|
|
|
|
require.NoError(s.T(), alice3Backend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Make Alice and Bob mutual contacts
|
2024-03-26 13:47:12 +00:00
|
|
|
bobPublicKey := bobMessenger.GetSelfContact().ID
|
2023-07-12 09:46:56 +00:00
|
|
|
request := &requests.SendContactRequest{
|
|
|
|
ID: bobPublicKey,
|
2024-03-26 13:47:12 +00:00
|
|
|
Message: protocol.RandomLettersString(5),
|
2023-07-12 09:46:56 +00:00
|
|
|
}
|
|
|
|
s.sendContactRequest(request, alice1Messenger)
|
2024-03-26 13:47:12 +00:00
|
|
|
contactRequest := s.receiveContactRequest(request.Message, bobMessenger)
|
2023-07-12 09:46:56 +00:00
|
|
|
s.acceptContactRequest(contactRequest, alice1Messenger, bobMessenger)
|
|
|
|
s.checkMutualContact(alice1Backend, bobPublicKey)
|
|
|
|
|
|
|
|
// We shouldn't sync ourselves as a contact, so we check there's only Bob
|
|
|
|
// https://github.com/status-im/status-go/issues/3667
|
|
|
|
s.Require().Equal(1, len(alice1Backend.Messenger().Contacts()))
|
|
|
|
|
|
|
|
// Pair alice-1 <-> alice-2
|
|
|
|
s.logger.Info("pairing Alice-1 and Alice-2")
|
|
|
|
s.pairAccounts(alice1Backend, alice1TmpDir, alice2Backend, alice2TmpDir)
|
|
|
|
|
|
|
|
s.checkMutualContact(alice2Backend, bobPublicKey)
|
|
|
|
s.Require().Equal(1, len(alice2Backend.Messenger().Contacts()))
|
|
|
|
|
|
|
|
// Pair Alice-2 <-> ALice-3
|
|
|
|
s.logger.Info("pairing Alice-2 and Alice-3")
|
|
|
|
s.pairAccounts(alice2Backend, alice2TmpDir, alice3Backend, alice3TmpDir)
|
|
|
|
|
|
|
|
s.checkMutualContact(alice3Backend, bobPublicKey)
|
|
|
|
s.Require().Equal(1, len(alice3Backend.Messenger().Contacts()))
|
|
|
|
}
|
|
|
|
|
2024-03-26 13:47:12 +00:00
|
|
|
func (s *SyncDeviceSuite) createUser(name string) (*api.GethStatusBackend, string) {
|
|
|
|
tmpDir := filepath.Join(s.tmpdir, name)
|
|
|
|
backend := s.prepareBackendWithAccount("", tmpDir)
|
|
|
|
_, err := backend.Messenger().Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
return backend, tmpDir
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) TestPairPendingContactRequest() {
|
|
|
|
bobBackend, _ := s.createUser("bob")
|
|
|
|
defer func() {
|
|
|
|
s.Require().NoError(bobBackend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
alice1Backend, alice1TmpDir := s.createUser("alice1")
|
|
|
|
defer func() {
|
|
|
|
s.Require().NoError(alice1Backend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Create a pending CR from alice to bob
|
|
|
|
bobPublicKey := bobBackend.Messenger().IdentityPublicKeyString()
|
|
|
|
alicePublicKey := alice1Backend.Messenger().IdentityPublicKeyString()
|
|
|
|
request := &requests.SendContactRequest{
|
|
|
|
ID: alicePublicKey,
|
|
|
|
Message: protocol.RandomLettersString(5),
|
|
|
|
}
|
|
|
|
s.sendContactRequest(request, bobBackend.Messenger())
|
|
|
|
contactRequest := s.receiveContactRequest(request.Message, alice1Backend.Messenger())
|
|
|
|
s.Require().Equal(request.Message, contactRequest.Text)
|
|
|
|
|
|
|
|
alice2TmpDir := filepath.Join(s.tmpdir, "alice2")
|
|
|
|
alice2Backend := s.prepareBackendWithoutAccount(alice2TmpDir)
|
|
|
|
defer func() {
|
|
|
|
s.Require().NoError(alice2Backend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Pair alice-1 <-> alice-2
|
|
|
|
s.logger.Info("pairing Alice-1 and Alice-2")
|
|
|
|
s.pairAccounts(alice1Backend, alice1TmpDir, alice2Backend, alice2TmpDir)
|
|
|
|
|
|
|
|
s.logger.Debug("public keys",
|
|
|
|
zap.String("alice", alice1Backend.Messenger().IdentityPublicKeyString()),
|
|
|
|
zap.String("bob", bobBackend.Messenger().IdentityPublicKeyString()),
|
|
|
|
)
|
|
|
|
|
|
|
|
ensurePendingContact := func(m *protocol.Messenger) {
|
|
|
|
contacts := m.Contacts()
|
|
|
|
s.Require().Len(contacts, 1)
|
|
|
|
|
|
|
|
c := contacts[0]
|
|
|
|
s.Require().Equal(bobPublicKey, c.ID)
|
|
|
|
s.Require().Equal(protocol.ContactRequestStateReceived, c.ContactRequestRemoteState)
|
|
|
|
s.Require().Equal(protocol.ContactRequestStateNone, c.ContactRequestLocalState)
|
|
|
|
|
|
|
|
acRequest := protocol.ActivityCenterNotificationsRequest{
|
|
|
|
ActivityTypes: []protocol.ActivityCenterType{
|
|
|
|
protocol.ActivityCenterNotificationTypeContactRequest,
|
|
|
|
},
|
|
|
|
ReadType: protocol.ActivityCenterQueryParamsReadAll,
|
|
|
|
Limit: 10,
|
|
|
|
}
|
|
|
|
r, err := m.ActivityCenterNotifications(acRequest)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(r.Notifications, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure both devices have the pending Bob contact
|
|
|
|
ensurePendingContact(alice1Backend.Messenger())
|
|
|
|
ensurePendingContact(alice2Backend.Messenger())
|
|
|
|
}
|
2024-05-15 00:01:47 +00:00
|
|
|
|
|
|
|
type contactRequestAction func(messenger *protocol.Messenger, contactRequestID string) (*protocol.MessengerResponse, error)
|
|
|
|
type notificationValidateFunc func(r *protocol.ActivityCenterPaginationResponse)
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) testPairContactRequest(requestAction contactRequestAction, validateFunc notificationValidateFunc) {
|
|
|
|
bobBackend, _ := s.createUser("bob")
|
|
|
|
defer func() {
|
|
|
|
s.Require().NoError(bobBackend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
alice1Backend, alice1TmpDir := s.createUser("alice1")
|
|
|
|
defer func() {
|
|
|
|
s.Require().NoError(alice1Backend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
alicePublicKey := alice1Backend.Messenger().IdentityPublicKeyString()
|
|
|
|
request := &requests.SendContactRequest{
|
|
|
|
ID: alicePublicKey,
|
|
|
|
Message: protocol.RandomLettersString(5),
|
|
|
|
}
|
|
|
|
s.sendContactRequest(request, bobBackend.Messenger())
|
|
|
|
contactRequest := s.receiveContactRequest(request.Message, alice1Backend.Messenger())
|
|
|
|
s.Require().Equal(request.Message, contactRequest.Text)
|
|
|
|
_, err := requestAction(alice1Backend.Messenger(), contactRequest.ID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
alice2TmpDir := filepath.Join(s.tmpdir, "alice2")
|
|
|
|
alice2Backend := s.prepareBackendWithoutAccount(alice2TmpDir)
|
|
|
|
defer func() {
|
|
|
|
s.Require().NoError(alice2Backend.Logout())
|
|
|
|
}()
|
|
|
|
s.pairAccounts(alice1Backend, alice1TmpDir, alice2Backend, alice2TmpDir)
|
|
|
|
|
|
|
|
internalNotificationValidateFunc := func(m *protocol.Messenger) {
|
|
|
|
acRequest := protocol.ActivityCenterNotificationsRequest{
|
|
|
|
ActivityTypes: []protocol.ActivityCenterType{
|
|
|
|
protocol.ActivityCenterNotificationTypeContactRequest,
|
|
|
|
},
|
|
|
|
ReadType: protocol.ActivityCenterQueryParamsReadAll,
|
|
|
|
Limit: 10,
|
|
|
|
}
|
|
|
|
r, err := m.ActivityCenterNotifications(acRequest)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
validateFunc(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
internalNotificationValidateFunc(alice1Backend.Messenger())
|
|
|
|
internalNotificationValidateFunc(alice2Backend.Messenger())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) TestPairDeclineContactRequest() {
|
|
|
|
declineContactRequest := func(messenger *protocol.Messenger, contactRequestID string) (*protocol.MessengerResponse, error) {
|
|
|
|
return messenger.DeclineContactRequest(context.Background(), &requests.DeclineContactRequest{ID: types.Hex2Bytes(contactRequestID)})
|
|
|
|
}
|
|
|
|
s.testPairContactRequest(declineContactRequest, func(r *protocol.ActivityCenterPaginationResponse) {
|
|
|
|
s.Require().Len(r.Notifications, 1)
|
|
|
|
s.Require().False(r.Notifications[0].Accepted)
|
|
|
|
s.Require().True(r.Notifications[0].Dismissed)
|
|
|
|
s.Require().True(r.Notifications[0].Read)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) TestPairAcceptContactRequest() {
|
|
|
|
acceptContactRequest := func(messenger *protocol.Messenger, contactRequestID string) (*protocol.MessengerResponse, error) {
|
|
|
|
return messenger.AcceptContactRequest(context.Background(), &requests.AcceptContactRequest{ID: types.Hex2Bytes(contactRequestID)})
|
|
|
|
}
|
|
|
|
s.testPairContactRequest(acceptContactRequest, func(r *protocol.ActivityCenterPaginationResponse) {
|
|
|
|
s.Require().Len(r.Notifications, 1)
|
|
|
|
s.Require().True(r.Notifications[0].Accepted)
|
|
|
|
s.Require().False(r.Notifications[0].Dismissed)
|
|
|
|
s.Require().True(r.Notifications[0].Read)
|
|
|
|
})
|
|
|
|
}
|
2024-03-26 13:47:12 +00:00
|
|
|
|
2023-05-12 08:31:34 +00:00
|
|
|
type testTimeSource struct{}
|
|
|
|
|
|
|
|
func (t *testTimeSource) GetCurrentTime() uint64 {
|
|
|
|
return uint64(time.Now().Unix())
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildTestMessage(chat *protocol.Chat) *common.Message {
|
|
|
|
clock, timestamp := chat.NextClockAndTimestamp(&testTimeSource{})
|
2023-08-18 11:39:59 +00:00
|
|
|
message := common.NewMessage()
|
2023-05-12 08:31:34 +00:00
|
|
|
message.Text = "text-input-message"
|
|
|
|
message.ChatId = chat.ID
|
|
|
|
message.Clock = clock
|
|
|
|
message.Timestamp = timestamp
|
|
|
|
message.WhisperTimestamp = clock
|
|
|
|
message.LocalChatID = chat.ID
|
|
|
|
message.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
|
|
|
switch chat.ChatType {
|
|
|
|
case protocol.ChatTypePublic, protocol.ChatTypeProfile:
|
|
|
|
message.MessageType = protobuf.MessageType_PUBLIC_GROUP
|
|
|
|
case protocol.ChatTypeOneToOne:
|
|
|
|
message.MessageType = protobuf.MessageType_ONE_TO_ONE
|
|
|
|
case protocol.ChatTypePrivateGroupChat:
|
|
|
|
message.MessageType = protobuf.MessageType_PRIVATE_GROUP
|
|
|
|
}
|
|
|
|
|
|
|
|
return message
|
|
|
|
}
|
2023-08-18 08:51:16 +00:00
|
|
|
|
2023-08-30 11:33:14 +00:00
|
|
|
func (s *SyncDeviceSuite) getSeedPhraseKeypairForTest(backend *api.GethStatusBackend, mnemonic string, server bool) *accounts.Keypair {
|
|
|
|
generatedAccount, err := backend.AccountManager().AccountsGenerator().ImportMnemonic(mnemonic, "")
|
2023-08-18 08:51:16 +00:00
|
|
|
require.NoError(s.T(), err)
|
|
|
|
generatedDerivedAccs, err := backend.AccountManager().AccountsGenerator().DeriveAddresses(generatedAccount.ID, []string{path0, path1})
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
seedPhraseKp := &accounts.Keypair{
|
|
|
|
KeyUID: generatedAccount.KeyUID,
|
|
|
|
Name: "SeedPhraseImported",
|
|
|
|
Type: accounts.KeypairTypeSeed,
|
|
|
|
DerivedFrom: generatedAccount.Address,
|
|
|
|
}
|
|
|
|
i := 0
|
|
|
|
for path, ga := range generatedDerivedAccs {
|
|
|
|
acc := &accounts.Account{
|
|
|
|
Address: types.HexToAddress(ga.Address),
|
|
|
|
KeyUID: generatedAccount.KeyUID,
|
|
|
|
Wallet: false,
|
|
|
|
Chat: false,
|
|
|
|
Type: accounts.AccountTypeSeed,
|
|
|
|
Path: path,
|
|
|
|
PublicKey: types.HexBytes(ga.PublicKey),
|
|
|
|
Name: fmt.Sprintf("Acc_%d", i),
|
|
|
|
Operable: accounts.AccountFullyOperable,
|
|
|
|
Emoji: fmt.Sprintf("Emoji_%d", i),
|
|
|
|
ColorID: "blue",
|
|
|
|
}
|
|
|
|
if !server {
|
|
|
|
acc.Operable = accounts.AccountNonOperable
|
|
|
|
}
|
|
|
|
seedPhraseKp.Accounts = append(seedPhraseKp.Accounts, acc)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
|
|
|
return seedPhraseKp
|
|
|
|
}
|
|
|
|
|
2023-08-30 11:33:14 +00:00
|
|
|
func containsKeystoreFile(directory, key string) bool {
|
|
|
|
files, err := os.ReadDir(directory)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, file := range files {
|
|
|
|
if strings.Contains(file.Name(), strings.ToLower(key)) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-08-18 08:51:16 +00:00
|
|
|
func (s *SyncDeviceSuite) TestTransferringKeystoreFiles() {
|
|
|
|
ctx := context.TODO()
|
|
|
|
|
2024-03-26 13:47:12 +00:00
|
|
|
serverTmpDir := filepath.Join(s.tmpdir, "server")
|
2023-08-30 11:33:14 +00:00
|
|
|
serverBackend := s.prepareBackendWithAccount(profileKeypairMnemonic, serverTmpDir)
|
2023-08-18 08:51:16 +00:00
|
|
|
|
2024-03-26 13:47:12 +00:00
|
|
|
clientTmpDir := filepath.Join(s.tmpdir, "client")
|
2023-08-30 11:33:14 +00:00
|
|
|
clientBackend := s.prepareBackendWithAccount(profileKeypairMnemonic, clientTmpDir)
|
2023-08-18 08:51:16 +00:00
|
|
|
defer func() {
|
|
|
|
require.NoError(s.T(), clientBackend.Logout())
|
|
|
|
require.NoError(s.T(), serverBackend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
serverBackend.Messenger().SetLocalPairing(true)
|
|
|
|
clientBackend.Messenger().SetLocalPairing(true)
|
|
|
|
|
|
|
|
serverActiveAccount, err := serverBackend.GetActiveAccount()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
clientActiveAccount, err := clientBackend.GetActiveAccount()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
require.True(s.T(), serverActiveAccount.KeyUID == clientActiveAccount.KeyUID)
|
|
|
|
|
2023-08-30 11:33:14 +00:00
|
|
|
serverSeedPhraseKp := s.getSeedPhraseKeypairForTest(serverBackend, seedKeypairMnemonic, true)
|
2023-08-18 08:51:16 +00:00
|
|
|
serverAccountsAPI := serverBackend.StatusNode().AccountService().APIs()[1].Service.(*accservice.API)
|
2023-08-30 11:33:14 +00:00
|
|
|
err = serverAccountsAPI.ImportMnemonic(ctx, seedKeypairMnemonic, s.password)
|
2023-08-18 08:51:16 +00:00
|
|
|
require.NoError(s.T(), err, "importing mnemonic for new keypair on server")
|
|
|
|
err = serverAccountsAPI.AddKeypair(ctx, s.password, serverSeedPhraseKp)
|
|
|
|
require.NoError(s.T(), err, "saving seed phrase keypair on server with keystore files created")
|
|
|
|
|
2023-08-30 11:33:14 +00:00
|
|
|
clientSeedPhraseKp := s.getSeedPhraseKeypairForTest(serverBackend, seedKeypairMnemonic, true)
|
2023-08-18 08:51:16 +00:00
|
|
|
clientAccountsAPI := clientBackend.StatusNode().AccountService().APIs()[1].Service.(*accservice.API)
|
|
|
|
err = clientAccountsAPI.SaveKeypair(ctx, clientSeedPhraseKp)
|
|
|
|
require.NoError(s.T(), err, "saving seed phrase keypair on client without keystore files")
|
|
|
|
|
|
|
|
// check server - server should contain keystore files for imported seed phrase
|
2024-08-14 20:10:19 +00:00
|
|
|
serverKeystorePath := filepath.Join(serverTmpDir, api.DefaultKeystoreRelativePath, serverActiveAccount.KeyUID)
|
2023-08-18 08:51:16 +00:00
|
|
|
require.True(s.T(), containsKeystoreFile(serverKeystorePath, serverSeedPhraseKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range serverSeedPhraseKp.Accounts {
|
|
|
|
require.True(s.T(), containsKeystoreFile(serverKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
// check client - client should not contain keystore files for imported seed phrase
|
2024-08-14 20:10:19 +00:00
|
|
|
clientKeystorePath := filepath.Join(clientTmpDir, api.DefaultKeystoreRelativePath, clientActiveAccount.KeyUID)
|
2023-08-18 08:51:16 +00:00
|
|
|
require.False(s.T(), containsKeystoreFile(clientKeystorePath, clientSeedPhraseKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range clientSeedPhraseKp.Accounts {
|
|
|
|
require.False(s.T(), containsKeystoreFile(clientKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare sender
|
|
|
|
var config = KeystoreFilesSenderServerConfig{
|
|
|
|
SenderConfig: &KeystoreFilesSenderConfig{
|
|
|
|
KeystoreFilesConfig: KeystoreFilesConfig{
|
|
|
|
KeystorePath: serverKeystorePath,
|
|
|
|
LoggedInKeyUID: serverActiveAccount.KeyUID,
|
|
|
|
Password: s.password,
|
|
|
|
},
|
|
|
|
KeypairsToExport: []string{serverSeedPhraseKp.KeyUID},
|
|
|
|
},
|
|
|
|
ServerConfig: new(ServerConfig),
|
|
|
|
}
|
|
|
|
configBytes, err := json.Marshal(config)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
cs, err := StartUpKeystoreFilesSenderServer(serverBackend, string(configBytes))
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
// prepare receiver
|
|
|
|
clientPayloadSourceConfig := KeystoreFilesReceiverClientConfig{
|
|
|
|
ReceiverConfig: &KeystoreFilesReceiverConfig{
|
|
|
|
KeystoreFilesConfig: KeystoreFilesConfig{
|
|
|
|
KeystorePath: clientKeystorePath,
|
|
|
|
LoggedInKeyUID: clientActiveAccount.KeyUID,
|
|
|
|
Password: s.password,
|
|
|
|
},
|
|
|
|
KeypairsToImport: []string{serverSeedPhraseKp.KeyUID},
|
|
|
|
},
|
|
|
|
ClientConfig: new(ClientConfig),
|
|
|
|
}
|
|
|
|
clientConfigBytes, err := json.Marshal(clientPayloadSourceConfig)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
err = StartUpKeystoreFilesReceivingClient(clientBackend, cs, string(clientConfigBytes))
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
|
|
|
|
// check client - client should contain keystore files for imported seed phrase
|
|
|
|
accountManager := clientBackend.AccountManager()
|
|
|
|
accGenerator := accountManager.AccountsGenerator()
|
|
|
|
require.True(s.T(), containsKeystoreFile(clientKeystorePath, clientSeedPhraseKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range clientSeedPhraseKp.Accounts {
|
|
|
|
require.True(s.T(), containsKeystoreFile(clientKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
// reinit keystore on client
|
|
|
|
require.NoError(s.T(), accountManager.InitKeystore(clientKeystorePath))
|
|
|
|
|
|
|
|
// check keystore on client
|
|
|
|
genAccInfo, err := accGenerator.LoadAccount(clientSeedPhraseKp.DerivedFrom, s.password)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.Equal(s.T(), clientSeedPhraseKp.KeyUID, genAccInfo.KeyUID)
|
|
|
|
for _, acc := range clientSeedPhraseKp.Accounts {
|
|
|
|
genAccInfo, err := accGenerator.LoadAccount(acc.Address.String(), s.password)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.Equal(s.T(), acc.Address.String(), genAccInfo.Address)
|
|
|
|
}
|
|
|
|
}
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
func (s *SyncDeviceSuite) TestTransferringKeystoreFilesAfterStopUisngKeycard() {
|
2024-02-26 09:12:37 +00:00
|
|
|
s.T().Skip("flaky test")
|
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
ctx := context.TODO()
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
// Prepare server
|
2024-03-26 13:47:12 +00:00
|
|
|
serverTmpDir := filepath.Join(s.tmpdir, "server")
|
2024-02-19 18:00:44 +00:00
|
|
|
serverBackend := s.prepareBackendWithAccount(profileKeypairMnemonic1, serverTmpDir)
|
|
|
|
serverMessenger := serverBackend.Messenger()
|
|
|
|
serverAccountsAPI := serverBackend.StatusNode().AccountService().APIs()[1].Service.(*accservice.API)
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
// Prepare client
|
2024-03-26 13:47:12 +00:00
|
|
|
clientTmpDir := filepath.Join(s.tmpdir, "client")
|
2024-02-19 18:00:44 +00:00
|
|
|
clientBackend := s.prepareBackendWithAccount(profileKeypairMnemonic1, clientTmpDir)
|
|
|
|
clientMessenger := clientBackend.Messenger()
|
|
|
|
clientAccountsAPI := clientBackend.StatusNode().AccountService().APIs()[1].Service.(*accservice.API)
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
defer func() {
|
|
|
|
require.NoError(s.T(), clientBackend.Logout())
|
|
|
|
require.NoError(s.T(), serverBackend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Pair server and client
|
|
|
|
im1 := &multidevice.InstallationMetadata{
|
|
|
|
Name: "client-device",
|
|
|
|
DeviceType: "client-device-type",
|
|
|
|
}
|
|
|
|
settings, err := clientBackend.GetSettings()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
err = clientMessenger.SetInstallationMetadata(settings.InstallationID, im1)
|
|
|
|
s.Require().NoError(err)
|
2024-10-07 14:05:37 +00:00
|
|
|
response, err := clientMessenger.SendPairInstallation(context.Background(), "", nil)
|
2024-02-19 18:00:44 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
s.Require().False(response.Chats()[0].Active)
|
|
|
|
|
|
|
|
response, err = protocol.WaitOnMessengerResponse(
|
|
|
|
serverMessenger,
|
|
|
|
func(r *protocol.MessengerResponse) bool {
|
feat: fallback pairing seed (#5614)
* 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: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
for _, i := range r.Installations() {
|
2024-02-19 18:00:44 +00:00
|
|
|
if i.ID == settings.InstallationID {
|
|
|
|
return true
|
2024-02-19 09:10:37 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-19 18:00:44 +00:00
|
|
|
return false
|
|
|
|
},
|
|
|
|
"installation not received",
|
|
|
|
)
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
s.Require().NoError(err)
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
found := false
|
feat: fallback pairing seed (#5614)
* 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: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
for _, i := range response.Installations() {
|
2024-02-19 18:00:44 +00:00
|
|
|
found = i.ID == settings.InstallationID &&
|
|
|
|
i.InstallationMetadata != nil &&
|
|
|
|
i.InstallationMetadata.Name == im1.Name &&
|
|
|
|
i.InstallationMetadata.DeviceType == im1.DeviceType
|
|
|
|
if found {
|
|
|
|
break
|
2023-08-30 11:33:14 +00:00
|
|
|
}
|
2024-02-19 18:00:44 +00:00
|
|
|
}
|
|
|
|
s.Require().True(found)
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-10-07 14:05:37 +00:00
|
|
|
_, err = serverMessenger.EnableInstallation(settings.InstallationID)
|
2024-02-19 18:00:44 +00:00
|
|
|
s.Require().NoError(err)
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
// Check if the logged in account is the same on server and client
|
|
|
|
serverActiveAccount, err := serverBackend.GetActiveAccount()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
clientActiveAccount, err := clientBackend.GetActiveAccount()
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
require.True(s.T(), serverActiveAccount.KeyUID == clientActiveAccount.KeyUID)
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// From this point this test is trying to simulate the following scenario:
|
|
|
|
// - add a new seed phrase keypair on server
|
|
|
|
// - sync it to client
|
|
|
|
// - convert it to a keycard keypair on server
|
|
|
|
// - sync it to client
|
|
|
|
// - stop using keycard on server
|
|
|
|
// - sync it to client
|
|
|
|
// - try to transfer keystore files from server to client
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Add new seed phrase keypair to server and sync it to client
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
serverSeedPhraseKp := s.getSeedPhraseKeypairForTest(serverBackend, seedKeypairMnemonic1, true)
|
|
|
|
err = serverAccountsAPI.ImportMnemonic(ctx, seedKeypairMnemonic1, s.password)
|
|
|
|
require.NoError(s.T(), err, "importing mnemonic for new keypair on server")
|
|
|
|
err = serverAccountsAPI.AddKeypair(ctx, s.password, serverSeedPhraseKp)
|
|
|
|
require.NoError(s.T(), err, "saving seed phrase keypair on server with keystore files created")
|
|
|
|
|
|
|
|
// Wait for sync messages to be received on client
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err := clientMessenger.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, kp := range response.Keypairs {
|
|
|
|
if kp.KeyUID == serverSeedPhraseKp.KeyUID {
|
|
|
|
return nil
|
2023-08-30 11:33:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
return errors.New("no sync keypair received")
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Check if the keypair saved on client is the same as the one on server
|
|
|
|
serverKp, err := serverAccountsAPI.GetKeypairByKeyUID(ctx, serverSeedPhraseKp.KeyUID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
clientKp, err := clientAccountsAPI.GetKeypairByKeyUID(ctx, serverSeedPhraseKp.KeyUID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().True(serverKp.KeyUID == clientKp.KeyUID &&
|
|
|
|
serverKp.Name == clientKp.Name &&
|
|
|
|
serverKp.Type == clientKp.Type &&
|
|
|
|
serverKp.DerivedFrom == clientKp.DerivedFrom &&
|
|
|
|
serverKp.LastUsedDerivationIndex == clientKp.LastUsedDerivationIndex &&
|
|
|
|
serverKp.Clock == clientKp.Clock &&
|
|
|
|
len(serverKp.Accounts) == len(clientKp.Accounts) &&
|
|
|
|
len(serverKp.Keycards) == len(clientKp.Keycards))
|
|
|
|
|
|
|
|
// Check server - server should contain keystore files for imported seed phrase
|
2024-08-14 20:10:19 +00:00
|
|
|
serverKeystorePath := filepath.Join(serverTmpDir, api.DefaultKeystoreRelativePath, serverActiveAccount.KeyUID)
|
2024-02-19 18:00:44 +00:00
|
|
|
require.True(s.T(), containsKeystoreFile(serverKeystorePath, serverKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range serverKp.Accounts {
|
|
|
|
require.True(s.T(), containsKeystoreFile(serverKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check client - client should not contain keystore files for imported seed phrase
|
2024-08-14 20:10:19 +00:00
|
|
|
clientKeystorePath := filepath.Join(clientTmpDir, api.DefaultKeystoreRelativePath, clientActiveAccount.KeyUID)
|
2024-02-19 18:00:44 +00:00
|
|
|
require.False(s.T(), containsKeystoreFile(clientKeystorePath, clientKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range clientKp.Accounts {
|
|
|
|
require.False(s.T(), containsKeystoreFile(clientKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Convert it to a keycard keypair on server and sync it to client
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
err = serverAccountsAPI.SaveOrUpdateKeycard(ctx, &accounts.Keycard{
|
|
|
|
KeycardUID: "1234",
|
|
|
|
KeycardName: "new-keycard",
|
|
|
|
KeyUID: serverKp.KeyUID,
|
|
|
|
AccountsAddresses: []types.Address{serverKp.Accounts[0].Address, serverKp.Accounts[1].Address},
|
|
|
|
}, false)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for sync messages to be received on client
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err := clientMessenger.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-08-30 11:33:14 +00:00
|
|
|
}
|
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
for _, kp := range response.Keypairs {
|
|
|
|
if kp.KeyUID == serverKp.KeyUID {
|
|
|
|
return nil
|
2023-08-30 11:33:14 +00:00
|
|
|
}
|
2024-02-19 18:00:44 +00:00
|
|
|
}
|
|
|
|
return errors.New("no sync keypair received")
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
// Check if the keypair saved on client is the same as the one on server
|
|
|
|
serverKp, err = serverAccountsAPI.GetKeypairByKeyUID(ctx, serverSeedPhraseKp.KeyUID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
clientKp, err = clientAccountsAPI.GetKeypairByKeyUID(ctx, serverSeedPhraseKp.KeyUID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().True(serverKp.KeyUID == clientKp.KeyUID &&
|
|
|
|
serverKp.Name == clientKp.Name &&
|
|
|
|
serverKp.Type == clientKp.Type &&
|
|
|
|
serverKp.DerivedFrom == clientKp.DerivedFrom &&
|
|
|
|
serverKp.LastUsedDerivationIndex == clientKp.LastUsedDerivationIndex &&
|
|
|
|
serverKp.Clock == clientKp.Clock &&
|
|
|
|
len(serverKp.Accounts) == len(clientKp.Accounts) &&
|
|
|
|
len(serverKp.Keycards) == len(clientKp.Keycards) &&
|
|
|
|
len(serverKp.Keycards) == 1)
|
|
|
|
|
|
|
|
// Check server - server should not contain keystore files for imported seed phrase
|
|
|
|
require.False(s.T(), containsKeystoreFile(serverKeystorePath, serverKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range serverKp.Accounts {
|
|
|
|
require.False(s.T(), containsKeystoreFile(serverKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check client - client should not contain keystore files for imported seed phrase
|
|
|
|
require.False(s.T(), containsKeystoreFile(clientKeystorePath, clientKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range clientKp.Accounts {
|
|
|
|
require.False(s.T(), containsKeystoreFile(clientKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Stop using keycard on server and sync it to client
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
err = serverAccountsAPI.MigrateNonProfileKeycardKeypairToApp(ctx, seedKeypairMnemonic1, s.password)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Wait for sync messages to be received on client
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err := clientMessenger.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2024-02-19 09:10:37 +00:00
|
|
|
}
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
for _, kp := range response.Keypairs {
|
|
|
|
if kp.KeyUID == serverKp.KeyUID {
|
|
|
|
return nil
|
|
|
|
}
|
2024-02-19 09:10:37 +00:00
|
|
|
}
|
2024-02-19 18:00:44 +00:00
|
|
|
return errors.New("no sync keypair received")
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Check if the keypair saved on client is the same as the one on server
|
|
|
|
serverKp, err = serverAccountsAPI.GetKeypairByKeyUID(ctx, serverSeedPhraseKp.KeyUID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
clientKp, err = clientAccountsAPI.GetKeypairByKeyUID(ctx, serverSeedPhraseKp.KeyUID)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().True(serverKp.KeyUID == clientKp.KeyUID &&
|
|
|
|
serverKp.Name == clientKp.Name &&
|
|
|
|
serverKp.Type == clientKp.Type &&
|
|
|
|
serverKp.DerivedFrom == clientKp.DerivedFrom &&
|
|
|
|
serverKp.LastUsedDerivationIndex == clientKp.LastUsedDerivationIndex &&
|
|
|
|
serverKp.Clock == clientKp.Clock &&
|
|
|
|
len(serverKp.Accounts) == len(clientKp.Accounts) &&
|
|
|
|
len(serverKp.Keycards) == len(clientKp.Keycards) &&
|
|
|
|
len(serverKp.Keycards) == 0)
|
|
|
|
|
|
|
|
// Check server - server should contain keystore files for imported seed phrase
|
|
|
|
require.True(s.T(), containsKeystoreFile(serverKeystorePath, serverKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range serverKp.Accounts {
|
|
|
|
require.True(s.T(), containsKeystoreFile(serverKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check client - client should not contain keystore files for imported seed phrase
|
|
|
|
require.False(s.T(), containsKeystoreFile(clientKeystorePath, clientKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range clientKp.Accounts {
|
|
|
|
require.False(s.T(), containsKeystoreFile(clientKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Try to transfer keystore files from server to client
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
serverMessenger.SetLocalPairing(true)
|
|
|
|
clientMessenger.SetLocalPairing(true)
|
|
|
|
|
|
|
|
// prepare sender
|
|
|
|
var config = KeystoreFilesSenderServerConfig{
|
|
|
|
SenderConfig: &KeystoreFilesSenderConfig{
|
|
|
|
KeystoreFilesConfig: KeystoreFilesConfig{
|
|
|
|
KeystorePath: serverKeystorePath,
|
|
|
|
LoggedInKeyUID: serverActiveAccount.KeyUID,
|
|
|
|
Password: s.password,
|
2023-08-30 11:33:14 +00:00
|
|
|
},
|
2024-02-19 18:00:44 +00:00
|
|
|
KeypairsToExport: []string{serverKp.KeyUID},
|
|
|
|
},
|
|
|
|
ServerConfig: new(ServerConfig),
|
|
|
|
}
|
|
|
|
configBytes, err := json.Marshal(config)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
cs, err := StartUpKeystoreFilesSenderServer(serverBackend, string(configBytes))
|
|
|
|
require.NoError(s.T(), err)
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
// prepare receiver
|
|
|
|
clientPayloadSourceConfig := KeystoreFilesReceiverClientConfig{
|
|
|
|
ReceiverConfig: &KeystoreFilesReceiverConfig{
|
|
|
|
KeystoreFilesConfig: KeystoreFilesConfig{
|
|
|
|
KeystorePath: clientKeystorePath,
|
|
|
|
LoggedInKeyUID: clientActiveAccount.KeyUID,
|
|
|
|
Password: s.password,
|
2023-08-30 11:33:14 +00:00
|
|
|
},
|
2024-02-19 18:00:44 +00:00
|
|
|
KeypairsToImport: []string{clientKp.KeyUID},
|
|
|
|
},
|
|
|
|
ClientConfig: new(ClientConfig),
|
|
|
|
}
|
|
|
|
clientConfigBytes, err := json.Marshal(clientPayloadSourceConfig)
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
err = StartUpKeystoreFilesReceivingClient(clientBackend, cs, string(clientConfigBytes))
|
|
|
|
require.NoError(s.T(), err)
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
// Check server - server should contain keystore files for imported seed phrase
|
|
|
|
require.True(s.T(), containsKeystoreFile(serverKeystorePath, serverKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range serverKp.Accounts {
|
|
|
|
require.True(s.T(), containsKeystoreFile(serverKeystorePath, acc.Address.String()[2:]))
|
|
|
|
}
|
2023-08-30 11:33:14 +00:00
|
|
|
|
2024-02-19 18:00:44 +00:00
|
|
|
// Check client - client should contain keystore files for imported seed phrase
|
|
|
|
require.True(s.T(), containsKeystoreFile(clientKeystorePath, clientKp.DerivedFrom[2:]))
|
|
|
|
for _, acc := range clientKp.Accounts {
|
|
|
|
require.True(s.T(), containsKeystoreFile(clientKeystorePath, acc.Address.String()[2:]))
|
2023-08-30 11:33:14 +00:00
|
|
|
}
|
2024-02-19 18:00:44 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 00:32:16 +00:00
|
|
|
func (s *SyncDeviceSuite) TestPreventLoggedInAccountLocalPairingClientAsReceiver() {
|
2024-03-26 13:47:12 +00:00
|
|
|
clientTmpDir := filepath.Join(s.tmpdir, "client")
|
2023-09-21 00:32:16 +00:00
|
|
|
clientBackend := s.prepareBackendWithAccount("", clientTmpDir)
|
2024-03-26 13:47:12 +00:00
|
|
|
serverTmpDir := filepath.Join(s.tmpdir, "server")
|
2023-09-21 00:32:16 +00:00
|
|
|
serverBackend := s.prepareBackendWithAccount("", serverTmpDir)
|
|
|
|
defer func() {
|
|
|
|
s.NoError(serverBackend.Logout())
|
|
|
|
s.NoError(clientBackend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
serverActiveAccount, err := serverBackend.GetActiveAccount()
|
|
|
|
s.NoError(err)
|
2024-08-14 20:10:19 +00:00
|
|
|
serverKeystorePath := filepath.Join(serverTmpDir, api.DefaultKeystoreRelativePath, serverActiveAccount.KeyUID)
|
2023-09-21 00:32:16 +00:00
|
|
|
var config = &SenderServerConfig{
|
|
|
|
SenderConfig: &SenderConfig{
|
|
|
|
KeystorePath: serverKeystorePath,
|
|
|
|
DeviceType: "desktop",
|
|
|
|
KeyUID: serverActiveAccount.KeyUID,
|
|
|
|
Password: s.password,
|
|
|
|
},
|
|
|
|
ServerConfig: new(ServerConfig),
|
|
|
|
}
|
|
|
|
configBytes, err := json.Marshal(config)
|
|
|
|
s.NoError(err)
|
|
|
|
cs, err := StartUpSenderServer(serverBackend, string(configBytes))
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
clientPayloadSourceConfig := ReceiverClientConfig{
|
|
|
|
ReceiverConfig: &ReceiverConfig{
|
2024-08-14 20:10:19 +00:00
|
|
|
CreateAccount: &requests.CreateAccount{
|
|
|
|
RootDataDir: clientTmpDir,
|
|
|
|
KdfIterations: expectedKDFIterations,
|
|
|
|
DeviceName: "client-device",
|
|
|
|
},
|
2023-09-21 00:32:16 +00:00
|
|
|
},
|
|
|
|
ClientConfig: new(ClientConfig),
|
|
|
|
}
|
|
|
|
clientConfigBytes, err := json.Marshal(clientPayloadSourceConfig)
|
|
|
|
s.NoError(err)
|
|
|
|
err = StartUpReceivingClient(clientBackend, cs, string(clientConfigBytes))
|
|
|
|
s.ErrorIs(err, ErrLoggedInKeyUIDConflict)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SyncDeviceSuite) TestPreventLoggedInAccountLocalPairingClientAsSender() {
|
2024-03-26 13:47:12 +00:00
|
|
|
clientTmpDir := filepath.Join(s.tmpdir, "client")
|
2023-09-21 00:32:16 +00:00
|
|
|
clientBackend := s.prepareBackendWithAccount("", clientTmpDir)
|
2024-03-26 13:47:12 +00:00
|
|
|
serverTmpDir := filepath.Join(s.tmpdir, "server")
|
2023-09-21 00:32:16 +00:00
|
|
|
serverBackend := s.prepareBackendWithAccount("", serverTmpDir)
|
|
|
|
defer func() {
|
|
|
|
s.NoError(serverBackend.Logout())
|
|
|
|
s.NoError(clientBackend.Logout())
|
|
|
|
}()
|
|
|
|
|
|
|
|
serverPayloadSourceConfig := &ReceiverServerConfig{
|
|
|
|
ReceiverConfig: &ReceiverConfig{
|
2024-08-14 20:10:19 +00:00
|
|
|
CreateAccount: &requests.CreateAccount{
|
|
|
|
RootDataDir: serverTmpDir,
|
|
|
|
KdfIterations: expectedKDFIterations,
|
|
|
|
DeviceName: "server-device",
|
|
|
|
},
|
2023-09-21 00:32:16 +00:00
|
|
|
},
|
|
|
|
ServerConfig: new(ServerConfig),
|
|
|
|
}
|
2024-08-14 20:10:19 +00:00
|
|
|
|
2023-09-21 00:32:16 +00:00
|
|
|
serverConfigBytes, err := json.Marshal(serverPayloadSourceConfig)
|
|
|
|
s.NoError(err)
|
|
|
|
cs, err := StartUpReceiverServer(serverBackend, string(serverConfigBytes))
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
clientActiveAccount, err := clientBackend.GetActiveAccount()
|
|
|
|
s.NoError(err)
|
2024-08-14 20:10:19 +00:00
|
|
|
clientKeystorePath := filepath.Join(clientTmpDir, api.DefaultKeystoreRelativePath, clientActiveAccount.KeyUID)
|
2023-09-21 00:32:16 +00:00
|
|
|
clientPayloadSourceConfig := SenderClientConfig{
|
|
|
|
SenderConfig: &SenderConfig{
|
|
|
|
KeystorePath: clientKeystorePath,
|
|
|
|
DeviceType: "android",
|
|
|
|
KeyUID: clientActiveAccount.KeyUID,
|
|
|
|
Password: s.password,
|
|
|
|
},
|
|
|
|
ClientConfig: new(ClientConfig),
|
|
|
|
}
|
|
|
|
clientConfigBytes, err := json.Marshal(clientPayloadSourceConfig)
|
|
|
|
s.NoError(err)
|
|
|
|
err = StartUpSendingClient(clientBackend, cs, string(clientConfigBytes))
|
|
|
|
s.ErrorContains(err, "[client] status not ok when sending account data, received '500 Internal Server Error'")
|
|
|
|
}
|