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
This commit is contained in:
frank 2023-05-18 22:00:55 +08:00 committed by GitHub
parent 0f0b6f7578
commit c7aebfeed3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 9 deletions

View File

@ -1 +1 @@
0.151.10
0.151.11

View File

@ -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)
}

View File

@ -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]

View File

@ -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
}