Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

password validation on the first step #1284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/action/auth-mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class AuthAction {
await this._setToKeyStore(PASS, newPass);
this._store.wallet.newPassword = newPass;
this._store.wallet.passwordVerify = newPass;
await this._wallet.checkNewPassword();
await this._wallet.checkNewPasswordConfirmation();
}

/**
Expand Down
14 changes: 13 additions & 1 deletion src/action/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,25 @@ class WalletAction {
this.initSetPassword();
}

checkNewPassword() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add method documentation if PR in general is good

const { newPassword } = this._store.wallet;
if (!newPassword || newPassword.length < MIN_PASSWORD_LENGTH) {
this.initSetPassword();
this._notification.display({
msg: `Set a password with at least ${MIN_PASSWORD_LENGTH} characters.`,
});
} else {
this._nav.goSetPasswordConfirm();
}
}

/**
* Check the wallet password that was chosen by the user has the correct
* length and that it was also entered correctly twice to make sure that
* there was no typo.
* @return {Promise<undefined>}
*/
async checkNewPassword() {
async checkNewPasswordConfirmation() {
const { newPassword, passwordVerify } = this._store.wallet;
let errorMsg;
if (!newPassword || newPassword.length < MIN_PASSWORD_LENGTH) {
Expand Down
6 changes: 4 additions & 2 deletions src/view/set-password-confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ const SetPasswordConfirmView = ({ store, wallet }) => (
placeholder="Confirm password"
password={store.wallet.passwordVerify}
onChangeText={password => wallet.setPasswordVerify({ password })}
onSubmitEditing={() => wallet.checkNewPassword()}
onSubmitEditing={() => wallet.checkNewPasswordConfirmation()}
/>
<GlasButton onPress={() => wallet.checkNewPassword()}>Next</GlasButton>
<GlasButton onPress={() => wallet.checkNewPasswordConfirmation()}>
Next
</GlasButton>
</MainContent>
</SplitBackground>
);
Expand Down
2 changes: 1 addition & 1 deletion src/view/set-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const SetPasswordView = ({ store, wallet, nav }) => (
newCopy={store.newPasswordCopy}
success={store.newPasswordSuccess}
/>
<GlasButton onPress={() => nav.goSetPasswordConfirm()}>Next</GlasButton>
<GlasButton onPress={() => wallet.checkNewPassword()}>Next</GlasButton>
</MainContent>
</SplitBackground>
);
Expand Down
2 changes: 1 addition & 1 deletion stories/screen-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const autopilot = sinon.createStubInstance(AtplAction);
sinon.stub(wallet, 'update');
sinon.stub(wallet, 'checkSeed');
sinon.stub(wallet, 'checkNewPassword');
sinon.stub(wallet, 'checkPassword');
sinon.stub(wallet, 'checkPasswordConfirmation');
sinon.stub(wallet, 'getExchangeRate');
const transaction = new TransactionAction(store, grpc, nav, notify);
sinon.stub(transaction, 'update');
Expand Down
2 changes: 1 addition & 1 deletion test/unit/action/auth-mobile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ describe('Action AuthMobile Unit Tests', () => {
);
expect(store.wallet.newPassword, 'to match', /^[0-9a-f]{64}$/);
expect(store.wallet.passwordVerify, 'to match', /^[0-9a-f]{64}$/);
expect(wallet.checkNewPassword, 'was called once');
expect(wallet.checkNewPasswordConfirmation, 'was called once');
});
});

Expand Down
10 changes: 5 additions & 5 deletions test/unit/action/wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('Action Wallet Unit Tests', () => {
});
});

describe('checkNewPassword()', () => {
describe('checkNewPasswordConfirmation()', () => {
beforeEach(() => {
sandbox.stub(wallet, 'initWallet');
sandbox.stub(wallet, 'initSetPassword');
Expand All @@ -218,7 +218,7 @@ describe('Action Wallet Unit Tests', () => {
it('init wallet if passwords match', async () => {
wallet.setNewPassword({ password: 'secret123' });
wallet.setPasswordVerify({ password: 'secret123' });
await wallet.checkNewPassword();
await wallet.checkNewPasswordConfirmation();
expect(wallet.initWallet, 'was called with', {
walletPassword: 'secret123',
seedMnemonic: ['foo', 'bar', 'baz'],
Expand All @@ -229,7 +229,7 @@ describe('Action Wallet Unit Tests', () => {
it('display notification if input does not match', async () => {
wallet.setNewPassword({ password: 'secret123' });
wallet.setPasswordVerify({ password: 'secret1234' });
await wallet.checkNewPassword();
await wallet.checkNewPasswordConfirmation();
expect(wallet.initWallet, 'was not called');
expect(wallet.initSetPassword, 'was called once');
expect(notification.display, 'was called once');
Expand All @@ -238,7 +238,7 @@ describe('Action Wallet Unit Tests', () => {
it('display notification if password is too short', async () => {
wallet.setNewPassword({ password: 'secret' });
wallet.setPasswordVerify({ password: 'secret' });
await wallet.checkNewPassword();
await wallet.checkNewPasswordConfirmation();
expect(wallet.initWallet, 'was not called');
expect(wallet.initSetPassword, 'was called once');
expect(notification.display, 'was called once');
Expand All @@ -250,7 +250,7 @@ describe('Action Wallet Unit Tests', () => {
store.settings.restoring = true;
wallet.setNewPassword({ password: 'secret123' });
wallet.setPasswordVerify({ password: 'secret123' });
await wallet.checkNewPassword();
await wallet.checkNewPasswordConfirmation();
expect(wallet.initWallet, 'was called with', {
walletPassword: 'secret123',
seedMnemonic: restoreSeed,
Expand Down