-
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathtoken-handler_test.js
More file actions
75 lines (68 loc) · 2.24 KB
/
Copy pathtoken-handler_test.js
File metadata and controls
75 lines (68 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
/**
* Module dependencies.
*/
const Request = require('../../../lib/request');
const Model = require('../../../lib/model');
const TokenHandler = require('../../../lib/handlers/token-handler');
const sinon = require('sinon');
const should = require('chai').should();
/**
* Test `TokenHandler`.
*/
describe('TokenHandler', function () {
describe('getClient()', function () {
it('should call `model.getClient()` with the provided secret', function () {
const model = Model.from({
getClient: sinon.stub().returns({ grants: ['password'] }),
saveToken: function () {},
});
const handler = new TokenHandler({
accessTokenLifetime: 120,
model: model,
refreshTokenLifetime: 120,
});
const request = new Request({
body: { client_id: 12345, client_secret: 'secret' },
headers: {},
method: {},
query: {},
});
return handler
.getClient(request)
.then(function () {
model.getClient.callCount.should.equal(1);
model.getClient.firstCall.args.should.have.length(2);
model.getClient.firstCall.args[0].should.equal(12345);
model.getClient.firstCall.args[1].should.equal('secret');
model.getClient.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
it('should call `model.getClient()` when no client secret is provided (public client)', function () {
const model = Model.from({
getClient: sinon.stub().returns({ grants: ['authorization_code'], type: 'public' }),
saveToken: function () {},
});
const handler = new TokenHandler({
accessTokenLifetime: 120,
model: model,
refreshTokenLifetime: 120,
});
const request = new Request({
body: { client_id: 'foo', grant_type: 'authorization_code' },
headers: {},
method: {},
query: {},
});
return handler
.getClient(request)
.then(function () {
model.getClient.callCount.should.equal(1);
model.getClient.firstCall.args[0].should.equal('foo');
should.equal(model.getClient.firstCall.args[1], null);
})
.catch(should.fail);
});
});
});