@strivacity/sdk-core 4.0.0-beta.0 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +228 -86
- package/dist/assets/oidc.cjs +1 -1
- package/dist/assets/oidc.cjs.map +1 -1
- package/dist/assets/oidc.mjs +1 -1
- package/dist/assets/oidc.mjs.map +1 -1
- package/dist/assets/server.cjs +1 -1
- package/dist/assets/server.cjs.map +1 -1
- package/dist/assets/server.mjs +1 -1
- package/dist/assets/server.mjs.map +1 -1
- package/dist/flows/base.cjs +1 -1
- package/dist/flows/base.cjs.map +1 -1
- package/dist/flows/base.d.ts +4 -2
- package/dist/flows/base.mjs +1 -1
- package/dist/flows/base.mjs.map +1 -1
- package/dist/flows/popup.cjs +1 -1
- package/dist/flows/popup.cjs.map +1 -1
- package/dist/flows/popup.mjs +1 -1
- package/dist/flows/popup.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/server/base.cjs +1 -1
- package/dist/server/base.cjs.map +1 -1
- package/dist/server/base.d.ts +2 -4
- package/dist/server/base.mjs +1 -1
- package/dist/server/base.mjs.map +1 -1
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.mjs +1 -1
- package/dist/storages/cache.cjs.map +1 -1
- package/dist/storages/cache.d.ts +1 -1
- package/dist/storages/cache.mjs.map +1 -1
- package/dist/storages/index.cjs +1 -1
- package/dist/storages/index.mjs +1 -1
- package/dist/storages/server.cjs +1 -1
- package/dist/storages/server.d.ts +29 -1
- package/dist/storages/server.mjs +1 -1
- package/dist/storages/worker.cjs.map +1 -1
- package/dist/storages/worker.d.ts +1 -1
- package/dist/storages/worker.mjs.map +1 -1
- package/dist/types/native.d.ts +67 -2
- package/dist/types/oidc.cjs.map +1 -1
- package/dist/types/oidc.d.ts +47 -6
- package/dist/types/oidc.mjs.map +1 -1
- package/dist/types/popup.d.ts +1 -1
- package/dist/types/server.d.ts +21 -9
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/native-login.cjs +2 -0
- package/dist/utils/native-login.cjs.map +1 -0
- package/dist/utils/native-login.d.ts +13 -0
- package/dist/utils/native-login.mjs +2 -0
- package/dist/utils/native-login.mjs.map +1 -0
- package/dist/utils/oidc.d.ts +3 -4
- package/dist/utils/path.cjs +2 -0
- package/dist/utils/path.cjs.map +1 -0
- package/dist/utils/path.d.ts +16 -0
- package/dist/utils/path.mjs +2 -0
- package/dist/utils/path.mjs.map +1 -0
- package/dist/utils/server.d.ts +5 -4
- package/dist/utils/session.cjs +1 -1
- package/dist/utils/session.cjs.map +1 -1
- package/dist/utils/session.d.ts +10 -1
- package/dist/utils/session.mjs +1 -1
- package/dist/utils/session.mjs.map +1 -1
- package/package.json +1 -1
- package/testing/tests/flows/base.spec.ts +0 -1030
- package/testing/tests/flows/embedded.spec.ts +0 -443
- package/testing/tests/flows/index.spec.ts +0 -8
- package/testing/tests/flows/native.spec.ts +0 -487
- package/testing/tests/flows/popup.spec.ts +0 -400
- package/testing/tests/flows/redirect.spec.ts +0 -369
- package/testing/tests/handlers/embedded.spec.ts +0 -199
- package/testing/tests/handlers/index.spec.ts +0 -8
- package/testing/tests/handlers/native.spec.ts +0 -283
- package/testing/tests/handlers/popup.spec.ts +0 -206
- package/testing/tests/handlers/redirect.spec.ts +0 -70
- package/testing/tests/index.spec.ts +0 -78
- package/testing/tests/server/base.spec.ts +0 -846
- package/testing/tests/server/index.spec.ts +0 -15
- package/testing/tests/storages/cache.spec.ts +0 -107
- package/testing/tests/storages/index.spec.ts +0 -22
- package/testing/tests/storages/indexeddb.spec.ts +0 -113
- package/testing/tests/storages/local.spec.ts +0 -46
- package/testing/tests/storages/memory.spec.ts +0 -51
- package/testing/tests/storages/server.spec.ts +0 -435
- package/testing/tests/storages/session.spec.ts +0 -46
- package/testing/tests/storages/worker.spec.ts +0 -106
- package/testing/tests/utils/common.spec.ts +0 -77
- package/testing/tests/utils/credentials.spec.ts +0 -195
- package/testing/tests/utils/dom.spec.ts +0 -37
- package/testing/tests/utils/index.spec.ts +0 -71
- package/testing/tests/utils/logging.spec.ts +0 -82
- package/testing/tests/utils/oidc.spec.ts +0 -744
- package/testing/tests/utils/server.spec.ts +0 -235
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, test, expect, vi } from 'vitest';
|
|
2
|
-
import { http, HttpResponse } from 'msw';
|
|
3
|
-
import { createOptions, getMockStorage } from '@strivacity/testing/mocks/sdk';
|
|
4
|
-
import { worker } from '@strivacity/testing/mocks/msw';
|
|
5
|
-
import { createPopupFlow } from '../../../src/flows/popup';
|
|
6
|
-
|
|
7
|
-
describe('createPopupFlow', () => {
|
|
8
|
-
let options: ReturnType<typeof createOptions>;
|
|
9
|
-
let flow: ReturnType<typeof createPopupFlow>;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
options = createOptions({ urlHandler: vi.fn().mockResolvedValue({ code: 'abc123' }) });
|
|
13
|
-
flow = createPopupFlow(options);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('init', () => {
|
|
17
|
-
test('lazyLoad: true', async () => {
|
|
18
|
-
flow = createPopupFlow(createOptions({ lazyLoad: true }));
|
|
19
|
-
|
|
20
|
-
// We need to wait for the next tick to ensure that any asynchronous initialization logic has a chance to run before we check the initialized state.
|
|
21
|
-
await Promise.resolve();
|
|
22
|
-
|
|
23
|
-
expect(flow.initialized).toBe(false);
|
|
24
|
-
|
|
25
|
-
await flow.init();
|
|
26
|
-
|
|
27
|
-
expect(flow.initialized).toBe(true);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('lazyLoad: false', async () => {
|
|
31
|
-
flow = createPopupFlow(createOptions({ lazyLoad: false }));
|
|
32
|
-
|
|
33
|
-
await vi.waitFor(() => expect(flow.initialized).toBe(true));
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('login', () => {
|
|
38
|
-
describe('w/o serverSessionUri', () => {
|
|
39
|
-
test('w/o params', async () => {
|
|
40
|
-
await flow.login().catch(() => undefined);
|
|
41
|
-
|
|
42
|
-
expect(flow.options.urlHandler).toHaveBeenCalledWith(expect.any(URL), { display: 'popup' });
|
|
43
|
-
|
|
44
|
-
const stateData = getMockStorage(options.stateStorage).getLastState();
|
|
45
|
-
const [url, params] = vi.mocked(options.urlHandler).mock.calls[0] as [URL, Record<string, unknown>];
|
|
46
|
-
|
|
47
|
-
expect(`${url.origin}${url.pathname}`).toBe('https://brandtegrity.io/oauth2/auth');
|
|
48
|
-
expect(url.searchParams.get('client_id')).toBe('client-id');
|
|
49
|
-
expect(url.searchParams.get('redirect_uri')).toBe('https://brandtegrity.io/callback');
|
|
50
|
-
expect(url.searchParams.get('response_type')).toBe('code');
|
|
51
|
-
expect(url.searchParams.get('response_mode')).toBe('query');
|
|
52
|
-
expect(url.searchParams.get('scope')).toBe('openid');
|
|
53
|
-
expect(url.searchParams.get('code_challenge_method')).toBe('S256');
|
|
54
|
-
expect(url.searchParams.get('state')).toBe(stateData?.id);
|
|
55
|
-
expect(url.searchParams.get('code_challenge')).toBe(stateData?.codeChallenge);
|
|
56
|
-
expect(url.searchParams.get('nonce')).toBe(stateData?.nonce);
|
|
57
|
-
expect(url.searchParams.has('prompt')).toBeFalsy();
|
|
58
|
-
expect(url.searchParams.get('display')).toBe('popup');
|
|
59
|
-
expect(url.searchParams.has('login_hint')).toBeFalsy();
|
|
60
|
-
expect(url.searchParams.has('acr_values')).toBeFalsy();
|
|
61
|
-
expect(url.searchParams.has('ui_locales')).toBeFalsy();
|
|
62
|
-
expect(url.searchParams.has('audience')).toBeFalsy();
|
|
63
|
-
expect(params).toEqual({ display: 'popup' });
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('w/ params', async () => {
|
|
67
|
-
const extraParams = {
|
|
68
|
-
prompt: 'login',
|
|
69
|
-
display: 'page',
|
|
70
|
-
loginHint: 'test@example.com',
|
|
71
|
-
acrValues: ['urn:mace:incommon:iap:silver', 'urn:mace:incommon:iap:bronze'],
|
|
72
|
-
uiLocales: ['en-US', 'hu-HU'],
|
|
73
|
-
audiences: ['https://api.example.com', 'https://api2.example.com'],
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
await flow.login(extraParams).catch(() => undefined);
|
|
77
|
-
|
|
78
|
-
expect(flow.options.urlHandler).toHaveBeenCalledWith(expect.any(URL), extraParams);
|
|
79
|
-
|
|
80
|
-
const stateData = getMockStorage(options.stateStorage).getLastState();
|
|
81
|
-
const [url, params] = vi.mocked(options.urlHandler).mock.calls[0] as [URL, Record<string, unknown>];
|
|
82
|
-
|
|
83
|
-
expect(`${url.origin}${url.pathname}`).toBe('https://brandtegrity.io/oauth2/auth');
|
|
84
|
-
expect(url.searchParams.get('client_id')).toBe('client-id');
|
|
85
|
-
expect(url.searchParams.get('redirect_uri')).toBe('https://brandtegrity.io/callback');
|
|
86
|
-
expect(url.searchParams.get('response_type')).toBe('code');
|
|
87
|
-
expect(url.searchParams.get('response_mode')).toBe('query');
|
|
88
|
-
expect(url.searchParams.get('scope')).toBe('openid');
|
|
89
|
-
expect(url.searchParams.get('code_challenge_method')).toBe('S256');
|
|
90
|
-
expect(url.searchParams.get('state')).toBe(stateData?.id);
|
|
91
|
-
expect(url.searchParams.get('code_challenge')).toBe(stateData?.codeChallenge);
|
|
92
|
-
expect(url.searchParams.get('nonce')).toBe(stateData?.nonce);
|
|
93
|
-
expect(url.searchParams.get('prompt')).toBe('login');
|
|
94
|
-
expect(url.searchParams.get('display')).toBe('popup');
|
|
95
|
-
expect(url.searchParams.get('login_hint')).toBe('test@example.com');
|
|
96
|
-
expect(url.searchParams.get('acr_values')).toBe('urn:mace:incommon:iap:silver urn:mace:incommon:iap:bronze');
|
|
97
|
-
expect(url.searchParams.get('ui_locales')).toBe('en-US hu-HU');
|
|
98
|
-
expect(url.searchParams.get('audience')).toBe('https://api.example.com https://api2.example.com');
|
|
99
|
-
expect(params).toEqual(extraParams);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe('w/ serverSessionUri', () => {
|
|
104
|
-
test('w/o params', async () => {
|
|
105
|
-
options = createOptions({ urlHandler: vi.fn().mockResolvedValue({}), serverSessionUri: 'https://app.example.com/login' });
|
|
106
|
-
flow = createPopupFlow(options);
|
|
107
|
-
|
|
108
|
-
await flow.login();
|
|
109
|
-
|
|
110
|
-
expect(flow.options.urlHandler).toHaveBeenCalledWith(expect.any(URL), { display: 'popup' });
|
|
111
|
-
|
|
112
|
-
const [url, params] = vi.mocked(options.urlHandler).mock.calls[0] as [URL, Record<string, unknown>];
|
|
113
|
-
|
|
114
|
-
expect(`${url.origin}${url.pathname}`).toBe('https://app.example.com/login');
|
|
115
|
-
expect(url.searchParams.has('client_id')).toBeFalsy();
|
|
116
|
-
expect(url.searchParams.has('redirect_uri')).toBeFalsy();
|
|
117
|
-
expect(url.searchParams.has('response_type')).toBeFalsy();
|
|
118
|
-
expect(url.searchParams.has('response_mode')).toBeFalsy();
|
|
119
|
-
expect(url.searchParams.has('scope')).toBeFalsy();
|
|
120
|
-
expect(url.searchParams.has('code_challenge_method')).toBeFalsy();
|
|
121
|
-
expect(url.searchParams.has('state')).toBeFalsy();
|
|
122
|
-
expect(url.searchParams.has('code_challenge')).toBeFalsy();
|
|
123
|
-
expect(url.searchParams.has('nonce')).toBeFalsy();
|
|
124
|
-
expect(url.searchParams.has('prompt')).toBeFalsy();
|
|
125
|
-
expect(url.searchParams.get('display')).toBe('popup');
|
|
126
|
-
expect(url.searchParams.has('login_hint')).toBeFalsy();
|
|
127
|
-
expect(url.searchParams.has('acr_values')).toBeFalsy();
|
|
128
|
-
expect(url.searchParams.has('ui_locales')).toBeFalsy();
|
|
129
|
-
expect(url.searchParams.has('audience')).toBeFalsy();
|
|
130
|
-
expect(params).toEqual({ display: 'popup' });
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('w/ params', async () => {
|
|
134
|
-
options = createOptions({ urlHandler: vi.fn().mockResolvedValue({}), serverSessionUri: 'https://app.example.com/login' });
|
|
135
|
-
flow = createPopupFlow(options);
|
|
136
|
-
|
|
137
|
-
const extraParams = {
|
|
138
|
-
prompt: 'login',
|
|
139
|
-
display: 'page',
|
|
140
|
-
loginHint: 'test@example.com',
|
|
141
|
-
acrValues: ['urn:mace:incommon:iap:silver', 'urn:mace:incommon:iap:bronze'],
|
|
142
|
-
uiLocales: ['en-US', 'hu-HU'],
|
|
143
|
-
audiences: ['https://api.example.com', 'https://api2.example.com'],
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
await flow.login(extraParams);
|
|
147
|
-
|
|
148
|
-
expect(flow.options.urlHandler).toHaveBeenCalledWith(expect.any(URL), extraParams);
|
|
149
|
-
|
|
150
|
-
const [url, params] = vi.mocked(options.urlHandler).mock.calls[0] as [URL, Record<string, unknown>];
|
|
151
|
-
|
|
152
|
-
expect(`${url.origin}${url.pathname}`).toBe('https://app.example.com/login');
|
|
153
|
-
expect(url.searchParams.has('client_id')).toBeFalsy();
|
|
154
|
-
expect(url.searchParams.has('redirect_uri')).toBeFalsy();
|
|
155
|
-
expect(url.searchParams.has('response_type')).toBeFalsy();
|
|
156
|
-
expect(url.searchParams.has('response_mode')).toBeFalsy();
|
|
157
|
-
expect(url.searchParams.has('scope')).toBeFalsy();
|
|
158
|
-
expect(url.searchParams.has('code_challenge_method')).toBeFalsy();
|
|
159
|
-
expect(url.searchParams.has('state')).toBeFalsy();
|
|
160
|
-
expect(url.searchParams.has('code_challenge')).toBeFalsy();
|
|
161
|
-
expect(url.searchParams.has('nonce')).toBeFalsy();
|
|
162
|
-
expect(url.searchParams.get('prompt')).toBe('login');
|
|
163
|
-
expect(url.searchParams.get('display')).toBe('popup');
|
|
164
|
-
expect(url.searchParams.get('login_hint')).toBe('test@example.com');
|
|
165
|
-
expect(url.searchParams.get('acr_values')).toBe('urn:mace:incommon:iap:silver urn:mace:incommon:iap:bronze');
|
|
166
|
-
expect(url.searchParams.get('ui_locales')).toBe('en-US hu-HU');
|
|
167
|
-
expect(url.searchParams.get('audience')).toBe('https://api.example.com https://api2.example.com');
|
|
168
|
-
expect(params).toEqual(extraParams);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('should exchange the code for tokens when serverSessionUri is not configured', async () => {
|
|
173
|
-
worker.use(
|
|
174
|
-
http.post('https://brandtegrity.io/oauth2/token', () => HttpResponse.json({ access_token: 'access-token', token_type: 'Bearer', expires_in: 3600 })),
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
options = createOptions({
|
|
178
|
-
lazyLoad: true,
|
|
179
|
-
urlHandler: vi.fn((url) => Promise.resolve({ code: 'abc123', state: new URL(url).searchParams.get('state') })),
|
|
180
|
-
});
|
|
181
|
-
flow = createPopupFlow(options);
|
|
182
|
-
|
|
183
|
-
await flow.login();
|
|
184
|
-
|
|
185
|
-
expect(flow.accessToken).toBe('access-token');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
test('should not exchange the code for tokens when serverSessionUri is configured', async () => {
|
|
189
|
-
options = createOptions({
|
|
190
|
-
lazyLoad: true,
|
|
191
|
-
serverSessionUri: 'https://app.example.com/login',
|
|
192
|
-
urlHandler: vi.fn().mockResolvedValue({ code: 'abc123' }),
|
|
193
|
-
});
|
|
194
|
-
flow = createPopupFlow(options);
|
|
195
|
-
|
|
196
|
-
await flow.login();
|
|
197
|
-
|
|
198
|
-
expect(flow.accessToken).toBeNull();
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
describe('register', () => {
|
|
203
|
-
describe('w/o serverSessionUri', () => {
|
|
204
|
-
test('w/o params', async () => {
|
|
205
|
-
await flow.register().catch(() => undefined);
|
|
206
|
-
|
|
207
|
-
expect(flow.options.urlHandler).toHaveBeenCalledWith(expect.any(URL), { prompt: 'create', display: 'popup' });
|
|
208
|
-
|
|
209
|
-
const stateData = getMockStorage(options.stateStorage).getLastState();
|
|
210
|
-
const [url, params] = vi.mocked(options.urlHandler).mock.calls[0] as [URL, Record<string, unknown>];
|
|
211
|
-
|
|
212
|
-
expect(`${url.origin}${url.pathname}`).toBe('https://brandtegrity.io/oauth2/auth');
|
|
213
|
-
expect(url.searchParams.get('client_id')).toBe('client-id');
|
|
214
|
-
expect(url.searchParams.get('redirect_uri')).toBe('https://brandtegrity.io/callback');
|
|
215
|
-
expect(url.searchParams.get('response_type')).toBe('code');
|
|
216
|
-
expect(url.searchParams.get('response_mode')).toBe('query');
|
|
217
|
-
expect(url.searchParams.get('scope')).toBe('openid');
|
|
218
|
-
expect(url.searchParams.get('code_challenge_method')).toBe('S256');
|
|
219
|
-
expect(url.searchParams.get('state')).toBe(stateData?.id);
|
|
220
|
-
expect(url.searchParams.get('code_challenge')).toBe(stateData?.codeChallenge);
|
|
221
|
-
expect(url.searchParams.get('nonce')).toBe(stateData?.nonce);
|
|
222
|
-
expect(url.searchParams.get('prompt')).toBe('create');
|
|
223
|
-
expect(url.searchParams.get('display')).toBe('popup');
|
|
224
|
-
expect(url.searchParams.has('login_hint')).toBeFalsy();
|
|
225
|
-
expect(url.searchParams.has('acr_values')).toBeFalsy();
|
|
226
|
-
expect(url.searchParams.has('ui_locales')).toBeFalsy();
|
|
227
|
-
expect(url.searchParams.has('audience')).toBeFalsy();
|
|
228
|
-
expect(params).toEqual({ prompt: 'create', display: 'popup' });
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test('w/ params', async () => {
|
|
232
|
-
const extraParams = {
|
|
233
|
-
prompt: 'create',
|
|
234
|
-
display: 'popup',
|
|
235
|
-
loginHint: 'test@example.com',
|
|
236
|
-
acrValues: ['urn:mace:incommon:iap:silver', 'urn:mace:incommon:iap:bronze'],
|
|
237
|
-
uiLocales: ['en-US', 'hu-HU'],
|
|
238
|
-
audiences: ['https://api.example.com', 'https://api2.example.com'],
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
await flow.register({ ...extraParams, prompt: undefined }).catch(() => undefined);
|
|
242
|
-
|
|
243
|
-
expect(flow.options.urlHandler).toHaveBeenCalledWith(expect.any(URL), extraParams);
|
|
244
|
-
|
|
245
|
-
const stateData = getMockStorage(options.stateStorage).getLastState();
|
|
246
|
-
const [url, params] = vi.mocked(options.urlHandler).mock.calls[0] as [URL, Record<string, unknown>];
|
|
247
|
-
|
|
248
|
-
expect(`${url.origin}${url.pathname}`).toBe('https://brandtegrity.io/oauth2/auth');
|
|
249
|
-
expect(url.searchParams.get('client_id')).toBe('client-id');
|
|
250
|
-
expect(url.searchParams.get('redirect_uri')).toBe('https://brandtegrity.io/callback');
|
|
251
|
-
expect(url.searchParams.get('response_type')).toBe('code');
|
|
252
|
-
expect(url.searchParams.get('response_mode')).toBe('query');
|
|
253
|
-
expect(url.searchParams.get('scope')).toBe('openid');
|
|
254
|
-
expect(url.searchParams.get('code_challenge_method')).toBe('S256');
|
|
255
|
-
expect(url.searchParams.get('state')).toBe(stateData?.id);
|
|
256
|
-
expect(url.searchParams.get('code_challenge')).toBe(stateData?.codeChallenge);
|
|
257
|
-
expect(url.searchParams.get('nonce')).toBe(stateData?.nonce);
|
|
258
|
-
expect(url.searchParams.get('prompt')).toBe('create');
|
|
259
|
-
expect(url.searchParams.get('display')).toBe('popup');
|
|
260
|
-
expect(url.searchParams.get('login_hint')).toBe('test@example.com');
|
|
261
|
-
expect(url.searchParams.get('acr_values')).toBe('urn:mace:incommon:iap:silver urn:mace:incommon:iap:bronze');
|
|
262
|
-
expect(url.searchParams.get('ui_locales')).toBe('en-US hu-HU');
|
|
263
|
-
expect(url.searchParams.get('audience')).toBe('https://api.example.com https://api2.example.com');
|
|
264
|
-
expect(params).toEqual(extraParams);
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
describe('w/ serverSessionUri', () => {
|
|
269
|
-
test('w/o params', async () => {
|
|
270
|
-
options = createOptions({ urlHandler: vi.fn().mockResolvedValue({}), serverSessionUri: 'https://app.example.com/login' });
|
|
271
|
-
flow = createPopupFlow(options);
|
|
272
|
-
|
|
273
|
-
await flow.register();
|
|
274
|
-
|
|
275
|
-
expect(flow.options.urlHandler).toHaveBeenCalledWith(expect.any(URL), { prompt: 'create', display: 'popup' });
|
|
276
|
-
|
|
277
|
-
const [url, params] = vi.mocked(options.urlHandler).mock.calls[0] as [URL, Record<string, unknown>];
|
|
278
|
-
|
|
279
|
-
expect(`${url.origin}${url.pathname}`).toBe('https://app.example.com/login');
|
|
280
|
-
expect(url.searchParams.has('client_id')).toBeFalsy();
|
|
281
|
-
expect(url.searchParams.has('redirect_uri')).toBeFalsy();
|
|
282
|
-
expect(url.searchParams.has('response_type')).toBeFalsy();
|
|
283
|
-
expect(url.searchParams.has('response_mode')).toBeFalsy();
|
|
284
|
-
expect(url.searchParams.has('scope')).toBeFalsy();
|
|
285
|
-
expect(url.searchParams.has('code_challenge_method')).toBeFalsy();
|
|
286
|
-
expect(url.searchParams.has('state')).toBeFalsy();
|
|
287
|
-
expect(url.searchParams.has('code_challenge')).toBeFalsy();
|
|
288
|
-
expect(url.searchParams.has('nonce')).toBeFalsy();
|
|
289
|
-
expect(url.searchParams.get('prompt')).toBe('create');
|
|
290
|
-
expect(url.searchParams.get('display')).toBe('popup');
|
|
291
|
-
expect(url.searchParams.has('login_hint')).toBeFalsy();
|
|
292
|
-
expect(url.searchParams.has('acr_values')).toBeFalsy();
|
|
293
|
-
expect(url.searchParams.has('ui_locales')).toBeFalsy();
|
|
294
|
-
expect(url.searchParams.has('audience')).toBeFalsy();
|
|
295
|
-
expect(params).toEqual({ prompt: 'create', display: 'popup' });
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test('w/ params', async () => {
|
|
299
|
-
options = createOptions({ urlHandler: vi.fn().mockResolvedValue({}), serverSessionUri: 'https://app.example.com/login' });
|
|
300
|
-
flow = createPopupFlow(options);
|
|
301
|
-
|
|
302
|
-
const extraParams = {
|
|
303
|
-
prompt: 'create',
|
|
304
|
-
display: 'popup',
|
|
305
|
-
loginHint: 'test@example.com',
|
|
306
|
-
acrValues: ['urn:mace:incommon:iap:silver', 'urn:mace:incommon:iap:bronze'],
|
|
307
|
-
uiLocales: ['en-US', 'hu-HU'],
|
|
308
|
-
audiences: ['https://api.example.com', 'https://api2.example.com'],
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
await flow.register({ ...extraParams, prompt: undefined });
|
|
312
|
-
|
|
313
|
-
expect(flow.options.urlHandler).toHaveBeenCalledWith(expect.any(URL), extraParams);
|
|
314
|
-
|
|
315
|
-
const [url, params] = vi.mocked(options.urlHandler).mock.calls[0] as [URL, Record<string, unknown>];
|
|
316
|
-
|
|
317
|
-
expect(`${url.origin}${url.pathname}`).toBe('https://app.example.com/login');
|
|
318
|
-
expect(url.searchParams.has('client_id')).toBeFalsy();
|
|
319
|
-
expect(url.searchParams.has('redirect_uri')).toBeFalsy();
|
|
320
|
-
expect(url.searchParams.has('response_type')).toBeFalsy();
|
|
321
|
-
expect(url.searchParams.has('response_mode')).toBeFalsy();
|
|
322
|
-
expect(url.searchParams.has('scope')).toBeFalsy();
|
|
323
|
-
expect(url.searchParams.has('code_challenge_method')).toBeFalsy();
|
|
324
|
-
expect(url.searchParams.has('state')).toBeFalsy();
|
|
325
|
-
expect(url.searchParams.has('code_challenge')).toBeFalsy();
|
|
326
|
-
expect(url.searchParams.has('nonce')).toBeFalsy();
|
|
327
|
-
expect(url.searchParams.get('prompt')).toBe('create');
|
|
328
|
-
expect(url.searchParams.get('display')).toBe('popup');
|
|
329
|
-
expect(url.searchParams.get('login_hint')).toBe('test@example.com');
|
|
330
|
-
expect(url.searchParams.get('acr_values')).toBe('urn:mace:incommon:iap:silver urn:mace:incommon:iap:bronze');
|
|
331
|
-
expect(url.searchParams.get('ui_locales')).toBe('en-US hu-HU');
|
|
332
|
-
expect(url.searchParams.get('audience')).toBe('https://api.example.com https://api2.example.com');
|
|
333
|
-
expect(params).toEqual(extraParams);
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
describe('entry', () => {
|
|
339
|
-
test('should redirect to the provider entry endpoint preserving query parameters', async () => {
|
|
340
|
-
await flow.entry('https://brandtegrity.io/entry?challenge=abc123&foo=bar');
|
|
341
|
-
|
|
342
|
-
const [url, params] = vi.mocked(options.urlHandler).mock.calls[0];
|
|
343
|
-
|
|
344
|
-
expect((url as URL).toString()).toBe('https://brandtegrity.io/provider/entry?challenge=abc123&foo=bar');
|
|
345
|
-
expect(params).toBeUndefined();
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
test('should default to the current window location when no url is provided', async () => {
|
|
349
|
-
window.location.search = '?challenge=abc123&foo=bar';
|
|
350
|
-
|
|
351
|
-
await flow.entry();
|
|
352
|
-
|
|
353
|
-
const [url] = vi.mocked(options.urlHandler).mock.calls[0];
|
|
354
|
-
|
|
355
|
-
expect((url as URL).toString()).toBe('https://brandtegrity.io/provider/entry?challenge=abc123&foo=bar');
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
test('flow state accessors', async () => {
|
|
360
|
-
options = createOptions({ lazyLoad: true, urlHandler: vi.fn().mockResolvedValue({ code: 'abc123' }) });
|
|
361
|
-
flow = createPopupFlow(options);
|
|
362
|
-
|
|
363
|
-
expect(flow.options).toBe(options);
|
|
364
|
-
expect(flow.initialized).toBeFalsy();
|
|
365
|
-
expect(flow.storage).toBe(options.storage);
|
|
366
|
-
expect(flow.httpClient).toBe(options.httpClient);
|
|
367
|
-
expect(flow.logging).toBe(options.logging);
|
|
368
|
-
expect(flow.sessionId).toBeNull();
|
|
369
|
-
expect(flow.shortAppId).toBeNull();
|
|
370
|
-
expect(flow.language).toBe('en-US');
|
|
371
|
-
await expect(flow.isAuthenticated).resolves.toBeFalsy();
|
|
372
|
-
expect(flow.isAuthenticatedSync).toBeFalsy();
|
|
373
|
-
expect(flow.accessToken).toBeNull();
|
|
374
|
-
expect(flow.accessTokenExpired).toBeTruthy();
|
|
375
|
-
expect(flow.accessTokenExpirationDate).toBeNull();
|
|
376
|
-
expect(flow.refreshToken).toBeNull();
|
|
377
|
-
expect(flow.idToken).toBeNull();
|
|
378
|
-
expect(flow.idTokenClaims).toBeNull();
|
|
379
|
-
|
|
380
|
-
await flow.init();
|
|
381
|
-
|
|
382
|
-
flow.sessionId = 'abc123';
|
|
383
|
-
flow.shortAppId = 'app';
|
|
384
|
-
flow.language = 'hu-HU';
|
|
385
|
-
flow.session = getMockStorage(options.storage).generateSession();
|
|
386
|
-
|
|
387
|
-
expect(flow.initialized).toBeTruthy();
|
|
388
|
-
expect(flow.sessionId).toBe('abc123');
|
|
389
|
-
expect(flow.shortAppId).toBe('app');
|
|
390
|
-
expect(flow.language).toBe('hu-HU');
|
|
391
|
-
await expect(flow.isAuthenticated).resolves.toBeTruthy();
|
|
392
|
-
expect(flow.isAuthenticatedSync).toBeTruthy();
|
|
393
|
-
expect(flow.accessToken).toBe(flow.session.access_token);
|
|
394
|
-
expect(flow.accessTokenExpired).toBeFalsy();
|
|
395
|
-
expect(flow.accessTokenExpirationDate).toBe(flow.session.expires_at);
|
|
396
|
-
expect(flow.refreshToken).toBe(flow.session.refresh_token);
|
|
397
|
-
expect(flow.idToken).toBe(flow.session.id_token);
|
|
398
|
-
expect(flow.idTokenClaims).toBe(flow.session?.claims);
|
|
399
|
-
});
|
|
400
|
-
});
|