From c7aebfeed36754e03d002cda03ff3339d3d1d2f7 Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 18 May 2023 22:00:55 +0800 Subject: [PATCH] Fix/mobile issue 15899 : error when trying login under updated password (#3493) * fix: unable to reset password for newly created account using CreateAccountAndLogin * remove unnecessary print * add TestCreateAccountAndLogin * update TestCreateAccountAndLogin * bump version --- VERSION | 2 +- api/create_account_and_login_test.go | 62 ++++++++++++++++++++++++++++ api/geth_backend.go | 6 ++- protocol/requests/create_account.go | 6 --- 4 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 api/create_account_and_login_test.go diff --git a/VERSION b/VERSION index f9b8e50eb..790507559 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.151.10 +0.151.11 diff --git a/api/create_account_and_login_test.go b/api/create_account_and_login_test.go new file mode 100644 index 000000000..9d98e2daf --- /dev/null +++ b/api/create_account_and_login_test.go @@ -0,0 +1,62 @@ +package api + +import ( + "encoding/json" + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/status-im/status-go/protocol/requests" +) + +func TestCreateAccountAndLogin(t *testing.T) { + rootDir := t.TempDir() + t.Logf("TestCreateAccountAndLogin: rootDir: %s", rootDir) + + requestJSONTemplateString := ` +{ + "upstreamConfig":"https://eth-archival.gateway.pokt.network/v1/lb/3ef2018191814b7e1009b8d9", + "openseaAPIKey":"", + "wakuV2Nameserver":"1.1.1.1", + "mnemonic":null, + "verifyENSContractAddress":"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", + "backupDisabledDataDir":"%s", + "password":"0x20756cad9b728c8225fd8cedb6badaf8731e174506950219ea657cd54f35f46c", + "displayName":"%s", + "logEnabled":true, + "verifyTransactionChainID":1, + "currentNetwork":"mainnet_rpc", + "customizationColor":"blue", + "previewPrivacy":true, + "verifyTransactionURL":"https://eth-archival.gateway.pokt.network/v1/lb/3ef2018191814b7e1009b8d9", + "imagePath":null, + "verifyENSURL":"https://eth-archival.gateway.pokt.network/v1/lb/3ef2018191814b7e1009b8d9", + "logLevel":"INFO", + "logFilePath":"%s", + "networkId":1 +} +` + requestJSON := fmt.Sprintf(requestJSONTemplateString, rootDir, "user1", rootDir) + var request requests.CreateAccount + err := json.Unmarshal([]byte(requestJSON), &request) + require.NoError(t, err) + statusBackend := NewGethStatusBackend() + err = statusBackend.CreateAccountAndLogin(&request) + require.NoError(t, err) + t.Logf("TestCreateAccountAndLogin: create account user1 and login successfully") + // wait waku node start working + time.Sleep(2 * time.Second) + + t.Logf("TestCreateAccountAndLogin: logouting") + err = statusBackend.Logout() + require.NoError(t, err) + t.Logf("TestCreateAccountAndLogin: logout done") + + requestJSON = fmt.Sprintf(requestJSONTemplateString, rootDir, "user2", rootDir) + err = json.Unmarshal([]byte(requestJSON), &request) + require.NoError(t, err) + err = statusBackend.CreateAccountAndLogin(&request) + require.NoError(t, err) +} diff --git a/api/geth_backend.go b/api/geth_backend.go index 7f346882e..91f594960 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -744,7 +744,7 @@ func (b *GethStatusBackend) GetKeyUIDByMnemonic(mnemonic string) (string, error) } func (b *GethStatusBackend) generateOrImportAccount(mnemonic string, request *requests.CreateAccount) error { - keystoreDir := filepath.Join(request.BackupDisabledDataDir, keystoreRelativePath) + keystoreDir := keystoreRelativePath b.UpdateRootDataDir(request.BackupDisabledDataDir) err := b.OpenAccounts() @@ -779,7 +779,7 @@ func (b *GethStatusBackend) generateOrImportAccount(mnemonic string, request *re userKeyStoreDir := filepath.Join(keystoreDir, info.KeyUID) // Initialize keystore dir with account - if err := b.accountManager.InitKeystore(userKeyStoreDir); err != nil { + if err := b.accountManager.InitKeystore(filepath.Join(b.rootDataDir, userKeyStoreDir)); err != nil { return err } @@ -813,6 +813,8 @@ func (b *GethStatusBackend) generateOrImportAccount(mnemonic string, request *re return err } + // when we set nodeConfig.KeyStoreDir, value of nodeConfig.KeyStoreDir should not contain the rootDataDir + // loadNodeConfig will add rootDataDir to nodeConfig.KeyStoreDir nodeConfig.KeyStoreDir = userKeyStoreDir walletDerivedAccount := derivedAddresses[pathDefaultWallet] diff --git a/protocol/requests/create_account.go b/protocol/requests/create_account.go index adb6f6244..efcd0c2c0 100644 --- a/protocol/requests/create_account.go +++ b/protocol/requests/create_account.go @@ -16,8 +16,6 @@ type CreateAccount struct { Password string `json:"password"` ImagePath string `json:"imagePath"` CustomizationColor string `json:"customizationColor"` - // RootKeystoreDir is the directory where keys are stored - RootKeystoreDir string `json:"rootKeystoreDir"` // BackupDisabledDataDir is the directory where backup is disabled BackupDisabledDataDir string `json:"backupDisabledDataDir"` @@ -53,10 +51,6 @@ func ValidateAccountCreationRequest(c CreateAccount) error { return ErrCreateAccountInvalidCustomizationColor } - if len(c.RootKeystoreDir) == 0 { - return ErrCreateAccountInvalidRootKeystoreDir - } - if len(c.BackupDisabledDataDir) == 0 { return ErrCreateAccountInvalidBackupDisabledDataDir }