From f863a55b4017008d16dc7474671b0e28468e6809 Mon Sep 17 00:00:00 2001 From: Evgenii Sokovikov Date: Mon, 5 Aug 2019 18:30:36 +0400 Subject: [PATCH] password validation on the first step --- src/action/auth-mobile.js | 2 +- src/action/wallet.js | 14 +++++++++++++- src/view/set-password-confirm.js | 6 ++++-- src/view/set-password.js | 2 +- stories/screen-story.js | 2 +- test/unit/action/auth-mobile.spec.js | 2 +- test/unit/action/wallet.spec.js | 10 +++++----- 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/action/auth-mobile.js b/src/action/auth-mobile.js index 4d86a963b..596340431 100644 --- a/src/action/auth-mobile.js +++ b/src/action/auth-mobile.js @@ -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(); } /** diff --git a/src/action/wallet.js b/src/action/wallet.js index 8606c591d..7a67ec896 100644 --- a/src/action/wallet.js +++ b/src/action/wallet.js @@ -201,13 +201,25 @@ class WalletAction { this.initSetPassword(); } + checkNewPassword() { + 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} */ - async checkNewPassword() { + async checkNewPasswordConfirmation() { const { newPassword, passwordVerify } = this._store.wallet; let errorMsg; if (!newPassword || newPassword.length < MIN_PASSWORD_LENGTH) { diff --git a/src/view/set-password-confirm.js b/src/view/set-password-confirm.js index 2d3c2847e..15525a39d 100644 --- a/src/view/set-password-confirm.js +++ b/src/view/set-password-confirm.js @@ -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()} /> - wallet.checkNewPassword()}>Next + wallet.checkNewPasswordConfirmation()}> + Next + ); diff --git a/src/view/set-password.js b/src/view/set-password.js index a6ee79209..6e71470d1 100644 --- a/src/view/set-password.js +++ b/src/view/set-password.js @@ -37,7 +37,7 @@ const SetPasswordView = ({ store, wallet, nav }) => ( newCopy={store.newPasswordCopy} success={store.newPasswordSuccess} /> - nav.goSetPasswordConfirm()}>Next + wallet.checkNewPassword()}>Next ); diff --git a/stories/screen-story.js b/stories/screen-story.js index f32695265..db3910464 100644 --- a/stories/screen-story.js +++ b/stories/screen-story.js @@ -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'); diff --git a/test/unit/action/auth-mobile.spec.js b/test/unit/action/auth-mobile.spec.js index 9e0a64d0d..1576584ba 100644 --- a/test/unit/action/auth-mobile.spec.js +++ b/test/unit/action/auth-mobile.spec.js @@ -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'); }); }); diff --git a/test/unit/action/wallet.spec.js b/test/unit/action/wallet.spec.js index e3f088d10..3ca0a5c11 100644 --- a/test/unit/action/wallet.spec.js +++ b/test/unit/action/wallet.spec.js @@ -206,7 +206,7 @@ describe('Action Wallet Unit Tests', () => { }); }); - describe('checkNewPassword()', () => { + describe('checkNewPasswordConfirmation()', () => { beforeEach(() => { sandbox.stub(wallet, 'initWallet'); sandbox.stub(wallet, 'initSetPassword'); @@ -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'], @@ -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'); @@ -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'); @@ -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,