-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ api: removal of FT_ENABLE_CERTIF_TOKEN_SCOPE
- Loading branch information
Showing
4 changed files
with
66 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,77 +215,44 @@ describe('Unit | Shared | Domain | Services | Token Service', function () { | |
}); | ||
|
||
describe('#extractCertificationResultsLink', function () { | ||
context('when FT_ENABLE_CERTIF_TOKEN_SCOPE is true', function () { | ||
beforeEach(function () { | ||
sinon.stub(settings.featureToggles, 'isCertificationTokenScopeEnabled').value(true); | ||
}); | ||
context('when the scope is valid', function () { | ||
it('should return the session id', function () { | ||
// given | ||
const token = jsonwebtoken.sign( | ||
{ | ||
session_id: 12345, | ||
scope: 'certificationResultsLink', | ||
}, | ||
settings.authentication.secret, | ||
{ expiresIn: config.jwtConfig.certificationResults.tokenLifespan }, | ||
); | ||
|
||
context('when the scope is valid', function () { | ||
it('should return the session id', function () { | ||
// given | ||
const token = jsonwebtoken.sign( | ||
{ | ||
session_id: 12345, | ||
scope: 'certificationResultsLink', | ||
}, | ||
settings.authentication.secret, | ||
{ expiresIn: config.jwtConfig.certificationResults.tokenLifespan }, | ||
); | ||
|
||
// when | ||
const tokenData = tokenService.extractCertificationResultsLink(token); | ||
|
||
// then | ||
expect(tokenData).to.deep.equal({ | ||
sessionId: 12345, | ||
}); | ||
}); | ||
}); | ||
// when | ||
const tokenData = tokenService.extractCertificationResultsLink(token); | ||
|
||
context('when the scope is invalid', function () { | ||
it('should throw an InvalidSessionResultTokenError', async function () { | ||
// given | ||
const invalidToken = jsonwebtoken.sign( | ||
{ | ||
session_id: 12345, | ||
}, | ||
settings.authentication.secret, | ||
{ expiresIn: '30d' }, | ||
); | ||
|
||
// when | ||
const error = await catchErr(tokenService.extractCertificationResultsLink)(invalidToken); | ||
|
||
// then | ||
expect(error).to.be.an.instanceof(InvalidSessionResultTokenError); | ||
// then | ||
expect(tokenData).to.deep.equal({ | ||
sessionId: 12345, | ||
}); | ||
}); | ||
}); | ||
|
||
context('when FT_ENABLE_CERTIF_TOKEN_SCOPE is false', function () { | ||
beforeEach(function () { | ||
sinon.stub(settings.featureToggles, 'isCertificationTokenScopeEnabled').value(false); | ||
}); | ||
context('when the scope is invalid', function () { | ||
it('should throw an InvalidSessionResultTokenError', async function () { | ||
// given | ||
const invalidToken = jsonwebtoken.sign( | ||
{ | ||
session_id: 12345, | ||
}, | ||
settings.authentication.secret, | ||
{ expiresIn: '30d' }, | ||
); | ||
|
||
context('when there is no scope', function () { | ||
it('should return the session id', function () { | ||
// given | ||
const token = jsonwebtoken.sign( | ||
{ | ||
session_id: 12345, | ||
}, | ||
settings.authentication.secret, | ||
{ expiresIn: '30d' }, | ||
); | ||
|
||
// when | ||
const tokenData = tokenService.extractCertificationResultsLink(token); | ||
|
||
// then | ||
expect(tokenData).to.deep.equal({ | ||
sessionId: 12345, | ||
}); | ||
}); | ||
// when | ||
const error = await catchErr(tokenService.extractCertificationResultsLink)(invalidToken); | ||
|
||
// then | ||
expect(error).to.be.an.instanceof(InvalidSessionResultTokenError); | ||
}); | ||
}); | ||
|
||
|
@@ -322,76 +289,44 @@ describe('Unit | Shared | Domain | Services | Token Service', function () { | |
}); | ||
|
||
describe('#extractCertificationResultsByRecipientEmailLink', function () { | ||
context('when FT_ENABLE_CERTIF_TOKEN_SCOPE is true', function () { | ||
beforeEach(function () { | ||
sinon.stub(settings.featureToggles, 'isCertificationTokenScopeEnabled').value(true); | ||
}); | ||
|
||
context('when the scope is valid', function () { | ||
it('should return the session id and result recipient email if the token is valid', function () { | ||
// given | ||
const token = jsonwebtoken.sign( | ||
{ | ||
result_recipient_email: '[email protected]', | ||
session_id: 12345, | ||
scope: 'certificationResultsByRecipientEmailLink', | ||
}, | ||
settings.authentication.secret, | ||
{ expiresIn: '30d' }, | ||
); | ||
|
||
// when | ||
const tokenData = tokenService.extractCertificationResultsByRecipientEmailLink(token); | ||
|
||
// then | ||
expect(tokenData).to.deep.equal({ | ||
resultRecipientEmail: '[email protected]', | ||
sessionId: 12345, | ||
}); | ||
}); | ||
}); | ||
|
||
context('when the scope is invalid', function () { | ||
it('should throw an InvalidResultRecipientTokenError', async function () { | ||
// given | ||
const invalidToken = jsonwebtoken.sign( | ||
{ result_recipient_email: '[email protected]', session_id: 12345 }, | ||
settings.authentication.secret, | ||
{ expiresIn: '30d' }, | ||
); | ||
context('when the scope is valid', function () { | ||
it('should return the session id and result recipient email if the token is valid', function () { | ||
// given | ||
const token = jsonwebtoken.sign( | ||
{ | ||
result_recipient_email: '[email protected]', | ||
session_id: 12345, | ||
scope: 'certificationResultsByRecipientEmailLink', | ||
}, | ||
settings.authentication.secret, | ||
{ expiresIn: '30d' }, | ||
); | ||
|
||
// when | ||
const error = await catchErr(tokenService.extractCertificationResultsByRecipientEmailLink)(invalidToken); | ||
// when | ||
const tokenData = tokenService.extractCertificationResultsByRecipientEmailLink(token); | ||
|
||
// then | ||
expect(error).to.be.an.instanceof(InvalidResultRecipientTokenError); | ||
// then | ||
expect(tokenData).to.deep.equal({ | ||
resultRecipientEmail: '[email protected]', | ||
sessionId: 12345, | ||
}); | ||
}); | ||
}); | ||
|
||
context('when FT_ENABLE_CERTIF_TOKEN_SCOPE is false', function () { | ||
beforeEach(function () { | ||
sinon.stub(settings.featureToggles, 'isCertificationTokenScopeEnabled').value(false); | ||
}); | ||
context('when the scope is invalid', function () { | ||
it('should throw an InvalidResultRecipientTokenError', async function () { | ||
// given | ||
const invalidToken = jsonwebtoken.sign( | ||
{ result_recipient_email: '[email protected]', session_id: 12345 }, | ||
settings.authentication.secret, | ||
{ expiresIn: '30d' }, | ||
); | ||
|
||
context('when there is no scope', function () { | ||
it('should return the session id', function () { | ||
// given | ||
const token = jsonwebtoken.sign( | ||
{ result_recipient_email: '[email protected]', session_id: 12345 }, | ||
settings.authentication.secret, | ||
{ expiresIn: '30d' }, | ||
); | ||
|
||
// when | ||
const tokenData = tokenService.extractCertificationResultsByRecipientEmailLink(token); | ||
|
||
// then | ||
expect(tokenData).to.deep.equal({ | ||
resultRecipientEmail: '[email protected]', | ||
sessionId: 12345, | ||
}); | ||
}); | ||
// when | ||
const error = await catchErr(tokenService.extractCertificationResultsByRecipientEmailLink)(invalidToken); | ||
|
||
// then | ||
expect(error).to.be.an.instanceof(InvalidResultRecipientTokenError); | ||
}); | ||
}); | ||
|
||
|