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

Commit

Permalink
remove 2fa code (#51)
Browse files Browse the repository at this point in the history
🐿 v2.7.0
  • Loading branch information
jkerr321 authored Feb 9, 2018
1 parent 1197827 commit 0b4461f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 61 deletions.
38 changes: 14 additions & 24 deletions lib/sessionClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,23 @@ options.headers = Object.assign({}, options.headers, {'X-API-KEY': config.API_GA
* @param {String} sessionKey - a FTsession_s token
* @returns {Promise} response -
*/
function verify (sessionKey, flags) {
function verify (sessionKey) {
const operation = 'sessionClient.verify';
log.debug({operation});

if (flags && flags.kat2fa) {
const url = `https://api.ft.com/sessions/s/${sessionKey}`;
return fetch(url, Object.assign({}, options))
.then(helpers.parseJsonRes)
.then(res => {
if (res.mfa !== true) {
const err = new clientErrors.ClientError('not a 2FA authenticated session');
err.status = 401;
log.error({ operation, msg: 'not a 2FA authenticated session' }, err);
throw err;
}
log.debug({ operation, res: 'success' });
return res;
});
} else { //TODO delete this block when 2fa becomes default in next major version
const url = `${config.API_GATEWAY_HOST}/sessions/${sessionKey}`;
return fetch(url, Object.assign({}, options))
.then(helpers.parseJsonRes)
.then(res => {
log.debug({ operation, res: 'success'});
return res;
});
}
const url = `https://api.ft.com/sessions/s/${sessionKey}`;
return fetch(url, Object.assign({}, options))
.then(helpers.parseJsonRes)
.then(res => {
if (res.mfa !== true) {
const err = new clientErrors.ClientError('not a 2FA authenticated session');
err.status = 401;
log.error({ operation, msg: 'not a 2FA authenticated session' }, err);
throw err;
}
log.debug({ operation, res: 'success' });
return res;
});
}

/**
Expand Down
41 changes: 4 additions & 37 deletions test/sessionClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,58 +35,25 @@ describe('Session Client', () => {

describe('verify', () => {

it('Should get user login info for a valid session when kat2fa flag is off', done => {
nock(baseUrl)
.get(`/sessions/${uuids.validFTSessionSecure}`)
.reply(200, () => require('./mocks/fixtures/sessionVerify'));

sessionClient.verify(uuids.validFTSessionSecure)
.then(response => {
expect(response).to.be.an('object');
expectOwnProperties(response, ['uuid', 'creationTime', 'rememberMe']);
expect(response.uuid).to.equal(uuids.validUser);

done();
})
.catch(done);
});

it('Should throw a NotFoundError for an invalid session when kat2fa flag is off', done => {
nock(baseUrl)
.get(`/sessions/${uuids.invalidFTSession}`)
.reply(404, () => null);

sessionClient.verify(uuids.invalidFTSession)
.then(() => {
done(new Error('Nothing thrown'));
})
.catch(err => {
expect(err).to.be.an.instanceof(clientErrors.NotFoundError);

done();
});
});


it('Should get user login info for a valid secure session when kat2fa flag is on', () => {
it('Should get user login info for a valid secure session', () => {
nock(baseUrl)
.get(`/sessions/s/${uuids.validFTSessionSecure}`)
.reply(200, () => require('./mocks/fixtures/sessionVerify'));

return sessionClient.verify(uuids.validFTSessionSecure, { kat2fa: true })
return sessionClient.verify(uuids.validFTSessionSecure)
.then(response => {
expect(response).to.be.an('object');
expectOwnProperties(response, ['uuid', 'creationTime', 'rememberMe']);
expect(response.uuid).to.equal(uuids.validUser);
});
});

it('Should throw a NotFoundError for an invalid session when kat2fa flag is on', done => {
it('Should throw a NotFoundError for an invalid session', done => {
nock(baseUrl)
.get(`/sessions/s/${uuids.invalidFTSession}`)
.reply(404, () => null);

sessionClient.verify(uuids.invalidFTSession, { kat2fa: true })
sessionClient.verify(uuids.invalidFTSession)
.then(() => {
done(new Error('Nothing thrown'));
})
Expand Down

0 comments on commit 0b4461f

Please sign in to comment.