@equinor/fusion-framework-vite-plugin-spa 4.0.17 → 4.1.0
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/CHANGELOG.md +37 -0
- package/README.md +123 -5
- package/dist/esm/html/bootstrap.js +23 -10
- package/dist/esm/html/bootstrap.js.map +1 -1
- package/dist/esm/html/is-enabled-env-value.js +10 -0
- package/dist/esm/html/is-enabled-env-value.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/html/bootstrap.js +5575 -45208
- package/dist/html/bootstrap.js.map +1 -1
- package/dist/index-B_3FYBBq.js +879 -0
- package/dist/index-B_3FYBBq.js.map +1 -0
- package/dist/module-w44_1T9j.js +39800 -0
- package/dist/module-w44_1T9j.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/html/html.d.ts +1 -1
- package/dist/types/html/is-enabled-env-value.d.ts +7 -0
- package/dist/types/types.d.ts +12 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -6
- package/src/html/bootstrap.ts +24 -10
- package/src/html/is-enabled-env-value.ts +9 -0
- package/src/types.ts +12 -0
- package/src/version.ts +1 -1
- package/tests/is-enabled-env-value.test.ts +13 -0
- package/vitest.config.ts +1 -1
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
import { a5 as MsalConfigurator, a6 as module$1 } from './module-w44_1T9j.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Encodes a value as base64url without padding, as used in JWT segments.
|
|
5
|
+
*
|
|
6
|
+
* @param value - Raw string to encode.
|
|
7
|
+
* @returns The base64url representation.
|
|
8
|
+
*/
|
|
9
|
+
const base64Url = (value) => {
|
|
10
|
+
// btoa operates on latin1; encodeURIComponent round-trip keeps non-ASCII names intact
|
|
11
|
+
const bytes = new TextEncoder().encode(value);
|
|
12
|
+
let binary = '';
|
|
13
|
+
// Iterate over encoded bytes so Unicode claims are preserved before base64url encoding.
|
|
14
|
+
for (const byte of bytes) {
|
|
15
|
+
binary += String.fromCharCode(byte);
|
|
16
|
+
}
|
|
17
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Creates a structurally valid, unsigned JWT for use in tests.
|
|
21
|
+
*
|
|
22
|
+
* The token has three base64url segments and decodes to the supplied claims, so
|
|
23
|
+
* code that splits, decodes, or inspects token claims behaves exactly as it does
|
|
24
|
+
* in production. The signature segment is a fixed placeholder — the token is
|
|
25
|
+
* **not** cryptographically valid and will be rejected by any real service.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* Timestamps default to a fixed issue time and a one-hour lifetime so repeated
|
|
29
|
+
* runs produce byte-identical tokens. A test that needs an expired token can set
|
|
30
|
+
* `exp` in the past.
|
|
31
|
+
*
|
|
32
|
+
* @param claims - Claims to embed in the token payload.
|
|
33
|
+
* @returns An unsigned JWT string in `header.payload.signature` form.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const token = createMockToken({ name: 'Test User', scp: 'Files.Read' });
|
|
38
|
+
* const [, payload] = token.split('.');
|
|
39
|
+
* JSON.parse(decodeJwtSegment(payload)).name; // 'Test User'
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
const createMockToken = (claims = {}) => {
|
|
43
|
+
const header = { alg: 'none', typ: 'JWT' };
|
|
44
|
+
// Fixed default clock keeps generated tokens byte-identical between runs
|
|
45
|
+
const issuedAt = claims.iat ?? 1_700_000_000;
|
|
46
|
+
const payload = {
|
|
47
|
+
iss: 'https://login.microsoftonline.com/fusion-test-tenant/v2.0',
|
|
48
|
+
aud: 'fusion-test-client',
|
|
49
|
+
tid: 'fusion-test-tenant',
|
|
50
|
+
oid: 'fusion-test-user',
|
|
51
|
+
iat: issuedAt,
|
|
52
|
+
nbf: issuedAt,
|
|
53
|
+
exp: issuedAt + 3600,
|
|
54
|
+
...claims,
|
|
55
|
+
};
|
|
56
|
+
return [
|
|
57
|
+
base64Url(JSON.stringify(header)),
|
|
58
|
+
base64Url(JSON.stringify(payload)),
|
|
59
|
+
'fusion-test-signature',
|
|
60
|
+
].join('.');
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A stand-in for the MSAL client that resolves tokens in-process.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Constructed from {@link MsalClientConfig} — the very same argument
|
|
68
|
+
* {@link MsalClient} takes — so it is a drop-in substitute rather than a second
|
|
69
|
+
* API to learn. `setClientConfig` therefore means the same thing whether a test
|
|
70
|
+
* runs against Entra ID or against this client.
|
|
71
|
+
*
|
|
72
|
+
* Only the boundary that would contact Entra ID is replaced. The real
|
|
73
|
+
* `MsalProvider` runs on top of it unchanged, so account handling, silent-token
|
|
74
|
+
* preference, scope resolution, proxy providers and telemetry behave as they do in
|
|
75
|
+
* production — the test exercises the framework rather than the mock.
|
|
76
|
+
*
|
|
77
|
+
* Tokens are structurally valid, unsigned JWTs and are byte-identical between runs.
|
|
78
|
+
* They are **not** cryptographically valid and are rejected by any real service.
|
|
79
|
+
*/
|
|
80
|
+
class MsalMockClient {
|
|
81
|
+
#user;
|
|
82
|
+
#cache = new Map();
|
|
83
|
+
#activeAccountId = null;
|
|
84
|
+
#token = null;
|
|
85
|
+
/**
|
|
86
|
+
* The account currently signed in, or `null`.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* Reads through the cache rather than holding an account of its own, so an
|
|
90
|
+
* account removed by a sign-out cannot linger as the active one.
|
|
91
|
+
*
|
|
92
|
+
* @returns The cached active account, or `null` when none is active.
|
|
93
|
+
*/
|
|
94
|
+
get #account() {
|
|
95
|
+
return this.#activeAccountId ? (this.#cache.get(this.#activeAccountId) ?? null) : null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Signs an account in, adding it to the cache and making it active.
|
|
99
|
+
*
|
|
100
|
+
* @param account - The account to sign in.
|
|
101
|
+
* @returns The signed-in account.
|
|
102
|
+
*/
|
|
103
|
+
#signIn(account) {
|
|
104
|
+
this.#cache.set(account.homeAccountId, account);
|
|
105
|
+
this.#activeAccountId = account.homeAccountId;
|
|
106
|
+
return account;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Signs the active account out, as MSAL does — the account leaves the cache.
|
|
110
|
+
*/
|
|
111
|
+
#signOut() {
|
|
112
|
+
// Only clear the cache entry when a session is active; this preserves an already signed-out state.
|
|
113
|
+
if (this.#activeAccountId) {
|
|
114
|
+
this.#cache.delete(this.#activeAccountId);
|
|
115
|
+
this.#activeAccountId = null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Mirrors MSAL's redirect completion, which is a no-op for this in-process mock.
|
|
120
|
+
* @returns Always `null`, because the mock performs no redirect.
|
|
121
|
+
*/
|
|
122
|
+
async handleRedirectPromise() {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Mirrors silent SSO and returns a token for the cached mock account.
|
|
127
|
+
* @param request - Silent SSO options and requested scopes.
|
|
128
|
+
* @returns A mock authentication result.
|
|
129
|
+
* @throws When no account is cached.
|
|
130
|
+
*/
|
|
131
|
+
async ssoSilent(request) {
|
|
132
|
+
// Silent SSO must fail without a session so providers exercise their login path.
|
|
133
|
+
if (!this.#account) {
|
|
134
|
+
throw new Error('MsalMockClient: no cached account for silent sign-in');
|
|
135
|
+
}
|
|
136
|
+
return this.#createResult(request.scopes);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Mirrors popup login by signing in the configured mock user immediately.
|
|
140
|
+
* @param request - Optional popup options and requested scopes.
|
|
141
|
+
* @returns A mock authentication result.
|
|
142
|
+
*/
|
|
143
|
+
async loginPopup(request) {
|
|
144
|
+
this.#signIn(this.#createAccount());
|
|
145
|
+
return this.#createResult(request?.scopes);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Mirrors redirect login without navigating, because the mock has no browser boundary.
|
|
149
|
+
* @param _request - Redirect options, accepted for interface compatibility.
|
|
150
|
+
*/
|
|
151
|
+
async loginRedirect(_request) {
|
|
152
|
+
this.#signIn(this.#createAccount());
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Mirrors the framework login entry point with an immediate mock sign-in.
|
|
156
|
+
* @param options - Login options including the requested scopes.
|
|
157
|
+
* @returns A mock login result.
|
|
158
|
+
*/
|
|
159
|
+
async login(options) {
|
|
160
|
+
this.#signIn(this.#createAccount());
|
|
161
|
+
return this.#createResult(options.request?.scopes);
|
|
162
|
+
}
|
|
163
|
+
/** Mirrors logout by removing the active mock account from the cache. */
|
|
164
|
+
async logout() {
|
|
165
|
+
this.#signOut();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Mirrors MSAL initialization without performing a network handshake.
|
|
169
|
+
* @param _request - Initialization options, accepted for interface compatibility.
|
|
170
|
+
*/
|
|
171
|
+
async initialize(_request) {
|
|
172
|
+
// No network handshake to perform
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Mirrors popup token acquisition using the mock login flow.
|
|
176
|
+
* @param request - Popup token request.
|
|
177
|
+
* @returns A mock authentication result.
|
|
178
|
+
*/
|
|
179
|
+
async acquireTokenPopup(request) {
|
|
180
|
+
return this.loginPopup(request);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Mirrors redirect token acquisition without browser navigation.
|
|
184
|
+
* @param request - Redirect token request.
|
|
185
|
+
*/
|
|
186
|
+
async acquireTokenRedirect(request) {
|
|
187
|
+
return this.loginRedirect(request);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Mirrors silent token acquisition for the cached mock account.
|
|
191
|
+
* @param request - Silent token request.
|
|
192
|
+
* @returns A mock authentication result.
|
|
193
|
+
* @throws When no account is cached.
|
|
194
|
+
*/
|
|
195
|
+
async acquireTokenSilent(request) {
|
|
196
|
+
// Silent acquisition must fail without a session, matching the real MSAL boundary.
|
|
197
|
+
if (!this.#account) {
|
|
198
|
+
throw new Error('MsalMockClient: no cached account for silent sign-in');
|
|
199
|
+
}
|
|
200
|
+
return this.#createResult(request.scopes);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Mirrors MSAL event registration; events are intentionally not emitted by the mock.
|
|
204
|
+
* @param _callback - Event handler, accepted for interface compatibility.
|
|
205
|
+
* @param _eventTypes - Event types, accepted for interface compatibility.
|
|
206
|
+
* @returns Always `null`, because the mock registers no callback.
|
|
207
|
+
*/
|
|
208
|
+
addEventCallback(_callback, _eventTypes) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Mirrors event removal as a no-op because this mock registers no callbacks.
|
|
213
|
+
* @param _callbackId - Callback identifier, accepted for interface compatibility.
|
|
214
|
+
*/
|
|
215
|
+
removeEventCallback(_callbackId) {
|
|
216
|
+
// No-op for mock
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Mirrors performance callback registration with a stable mock identifier.
|
|
220
|
+
* @param _callback - Performance handler, accepted for interface compatibility.
|
|
221
|
+
* @returns A stable mock callback identifier.
|
|
222
|
+
*/
|
|
223
|
+
addPerformanceCallback(_callback) {
|
|
224
|
+
return 'mock-performance-callback';
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Mirrors performance callback removal and reports successful mock removal.
|
|
228
|
+
* @param _callbackId - Callback identifier, accepted for interface compatibility.
|
|
229
|
+
* @returns Always `true` because no callback state is retained.
|
|
230
|
+
*/
|
|
231
|
+
removePerformanceCallback(_callbackId) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Mirrors MSAL account lookup against the mock cache.
|
|
236
|
+
* @param accountFilter - Account fields to match.
|
|
237
|
+
* @returns The first matching account, or `null`.
|
|
238
|
+
*/
|
|
239
|
+
getAccount(accountFilter) {
|
|
240
|
+
const filter = (accountFilter ?? {});
|
|
241
|
+
// Filter the cache so callers observe the same account-selection semantics as MSAL.
|
|
242
|
+
const matches = this.getAllAccounts().filter((account) => (filter.homeAccountId === undefined || filter.homeAccountId === account.homeAccountId) &&
|
|
243
|
+
(filter.localAccountId === undefined || filter.localAccountId === account.localAccountId) &&
|
|
244
|
+
(filter.username === undefined || filter.username === account.username) &&
|
|
245
|
+
(filter.tenantId === undefined || filter.tenantId === account.tenantId));
|
|
246
|
+
return matches[0] ?? null;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Mirrors MSAL account enumeration using the mock cache.
|
|
250
|
+
* @param _accountFilter - Account filter, accepted for interface compatibility.
|
|
251
|
+
* @returns All accounts currently in the mock cache.
|
|
252
|
+
*/
|
|
253
|
+
getAllAccounts(_accountFilter) {
|
|
254
|
+
return [...this.#cache.values()];
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Mirrors redirect logout without navigating in the mock environment.
|
|
258
|
+
* @param _request - Logout options, accepted for interface compatibility.
|
|
259
|
+
*/
|
|
260
|
+
async logoutRedirect(_request) {
|
|
261
|
+
this.#signOut();
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Mirrors popup logout without opening a browser window.
|
|
265
|
+
* @param _request - Logout options, accepted for interface compatibility.
|
|
266
|
+
*/
|
|
267
|
+
async logoutPopup(_request) {
|
|
268
|
+
this.#signOut();
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Mirrors MSAL logger access; the mock does not retain a logger.
|
|
272
|
+
* @returns An interface-compatible empty logger value.
|
|
273
|
+
*/
|
|
274
|
+
getLogger() {
|
|
275
|
+
// MSAL's Logger has a large internal surface with no mock consumers depend on; callers only pass it through
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Mirrors logger configuration as a no-op for the mock.
|
|
280
|
+
* @param _logger - Logger, accepted for interface compatibility.
|
|
281
|
+
*/
|
|
282
|
+
setLogger(_logger) {
|
|
283
|
+
// No-op for mock
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Mirrors wrapper metadata initialization as a no-op for the mock.
|
|
287
|
+
* @param _sku - Wrapper identifier, accepted for interface compatibility.
|
|
288
|
+
* @param _version - Wrapper version, accepted for interface compatibility.
|
|
289
|
+
*/
|
|
290
|
+
initializeWrapperLibrary(_sku, _version) {
|
|
291
|
+
// No-op for mock wrapper
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Mirrors navigation-client configuration as a no-op because no navigation occurs.
|
|
295
|
+
* @param _navigationClient - Navigation client, accepted for interface compatibility.
|
|
296
|
+
*/
|
|
297
|
+
setNavigationClient(_navigationClient) {
|
|
298
|
+
// No-op for mock
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Mirrors configuration access and rejects it because the mock has no browser config.
|
|
302
|
+
* @returns Never; this mock does not expose browser configuration.
|
|
303
|
+
* @throws Always, because browser configuration is unsupported.
|
|
304
|
+
*/
|
|
305
|
+
getConfiguration() {
|
|
306
|
+
throw new Error('MsalMockClient: getConfiguration is not supported in the mock client');
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Mirrors cache hydration as a no-op because mock tokens are created in-process.
|
|
310
|
+
* @param _result - Authentication result, accepted for interface compatibility.
|
|
311
|
+
* @param _request - Original token request, accepted for interface compatibility.
|
|
312
|
+
*/
|
|
313
|
+
async hydrateCache(_result, _request) {
|
|
314
|
+
// No-op for mock
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Mirrors MSAL cache clearing by removing every mock account.
|
|
318
|
+
* @param _request - Cache-clear options, accepted for interface compatibility.
|
|
319
|
+
*/
|
|
320
|
+
async clearCache(_request) {
|
|
321
|
+
this.#cache.clear();
|
|
322
|
+
this.#activeAccountId = null;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Mirrors the generic token acquisition entry point for the active mock account.
|
|
326
|
+
* @param options - Token acquisition options.
|
|
327
|
+
* @returns A mock result, or `null` without an active account.
|
|
328
|
+
*/
|
|
329
|
+
async acquireToken(options) {
|
|
330
|
+
// Generic acquisition returns no result when no account is active, matching MSAL's nullable result.
|
|
331
|
+
if (!this.#account) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
return this.#createResult(options.request?.scopes);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Mirrors authorization-code exchange by signing in and returning a mock result.
|
|
338
|
+
* @param request - Authorization-code request.
|
|
339
|
+
* @returns A mock authentication result.
|
|
340
|
+
*/
|
|
341
|
+
async acquireTokenByCode(request) {
|
|
342
|
+
this.#signIn(this.#createAccount());
|
|
343
|
+
return this.#createResult(request?.scopes);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Creates a mock client for the services the given configuration points at.
|
|
347
|
+
*
|
|
348
|
+
* @remarks
|
|
349
|
+
* Takes the same argument as {@link MsalClient}. A user named `Test User` is
|
|
350
|
+
* already in the account cache, so a provider built on this client boots the
|
|
351
|
+
* way one does for a returning user with a live session — no sign-in runs, and
|
|
352
|
+
* the provider's start-up path sees the state it would see in production. Use
|
|
353
|
+
* {@link MsalMockClient.setUser | setUser} to say who that user is.
|
|
354
|
+
*
|
|
355
|
+
* @param config - The same client configuration the real client is built from.
|
|
356
|
+
*/
|
|
357
|
+
constructor(config) {
|
|
358
|
+
const tenantId = config.auth.tenantId ?? MsalMockClient.#tenantFromAuthority(config.auth);
|
|
359
|
+
this.#user = {
|
|
360
|
+
name: 'Test User',
|
|
361
|
+
username: 'test.user@equinor.com',
|
|
362
|
+
userId: 'fusion-mock-user',
|
|
363
|
+
tenantId: tenantId ?? 'fusion-mock-tenant',
|
|
364
|
+
scopes: ['fusion-mock-scope'],
|
|
365
|
+
clientId: config.auth.clientId,
|
|
366
|
+
};
|
|
367
|
+
this.#signIn(this.#createAccount());
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Reads the tenant out of an authority URL.
|
|
371
|
+
*
|
|
372
|
+
* @remarks
|
|
373
|
+
* A configuration may carry only `authority`, in which case the tenant still
|
|
374
|
+
* has to end up on the tokens this client mints for the account to look like
|
|
375
|
+
* the one a real sign-in would have produced.
|
|
376
|
+
*
|
|
377
|
+
* @param auth - The auth section of the client configuration.
|
|
378
|
+
* @returns The tenant, or `undefined` when the authority carries none.
|
|
379
|
+
*/
|
|
380
|
+
static #tenantFromAuthority(auth) {
|
|
381
|
+
// An explicit tenant takes precedence; only parse authority when configuration omitted it.
|
|
382
|
+
if (!auth.authority) {
|
|
383
|
+
return undefined;
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
// Remove empty URL path segments to identify the authority's tenant consistently.
|
|
387
|
+
const segments = new URL(auth.authority).pathname.split('/').filter(Boolean);
|
|
388
|
+
return segments.at(-1);
|
|
389
|
+
}
|
|
390
|
+
catch {
|
|
391
|
+
return undefined;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Returns the client identifier used by tokens minted by this mock.
|
|
396
|
+
* @returns The configured client identifier.
|
|
397
|
+
*/
|
|
398
|
+
get clientId() {
|
|
399
|
+
return this.#user.clientId;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Returns the tenant identifier used by tokens minted by this mock.
|
|
403
|
+
* @returns The configured tenant identifier.
|
|
404
|
+
*/
|
|
405
|
+
get tenantId() {
|
|
406
|
+
return this.#user.tenantId;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Reports whether the mock currently has an active account.
|
|
410
|
+
* @returns Whether an account is active.
|
|
411
|
+
*/
|
|
412
|
+
get hasValidClaims() {
|
|
413
|
+
return this.#account !== null;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Mirrors MSAL active-account access using the mock's single active account.
|
|
417
|
+
* @returns The active account, or `null`.
|
|
418
|
+
*/
|
|
419
|
+
getActiveAccount() {
|
|
420
|
+
return this.#account;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Makes an account the active one, adding it to the cache if it is unknown.
|
|
424
|
+
*
|
|
425
|
+
* @remarks
|
|
426
|
+
* Real MSAL requires the account to already be cached. Accepting an unknown
|
|
427
|
+
* one is a deliberate concession to tests: it is the shortest way to swap the
|
|
428
|
+
* signed-in user between runs, without reconstructing the framework.
|
|
429
|
+
*
|
|
430
|
+
* @param next - The account to make active, or `null` to sign out.
|
|
431
|
+
*/
|
|
432
|
+
setActiveAccount(next) {
|
|
433
|
+
// A null account is the MSAL sign-out signal, so clear the active mock session.
|
|
434
|
+
if (!next) {
|
|
435
|
+
this.#signOut();
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
this.#signIn(next);
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Declares who is signed in, replacing whoever was.
|
|
442
|
+
*
|
|
443
|
+
* @remarks
|
|
444
|
+
* This is the counterpart to a real sign-in: the client is configured with
|
|
445
|
+
* what it talks to, and learns the user separately. `MsalMockConfigurator`
|
|
446
|
+
* applies it as the configuration is assembled, so the account is in the cache
|
|
447
|
+
* before `MsalProvider.initialize` runs — the provider then behaves as it does
|
|
448
|
+
* for a returning user with a live session.
|
|
449
|
+
*
|
|
450
|
+
* Values left out keep whatever they were. Passing `null` signs out and
|
|
451
|
+
* forgets the identity, so the provider follows its unauthenticated path;
|
|
452
|
+
* `{ signedOut: true }` does the same but keeps the identity, so a later login
|
|
453
|
+
* resolves as that user.
|
|
454
|
+
*
|
|
455
|
+
* @param user - The user to sign in, or `null` when nobody is.
|
|
456
|
+
*/
|
|
457
|
+
setUser(user) {
|
|
458
|
+
// Declaring a user replaces the session rather than adding to it, so a test
|
|
459
|
+
// that names a second user does not silently end up with two cached accounts
|
|
460
|
+
this.#cache.clear();
|
|
461
|
+
this.#activeAccountId = null;
|
|
462
|
+
// A null user explicitly clears the session and identity supplied to the mock.
|
|
463
|
+
if (!user) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const { account, signedOut, ...rest } = user;
|
|
467
|
+
// Merge overrides while retaining defaults for fields omitted by the test.
|
|
468
|
+
this.#user = {
|
|
469
|
+
...this.#user,
|
|
470
|
+
...rest,
|
|
471
|
+
name: rest.name ?? account?.name ?? this.#user.name,
|
|
472
|
+
username: rest.username ?? account?.username ?? this.#user.username,
|
|
473
|
+
userId: rest.userId ?? account?.localAccountId ?? this.#user.userId,
|
|
474
|
+
tenantId: rest.tenantId ?? account?.tenantId ?? this.#user.tenantId,
|
|
475
|
+
scopes: rest.scopes ?? this.#user.scopes,
|
|
476
|
+
};
|
|
477
|
+
// Keep identity data without caching an account when the test starts signed out.
|
|
478
|
+
if (signedOut) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
this.#signIn(account ?? this.#createAccount());
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Overrides the token returned by future results, independent of who is signed in.
|
|
485
|
+
*
|
|
486
|
+
* @remarks
|
|
487
|
+
* Use this when a backend mock validates its own tokens (specific claims, an
|
|
488
|
+
* audience, or a signature) — supplying the exact token here means that
|
|
489
|
+
* backend sees the token it issued, rather than a mock-shaped substitute this
|
|
490
|
+
* client would otherwise fabricate from the signed-in user's fields.
|
|
491
|
+
*
|
|
492
|
+
* @param token - The token to return verbatim, or `null` to resume generating one.
|
|
493
|
+
*/
|
|
494
|
+
setToken(token) {
|
|
495
|
+
this.#token = token;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Creates the one account represented by this mock's configured identity.
|
|
499
|
+
* @returns An MSAL-shaped account for the configured user.
|
|
500
|
+
*/
|
|
501
|
+
#createAccount() {
|
|
502
|
+
return {
|
|
503
|
+
homeAccountId: `${this.#user.userId}.${this.#user.tenantId}`,
|
|
504
|
+
localAccountId: this.#user.userId,
|
|
505
|
+
environment: 'login.microsoftonline.com',
|
|
506
|
+
tenantId: this.#user.tenantId,
|
|
507
|
+
username: this.#user.username,
|
|
508
|
+
name: this.#user.name,
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Creates an MSAL-shaped token result for the requested or default scopes.
|
|
513
|
+
* @param scopes - Requested scopes, or the user's configured defaults.
|
|
514
|
+
* @returns An MSAL-shaped mock authentication result.
|
|
515
|
+
*/
|
|
516
|
+
#createResult(scopes) {
|
|
517
|
+
const granted = scopes?.length ? scopes : this.#user.scopes;
|
|
518
|
+
// a caller-supplied token is sent verbatim so a backend mock validating it sees what it expects
|
|
519
|
+
const token = this.#token ??
|
|
520
|
+
createMockToken({
|
|
521
|
+
name: this.#user.name,
|
|
522
|
+
preferred_username: this.#user.username,
|
|
523
|
+
oid: this.#user.userId,
|
|
524
|
+
tid: this.#user.tenantId,
|
|
525
|
+
aud: this.#user.clientId,
|
|
526
|
+
scp: granted.join(' '),
|
|
527
|
+
});
|
|
528
|
+
// Object shape matches AuthenticationResult's fields consumers rely on; the real
|
|
529
|
+
// type also carries browser-only fields (e.g. `familyId`) this mock intentionally omits
|
|
530
|
+
return {
|
|
531
|
+
account: this.#account ?? this.#createAccount(),
|
|
532
|
+
accessToken: token,
|
|
533
|
+
idToken: token,
|
|
534
|
+
scopes: granted,
|
|
535
|
+
tokenType: 'Bearer',
|
|
536
|
+
expiresOn: new Date('2033-11-14T22:13:20.000Z'),
|
|
537
|
+
authority: `https://login.microsoftonline.com/${this.#user.tenantId}`,
|
|
538
|
+
uniqueId: this.#user.userId,
|
|
539
|
+
tenantId: this.#user.tenantId,
|
|
540
|
+
fromCache: false,
|
|
541
|
+
correlationId: 'fusion-mock-correlation',
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Decodes a base64url segment of a {@link createMockToken} JWT back to its JSON string.
|
|
548
|
+
*
|
|
549
|
+
* @remarks
|
|
550
|
+
* Plain `atob` alone mangles non-ASCII claims: it treats its output as latin1,
|
|
551
|
+
* while segments are UTF-8 encoded. This reverses that encoding and also
|
|
552
|
+
* restores the standard base64 alphabet/padding `atob` expects.
|
|
553
|
+
*
|
|
554
|
+
* @param segment - A base64url segment, e.g. from splitting a JWT on `.`.
|
|
555
|
+
* @returns The decoded UTF-8 string.
|
|
556
|
+
*/
|
|
557
|
+
function decodeJwtSegment(segment) {
|
|
558
|
+
const base64 = segment
|
|
559
|
+
.replace(/-/g, '+')
|
|
560
|
+
.replace(/_/g, '/')
|
|
561
|
+
.padEnd(segment.length + ((4 - (segment.length % 4)) % 4), '=');
|
|
562
|
+
const binary = atob(base64);
|
|
563
|
+
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
564
|
+
return new TextDecoder().decode(bytes);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Derives a {@link MsalMockUser} from a JWT's payload claims, so a token minted
|
|
569
|
+
* outside this module (e.g. by a backend's own mock) can drive who the mock
|
|
570
|
+
* signs in as.
|
|
571
|
+
*
|
|
572
|
+
* @remarks
|
|
573
|
+
* Maps the standard Entra ID claims Fusion applications read — `name`,
|
|
574
|
+
* `preferred_username`, `oid`, `tid`, `scp` — onto the matching
|
|
575
|
+
* {@link MsalMockUser} fields. Identity only: it does not affect which token
|
|
576
|
+
* the client returns — use {@link MsalMockConfigurator.setToken} for that.
|
|
577
|
+
*
|
|
578
|
+
* @param token - A JWT (e.g. from {@link createMockToken}, or issued by an
|
|
579
|
+
* external mock) with a base64url-encoded payload segment.
|
|
580
|
+
* @returns A mock user built from the token's claims.
|
|
581
|
+
* @throws When the token has no payload segment (`header.payload.signature`).
|
|
582
|
+
*
|
|
583
|
+
* @example
|
|
584
|
+
* ```typescript
|
|
585
|
+
* enableMsalMock(configurator, (builder) => {
|
|
586
|
+
* builder.setAccount(createMockUserFromToken(token));
|
|
587
|
+
* });
|
|
588
|
+
* ```
|
|
589
|
+
*/
|
|
590
|
+
const createMockUserFromToken = (token) => {
|
|
591
|
+
const [, payload] = token.split('.');
|
|
592
|
+
// fail loudly rather than signing in an empty/garbage user from a malformed token
|
|
593
|
+
if (!payload) {
|
|
594
|
+
throw new Error('createMockUserFromToken: expected a JWT with a payload segment (header.payload.signature)');
|
|
595
|
+
}
|
|
596
|
+
const claims = JSON.parse(decodeJwtSegment(payload));
|
|
597
|
+
return {
|
|
598
|
+
name: claims.name,
|
|
599
|
+
username: claims.preferred_username,
|
|
600
|
+
userId: claims.oid,
|
|
601
|
+
tenantId: claims.tid,
|
|
602
|
+
scopes: claims.scp?.split(' '),
|
|
603
|
+
};
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* The client configuration used when a test declares none.
|
|
608
|
+
*
|
|
609
|
+
* @remarks
|
|
610
|
+
* `MsalClientConfig.auth.clientId` is required, so a mock still needs a client
|
|
611
|
+
* configuration to exist. Supplying a default is what lets an application boot
|
|
612
|
+
* under test without declaring credentials it does not have.
|
|
613
|
+
*/
|
|
614
|
+
const defaultMockClientConfig = {
|
|
615
|
+
auth: {
|
|
616
|
+
clientId: 'fusion-mock-client',
|
|
617
|
+
tenantId: 'fusion-mock-tenant',
|
|
618
|
+
},
|
|
619
|
+
};
|
|
620
|
+
/**
|
|
621
|
+
* The real MSAL configurator, backed by an in-process client.
|
|
622
|
+
*
|
|
623
|
+
* @remarks
|
|
624
|
+
* Nothing else changes: the same builder API, the same validation and the same
|
|
625
|
+
* `MsalProvider` are used. Only the boundary that would contact Entra ID is
|
|
626
|
+
* substituted, through the same
|
|
627
|
+
* {@link MsalConfigurator._createClient | _createClient} seam the real
|
|
628
|
+
* configurator builds its own client from — and from the same
|
|
629
|
+
* {@link MsalConfigurator._createClientConfig | _createClientConfig}, so
|
|
630
|
+
* `setClientConfig` means exactly what it means in production.
|
|
631
|
+
*
|
|
632
|
+
* A user named `Test User` is signed in by default, so an application boots
|
|
633
|
+
* without declaring anything.
|
|
634
|
+
*
|
|
635
|
+
* @example Name the signed-in user
|
|
636
|
+
* ```typescript
|
|
637
|
+
* enableMsalMock(configurator, (builder) => {
|
|
638
|
+
* builder.setAccount({ name: 'Ada Lovelace', username: 'ada@equinor.com' });
|
|
639
|
+
* });
|
|
640
|
+
* ```
|
|
641
|
+
*
|
|
642
|
+
* @example Configure the client exactly as in production
|
|
643
|
+
* ```typescript
|
|
644
|
+
* enableMsalMock(configurator, (builder) => {
|
|
645
|
+
* builder.setClientConfig({ auth: { clientId: 'my-app', tenantId: 'my-tenant' } });
|
|
646
|
+
* });
|
|
647
|
+
* ```
|
|
648
|
+
*
|
|
649
|
+
* @example Take full control of authentication
|
|
650
|
+
* ```typescript
|
|
651
|
+
* enableMsalMock(configurator, (builder) => {
|
|
652
|
+
* builder.setClient(new MyOwnMsalClient());
|
|
653
|
+
* });
|
|
654
|
+
* ```
|
|
655
|
+
*/
|
|
656
|
+
class MsalMockConfigurator extends MsalConfigurator {
|
|
657
|
+
/**
|
|
658
|
+
* Declares the user to sign in.
|
|
659
|
+
*
|
|
660
|
+
* @remarks
|
|
661
|
+
* Who is signed in is session state, not client configuration — which is what
|
|
662
|
+
* lets {@link MsalMockClient} take the same argument the real client takes: a
|
|
663
|
+
* client is configured with *what it talks to*, never with *who is signed in*.
|
|
664
|
+
*
|
|
665
|
+
* The user is therefore recorded on the configuration as `mock.account`, not
|
|
666
|
+
* on this builder, and is signed in on whichever client the module ends up
|
|
667
|
+
* authenticating through — wherever that client was built:
|
|
668
|
+
*
|
|
669
|
+
* - The client this builder builds, normally. The user is in place before
|
|
670
|
+
* `MsalProvider.initialize` runs, which is what makes the provider's own
|
|
671
|
+
* start-up path observable: with `signedOut` and `setRequiresAuth(true)`, a
|
|
672
|
+
* test sees the real automatic login run.
|
|
673
|
+
* - The **host's** client when the module is hoisted onto a host
|
|
674
|
+
* application's provider, because none is built here. An application inside
|
|
675
|
+
* a portal shares the portal's session, so this changes who the host sees
|
|
676
|
+
* signed in too, as it would in production.
|
|
677
|
+
* - A client supplied through {@link MsalConfigurator.setClient | setClient},
|
|
678
|
+
* when that client is a {@link MsalMockClient}.
|
|
679
|
+
*
|
|
680
|
+
* Throws when that client cannot represent a declared user, rather than
|
|
681
|
+
* failing quietly — a silent no-op is the whole failure mode this exists to
|
|
682
|
+
* prevent.
|
|
683
|
+
*
|
|
684
|
+
* Pass `null` when nobody is signed in, or `{ signedOut: true }` to keep an
|
|
685
|
+
* identity without a session — a later login then resolves as that user.
|
|
686
|
+
*
|
|
687
|
+
* @param account - The user, or an ordinary config-builder callback resolving it.
|
|
688
|
+
* @returns The builder, for chaining.
|
|
689
|
+
*
|
|
690
|
+
* @example Derive the user from the modules in scope
|
|
691
|
+
* ```typescript
|
|
692
|
+
* builder.setAccount(async ({ hasModule }) => ({
|
|
693
|
+
* name: hasModule('app') ? 'App User' : 'Portal User',
|
|
694
|
+
* }));
|
|
695
|
+
* ```
|
|
696
|
+
*/
|
|
697
|
+
setAccount(account) {
|
|
698
|
+
this._set('mock.account', account);
|
|
699
|
+
return this;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Declares the token to return, independent of who is signed in.
|
|
703
|
+
*
|
|
704
|
+
* @remarks
|
|
705
|
+
* Use this when a backend mock validates its own tokens (specific claims, an
|
|
706
|
+
* audience, or a signature) — the client then returns this token verbatim
|
|
707
|
+
* instead of fabricating one from the signed-in user's fields.
|
|
708
|
+
*
|
|
709
|
+
* @param token - A JWT (e.g. from `createMockToken`, or issued by an external mock).
|
|
710
|
+
* @param skipResolve - When `true`, override only the token and leave an account
|
|
711
|
+
* declared through {@link setAccount} untouched. Defaults to `false`, which also signs
|
|
712
|
+
* in the user described by the token's claims, via {@link createMockUserFromToken}.
|
|
713
|
+
* @returns The builder, for chaining.
|
|
714
|
+
*
|
|
715
|
+
* @example Sign in as whoever the token names
|
|
716
|
+
* ```typescript
|
|
717
|
+
* builder.setToken(token);
|
|
718
|
+
* ```
|
|
719
|
+
*
|
|
720
|
+
* @example Keep a separately declared account, but return this exact token
|
|
721
|
+
* ```typescript
|
|
722
|
+
* builder.setAccount({ name: 'Ada Lovelace' }).setToken(token, true);
|
|
723
|
+
* ```
|
|
724
|
+
*/
|
|
725
|
+
setToken(token, skipResolve = false) {
|
|
726
|
+
this._set('mock.token', token);
|
|
727
|
+
// skipResolve defaults to false - most callers want the token's claims to name who is signed in
|
|
728
|
+
if (!skipResolve) {
|
|
729
|
+
this.setAccount(createMockUserFromToken(token));
|
|
730
|
+
}
|
|
731
|
+
return this;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Resolves the client the module authenticates through, wherever it was built.
|
|
735
|
+
*
|
|
736
|
+
* @remarks
|
|
737
|
+
* Shared by {@link setAccount} and {@link setToken} application: neither can
|
|
738
|
+
* assume the scope declaring mock state is the scope that built the client,
|
|
739
|
+
* which is exactly what is not true when an application is tested inside a
|
|
740
|
+
* portal. The host built that client, in a scope this builder never sees, so
|
|
741
|
+
* the client has to be located rather than assumed.
|
|
742
|
+
*
|
|
743
|
+
* @param config - The validated configuration, carrying the client when one was built.
|
|
744
|
+
* @param init - The builder arguments, carrying the host reference when hoisted.
|
|
745
|
+
* @param action - Describes what could not be applied, for the thrown error.
|
|
746
|
+
* @returns The resolved mock client.
|
|
747
|
+
* @throws When the resolved client is not a {@link MsalMockClient}.
|
|
748
|
+
*/
|
|
749
|
+
#getClient(config, init, action) {
|
|
750
|
+
const host = init?.ref?.auth;
|
|
751
|
+
const client = config.client ?? host?.client;
|
|
752
|
+
// Reject a real client because mock state cannot be applied to it.
|
|
753
|
+
if (!(client instanceof MsalMockClient)) {
|
|
754
|
+
throw new Error(`MsalMockConfigurator: cannot ${action}, because this module does not authenticate through a mock client. Declare it where that client is configured instead.`);
|
|
755
|
+
}
|
|
756
|
+
return client;
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Signs the declared user in on the client the module authenticates through.
|
|
760
|
+
*
|
|
761
|
+
* @param account - The user to sign in, or `null` when nobody is.
|
|
762
|
+
* @param config - The validated configuration, carrying the client when one was built.
|
|
763
|
+
* @param init - The builder arguments, carrying the host reference when hoisted.
|
|
764
|
+
* @throws When the resolved client is not a {@link MsalMockClient}.
|
|
765
|
+
*/
|
|
766
|
+
#signIn(account, config, init) {
|
|
767
|
+
this.#getClient(config, init, 'sign a user in').setUser(account);
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Assembles the configuration, then signs the declared user in.
|
|
771
|
+
*
|
|
772
|
+
* @remarks
|
|
773
|
+
* Stands a client configuration in first when this builder is the one that
|
|
774
|
+
* will build a client: `MsalClientConfig.auth.clientId` is required to build
|
|
775
|
+
* any client at all and a test has no real credentials to declare. It then
|
|
776
|
+
* flows through the very same
|
|
777
|
+
* {@link MsalConfigurator._createClientConfig | _createClientConfig}
|
|
778
|
+
* enrichment the real client is built from, and anything declared through
|
|
779
|
+
* {@link MsalConfigurator.setClientConfig | setClientConfig} wins — exactly as
|
|
780
|
+
* in production.
|
|
781
|
+
*
|
|
782
|
+
* Doing that here rather than in the constructor is deliberate: a hoisted
|
|
783
|
+
* module authenticates through the host and builds no client, so it must not
|
|
784
|
+
* look configured either.
|
|
785
|
+
*
|
|
786
|
+
* The user is read from `rawConfig`, because the schema strips `mock` when it
|
|
787
|
+
* validates — the key exists to carry a test's declaration through the
|
|
788
|
+
* builder, never to reach the provider.
|
|
789
|
+
*
|
|
790
|
+
* @param rawConfig - The raw configuration to process.
|
|
791
|
+
* @param init - The builder arguments, carrying the host reference when hoisted.
|
|
792
|
+
* @returns The processed and validated configuration.
|
|
793
|
+
*/
|
|
794
|
+
async _processConfig(rawConfig, init) {
|
|
795
|
+
// Supply mock credentials only when this builder owns client construction.
|
|
796
|
+
if (!this._isHoisted(init) && !this.getClientConfig()) {
|
|
797
|
+
this.setClientConfig(defaultMockClientConfig);
|
|
798
|
+
}
|
|
799
|
+
const config = await super._processConfig(rawConfig, init);
|
|
800
|
+
// `null` is a declaration in its own right — nobody is signed in — so only
|
|
801
|
+
// an absent one means the test said nothing about the user
|
|
802
|
+
const account = rawConfig.mock?.account;
|
|
803
|
+
// Apply even null because null explicitly requests a signed-out mock state.
|
|
804
|
+
if (account !== undefined) {
|
|
805
|
+
this.#signIn(account, config, init);
|
|
806
|
+
}
|
|
807
|
+
// Applied after the account so a token declared alongside `skipResolve: true`
|
|
808
|
+
// overrides whatever `setUser` above just fabricated.
|
|
809
|
+
const token = rawConfig.mock?.token;
|
|
810
|
+
// absent means the test declared no token override; leave the client generating its own
|
|
811
|
+
if (token !== undefined) {
|
|
812
|
+
this.#getClient(config, init, 'set a token').setToken(token);
|
|
813
|
+
}
|
|
814
|
+
return config;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Builds an in-process client.
|
|
818
|
+
*
|
|
819
|
+
* @remarks
|
|
820
|
+
* Called only when no client was set, so
|
|
821
|
+
* {@link MsalConfigurator.setClient | setClient} still replaces authentication
|
|
822
|
+
* outright.
|
|
823
|
+
*
|
|
824
|
+
* Deliberately does not delegate to `super`, which would build a real
|
|
825
|
+
* `MsalClient` and contact Entra ID. It is never reached when the module is
|
|
826
|
+
* hoisted onto a host application's provider, because the base configurator
|
|
827
|
+
* gates client creation on {@link MsalConfigurator._isHoisted | _isHoisted} —
|
|
828
|
+
* a mock client built there would shadow the host's client, the exact scenario
|
|
829
|
+
* an application-inside-a-portal test exists to cover.
|
|
830
|
+
*
|
|
831
|
+
* Knows nothing about who is signed in: a client is built from what it talks
|
|
832
|
+
* to, and the declared user is applied to it afterwards.
|
|
833
|
+
*
|
|
834
|
+
* @param config - The validated configuration the client is built from.
|
|
835
|
+
* @returns A client resolving tokens in-process.
|
|
836
|
+
*/
|
|
837
|
+
async _createClient(config) {
|
|
838
|
+
return new MsalMockClient(this._createClientConfig(config) ?? defaultMockClientConfig);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* The MSAL module with a mock client instead of a live connection to Entra ID.
|
|
844
|
+
*
|
|
845
|
+
* @remarks
|
|
846
|
+
* Only `configure` differs from the real module. `initialize` is the production
|
|
847
|
+
* one, untouched, so proxy providers, host-provider hoisting and provider
|
|
848
|
+
* initialization all behave exactly as they do in production — and a test
|
|
849
|
+
* observes the real start-up path rather than a rehearsal of it.
|
|
850
|
+
*/
|
|
851
|
+
const msalMockModule = {
|
|
852
|
+
...module$1,
|
|
853
|
+
configure: () => new MsalMockConfigurator(),
|
|
854
|
+
};
|
|
855
|
+
/**
|
|
856
|
+
* Enables MSAL against a mock client, so a test needs no credentials and no network.
|
|
857
|
+
*
|
|
858
|
+
* @remarks
|
|
859
|
+
* Registered last, this replaces whichever auth module the configurator already
|
|
860
|
+
* carries, so it works on a `FrameworkConfigurator` that pre-registers the real one.
|
|
861
|
+
*
|
|
862
|
+
* @param configurator - The modules configurator to register on.
|
|
863
|
+
* @param configure - Optional callback to override the default mock client.
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
* ```typescript
|
|
867
|
+
* enableMsalMock(configurator, (builder) => {
|
|
868
|
+
* builder.setAccount({ name: 'Ada Lovelace' });
|
|
869
|
+
* });
|
|
870
|
+
* ```
|
|
871
|
+
*/
|
|
872
|
+
const enableMsalMock = (
|
|
873
|
+
// biome-ignore lint/suspicious/noExplicitAny: must be any to support all module types
|
|
874
|
+
configurator, configure) => {
|
|
875
|
+
configurator.addConfig({ module: msalMockModule, configure });
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
export { MsalMockClient, MsalMockConfigurator, createMockToken, createMockUserFromToken, decodeJwtSegment, enableMsalMock, msalMockModule };
|
|
879
|
+
//# sourceMappingURL=index-B_3FYBBq.js.map
|