chore(multiaccount)_: Provide geth_backend API to accept terms

This commit is contained in:
Icaro Motta 2024-08-23 16:18:24 -03:00
parent 1682f95ece
commit 770530cf0b
No known key found for this signature in database
GPG Key ID: 009557D9D014DF07
4 changed files with 66 additions and 0 deletions

View File

@ -869,6 +869,7 @@ func TestLoginAccount(t *testing.T) {
require.NotEmpty(t, accounts[0].KeyUID)
require.Equal(t, acc.KeyUID, accounts[0].KeyUID)
require.True(t, acc.HasAcceptedTerms)
loginAccountRequest := &requests.Login{
KeyUID: accounts[0].KeyUID,
@ -1760,6 +1761,32 @@ func TestRestoreAccountAndLogin(t *testing.T) {
require.Empty(t, mnemonic)
}
func TestAcceptTerms(t *testing.T) {
tmpdir := t.TempDir()
b := NewGethStatusBackend()
conf, err := params.NewNodeConfig(tmpdir, 1777)
require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
b.UpdateRootDataDir(conf.DataDir)
require.NoError(t, b.OpenAccounts())
nameserver := "8.8.8.8"
createAccountRequest := &requests.CreateAccount{
DisplayName: "some-display-name",
CustomizationColor: "#ffffff",
Password: "some-password",
RootDataDir: tmpdir,
LogFilePath: tmpdir + "/log",
WakuV2Nameserver: &nameserver,
WakuV2Fleet: "status.staging",
}
_, err = b.CreateAccountAndLogin(createAccountRequest)
require.NoError(t, err)
err = b.AcceptTerms()
require.NoError(t, err)
}
func TestCreateAccountPathsValidation(t *testing.T) {
tmpdir := t.TempDir()

View File

@ -238,6 +238,24 @@ func (b *GethStatusBackend) GetAccounts() ([]multiaccounts.Account, error) {
return b.multiaccountsDB.GetAccounts()
}
func (b *GethStatusBackend) AcceptTerms() error {
b.mu.Lock()
defer b.mu.Unlock()
if b.multiaccountsDB == nil {
return errors.New("accounts db wasn't initialized")
}
accounts, err := b.multiaccountsDB.GetAccounts()
if err != nil {
return err
}
if len(accounts) == 0 {
return errors.New("accounts is empty")
}
return b.multiaccountsDB.UpdateHasAcceptedTerms(accounts[0].KeyUID, true)
}
func (b *GethStatusBackend) getAccountByKeyUID(keyUID string) (*multiaccounts.Account, error) {
b.mu.Lock()
defer b.mu.Unlock()
@ -1576,6 +1594,14 @@ func (b *GethStatusBackend) buildAccount(request *requests.CreateAccount, input
acc.KDFIterations = dbsetup.ReducedKDFIterationsNumber
}
count, err := b.multiaccountsDB.GetAccountsCount()
if err != nil {
return nil, err
}
if count == 0 {
acc.HasAcceptedTerms = true
}
if request.ImagePath != "" {
imageCropRectangle := request.ImageCropRectangle
if imageCropRectangle == nil {

View File

@ -141,6 +141,11 @@ func (s *OldMobileUserUpgradingFromV1ToV2Test) TestLoginAndMigrationsStillWorkWi
s.Require().True(len(keyKps[0].Accounts) == 1)
info, err = generator.LoadAccount(keyKps[0].Accounts[0].Address.Hex(), oldMobileUserPasswd)
s.Require().NoError(err)
// The user should manually accept terms, so we make sure we don't set it
// automatically by mistake.
s.Require().False(info.ToMultiAccount().HasAcceptedTerms)
s.Require().Equal(keyKps[0].KeyUID, info.KeyUID)
s.Require().Equal(keyKps[0].Accounts[0].KeyUID, info.KeyUID)
info, err = generator.ImportPrivateKey("c3ad0b50652318f845565c13761e5369ce75dcbc2a94616e15b829d4b07410fe")

View File

@ -349,6 +349,14 @@ func CreateAccountAndLogin(requestJSON string) string {
return makeJSONResponse(nil)
}
func AcceptTerms() string {
err := statusBackend.AcceptTerms()
if err != nil {
return makeJSONResponse(err)
}
return makeJSONResponse(nil)
}
func LoginAccount(requestJSON string) string {
var request requests.Login
err := json.Unmarshal([]byte(requestJSON), &request)