Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Prevent regular login with non-bip39-passphrase and ENTER-key
Browse files Browse the repository at this point in the history
Closes #112
  • Loading branch information
slaweet committed Apr 18, 2017
1 parent a0cb4d7 commit 22c5e10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/app/components/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -65,6 +67,7 @@ app.component('login', {
} else {
this.valid = 1;
}
return this.valid;
}

startGenratingNewPassphrase() {
Expand Down
10 changes: 6 additions & 4 deletions src/test/components/login/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ describe('Login controller', () => {
let $scope;
let controller;
let $componentController;
let testPassphrase;

beforeEach(inject((_$componentController_, _$rootScope_) => {
$componentController = _$componentController_;
$rootScope = _$rootScope_;
}));

beforeEach(() => {
testPassphrase = 'glow two glimpse camp aware tip brief confirm similar code float defense';
$scope = $rootScope.$new();
controller = $componentController('login', $scope, { });
controller.onLogin = function () {};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -200,15 +204,13 @@ 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();
expect(controller.input_passphrase).to.equal(testPassphrase);
});

it('does nothing if cooke called passphrase not present', () => {
const testPassphrase = 'test passphrase';
controller.input_passphrase = testPassphrase;
const mock = sinon.mock(controller.$cookies);

Expand Down

0 comments on commit 22c5e10

Please sign in to comment.