Skip to content

Commit 4d8f50a

Browse files
committed
Move tests in a specific file
1 parent fdc1f04 commit 4d8f50a

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

Diff for: test/option-complete.test.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const jws = require('jws');
4+
const expect = require('chai').expect;
5+
const path = require('path');
6+
const fs = require('fs');
7+
const testUtils = require('./test-utils')
8+
9+
describe('complete option', function () {
10+
const secret = fs.readFileSync(path.join(__dirname, 'priv.pem'));
11+
const pub = fs.readFileSync(path.join(__dirname, 'pub.pem'));
12+
13+
const header = { alg: 'RS256' };
14+
const payload = { iat: Math.floor(Date.now() / 1000 ) };
15+
const signed = jws.sign({ header, payload, secret, encoding: 'utf8' });
16+
const signature = jws.decode(signed).signature;
17+
18+
[
19+
{
20+
description: 'should return header, payload and signature',
21+
complete: true,
22+
},
23+
].forEach((testCase) => {
24+
it(testCase.description, function (done) {
25+
testUtils.verifyJWTHelper(signed, pub, { typ: 'JWT', complete: testCase.complete }, (err, decoded) => {
26+
testUtils.asyncCheck(done, () => {
27+
expect(err).to.be.null;
28+
expect(decoded.header).to.have.property('alg', header.alg);
29+
expect(decoded.payload).to.have.property('iat', payload.iat);
30+
expect(decoded).to.have.property('signature', signature);
31+
});
32+
});
33+
});
34+
});
35+
[
36+
{
37+
description: 'should return payload',
38+
complete: false,
39+
},
40+
].forEach((testCase) => {
41+
it(testCase.description, function (done) {
42+
testUtils.verifyJWTHelper(signed, pub, { typ: 'JWT', complete: testCase.complete }, (err, decoded) => {
43+
testUtils.asyncCheck(done, () => {
44+
expect(err).to.be.null;
45+
expect(decoded.header).to.be.undefined;
46+
expect(decoded.payload).to.be.undefined;
47+
expect(decoded.signature).to.be.undefined;
48+
expect(decoded).to.have.property('iat', payload.iat);
49+
});
50+
});
51+
});
52+
});
53+
});

Diff for: test/verify.tests.js

-24
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,6 @@ describe('verify', function() {
6969
});
7070
});
7171

72-
describe('option: complete', function() {
73-
it('should return header, payload and signature', function (done) {
74-
var header = { alg: 'RS256' };
75-
var payload = { iat: Math.floor(Date.now() / 1000 ) };
76-
77-
var signed = jws.sign({
78-
header: header,
79-
payload: payload,
80-
secret: priv,
81-
encoding: 'utf8'
82-
});
83-
84-
var signature = jws.decode(signed).signature;
85-
86-
jwt.verify(signed, pub, {typ: 'JWT', complete: true}, function(err, p) {
87-
assert.isNull(err);
88-
assert.deepEqual(p.header, header);
89-
assert.deepEqual(p.payload, payload);
90-
assert.deepEqual(p.signature, signature);
91-
done();
92-
});
93-
});
94-
});
95-
9672
describe('secret or token as callback', function () {
9773
var token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MzcwMTg1ODIsImV4cCI6MTQzNzAxODU5Mn0.3aR3vocmgRpG05rsI9MpR6z2T_BGtMQaPq2YR6QaroU';
9874
var key = 'key';

0 commit comments

Comments
 (0)