-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bypass 2FA for accounts which haven't yet logged in
ref ENG-1681
- Loading branch information
Showing
6 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,8 @@ describe('Session controller', function () { | |
const fakeUser = models.User.forge({}); | ||
sinon.stub(models.User, 'check') | ||
.resolves(fakeUser); | ||
sinon.stub(models.User, 'getByEmail') | ||
.resolves(fakeUser); | ||
|
||
const createSessionStub = sinon.stub(sessionServiceMiddleware, 'createSession'); | ||
|
||
|
@@ -88,6 +90,8 @@ describe('Session controller', function () { | |
const fakeUser = models.User.forge({}); | ||
sinon.stub(models.User, 'check') | ||
.resolves(fakeUser); | ||
sinon.stub(models.User, 'getByEmail') | ||
.resolves(fakeUser); | ||
|
||
sinon.stub(sessionServiceMiddleware, 'createSession'); | ||
|
||
|
@@ -102,6 +106,74 @@ describe('Session controller', function () { | |
should.equal(fakeNext.args[0][0], resetError); | ||
}); | ||
}); | ||
|
||
it('it creates a verified session when the user has not logged in before', function () { | ||
const fakeReq = { | ||
brute: { | ||
reset: sinon.stub().callsArg(0) | ||
} | ||
}; | ||
const fakeRes = {}; | ||
const fakeNext = () => {}; | ||
const fakeUser = models.User.forge({}); | ||
sinon.stub(models.User, 'check') | ||
.resolves(fakeUser); | ||
sinon.stub(models.User, 'getByEmail') | ||
.resolves(fakeUser); | ||
|
||
const createSessionStub = sinon.stub(sessionServiceMiddleware, 'createSession'); | ||
|
||
return sessionController.add({data: { | ||
username: '[email protected]', | ||
password: 'qu33nRul35' | ||
}}).then((fn) => { | ||
fn(fakeReq, fakeRes, fakeNext); | ||
}).then(function () { | ||
should.equal(fakeReq.brute.reset.callCount, 1); | ||
|
||
const createSessionStubCall = createSessionStub.getCall(0); | ||
should.equal(fakeReq.user, fakeUser); | ||
should.equal(createSessionStubCall.args[0], fakeReq); | ||
should.equal(createSessionStubCall.args[1], fakeRes); | ||
should.equal(createSessionStubCall.args[2], fakeNext); | ||
|
||
should.equal(fakeReq.skipVerification, true); | ||
}); | ||
}); | ||
|
||
it('it creates a non-verified session when the user has logged in before', function () { | ||
const fakeReq = { | ||
brute: { | ||
reset: sinon.stub().callsArg(0) | ||
} | ||
}; | ||
const fakeRes = {}; | ||
const fakeNext = () => {}; | ||
const fakeUser = models.User.forge({last_seen: new Date()}); | ||
sinon.stub(models.User, 'check') | ||
.resolves(fakeUser); | ||
sinon.stub(models.User, 'getByEmail') | ||
.resolves(fakeUser); | ||
|
||
const createSessionStub = sinon.stub(sessionServiceMiddleware, 'createSession'); | ||
|
||
return sessionController.add({data: { | ||
username: '[email protected]', | ||
password: 'qu33nRul35' | ||
}}).then((fn) => { | ||
fn(fakeReq, fakeRes, fakeNext); | ||
}).then(function () { | ||
should.equal(fakeReq.brute.reset.callCount, 1); | ||
|
||
const createSessionStubCall = createSessionStub.getCall(0); | ||
should.equal(fakeReq.user, fakeUser); | ||
should.equal(createSessionStubCall.args[0], fakeReq); | ||
should.equal(createSessionStubCall.args[1], fakeRes); | ||
should.equal(createSessionStubCall.args[2], fakeNext); | ||
|
||
should.equal(fakeReq.skipVerification, false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#delete', function () { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,7 +134,8 @@ DataGenerator.Content = { | |
email: '[email protected]', | ||
password: 'Sl1m3rson99', | ||
profile_image: 'https://example.com/super_photo.jpg', | ||
paid_subscription_canceled_notification: true | ||
paid_subscription_canceled_notification: true, | ||
last_seen: moment().subtract(1, 'hour').toDate() | ||
}, | ||
{ | ||
// admin | ||
|