-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBrowserAuthorizationClient.test.ts
More file actions
143 lines (112 loc) · 5.57 KB
/
BrowserAuthorizationClient.test.ts
File metadata and controls
143 lines (112 loc) · 5.57 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { assert } from "chai";
import { BrowserAuthorizationClient } from "../Client";
import { getImsAuthority } from "../utils";
import type { BrowserAuthorizationClientConfiguration } from "../types";
describe("BrowserAuthorizationClient", () => {
describe("#constructor", () => {
const TEST_AUTHORITY = "https://test.authority.com";
let testClient: BrowserAuthorizationClient;
let testConfig: BrowserAuthorizationClientConfiguration;
let testConfigWithoutAuthority: BrowserAuthorizationClientConfiguration;
before(() => {
testConfigWithoutAuthority = {
clientId: "test_clientId",
redirectUri: "test_redirectUri",
postSignoutRedirectUri: "test_postSignoutRedirectUri",
scope: "test_scope",
responseType: "code",
noSilentSignInOnAppStartup: false,
silentRedirectUri: "test_silentRedirectUri",
responseMode: "query",
};
testConfig = {
...testConfigWithoutAuthority,
authority: TEST_AUTHORITY,
};
testClient = new BrowserAuthorizationClient(testConfig);
});
it("_basicSettings contains passed in configuration", () => {
const settings = testClient["_basicSettings"]; // eslint-disable-line @typescript-eslint/dot-notation
assert.equal(settings.authority, TEST_AUTHORITY);
assert.equal(settings.clientId, "test_clientId");
assert.equal(settings.redirectUri, "test_redirectUri");
assert.equal(
settings.postSignoutRedirectUri,
"test_postSignoutRedirectUri",
);
assert.equal(settings.scope, "test_scope");
assert.equal(settings.responseType, "code");
assert.equal(settings.noSilentSignInOnAppStartup, false);
assert.equal(settings.silentRedirectUri, "test_silentRedirectUri");
});
it("given authority is used", () => {
assert.equal(testClient.authorityUrl, TEST_AUTHORITY);
});
it("given authority is used and environment prefix is ignored", async () => {
process.env.IMJS_URL_PREFIX = "prefix-";
assert.equal(testClient.authorityUrl, TEST_AUTHORITY);
});
it("given authority is used when no prefix is defined", async () => {
process.env.IMJS_URL_PREFIX = "";
assert.equal(testClient.authorityUrl, TEST_AUTHORITY);
});
it("default authority is used when none is given", () => {
const client = new BrowserAuthorizationClient(testConfigWithoutAuthority);
// getImsAuthority manages the value of the default authority
assert.equal(client.authorityUrl, getImsAuthority()); // eslint-disable-line @typescript-eslint/no-deprecated
});
it("default authority is used and when none is given and uses environment prefix", () => {
process.env.IMJS_URL_PREFIX = "prefix-";
const client = new BrowserAuthorizationClient(testConfigWithoutAuthority);
// getImsAuthority manages the value of the default authority
assert.equal(client.authorityUrl, getImsAuthority()); // eslint-disable-line @typescript-eslint/no-deprecated
});
it("_basicSettings contains passed in configuration", () => {
const settings = testClient["_basicSettings"]; // eslint-disable-line @typescript-eslint/dot-notation
assert.equal(settings.authority, TEST_AUTHORITY);
assert.equal(settings.clientId, "test_clientId");
assert.equal(settings.redirectUri, "test_redirectUri");
assert.equal(settings.responseMode, "query");
});
it("given authority is used", () => {
assert.equal(testClient.authorityUrl, TEST_AUTHORITY);
});
it("given authority is used and environment prefix is ignored", async () => {
process.env.IMJS_URL_PREFIX = "prefix-";
assert.equal(testClient.authorityUrl, TEST_AUTHORITY);
});
it("given authority is when no prefix is defined", async () => {
process.env.IMJS_URL_PREFIX = "";
assert.equal(testClient.authorityUrl, TEST_AUTHORITY);
});
it("default authority is used when none is given", () => {
const client = new BrowserAuthorizationClient(testConfigWithoutAuthority);
// getImsAuthority manages the value of the default authority
assert.equal(client.authorityUrl, getImsAuthority()); // eslint-disable-line @typescript-eslint/no-deprecated
});
it("default authority is used and when none is given and uses environment prefix", () => {
process.env.IMJS_URL_PREFIX = "prefix-";
const client = new BrowserAuthorizationClient(testConfigWithoutAuthority);
// getImsAuthority manages the value of the default authority
assert.equal(client.authorityUrl, getImsAuthority()); // eslint-disable-line @typescript-eslint/no-deprecated
});
it('successfully sets "query" as response mode', () => {
const client = new BrowserAuthorizationClient({
...testConfig,
responseMode: "query",
});
assert.equal(client["_basicSettings"].responseMode, "query"); // eslint-disable-line @typescript-eslint/dot-notation
});
it('successfully sets "fragment" as response mode', () => {
const client = new BrowserAuthorizationClient({
...testConfig,
responseMode: "fragment",
});
assert.equal(client["_basicSettings"].responseMode, "fragment"); // eslint-disable-line @typescript-eslint/dot-notation
});
});
});