Skip to content

Commit 00763fa

Browse files
loucadufaultjfromaniello
authored andcommitted
Modify tests to actually exercise wrong signature case by removing base64 padding chars from test token
1 parent d15b92c commit 00763fa

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

test/jwt.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ describe('failure tests', function () {
227227
const secret = "shhh";
228228
const token = jwt.sign({ foo: 'bar', iss: 'http://www' }, secret);
229229
// manipulate the token
230-
const newContent = Buffer.from("{foo: 'bar', edg: 'ar'}").toString('base64');
230+
const newContent = Buffer
231+
.from('{"foo": "bar", "edg": "ar"}')
232+
.toString('base64')
233+
.replace(/=/g, '');
231234
const splitetToken = token.split(".");
232235
splitetToken[1] = newContent;
233236
const newToken = splitetToken.join(".");
@@ -238,7 +241,7 @@ describe('failure tests', function () {
238241
expressjwt({ secret: secret, algorithms: ['HS256'] })(req, res, function (err) {
239242
assert.ok(err);
240243
assert.equal(err.code, 'invalid_token');
241-
assert.equal(err.message, 'invalid token');
244+
assert.equal(err.message, 'invalid signature');
242245
done();
243246
});
244247
});

0 commit comments

Comments
 (0)