forked from authts/oidc-client-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignoutRequest.test.ts
More file actions
109 lines (86 loc) · 3.43 KB
/
Copy pathSignoutRequest.test.ts
File metadata and controls
109 lines (86 loc) · 3.43 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
// 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 { SignoutRequest, type SignoutRequestArgs } from "./SignoutRequest";
describe("SignoutRequest", () => {
let subject: SignoutRequest;
let settings: SignoutRequestArgs;
beforeEach(() => {
settings = {
url: "http://sts/signout",
id_token_hint: "hint",
post_logout_redirect_uri: "loggedout",
state_data: { data: "test" },
};
subject = new SignoutRequest(settings);
});
describe("constructor", () => {
it("should require a url param", () => {
// arrange
Object.assign(settings, { url: undefined });
// act
try {
new SignoutRequest(settings);
fail("should not come here");
}
catch (err) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toContain("url");
}
});
});
describe("url", () => {
it("should include url", () => {
// assert
expect(subject.url.indexOf("http://sts/signout")).toEqual(0);
});
it("should include id_token_hint", () => {
// assert
expect(subject.url).toContain("id_token_hint=hint");
});
it("should include post_logout_redirect_uri if id_token_hint also provided", () => {
// assert
expect(subject.url).toContain("post_logout_redirect_uri=loggedout");
});
it("should include post_logout_redirect_uri if no id_token_hint provided", () => {
// arrange
delete settings.id_token_hint;
// act
subject = new SignoutRequest(settings);
// assert
expect(subject.url).toContain("post_logout_redirect_uri=loggedout");
});
it("should include state if post_logout_redirect_uri provided", () => {
// assert
expect(subject.state).toBeDefined();
expect(subject.url).toContain("state=" + subject.state!.id);
});
it("should not include state if no post_logout_redirect_uri provided", () => {
// arrange
delete settings.post_logout_redirect_uri;
// act
subject = new SignoutRequest(settings);
// assert
expect(subject.url).not.toContain("state=");
});
it("should include id_token_hint, post_logout_redirect_uri, and state", () => {
// assert
const url = subject.url;
expect(url.indexOf("http://sts/signout?")).toEqual(0);
expect(url).toContain("id_token_hint=hint");
expect(url).toContain("post_logout_redirect_uri=loggedout");
expect(subject.state).toBeDefined();
expect(url).toContain("state=" + subject.state!.id);
});
it("should include extra query params", () => {
// arrange
settings.extraQueryParams = {
"TargetResource": "logouturl.com",
"InErrorResource": "errorurl.com",
};
// act
subject = new SignoutRequest(settings);
// assert
expect(subject.url).toContain("TargetResource=logouturl.com&InErrorResource=errorurl.com");
});
});
});