Skip to content

Commit ff6a450

Browse files
authored
Merge pull request #43 from node-oauth/fix-sha1-to-sha256
use sha256 for token generation
2 parents 26b3eb3 + 769878d commit ff6a450

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

lib/utils/token-util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
generateRandomToken: function() {
2121
return randomBytes(256).then(function(buffer) {
2222
return crypto
23-
.createHash('sha1')
23+
.createHash('sha256')
2424
.update(buffer)
2525
.digest('hex');
2626
});

test/assertions.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
var chai = require('chai');
88

99
/**
10-
* SHA-1 assertion.
10+
* SHA-256 assertion.
1111
*/
12-
chai.use(function (_chai, utils) {
1312

14-
utils.addMethod(chai.Assertion.prototype, 'sha1', function () {
13+
chai.use(function (_chai, utils) {
14+
chai.Assertion.addMethod('sha256', function (...args) {
1515
var obj = utils.flag(this, 'object');
16-
new chai.Assertion(obj).match(/^[a-f0-9]{40}$/i);
16+
new chai.Assertion(obj).match(/^[a-f0-9]{64}$/i);
1717
});
18-
1918
});

test/integration/grant-types/abstract-grant-type_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('AbstractGrantType integration', function() {
6464

6565
return handler.generateAccessToken()
6666
.then(function(data) {
67-
data.should.be.a.sha1;
67+
data.should.be.a.sha256();
6868
})
6969
.catch(should.fail);
7070
});
@@ -98,7 +98,7 @@ describe('AbstractGrantType integration', function() {
9898

9999
return handler.generateRefreshToken()
100100
.then(function(data) {
101-
data.should.be.a.sha1;
101+
data.should.be.a.sha256();
102102
})
103103
.catch(should.fail);
104104
});

test/integration/handlers/authorize-handler_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ describe('AuthorizeHandler integration', function() {
587587

588588
return handler.generateAuthorizationCode()
589589
.then(function(data) {
590-
data.should.be.a.sha1;
590+
data.should.be.a.sha256();
591591
})
592592
.catch(should.fail);
593593
});

test/integration/handlers/token-handler_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ describe('TokenHandler integration', function() {
492492
var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });
493493
var request = new Request({
494494
body: {},
495-
headers: { 'authorization': util.format('Basic %s', new Buffer('foo:bar').toString('base64')) },
495+
headers: { 'authorization': util.format('Basic %s', Buffer.from('foo:bar').toString('base64')) },
496496
method: {},
497497
query: {}
498498
});
@@ -571,7 +571,7 @@ describe('TokenHandler integration', function() {
571571
});
572572
var request = new Request({
573573
body: { grant_type: 'password'},
574-
headers: { 'authorization': util.format('Basic %s', new Buffer('blah:').toString('base64')) },
574+
headers: { 'authorization': util.format('Basic %s', Buffer.from('blah:').toString('base64')) },
575575
method: {},
576576
query: {}
577577
});
@@ -679,7 +679,7 @@ describe('TokenHandler integration', function() {
679679
var request = new Request({
680680
body: {},
681681
headers: {
682-
'authorization': util.format('Basic %s', new Buffer('foo:bar').toString('base64'))
682+
'authorization': util.format('Basic %s', Buffer.from('foo:bar').toString('base64'))
683683
},
684684
method: {},
685685
query: {}

test/integration/utils/token-util_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ var should = require('chai').should();
1313

1414
describe('TokenUtil integration', function() {
1515
describe('generateRandomToken()', function() {
16-
it('should return a sha-1 token', function() {
16+
it('should return a sha-256 token', function() {
1717
return TokenUtil.generateRandomToken()
1818
.then(function(token) {
19-
token.should.be.a.sha1;
19+
token.should.be.a.sha256();
2020
})
2121
.catch(should.fail);
2222
});

0 commit comments

Comments
 (0)