Skip to content

Commit

Permalink
Force use_strict during testing (#577)
Browse files Browse the repository at this point in the history
* Force use_strict during testing

* Add string payload test cases to .iat tests
  • Loading branch information
lionello authored and ziluvatar committed Feb 20, 2019
1 parent 0c24fe6 commit 7b60c12
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"lint": "eslint .",
"coverage": "nyc mocha",
"coverage": "nyc mocha --use_strict",
"test": "npm run lint && npm run coverage && cost-of-modules"
},
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ module.exports = function (payload, secretOrPrivateKey, options, callback) {

var timestamp = payload.iat || Math.floor(Date.now() / 1000);

if (!options.noTimestamp) {
payload.iat = timestamp;
} else {
if (options.noTimestamp) {
delete payload.iat;
} else if (isObjectPayload) {
payload.iat = timestamp;
}

if (typeof options.notBefore !== 'undefined') {
Expand Down
26 changes: 26 additions & 0 deletions test/claim-iat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,30 @@ describe('issue at', function() {
});
});
});

describe('with string payload', function () {
it('should not add iat to string', function (done) {
const payload = 'string payload';
const options = {algorithm: 'none'};
testUtils.signJWTHelper(payload, 'secret', options, (err, token) => {
const decoded = jwt.decode(token);
testUtils.asyncCheck(done, () => {
expect(err).to.be.null;
expect(decoded).to.equal(payload);
});
});
});

it('should not add iat to stringified object', function (done) {
const payload = '{}';
const options = {algorithm: 'none', header: {typ: 'JWT'}};
testUtils.signJWTHelper(payload, 'secret', options, (err, token) => {
const decoded = jwt.decode(token);
testUtils.asyncCheck(done, () => {
expect(err).to.equal(null);
expect(JSON.stringify(decoded)).to.equal(payload);
});
});
});
});
});

0 comments on commit 7b60c12

Please sign in to comment.