-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathClient.test.ts
More file actions
81 lines (66 loc) · 3.22 KB
/
Client.test.ts
File metadata and controls
81 lines (66 loc) · 3.22 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import chai = require("chai");
import chaiAsPromised = require("chai-as-promised");
import { BakedAuthorizationConfiguration } from "../Client.js";
import type { NodeCliAuthorizationConfiguration } from "../Client.js";
chai.use(chaiAsPromised);
describe("NodeCliAuthorizationConfiguration defaults", () => {
it("should throw if clientId is an empty string", () => {
chai.expect(() => new BakedAuthorizationConfiguration({ clientId: "", scope: "testScope" })).to.throw();
});
it("should throw if scope is an empty string", () => {
chai.expect(() => new BakedAuthorizationConfiguration({ clientId: "testClientId", scope: "" })).to.throw();
});
});
describe("NodeCliAuthorizationConfiguration Authority URL Logic", () => {
const config: NodeCliAuthorizationConfiguration = {
clientId: "testClientId",
scope: "testScope",
};
const testAuthority = "https://test.authority.com";
it("should use config authority without prefix", async () => {
process.env.IMJS_URL_PREFIX = "";
const bakedConfig = new BakedAuthorizationConfiguration({ ...config, issuerUrl: testAuthority });
chai.expect(bakedConfig.issuerUrl).equals(testAuthority);
});
it("should use config authority and ignore prefix", async () => {
process.env.IMJS_URL_PREFIX = "prefix-";
const bakedConfig = new BakedAuthorizationConfiguration({ ...config, issuerUrl: testAuthority });
chai.expect(bakedConfig.issuerUrl).equals("https://test.authority.com");
});
it("should use default authority without prefix ", async () => {
process.env.IMJS_URL_PREFIX = "";
const bakedConfig = new BakedAuthorizationConfiguration(config);
chai.expect(bakedConfig.issuerUrl).equals("https://ims.bentley.com");
});
it("should use default authority with prefix ", async () => {
process.env.IMJS_URL_PREFIX = "prefix-";
const bakedConfig = new BakedAuthorizationConfiguration(config);
chai.expect(bakedConfig.issuerUrl).equals("https://prefix-ims.bentley.com");
});
it("should reroute dev prefix to qa if on default ", async () => {
process.env.IMJS_URL_PREFIX = "dev-";
const bakedConfig = new BakedAuthorizationConfiguration(config);
chai.expect(bakedConfig.issuerUrl).equals("https://qa-ims.bentley.com");
});
});
describe("NodeCliAuthorizationConfiguration Config Scope Logic", () => {
const config: NodeCliAuthorizationConfiguration = {
clientId: "testClientId",
scope: "testScope",
};
it("Should add offline_access scope", async () => {
const bakedConfig = new BakedAuthorizationConfiguration(config);
chai.expect(bakedConfig.scopes).equals(`${config.scope} offline_access`);
});
it("Should not add offline_access scope", async () => {
const bakedConfig = new BakedAuthorizationConfiguration({
clientId: "testClientId",
scope: "testScope offline_access",
});
chai.expect(bakedConfig.scopes).equals("testScope offline_access");
});
});