From 22c5e104e0ace0d10d36161e3f93ec8dcbbf73a9 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Tue, 18 Apr 2017 11:24:46 +0200 Subject: [PATCH] Prevent regular login with non-bip39-passphrase and ENTER-key Closes #112 --- src/app/components/login/login.js | 9 ++++++--- src/test/components/login/login.spec.js | 10 ++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app/components/login/login.js b/src/app/components/login/login.js index bbbbbd31b..3f7a87213 100644 --- a/src/app/components/login/login.js +++ b/src/app/components/login/login.js @@ -49,10 +49,12 @@ app.component('login', { } doTheLogin() { - this.passphrase = login.fixCaseAndWhitespace(this.input_passphrase); + if (this.isValidPassphrase(this.input_passphrase) === 1) { + this.passphrase = login.fixCaseAndWhitespace(this.input_passphrase); - this.reset(); - this.$timeout(this.onLogin); + this.reset(); + this.$timeout(this.onLogin); + } } isValidPassphrase(value) { @@ -65,6 +67,7 @@ app.component('login', { } else { this.valid = 1; } + return this.valid; } startGenratingNewPassphrase() { diff --git a/src/test/components/login/login.spec.js b/src/test/components/login/login.spec.js index 38889290a..7721e3a2e 100644 --- a/src/test/components/login/login.spec.js +++ b/src/test/components/login/login.spec.js @@ -59,6 +59,7 @@ describe('Login controller', () => { let $scope; let controller; let $componentController; + let testPassphrase; beforeEach(inject((_$componentController_, _$rootScope_) => { $componentController = _$componentController_; @@ -66,6 +67,7 @@ describe('Login controller', () => { })); beforeEach(() => { + testPassphrase = 'glow two glimpse camp aware tip brief confirm similar code float defense'; $scope = $rootScope.$new(); controller = $componentController('login', $scope, { }); controller.onLogin = function () {}; @@ -151,18 +153,20 @@ describe('Login controller', () => { describe('$scope.doTheLogin()', () => { it('sets this.phassphrase as this.input_passphrase processed by fixCaseAndWhitespace', () => { - controller.input_passphrase = '\tTEST PassPHrASe '; + controller.input_passphrase = '\tGLOW two GliMpse camp aware tip brief confirm similar code float defense '; controller.doTheLogin(); - expect(controller.passphrase).to.equal('test passphrase'); + expect(controller.passphrase).to.equal('glow two glimpse camp aware tip brief confirm similar code float defense'); }); it('calls this.reset()', () => { + controller.input_passphrase = testPassphrase; const spy = sinon.spy(controller, 'reset'); controller.doTheLogin(); expect(spy).to.have.been.calledWith(); }); it('sets timeout with this.onLogin', () => { + controller.input_passphrase = testPassphrase; const spy = sinon.spy(controller, '$timeout'); controller.doTheLogin(); expect(spy).to.have.been.calledWith(controller.onLogin); @@ -200,7 +204,6 @@ describe('Login controller', () => { describe('$scope.devTestAccount()', () => { it('sets input_passphrase from cookie called passphrase if present', () => { - const testPassphrase = 'test passphrase'; const mock = sinon.mock(controller.$cookies); mock.expects('get').returns(testPassphrase); controller.devTestAccount(); @@ -208,7 +211,6 @@ describe('Login controller', () => { }); it('does nothing if cooke called passphrase not present', () => { - const testPassphrase = 'test passphrase'; controller.input_passphrase = testPassphrase; const mock = sinon.mock(controller.$cookies);