forked from DuendeArchive/identity-model-oidc-client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserManager.spec.js
More file actions
126 lines (95 loc) · 3.8 KB
/
Copy pathUserManager.spec.js
File metadata and controls
126 lines (95 loc) · 3.8 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
import UserManager from '../../src/UserManager';
import Log from '../../src/Log';
import Global from '../../src/Global';
import UserManagerSettings from '../../src/UserManagerSettings';
import User from '../../src/User';
import StubMetadataService from './StubMetadataService';
import StubSilentRenewService from './StubSilentRenewService';
import StubStateStore from './StubStateStore';
import StubResponseValidator from './StubResponseValidator';
import StubTokenRevocationClient from './StubTokenRevocationClient';
import chai from 'chai';
chai.should();
let assert = chai.assert;
describe("UserManager", function () {
let settings;
let subject;
let stubMetadataService;
let stubStateStore;
let stubValidator;
let stubSilentRenewService;
let stubNavigator;
let stubUserStore;
let stubTokenRevocationClient;
beforeEach(function () {
Global._testing();
Log.logger = console;
Log.level = Log.NONE;
stubNavigator = {};
stubUserStore = new StubStateStore();
stubStateStore = new StubStateStore();
stubValidator = new StubResponseValidator();
stubSilentRenewService = new StubSilentRenewService();
stubMetadataService = new StubMetadataService();
stubTokenRevocationClient = new StubTokenRevocationClient();
settings = {
authority: 'http://sts/oidc',
client_id: 'client',
monitorSession : false,
navigator: stubNavigator,
userStore: stubUserStore,
stateStore: stubStateStore,
ResponseValidatorCtor: () => stubValidator,
MetadataServiceCtor: () => stubMetadataService
};
subject = new UserManager(settings,
() => stubSilentRenewService,
null,
() => stubTokenRevocationClient);
});
describe("constructor", function () {
it("should accept settings", function () {
subject.settings.client_id.should.equal('client');
});
});
describe("settings", function () {
it("should be UserManagerSettings", function () {
subject.settings.should.be.instanceof(UserManagerSettings);
});
});
describe("userLoaded", function () {
it("should be able to call getUser without recursion", function (done) {
stubUserStore.item = new User({id_token:"id_token"}).toStorageString();
subject.events.addUserLoaded(user => {
subject.getUser().then(user => {
done();
});
});
subject.events.load({});
});
});
describe("signinSilent", function(){
it("should pass silentRequestTimeout from settings", function(done){
settings.silentRequestTimeout = 123;
settings.silent_redirect_uri = "http://client/silent_callback";
subject = new UserManager(settings);
subject._signin = function(args, nav, navArgs){
Log.debug("_signin", args, nav, navArgs);
navArgs.silentRequestTimeout.should.equal(123);
done();
}
subject.signinSilent();
});
it("should pass silentRequestTimeout from params", function(done){
settings.silent_redirect_uri = "http://client/silent_callback";
subject = new UserManager(settings);
subject._signin = function(args, nav, navArgs){
navArgs.silentRequestTimeout.should.equal(234);
done();
}
subject.signinSilent({silentRequestTimeout:234});
});
});
});