Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove node 4-7 support #801

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 16 additions & 28 deletions .circleci/config.yml
Expand Up @@ -17,55 +17,43 @@ commands:
command: npm test

jobs:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the CI config, I've opted to change it to primarily using even-numbered releases, as they are the long-term-support versions, whereas the odd numbers are essentially development versions. It doesn't really make sense to test against, say node 9 or 11, the majority of people use the stable versions such as 10 or 12.

node-v4:
docker:
- image: node:4
steps:
- test-nodejs
node-v5:
docker:
- image: node:5
steps:
- test-nodejs
node-v6:
node-v8:
docker:
- image: node:6
- image: node:8
steps:
- test-nodejs
node-v7:
node-v10:
docker:
- image: node:7
- image: node:10
steps:
- test-nodejs
node-v8:
node-v12:
docker:
- image: node:8
- image: node:12
steps:
- test-nodejs
node-v9:
node-v14:
docker:
- image: node:9
- image: node:14
steps:
- test-nodejs
node-v10:
node-v15:
docker:
- image: node:10
- image: node:15
steps:
- test-nodejs
node-v11:
node-v16:
docker:
- image: node:11
- image: node:16
steps:
- test-nodejs

workflows:
node-multi-build:
jobs:
- node-v4
- node-v5
- node-v6
- node-v7
- node-v8
- node-v9
- node-v10
- node-v11
- node-v12
- node-v14
- node-v15
- node-v16
3 changes: 0 additions & 3 deletions lib/psSupported.js

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -44,8 +44,7 @@
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"lodash.once": "^4.0.0",
"ms": "^2.1.1",
"semver": "^5.6.0"
"ms": "^2.1.1"
},
"devDependencies": {
"atob": "^2.1.2",
Expand All @@ -60,7 +59,7 @@
},
"engines": {
"npm": ">=1.4.28",
"node": ">=4"
"node": ">=8"
},
"files": [
"lib",
Expand Down
6 changes: 1 addition & 5 deletions sign.js
@@ -1,5 +1,4 @@
var timespan = require('./lib/timespan');
var PS_SUPPORTED = require('./lib/psSupported');
var jws = require('jws');
var includes = require('lodash.includes');
var isBoolean = require('lodash.isboolean');
Expand All @@ -9,10 +8,7 @@ var isPlainObject = require('lodash.isplainobject');
var isString = require('lodash.isstring');
var once = require('lodash.once');

var SUPPORTED_ALGS = ['RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512', 'HS256', 'HS384', 'HS512', 'none'];
if (PS_SUPPORTED) {
SUPPORTED_ALGS.splice(3, 0, 'PS256', 'PS384', 'PS512');
}
var SUPPORTED_ALGS = ['RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512', 'ES256', 'ES384', 'ES512', 'HS256', 'HS384', 'HS512', 'none'];

var sign_options_schema = {
expiresIn: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"expiresIn" should be a number of seconds or string representing a timespan' },
Expand Down
15 changes: 6 additions & 9 deletions test/async_sign.tests.js
@@ -1,7 +1,6 @@
var jwt = require('../index');
var expect = require('chai').expect;
var jws = require('jws');
var PS_SUPPORTED = require('../lib/psSupported');

describe('signing a token asynchronously', function() {

Expand Down Expand Up @@ -59,15 +58,13 @@ describe('signing a token asynchronously', function() {
});
});

if (PS_SUPPORTED) {
it('should return error when secret is not a cert for PS256', function(done) {
//this throw an error because the secret is not a cert and PS256 requires a cert.
jwt.sign({ foo: 'bar' }, secret, { algorithm: 'PS256' }, function (err) {
expect(err).to.be.ok;
done();
});
it('should return error when secret is not a cert for PS256', function(done) {
//this throw an error because the secret is not a cert and PS256 requires a cert.
jwt.sign({ foo: 'bar' }, secret, { algorithm: 'PS256' }, function (err) {
expect(err).to.be.ok;
done();
});
}
});

it('should return error on wrong arguments', function(done) {
//this throw an error because the secret is not a cert and RS256 requires a cert.
Expand Down
13 changes: 4 additions & 9 deletions test/jwt.asymmetric_signing.tests.js
@@ -1,5 +1,4 @@
var jwt = require('../index');
var PS_SUPPORTED = require('../lib/psSupported');
var fs = require('fs');
var path = require('path');

Expand All @@ -23,17 +22,13 @@ var algorithms = {
// openssl ec -in ecdsa-private.pem -pubout -out ecdsa-public.pem
pub_key: loadKey('ecdsa-public.pem'),
invalid_pub_key: loadKey('ecdsa-public-invalid.pem')
}
};

if (PS_SUPPORTED) {
algorithms.PS256 = {
},
PS256: {
pub_key: loadKey('pub.pem'),
priv_key: loadKey('priv.pem'),
invalid_pub_key: loadKey('invalid_pub.pem')
};
}

}
};

describe('Asymmetric Algorithms', function(){

Expand Down
17 changes: 7 additions & 10 deletions test/rsa-public-key.tests.js
@@ -1,5 +1,4 @@
var jwt = require('../');
var PS_SUPPORTED = require('../lib/psSupported');

describe('public key start with BEGIN RSA PUBLIC KEY', function () {

Expand All @@ -13,16 +12,14 @@ describe('public key start with BEGIN RSA PUBLIC KEY', function () {
jwt.verify(token, cert_pub, done);
});

if (PS_SUPPORTED) {
it('should work for PS family of algorithms', function (done) {
var fs = require('fs');
var cert_pub = fs.readFileSync(__dirname + '/rsa-public-key.pem');
var cert_priv = fs.readFileSync(__dirname + '/rsa-private.pem');
it('should work for PS family of algorithms', function (done) {
var fs = require('fs');
var cert_pub = fs.readFileSync(__dirname + '/rsa-public-key.pem');
var cert_priv = fs.readFileSync(__dirname + '/rsa-private.pem');

var token = jwt.sign({ foo: 'bar' }, cert_priv, { algorithm: 'PS256'});
var token = jwt.sign({ foo: 'bar' }, cert_priv, { algorithm: 'PS256'});

jwt.verify(token, cert_pub, done);
});
}
jwt.verify(token, cert_pub, done);
});

});
9 changes: 3 additions & 6 deletions test/schema.tests.js
@@ -1,7 +1,6 @@
var jwt = require('../index');
var expect = require('chai').expect;
var fs = require('fs');
var PS_SUPPORTED = require('../lib/psSupported');

describe('schema', function() {

Expand All @@ -22,11 +21,9 @@ describe('schema', function() {
sign({algorithm: 'RS256'});
sign({algorithm: 'RS384'});
sign({algorithm: 'RS512'});
if (PS_SUPPORTED) {
sign({algorithm: 'PS256'});
sign({algorithm: 'PS384'});
sign({algorithm: 'PS512'});
}
sign({algorithm: 'PS256'});
sign({algorithm: 'PS384'});
sign({algorithm: 'PS512'});
sign({algorithm: 'ES256'});
sign({algorithm: 'ES384'});
sign({algorithm: 'ES512'});
Expand Down
15 changes: 6 additions & 9 deletions test/wrong_alg.tests.js
Expand Up @@ -2,7 +2,6 @@ var fs = require('fs');
var path = require('path');
var jwt = require('../index');
var JsonWebTokenError = require('../lib/JsonWebTokenError');
var PS_SUPPORTED = require('../lib/psSupported');
var expect = require('chai').expect;


Expand Down Expand Up @@ -30,15 +29,13 @@ describe('when setting a wrong `header.alg`', function () {
});
});

if (PS_SUPPORTED) {
describe('signing with pub key as HS256 and whitelisting only PS256', function () {
it('should not verify', function () {
expect(function () {
jwt.verify(TOKEN, pub, {algorithms: ['PS256']});
}).to.throw(JsonWebTokenError, /invalid algorithm/);
});
describe('signing with pub key as HS256 and whitelisting only PS256', function () {
it('should not verify', function () {
expect(function () {
jwt.verify(TOKEN, pub, {algorithms: ['PS256']});
}).to.throw(JsonWebTokenError, /invalid algorithm/);
});
}
});

describe('signing with HS256 and checking with HS384', function () {
it('should not verify', function () {
Expand Down
10 changes: 2 additions & 8 deletions verify.js
Expand Up @@ -3,18 +3,12 @@ var NotBeforeError = require('./lib/NotBeforeError');
var TokenExpiredError = require('./lib/TokenExpiredError');
var decode = require('./decode');
var timespan = require('./lib/timespan');
var PS_SUPPORTED = require('./lib/psSupported');
var jws = require('jws');

var PUB_KEY_ALGS = ['RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512'];
var RSA_KEY_ALGS = ['RS256', 'RS384', 'RS512'];
var PUB_KEY_ALGS = ['RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512', 'ES256', 'ES384', 'ES512'];
var RSA_KEY_ALGS = ['RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512'];
var HS_ALGS = ['HS256', 'HS384', 'HS512'];

if (PS_SUPPORTED) {
PUB_KEY_ALGS.splice(3, 0, 'PS256', 'PS384', 'PS512');
RSA_KEY_ALGS.splice(3, 0, 'PS256', 'PS384', 'PS512');
}

module.exports = function (jwtString, secretOrPublicKey, options, callback) {
if ((typeof options === 'function') && !callback) {
callback = options;
Expand Down