@classic-homes/auth 0.1.23 → 0.1.24
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 +486 -81
- package/dist/config-C-iBNu07.d.ts +86 -0
- package/dist/core/index.d.ts +72 -94
- package/dist/core/index.js +822 -430
- package/dist/index.d.ts +3 -2
- package/dist/index.js +867 -718
- package/dist/svelte/index.d.ts +12 -1
- package/dist/svelte/index.js +840 -193
- package/dist/testing/index.d.ts +1082 -0
- package/dist/testing/index.js +2033 -0
- package/dist/{types-exFUQyBX.d.ts → types-DGN45Uih.d.ts} +9 -1
- package/package.json +5 -1
|
@@ -0,0 +1,1082 @@
|
|
|
1
|
+
import { U as User, a as LoginResponse, b as LogoutResponse, c as RegisterResponse, M as MFASetupResponse, f as MFAStatus, S as Session, D as Device, d as ApiKey, i as LinkedAccount, j as SecurityEvent, h as UserPreferences, A as AuthState } from '../types-DGN45Uih.js';
|
|
2
|
+
import { e as StorageAdapter, A as AuthConfig } from '../config-C-iBNu07.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* User Fixtures
|
|
6
|
+
*
|
|
7
|
+
* Pre-defined user objects for testing authentication scenarios.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Standard authenticated user with basic permissions.
|
|
12
|
+
*/
|
|
13
|
+
declare const mockUser: User;
|
|
14
|
+
/**
|
|
15
|
+
* Admin user with elevated permissions.
|
|
16
|
+
*/
|
|
17
|
+
declare const mockAdminUser: User;
|
|
18
|
+
/**
|
|
19
|
+
* SSO-authenticated user.
|
|
20
|
+
*/
|
|
21
|
+
declare const mockSSOUser: User;
|
|
22
|
+
/**
|
|
23
|
+
* User with MFA enabled.
|
|
24
|
+
*/
|
|
25
|
+
declare const mockMFAUser: User;
|
|
26
|
+
/**
|
|
27
|
+
* User with unverified email.
|
|
28
|
+
*/
|
|
29
|
+
declare const mockUnverifiedUser: User;
|
|
30
|
+
/**
|
|
31
|
+
* Inactive/deactivated user.
|
|
32
|
+
*/
|
|
33
|
+
declare const mockInactiveUser: User;
|
|
34
|
+
/**
|
|
35
|
+
* Create a mock user with custom overrides.
|
|
36
|
+
* @param overrides - Partial user properties to override
|
|
37
|
+
*/
|
|
38
|
+
declare function createMockUser(overrides?: Partial<User>): User;
|
|
39
|
+
/**
|
|
40
|
+
* Create a mock user with specific roles and permissions.
|
|
41
|
+
* @param roles - Array of role strings
|
|
42
|
+
* @param permissions - Array of permission strings
|
|
43
|
+
* @param overrides - Additional user property overrides
|
|
44
|
+
*/
|
|
45
|
+
declare function createMockUserWithRoles(roles: string[], permissions: string[], overrides?: Partial<User>): User;
|
|
46
|
+
/**
|
|
47
|
+
* Create a mock user with specific auth method.
|
|
48
|
+
* @param authMethod - The authentication method used
|
|
49
|
+
* @param overrides - Additional user property overrides
|
|
50
|
+
*/
|
|
51
|
+
declare function createMockUserWithAuthMethod(authMethod: 'password' | 'oauth' | 'both', overrides?: Partial<User>): User;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Token Fixtures
|
|
55
|
+
*
|
|
56
|
+
* Pre-defined JWT tokens for testing authentication scenarios.
|
|
57
|
+
* Note: These are example tokens with fake signatures - not cryptographically valid.
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Valid access token (1 hour expiry).
|
|
61
|
+
*/
|
|
62
|
+
declare const mockAccessToken: string;
|
|
63
|
+
/**
|
|
64
|
+
* Valid refresh token (7 days expiry).
|
|
65
|
+
*/
|
|
66
|
+
declare const mockRefreshToken: string;
|
|
67
|
+
/**
|
|
68
|
+
* Expired access token.
|
|
69
|
+
*/
|
|
70
|
+
declare const mockExpiredToken: string;
|
|
71
|
+
/**
|
|
72
|
+
* Admin access token with elevated permissions.
|
|
73
|
+
*/
|
|
74
|
+
declare const mockAdminToken: string;
|
|
75
|
+
/**
|
|
76
|
+
* MFA challenge token (short-lived, used during MFA verification).
|
|
77
|
+
*/
|
|
78
|
+
declare const mockMFAToken: string;
|
|
79
|
+
/**
|
|
80
|
+
* Session token for trusted device.
|
|
81
|
+
*/
|
|
82
|
+
declare const mockSessionToken: string;
|
|
83
|
+
interface JWTPayloadOptions {
|
|
84
|
+
sub?: string;
|
|
85
|
+
username?: string;
|
|
86
|
+
email?: string;
|
|
87
|
+
roles?: string[];
|
|
88
|
+
permissions?: string[];
|
|
89
|
+
type?: 'access' | 'refresh' | 'mfa_challenge' | 'session';
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create a custom mock JWT token.
|
|
94
|
+
* @param payload - JWT payload claims
|
|
95
|
+
* @param expiresIn - Expiry time in seconds (default: 3600)
|
|
96
|
+
*/
|
|
97
|
+
declare function createMockJWT(payload?: JWTPayloadOptions, expiresIn?: number): string;
|
|
98
|
+
/**
|
|
99
|
+
* Create an expired mock JWT token.
|
|
100
|
+
* @param payload - JWT payload claims
|
|
101
|
+
* @param expiredSecondsAgo - How many seconds ago the token expired (default: 3600)
|
|
102
|
+
*/
|
|
103
|
+
declare function createExpiredMockJWT(payload?: JWTPayloadOptions, expiredSecondsAgo?: number): string;
|
|
104
|
+
/**
|
|
105
|
+
* Create a token pair (access + refresh).
|
|
106
|
+
* @param userId - User ID for the tokens
|
|
107
|
+
* @param options - Additional token options
|
|
108
|
+
*/
|
|
109
|
+
declare function createMockTokenPair(userId?: string, options?: {
|
|
110
|
+
accessExpiresIn?: number;
|
|
111
|
+
refreshExpiresIn?: number;
|
|
112
|
+
roles?: string[];
|
|
113
|
+
permissions?: string[];
|
|
114
|
+
}): {
|
|
115
|
+
accessToken: string;
|
|
116
|
+
refreshToken: string;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Create an MFA challenge token.
|
|
120
|
+
* @param userId - User ID for the token
|
|
121
|
+
* @param expiresIn - Expiry time in seconds (default: 300 for 5 minutes)
|
|
122
|
+
*/
|
|
123
|
+
declare function createMockMFAToken(userId?: string, expiresIn?: number): string;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Response Fixtures
|
|
127
|
+
*
|
|
128
|
+
* Pre-defined API response objects for testing authentication flows.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Successful login response with tokens and user.
|
|
133
|
+
*/
|
|
134
|
+
declare const mockLoginSuccess: LoginResponse;
|
|
135
|
+
/**
|
|
136
|
+
* Login response requiring MFA verification.
|
|
137
|
+
*/
|
|
138
|
+
declare const mockMFARequired: LoginResponse;
|
|
139
|
+
/**
|
|
140
|
+
* Login response with legacy MFA fields.
|
|
141
|
+
*/
|
|
142
|
+
declare const mockMFARequiredLegacy: LoginResponse;
|
|
143
|
+
/**
|
|
144
|
+
* Admin login success response.
|
|
145
|
+
*/
|
|
146
|
+
declare const mockAdminLoginSuccess: LoginResponse;
|
|
147
|
+
/**
|
|
148
|
+
* SSO login success response.
|
|
149
|
+
*/
|
|
150
|
+
declare const mockSSOLoginSuccess: LoginResponse;
|
|
151
|
+
/**
|
|
152
|
+
* Standard logout success response.
|
|
153
|
+
*/
|
|
154
|
+
declare const mockLogoutSuccess: LogoutResponse;
|
|
155
|
+
/**
|
|
156
|
+
* SSO logout response with redirect URL.
|
|
157
|
+
*/
|
|
158
|
+
declare const mockSSOLogoutResponse: LogoutResponse;
|
|
159
|
+
/**
|
|
160
|
+
* Standard registration success response.
|
|
161
|
+
*/
|
|
162
|
+
declare const mockRegisterSuccess: RegisterResponse;
|
|
163
|
+
/**
|
|
164
|
+
* Registration response requiring email verification.
|
|
165
|
+
*/
|
|
166
|
+
declare const mockRegisterRequiresVerification: RegisterResponse;
|
|
167
|
+
/**
|
|
168
|
+
* MFA setup response with QR code and backup codes.
|
|
169
|
+
*/
|
|
170
|
+
declare const mockMFASetup: MFASetupResponse;
|
|
171
|
+
/**
|
|
172
|
+
* MFA status - enabled.
|
|
173
|
+
*/
|
|
174
|
+
declare const mockMFAStatusEnabled: MFAStatus;
|
|
175
|
+
/**
|
|
176
|
+
* MFA status - disabled.
|
|
177
|
+
*/
|
|
178
|
+
declare const mockMFAStatusDisabled: MFAStatus;
|
|
179
|
+
/**
|
|
180
|
+
* Current session fixture.
|
|
181
|
+
*/
|
|
182
|
+
declare const mockCurrentSession: Session;
|
|
183
|
+
/**
|
|
184
|
+
* Other session fixture.
|
|
185
|
+
*/
|
|
186
|
+
declare const mockOtherSession: Session;
|
|
187
|
+
/**
|
|
188
|
+
* Array of session fixtures.
|
|
189
|
+
*/
|
|
190
|
+
declare const mockSessions: Session[];
|
|
191
|
+
/**
|
|
192
|
+
* Trusted device fixture.
|
|
193
|
+
*/
|
|
194
|
+
declare const mockTrustedDevice: Device;
|
|
195
|
+
/**
|
|
196
|
+
* Untrusted device fixture.
|
|
197
|
+
*/
|
|
198
|
+
declare const mockUntrustedDevice: Device;
|
|
199
|
+
/**
|
|
200
|
+
* Array of device fixtures.
|
|
201
|
+
*/
|
|
202
|
+
declare const mockDevices: Device[];
|
|
203
|
+
/**
|
|
204
|
+
* Active API key fixture.
|
|
205
|
+
*/
|
|
206
|
+
declare const mockApiKey: ApiKey;
|
|
207
|
+
/**
|
|
208
|
+
* Array of API key fixtures.
|
|
209
|
+
*/
|
|
210
|
+
declare const mockApiKeys: ApiKey[];
|
|
211
|
+
/**
|
|
212
|
+
* Linked SSO account fixture.
|
|
213
|
+
*/
|
|
214
|
+
declare const mockLinkedAccount: LinkedAccount;
|
|
215
|
+
/**
|
|
216
|
+
* Login security event fixture.
|
|
217
|
+
*/
|
|
218
|
+
declare const mockSecurityEventLogin: SecurityEvent;
|
|
219
|
+
/**
|
|
220
|
+
* Password change security event fixture.
|
|
221
|
+
*/
|
|
222
|
+
declare const mockSecurityEventPasswordChange: SecurityEvent;
|
|
223
|
+
/**
|
|
224
|
+
* Suspicious activity security event fixture.
|
|
225
|
+
*/
|
|
226
|
+
declare const mockSecurityEventSuspicious: SecurityEvent;
|
|
227
|
+
/**
|
|
228
|
+
* Array of security event fixtures.
|
|
229
|
+
*/
|
|
230
|
+
declare const mockSecurityEvents: SecurityEvent[];
|
|
231
|
+
/**
|
|
232
|
+
* Default user preferences fixture.
|
|
233
|
+
*/
|
|
234
|
+
declare const mockUserPreferences: UserPreferences;
|
|
235
|
+
/**
|
|
236
|
+
* Create a login success response with custom options.
|
|
237
|
+
*/
|
|
238
|
+
declare function createMockLoginSuccess(options?: {
|
|
239
|
+
userId?: string;
|
|
240
|
+
user?: Partial<typeof mockUser>;
|
|
241
|
+
expiresIn?: number;
|
|
242
|
+
}): LoginResponse;
|
|
243
|
+
/**
|
|
244
|
+
* Create an MFA required response with custom options.
|
|
245
|
+
*/
|
|
246
|
+
declare function createMockMFARequired(options?: {
|
|
247
|
+
availableMethods?: string[];
|
|
248
|
+
mfaToken?: string;
|
|
249
|
+
}): LoginResponse;
|
|
250
|
+
/**
|
|
251
|
+
* Create a session fixture with custom options.
|
|
252
|
+
*/
|
|
253
|
+
declare function createMockSession(overrides?: Partial<Session>): Session;
|
|
254
|
+
/**
|
|
255
|
+
* Create a device fixture with custom options.
|
|
256
|
+
*/
|
|
257
|
+
declare function createMockDevice(overrides?: Partial<Device>): Device;
|
|
258
|
+
/**
|
|
259
|
+
* Create a security event fixture with custom options.
|
|
260
|
+
*/
|
|
261
|
+
declare function createMockSecurityEvent(overrides?: Partial<SecurityEvent>): SecurityEvent;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Mock Storage Adapter
|
|
265
|
+
*
|
|
266
|
+
* In-memory storage adapter for testing with call tracking.
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
interface StorageCall {
|
|
270
|
+
method: 'getItem' | 'setItem' | 'removeItem';
|
|
271
|
+
key: string;
|
|
272
|
+
value?: string;
|
|
273
|
+
timestamp: number;
|
|
274
|
+
}
|
|
275
|
+
interface MockStorageOptions {
|
|
276
|
+
/** Initial data to populate the storage */
|
|
277
|
+
initialData?: Record<string, string>;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* In-memory storage adapter for testing.
|
|
281
|
+
* Implements the StorageAdapter interface with additional test utilities.
|
|
282
|
+
*/
|
|
283
|
+
declare class MockStorageAdapter implements StorageAdapter {
|
|
284
|
+
private data;
|
|
285
|
+
private callHistory;
|
|
286
|
+
constructor(options?: MockStorageOptions);
|
|
287
|
+
/**
|
|
288
|
+
* Get an item from storage.
|
|
289
|
+
*/
|
|
290
|
+
getItem(key: string): string | null;
|
|
291
|
+
/**
|
|
292
|
+
* Set an item in storage.
|
|
293
|
+
*/
|
|
294
|
+
setItem(key: string, value: string): void;
|
|
295
|
+
/**
|
|
296
|
+
* Remove an item from storage.
|
|
297
|
+
*/
|
|
298
|
+
removeItem(key: string): void;
|
|
299
|
+
/**
|
|
300
|
+
* Clear all data from storage.
|
|
301
|
+
*/
|
|
302
|
+
clear(): void;
|
|
303
|
+
/**
|
|
304
|
+
* Reset the call history.
|
|
305
|
+
*/
|
|
306
|
+
resetHistory(): void;
|
|
307
|
+
/**
|
|
308
|
+
* Reset both data and history.
|
|
309
|
+
*/
|
|
310
|
+
reset(): void;
|
|
311
|
+
/**
|
|
312
|
+
* Get all storage keys.
|
|
313
|
+
*/
|
|
314
|
+
keys(): string[];
|
|
315
|
+
/**
|
|
316
|
+
* Check if a key exists in storage.
|
|
317
|
+
*/
|
|
318
|
+
has(key: string): boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Get the number of items in storage.
|
|
321
|
+
*/
|
|
322
|
+
get size(): number;
|
|
323
|
+
/**
|
|
324
|
+
* Get all data as a plain object.
|
|
325
|
+
*/
|
|
326
|
+
getData(): Record<string, string>;
|
|
327
|
+
/**
|
|
328
|
+
* Set multiple items at once.
|
|
329
|
+
*/
|
|
330
|
+
setData(data: Record<string, string>): void;
|
|
331
|
+
/**
|
|
332
|
+
* Get the full call history.
|
|
333
|
+
*/
|
|
334
|
+
getHistory(): StorageCall[];
|
|
335
|
+
/**
|
|
336
|
+
* Get calls for a specific method.
|
|
337
|
+
*/
|
|
338
|
+
getCallsFor(method: 'getItem' | 'setItem' | 'removeItem'): StorageCall[];
|
|
339
|
+
/**
|
|
340
|
+
* Get calls for a specific key.
|
|
341
|
+
*/
|
|
342
|
+
getCallsForKey(key: string): StorageCall[];
|
|
343
|
+
/**
|
|
344
|
+
* Check if a method was called.
|
|
345
|
+
*/
|
|
346
|
+
wasCalled(method: 'getItem' | 'setItem' | 'removeItem'): boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Check if a method was called with a specific key.
|
|
349
|
+
*/
|
|
350
|
+
wasCalledWith(method: 'getItem' | 'setItem' | 'removeItem', key: string): boolean;
|
|
351
|
+
/**
|
|
352
|
+
* Get the last call made.
|
|
353
|
+
*/
|
|
354
|
+
getLastCall(): StorageCall | undefined;
|
|
355
|
+
/**
|
|
356
|
+
* Get the total number of calls made.
|
|
357
|
+
*/
|
|
358
|
+
get callCount(): number;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Create a mock storage adapter.
|
|
362
|
+
*/
|
|
363
|
+
declare function createMockStorage(options?: MockStorageOptions): MockStorageAdapter;
|
|
364
|
+
/**
|
|
365
|
+
* Create a mock storage with auth data pre-populated.
|
|
366
|
+
*/
|
|
367
|
+
declare function createMockStorageWithAuth(accessToken: string, refreshToken: string, user: object, storageKey?: string): MockStorageAdapter;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Mock Fetch Instance
|
|
371
|
+
*
|
|
372
|
+
* Configurable mock fetch for testing API interactions.
|
|
373
|
+
*/
|
|
374
|
+
interface MockRoute {
|
|
375
|
+
/** HTTP method to match */
|
|
376
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
377
|
+
/** URL pattern to match (can use wildcards like /auth/sessions/*) */
|
|
378
|
+
path: string | RegExp;
|
|
379
|
+
/** Response status code */
|
|
380
|
+
status?: number;
|
|
381
|
+
/** Response body */
|
|
382
|
+
response?: unknown;
|
|
383
|
+
/** Response headers */
|
|
384
|
+
headers?: Record<string, string>;
|
|
385
|
+
/** Delay in ms before responding */
|
|
386
|
+
delay?: number;
|
|
387
|
+
/** Function to generate dynamic response */
|
|
388
|
+
handler?: (request: MockRequest) => MockRouteResponse | Promise<MockRouteResponse>;
|
|
389
|
+
}
|
|
390
|
+
interface MockRouteResponse {
|
|
391
|
+
status?: number;
|
|
392
|
+
response?: unknown;
|
|
393
|
+
headers?: Record<string, string>;
|
|
394
|
+
}
|
|
395
|
+
interface MockRequest {
|
|
396
|
+
method: string;
|
|
397
|
+
url: string;
|
|
398
|
+
path: string;
|
|
399
|
+
body: unknown;
|
|
400
|
+
headers: Headers;
|
|
401
|
+
}
|
|
402
|
+
interface FetchCall {
|
|
403
|
+
url: string;
|
|
404
|
+
options: RequestInit;
|
|
405
|
+
timestamp: number;
|
|
406
|
+
}
|
|
407
|
+
interface MockFetchOptions {
|
|
408
|
+
/** Base URL to strip from paths */
|
|
409
|
+
baseUrl?: string;
|
|
410
|
+
/** Default response for unmatched routes */
|
|
411
|
+
defaultResponse?: MockRouteResponse;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Mock fetch implementation for testing.
|
|
415
|
+
* Provides configurable routes and call tracking.
|
|
416
|
+
*/
|
|
417
|
+
declare class MockFetchInstance {
|
|
418
|
+
private routes;
|
|
419
|
+
private callHistory;
|
|
420
|
+
private baseUrl;
|
|
421
|
+
private defaultResponse;
|
|
422
|
+
constructor(options?: MockFetchOptions);
|
|
423
|
+
/**
|
|
424
|
+
* Add a route to the mock.
|
|
425
|
+
*/
|
|
426
|
+
addRoute(route: MockRoute): this;
|
|
427
|
+
/**
|
|
428
|
+
* Add multiple routes at once.
|
|
429
|
+
*/
|
|
430
|
+
addRoutes(routes: MockRoute[]): this;
|
|
431
|
+
/**
|
|
432
|
+
* Remove a route by path and method.
|
|
433
|
+
*/
|
|
434
|
+
removeRoute(method: string, path: string | RegExp): this;
|
|
435
|
+
/**
|
|
436
|
+
* Clear all routes.
|
|
437
|
+
*/
|
|
438
|
+
clearRoutes(): this;
|
|
439
|
+
/**
|
|
440
|
+
* Reset to default routes.
|
|
441
|
+
*/
|
|
442
|
+
reset(): this;
|
|
443
|
+
/**
|
|
444
|
+
* The mock fetch function.
|
|
445
|
+
*/
|
|
446
|
+
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
447
|
+
private createResponse;
|
|
448
|
+
private extractPath;
|
|
449
|
+
private pathMatches;
|
|
450
|
+
/**
|
|
451
|
+
* Get all recorded calls.
|
|
452
|
+
*/
|
|
453
|
+
getCalls(): FetchCall[];
|
|
454
|
+
/**
|
|
455
|
+
* Get calls to a specific path.
|
|
456
|
+
*/
|
|
457
|
+
getCallsTo(path: string): FetchCall[];
|
|
458
|
+
/**
|
|
459
|
+
* Get calls with a specific method.
|
|
460
|
+
*/
|
|
461
|
+
getCallsWithMethod(method: string): FetchCall[];
|
|
462
|
+
/**
|
|
463
|
+
* Check if a path was called.
|
|
464
|
+
*/
|
|
465
|
+
wasCalled(path: string): boolean;
|
|
466
|
+
/**
|
|
467
|
+
* Check if a path was called with a specific method.
|
|
468
|
+
*/
|
|
469
|
+
wasCalledWith(method: string, path: string): boolean;
|
|
470
|
+
/**
|
|
471
|
+
* Assert that a path was called.
|
|
472
|
+
*/
|
|
473
|
+
assertCalled(path: string, message?: string): void;
|
|
474
|
+
/**
|
|
475
|
+
* Assert that a path was not called.
|
|
476
|
+
*/
|
|
477
|
+
assertNotCalled(path: string, message?: string): void;
|
|
478
|
+
/**
|
|
479
|
+
* Get the last call made.
|
|
480
|
+
*/
|
|
481
|
+
getLastCall(): FetchCall | undefined;
|
|
482
|
+
/**
|
|
483
|
+
* Clear call history.
|
|
484
|
+
*/
|
|
485
|
+
clearHistory(): this;
|
|
486
|
+
/**
|
|
487
|
+
* Get total call count.
|
|
488
|
+
*/
|
|
489
|
+
get callCount(): number;
|
|
490
|
+
/**
|
|
491
|
+
* Configure login to require MFA.
|
|
492
|
+
*/
|
|
493
|
+
requireMFA(): this;
|
|
494
|
+
/**
|
|
495
|
+
* Configure login to fail.
|
|
496
|
+
*/
|
|
497
|
+
failLogin(error?: string): this;
|
|
498
|
+
/**
|
|
499
|
+
* Configure an endpoint to fail.
|
|
500
|
+
*/
|
|
501
|
+
failEndpoint(method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', path: string, status?: number, error?: string): this;
|
|
502
|
+
/**
|
|
503
|
+
* Configure logout to return SSO redirect URL.
|
|
504
|
+
*/
|
|
505
|
+
enableSSOLogout(logoutUrl?: string): this;
|
|
506
|
+
/**
|
|
507
|
+
* Add response delay to all routes.
|
|
508
|
+
*/
|
|
509
|
+
setDelay(delay: number): this;
|
|
510
|
+
private setupDefaultRoutes;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Create a mock fetch instance.
|
|
514
|
+
*/
|
|
515
|
+
declare function createMockFetch(options?: MockFetchOptions): MockFetchInstance;
|
|
516
|
+
/**
|
|
517
|
+
* Create a mock fetch with custom routes only (no defaults).
|
|
518
|
+
*/
|
|
519
|
+
declare function createMockFetchWithRoutes(routes: MockRoute[]): MockFetchInstance;
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Mock Auth Store
|
|
523
|
+
*
|
|
524
|
+
* Mock implementation of the Svelte auth store for testing.
|
|
525
|
+
*/
|
|
526
|
+
|
|
527
|
+
type Subscriber<T> = (value: T) => void;
|
|
528
|
+
type Unsubscriber = () => void;
|
|
529
|
+
interface StoreCall {
|
|
530
|
+
method: string;
|
|
531
|
+
args: unknown[];
|
|
532
|
+
timestamp: number;
|
|
533
|
+
}
|
|
534
|
+
interface MockAuthStoreOptions {
|
|
535
|
+
/** Initial auth state */
|
|
536
|
+
initialState?: Partial<AuthState>;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Mock implementation of the auth store.
|
|
540
|
+
* Implements the same interface as the real store with additional test utilities.
|
|
541
|
+
*/
|
|
542
|
+
declare class MockAuthStore {
|
|
543
|
+
private state;
|
|
544
|
+
private subscribers;
|
|
545
|
+
private callHistory;
|
|
546
|
+
constructor(options?: MockAuthStoreOptions);
|
|
547
|
+
/**
|
|
548
|
+
* Subscribe to state changes (Svelte store contract).
|
|
549
|
+
*/
|
|
550
|
+
subscribe(subscriber: Subscriber<AuthState>): Unsubscriber;
|
|
551
|
+
private notify;
|
|
552
|
+
private recordCall;
|
|
553
|
+
get accessToken(): string | null;
|
|
554
|
+
get refreshToken(): string | null;
|
|
555
|
+
get user(): User | null;
|
|
556
|
+
get isAuthenticated(): boolean;
|
|
557
|
+
/**
|
|
558
|
+
* Get the current auth state snapshot.
|
|
559
|
+
*/
|
|
560
|
+
getState(): AuthState;
|
|
561
|
+
/**
|
|
562
|
+
* Set auth data after successful login.
|
|
563
|
+
*/
|
|
564
|
+
setAuth(accessToken: string, refreshToken: string, user: User, sessionToken?: string): void;
|
|
565
|
+
/**
|
|
566
|
+
* Update tokens (e.g., after refresh).
|
|
567
|
+
*/
|
|
568
|
+
updateTokens(accessToken: string, refreshToken: string): void;
|
|
569
|
+
/**
|
|
570
|
+
* Update user data.
|
|
571
|
+
*/
|
|
572
|
+
updateUser(user: User): void;
|
|
573
|
+
/**
|
|
574
|
+
* Clear auth state (logout).
|
|
575
|
+
*/
|
|
576
|
+
logout(): void;
|
|
577
|
+
/**
|
|
578
|
+
* Logout with SSO support.
|
|
579
|
+
*/
|
|
580
|
+
logoutWithSSO(): Promise<{
|
|
581
|
+
ssoLogoutUrl?: string;
|
|
582
|
+
}>;
|
|
583
|
+
/**
|
|
584
|
+
* Re-hydrate state from storage.
|
|
585
|
+
*/
|
|
586
|
+
rehydrate(): void;
|
|
587
|
+
/**
|
|
588
|
+
* Check if user has a specific permission.
|
|
589
|
+
*/
|
|
590
|
+
hasPermission(permission: string): boolean;
|
|
591
|
+
/**
|
|
592
|
+
* Check if user has a specific role.
|
|
593
|
+
*/
|
|
594
|
+
hasRole(role: string): boolean;
|
|
595
|
+
/**
|
|
596
|
+
* Check if user has any of the specified roles.
|
|
597
|
+
*/
|
|
598
|
+
hasAnyRole(roles: string[]): boolean;
|
|
599
|
+
/**
|
|
600
|
+
* Check if user has all of the specified roles.
|
|
601
|
+
*/
|
|
602
|
+
hasAllRoles(roles: string[]): boolean;
|
|
603
|
+
/**
|
|
604
|
+
* Check if user has any of the specified permissions.
|
|
605
|
+
*/
|
|
606
|
+
hasAnyPermission(permissions: string[]): boolean;
|
|
607
|
+
/**
|
|
608
|
+
* Check if user has all of the specified permissions.
|
|
609
|
+
*/
|
|
610
|
+
hasAllPermissions(permissions: string[]): boolean;
|
|
611
|
+
/**
|
|
612
|
+
* Reset the store to initial state.
|
|
613
|
+
*/
|
|
614
|
+
reset(): void;
|
|
615
|
+
/**
|
|
616
|
+
* Simulate an authenticated state.
|
|
617
|
+
*/
|
|
618
|
+
simulateAuthenticated(user?: User): void;
|
|
619
|
+
/**
|
|
620
|
+
* Simulate an unauthenticated state.
|
|
621
|
+
*/
|
|
622
|
+
simulateUnauthenticated(): void;
|
|
623
|
+
/**
|
|
624
|
+
* Set the state directly for testing.
|
|
625
|
+
*/
|
|
626
|
+
setState(state: Partial<AuthState>): void;
|
|
627
|
+
/**
|
|
628
|
+
* Get all recorded method calls.
|
|
629
|
+
*/
|
|
630
|
+
getCalls(): StoreCall[];
|
|
631
|
+
/**
|
|
632
|
+
* Get calls for a specific method.
|
|
633
|
+
*/
|
|
634
|
+
getCallsFor(method: string): StoreCall[];
|
|
635
|
+
/**
|
|
636
|
+
* Check if a method was called.
|
|
637
|
+
*/
|
|
638
|
+
wasCalled(method: string): boolean;
|
|
639
|
+
/**
|
|
640
|
+
* Assert that a method was called.
|
|
641
|
+
*/
|
|
642
|
+
assertMethodCalled(method: string, message?: string): void;
|
|
643
|
+
/**
|
|
644
|
+
* Assert that a method was not called.
|
|
645
|
+
*/
|
|
646
|
+
assertMethodNotCalled(method: string, message?: string): void;
|
|
647
|
+
/**
|
|
648
|
+
* Get the last call made.
|
|
649
|
+
*/
|
|
650
|
+
getLastCall(): StoreCall | undefined;
|
|
651
|
+
/**
|
|
652
|
+
* Get the last call to a specific method.
|
|
653
|
+
*/
|
|
654
|
+
getLastCallTo(method: string): StoreCall | undefined;
|
|
655
|
+
/**
|
|
656
|
+
* Get total call count.
|
|
657
|
+
*/
|
|
658
|
+
get callCount(): number;
|
|
659
|
+
/**
|
|
660
|
+
* Clear call history.
|
|
661
|
+
*/
|
|
662
|
+
clearHistory(): void;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Create a mock auth store.
|
|
666
|
+
*/
|
|
667
|
+
declare function createMockAuthStore(options?: MockAuthStoreOptions): MockAuthStore;
|
|
668
|
+
/**
|
|
669
|
+
* Create a mock auth store in authenticated state.
|
|
670
|
+
*/
|
|
671
|
+
declare function createAuthenticatedMockStore(user?: User): MockAuthStore;
|
|
672
|
+
/**
|
|
673
|
+
* Create mock auth actions that delegate to a store.
|
|
674
|
+
*/
|
|
675
|
+
declare function createMockAuthActions(store: MockAuthStore): {
|
|
676
|
+
setAuth: (accessToken: string, refreshToken: string, user: User, sessionToken?: string) => void;
|
|
677
|
+
updateTokens: (accessToken: string, refreshToken: string) => void;
|
|
678
|
+
updateUser: (user: User) => void;
|
|
679
|
+
logout: () => void;
|
|
680
|
+
logoutWithSSO: () => Promise<{
|
|
681
|
+
ssoLogoutUrl?: string;
|
|
682
|
+
}>;
|
|
683
|
+
hasPermission: (permission: string) => boolean;
|
|
684
|
+
hasRole: (role: string) => boolean;
|
|
685
|
+
hasAnyRole: (roles: string[]) => boolean;
|
|
686
|
+
hasAllRoles: (roles: string[]) => boolean;
|
|
687
|
+
hasAnyPermission: (permissions: string[]) => boolean;
|
|
688
|
+
hasAllPermissions: (permissions: string[]) => boolean;
|
|
689
|
+
rehydrate: () => void;
|
|
690
|
+
};
|
|
691
|
+
/**
|
|
692
|
+
* Create a mock isAuthenticated derived store.
|
|
693
|
+
*/
|
|
694
|
+
declare function createMockIsAuthenticated(store: MockAuthStore): {
|
|
695
|
+
subscribe: (subscriber: Subscriber<boolean>) => Unsubscriber;
|
|
696
|
+
};
|
|
697
|
+
/**
|
|
698
|
+
* Create a mock currentUser derived store.
|
|
699
|
+
*/
|
|
700
|
+
declare function createMockCurrentUser(store: MockAuthStore): {
|
|
701
|
+
subscribe: (subscriber: Subscriber<User | null>) => Unsubscriber;
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Test Setup Utilities
|
|
706
|
+
*
|
|
707
|
+
* Helpers for setting up and tearing down test environments.
|
|
708
|
+
*/
|
|
709
|
+
|
|
710
|
+
interface TestAuthContext {
|
|
711
|
+
/** Mock fetch instance */
|
|
712
|
+
mockFetch: MockFetchInstance;
|
|
713
|
+
/** Mock storage adapter */
|
|
714
|
+
mockStorage: MockStorageAdapter;
|
|
715
|
+
/** Mock auth store */
|
|
716
|
+
mockStore: MockAuthStore;
|
|
717
|
+
/** Cleanup function to call in afterEach */
|
|
718
|
+
cleanup: () => void;
|
|
719
|
+
}
|
|
720
|
+
interface SetupTestAuthOptions {
|
|
721
|
+
/** Base URL for the mock API */
|
|
722
|
+
baseUrl?: string;
|
|
723
|
+
/** Storage key for auth data */
|
|
724
|
+
storageKey?: string;
|
|
725
|
+
/** Initial storage data */
|
|
726
|
+
initialStorage?: Record<string, string>;
|
|
727
|
+
/** Initial auth store state */
|
|
728
|
+
initialAuthState?: MockAuthStoreOptions['initialState'];
|
|
729
|
+
/** Mock fetch options */
|
|
730
|
+
fetchOptions?: MockFetchOptions;
|
|
731
|
+
/** Whether to initialize auth config (default: true) */
|
|
732
|
+
initConfig?: boolean;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Complete test setup for auth.
|
|
736
|
+
* Creates mock fetch, storage, and store, initializes auth config, and returns cleanup function.
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```ts
|
|
740
|
+
* describe('Login', () => {
|
|
741
|
+
* let ctx: TestAuthContext;
|
|
742
|
+
*
|
|
743
|
+
* beforeEach(() => {
|
|
744
|
+
* ctx = setupTestAuth();
|
|
745
|
+
* });
|
|
746
|
+
*
|
|
747
|
+
* afterEach(() => {
|
|
748
|
+
* ctx.cleanup();
|
|
749
|
+
* });
|
|
750
|
+
*
|
|
751
|
+
* it('handles login', async () => {
|
|
752
|
+
* const response = await authService.login({ username: 'test', password: 'pass' });
|
|
753
|
+
* expect(ctx.mockFetch.wasCalled('/auth/login')).toBe(true);
|
|
754
|
+
* });
|
|
755
|
+
* });
|
|
756
|
+
* ```
|
|
757
|
+
*/
|
|
758
|
+
declare function setupTestAuth(options?: SetupTestAuthOptions): TestAuthContext;
|
|
759
|
+
/**
|
|
760
|
+
* Create test auth helpers for Vitest/Jest.
|
|
761
|
+
* Returns beforeEach and afterEach compatible setup/cleanup functions.
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* import { describe, beforeEach, afterEach } from 'vitest';
|
|
766
|
+
*
|
|
767
|
+
* const { setup, cleanup, getContext } = createTestAuthHelpers();
|
|
768
|
+
*
|
|
769
|
+
* describe('Login', () => {
|
|
770
|
+
* beforeEach(setup);
|
|
771
|
+
* afterEach(cleanup);
|
|
772
|
+
*
|
|
773
|
+
* it('handles login', async () => {
|
|
774
|
+
* const { mockFetch } = getContext();
|
|
775
|
+
* // ... test code
|
|
776
|
+
* });
|
|
777
|
+
* });
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
declare function createTestAuthHelpers(options?: SetupTestAuthOptions): {
|
|
781
|
+
/**
|
|
782
|
+
* Setup function to call in beforeEach.
|
|
783
|
+
*/
|
|
784
|
+
setup: () => TestAuthContext;
|
|
785
|
+
/**
|
|
786
|
+
* Cleanup function to call in afterEach.
|
|
787
|
+
*/
|
|
788
|
+
cleanup: () => void;
|
|
789
|
+
/**
|
|
790
|
+
* Get the current test context.
|
|
791
|
+
*/
|
|
792
|
+
getContext: () => TestAuthContext;
|
|
793
|
+
/**
|
|
794
|
+
* Get mocks directly (convenience accessors).
|
|
795
|
+
*/
|
|
796
|
+
getMockFetch: () => MockFetchInstance | null;
|
|
797
|
+
getMockStorage: () => MockStorageAdapter | null;
|
|
798
|
+
getMockStore: () => MockAuthStore | null;
|
|
799
|
+
};
|
|
800
|
+
/**
|
|
801
|
+
* Quick setup that returns only the cleanup function.
|
|
802
|
+
* Useful for simple test cases.
|
|
803
|
+
*
|
|
804
|
+
* @example
|
|
805
|
+
* ```ts
|
|
806
|
+
* let cleanup: () => void;
|
|
807
|
+
*
|
|
808
|
+
* beforeEach(() => {
|
|
809
|
+
* cleanup = quickSetupAuth();
|
|
810
|
+
* });
|
|
811
|
+
*
|
|
812
|
+
* afterEach(() => cleanup());
|
|
813
|
+
* ```
|
|
814
|
+
*/
|
|
815
|
+
declare function quickSetupAuth(options?: SetupTestAuthOptions): () => void;
|
|
816
|
+
/**
|
|
817
|
+
* Initialize auth with mock dependencies.
|
|
818
|
+
* Lower-level function for custom setups.
|
|
819
|
+
*/
|
|
820
|
+
declare function initAuthWithMocks(mockFetch: MockFetchInstance, mockStorage: MockStorageAdapter, options?: Partial<AuthConfig>): void;
|
|
821
|
+
/**
|
|
822
|
+
* Reset auth config and all mocks.
|
|
823
|
+
*/
|
|
824
|
+
declare function resetTestAuth(mockFetch?: MockFetchInstance, mockStorage?: MockStorageAdapter, mockStore?: MockAuthStore): void;
|
|
825
|
+
/**
|
|
826
|
+
* Run a test in an isolated auth context.
|
|
827
|
+
* Automatically sets up and tears down the context.
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
830
|
+
* ```ts
|
|
831
|
+
* await withTestAuth(async ({ mockFetch, mockStore }) => {
|
|
832
|
+
* mockFetch.requireMFA();
|
|
833
|
+
* const response = await authService.login({ username: 'test', password: 'pass' });
|
|
834
|
+
* expect(response.requiresMFA).toBe(true);
|
|
835
|
+
* });
|
|
836
|
+
* ```
|
|
837
|
+
*/
|
|
838
|
+
declare function withTestAuth<T>(fn: (context: TestAuthContext) => T | Promise<T>, options?: SetupTestAuthOptions): Promise<T>;
|
|
839
|
+
/**
|
|
840
|
+
* Run multiple tests in isolated contexts.
|
|
841
|
+
* Each test gets its own fresh context.
|
|
842
|
+
*/
|
|
843
|
+
declare function withTestAuthEach<T>(tests: Array<(context: TestAuthContext) => T | Promise<T>>, options?: SetupTestAuthOptions): Promise<T[]>;
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Auth State Simulation Helpers
|
|
847
|
+
*
|
|
848
|
+
* Utilities for simulating various authentication states and scenarios.
|
|
849
|
+
*/
|
|
850
|
+
|
|
851
|
+
type AuthScenario = 'unauthenticated' | 'authenticated' | 'admin' | 'ssoUser' | 'mfaEnabled' | 'unverifiedEmail' | 'inactive' | 'expiredToken';
|
|
852
|
+
interface ScenarioState {
|
|
853
|
+
state: AuthState;
|
|
854
|
+
user: User | null;
|
|
855
|
+
description: string;
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Pre-defined authentication scenarios for testing.
|
|
859
|
+
*/
|
|
860
|
+
declare const authScenarios: Record<AuthScenario, ScenarioState>;
|
|
861
|
+
/**
|
|
862
|
+
* Apply a pre-defined scenario to a mock store.
|
|
863
|
+
*/
|
|
864
|
+
declare function applyScenario(store: MockAuthStore, scenario: AuthScenario): void;
|
|
865
|
+
/**
|
|
866
|
+
* Apply multiple scenarios in sequence (useful for testing state transitions).
|
|
867
|
+
*/
|
|
868
|
+
declare function applyScenarios(store: MockAuthStore, scenarios: AuthScenario[]): void;
|
|
869
|
+
/**
|
|
870
|
+
* Get scenario state for assertions.
|
|
871
|
+
*/
|
|
872
|
+
declare function getScenarioState(scenario: AuthScenario): ScenarioState;
|
|
873
|
+
/**
|
|
874
|
+
* Configure mock fetch for MFA login flow.
|
|
875
|
+
* First login returns MFA required, subsequent verify completes login.
|
|
876
|
+
*/
|
|
877
|
+
declare function configureMFAFlow(mockFetch: MockFetchInstance): void;
|
|
878
|
+
/**
|
|
879
|
+
* Configure mock fetch for token refresh scenarios.
|
|
880
|
+
*/
|
|
881
|
+
declare function configureTokenRefresh(mockFetch: MockFetchInstance, options?: {
|
|
882
|
+
/** Whether refresh should succeed */
|
|
883
|
+
success?: boolean;
|
|
884
|
+
/** New tokens to return on success */
|
|
885
|
+
newTokens?: {
|
|
886
|
+
accessToken: string;
|
|
887
|
+
refreshToken: string;
|
|
888
|
+
};
|
|
889
|
+
/** Error message on failure */
|
|
890
|
+
errorMessage?: string;
|
|
891
|
+
}): void;
|
|
892
|
+
/**
|
|
893
|
+
* Configure mock fetch for SSO logout flow.
|
|
894
|
+
*/
|
|
895
|
+
declare function configureSSOLogout(mockFetch: MockFetchInstance, logoutUrl?: string): void;
|
|
896
|
+
/**
|
|
897
|
+
* Configure mock fetch for failed authentication.
|
|
898
|
+
*/
|
|
899
|
+
declare function configureAuthFailure(mockFetch: MockFetchInstance, options?: {
|
|
900
|
+
/** Specific endpoint to fail (default: all auth endpoints) */
|
|
901
|
+
endpoint?: string;
|
|
902
|
+
/** Error status code */
|
|
903
|
+
status?: number;
|
|
904
|
+
/** Error message */
|
|
905
|
+
message?: string;
|
|
906
|
+
}): void;
|
|
907
|
+
/**
|
|
908
|
+
* Configure mock fetch for rate limiting.
|
|
909
|
+
*/
|
|
910
|
+
declare function configureRateLimiting(mockFetch: MockFetchInstance, endpoint: string): void;
|
|
911
|
+
/**
|
|
912
|
+
* Create a test user with specific permissions and roles.
|
|
913
|
+
*/
|
|
914
|
+
declare function createTestUserWithPermissions(permissions: string[], roles?: string[], overrides?: Partial<User>): User;
|
|
915
|
+
/**
|
|
916
|
+
* Create a test user for admin testing.
|
|
917
|
+
*/
|
|
918
|
+
declare function createTestAdminUser(overrides?: Partial<User>): User;
|
|
919
|
+
/**
|
|
920
|
+
* Create a test user for SSO testing.
|
|
921
|
+
*/
|
|
922
|
+
declare function createTestSSOUser(provider?: string, overrides?: Partial<User>): User;
|
|
923
|
+
/**
|
|
924
|
+
* Simulate a login flow on the mock store.
|
|
925
|
+
*/
|
|
926
|
+
declare function simulateLogin(store: MockAuthStore, user?: User, tokens?: {
|
|
927
|
+
accessToken: string;
|
|
928
|
+
refreshToken: string;
|
|
929
|
+
}): void;
|
|
930
|
+
/**
|
|
931
|
+
* Simulate a logout flow on the mock store.
|
|
932
|
+
*/
|
|
933
|
+
declare function simulateLogout(store: MockAuthStore): void;
|
|
934
|
+
/**
|
|
935
|
+
* Simulate a token refresh on the mock store.
|
|
936
|
+
*/
|
|
937
|
+
declare function simulateTokenRefresh(store: MockAuthStore, newTokens?: {
|
|
938
|
+
accessToken: string;
|
|
939
|
+
refreshToken: string;
|
|
940
|
+
}): void;
|
|
941
|
+
/**
|
|
942
|
+
* Simulate a profile update on the mock store.
|
|
943
|
+
*/
|
|
944
|
+
declare function simulateProfileUpdate(store: MockAuthStore, updates: Partial<User>): void;
|
|
945
|
+
/**
|
|
946
|
+
* Configure a complete MFA enrollment flow.
|
|
947
|
+
*/
|
|
948
|
+
declare function configureMFAEnrollmentFlow(mockFetch: MockFetchInstance): void;
|
|
949
|
+
/**
|
|
950
|
+
* Configure a complete password reset flow.
|
|
951
|
+
*/
|
|
952
|
+
declare function configurePasswordResetFlow(mockFetch: MockFetchInstance): void;
|
|
953
|
+
/**
|
|
954
|
+
* Configure a session management test scenario.
|
|
955
|
+
*/
|
|
956
|
+
declare function configureSessionManagementFlow(mockFetch: MockFetchInstance, sessionCount?: number): void;
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Auth Test Assertions
|
|
960
|
+
*
|
|
961
|
+
* Custom assertions for testing authentication functionality.
|
|
962
|
+
*/
|
|
963
|
+
|
|
964
|
+
interface AssertApiCalledOptions {
|
|
965
|
+
/** Expected number of calls (if specified) */
|
|
966
|
+
times?: number;
|
|
967
|
+
/** Expected request body */
|
|
968
|
+
body?: unknown;
|
|
969
|
+
/** Expected headers */
|
|
970
|
+
headers?: Record<string, string>;
|
|
971
|
+
}
|
|
972
|
+
interface AssertStoreMethodCalledOptions {
|
|
973
|
+
/** Expected number of calls */
|
|
974
|
+
times?: number;
|
|
975
|
+
/** Expected arguments */
|
|
976
|
+
args?: unknown[];
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Assert that the auth state is authenticated.
|
|
980
|
+
*/
|
|
981
|
+
declare function assertAuthenticated(state: AuthState, message?: string): void;
|
|
982
|
+
/**
|
|
983
|
+
* Assert that the auth state is unauthenticated.
|
|
984
|
+
*/
|
|
985
|
+
declare function assertUnauthenticated(state: AuthState, message?: string): void;
|
|
986
|
+
/**
|
|
987
|
+
* Assert that the auth state has specific user.
|
|
988
|
+
*/
|
|
989
|
+
declare function assertHasUser(state: AuthState, userId: string, message?: string): void;
|
|
990
|
+
/**
|
|
991
|
+
* Assert that a user has specific permissions.
|
|
992
|
+
*/
|
|
993
|
+
declare function assertHasPermissions(user: User, permissions: string[], message?: string): void;
|
|
994
|
+
/**
|
|
995
|
+
* Assert that a user does not have specific permissions.
|
|
996
|
+
*/
|
|
997
|
+
declare function assertLacksPermissions(user: User, permissions: string[], message?: string): void;
|
|
998
|
+
/**
|
|
999
|
+
* Assert that a user has specific roles.
|
|
1000
|
+
*/
|
|
1001
|
+
declare function assertHasRoles(user: User, roles: string[], message?: string): void;
|
|
1002
|
+
/**
|
|
1003
|
+
* Assert that a user does not have specific roles.
|
|
1004
|
+
*/
|
|
1005
|
+
declare function assertLacksRoles(user: User, roles: string[], message?: string): void;
|
|
1006
|
+
/**
|
|
1007
|
+
* Assert that a token is valid (not expired).
|
|
1008
|
+
*/
|
|
1009
|
+
declare function assertTokenValid(token: string, message?: string): void;
|
|
1010
|
+
/**
|
|
1011
|
+
* Assert that a token is expired.
|
|
1012
|
+
*/
|
|
1013
|
+
declare function assertTokenExpired(token: string, message?: string): void;
|
|
1014
|
+
/**
|
|
1015
|
+
* Assert that a token contains specific claims.
|
|
1016
|
+
*/
|
|
1017
|
+
declare function assertTokenHasClaims(token: string, claims: Record<string, unknown>, message?: string): void;
|
|
1018
|
+
/**
|
|
1019
|
+
* Assert that a token has specific subject (user ID).
|
|
1020
|
+
*/
|
|
1021
|
+
declare function assertTokenSubject(token: string, subject: string, message?: string): void;
|
|
1022
|
+
/**
|
|
1023
|
+
* Assert that an API endpoint was called.
|
|
1024
|
+
*/
|
|
1025
|
+
declare function assertApiCalled(mockFetch: MockFetchInstance, method: string, path: string, options?: AssertApiCalledOptions): void;
|
|
1026
|
+
/**
|
|
1027
|
+
* Assert that an API endpoint was not called.
|
|
1028
|
+
*/
|
|
1029
|
+
declare function assertApiNotCalled(mockFetch: MockFetchInstance, method: string, path: string, message?: string): void;
|
|
1030
|
+
/**
|
|
1031
|
+
* Assert the order of API calls.
|
|
1032
|
+
*/
|
|
1033
|
+
declare function assertApiCallOrder(mockFetch: MockFetchInstance, expectedOrder: Array<{
|
|
1034
|
+
method: string;
|
|
1035
|
+
path: string;
|
|
1036
|
+
}>): void;
|
|
1037
|
+
/**
|
|
1038
|
+
* Assert that a store method was called.
|
|
1039
|
+
*/
|
|
1040
|
+
declare function assertStoreMethodCalled(store: MockAuthStore, method: string, options?: AssertStoreMethodCalledOptions): void;
|
|
1041
|
+
/**
|
|
1042
|
+
* Assert that a store method was not called.
|
|
1043
|
+
*/
|
|
1044
|
+
declare function assertStoreMethodNotCalled(store: MockAuthStore, method: string, message?: string): void;
|
|
1045
|
+
/**
|
|
1046
|
+
* Assert that a login response requires MFA.
|
|
1047
|
+
*/
|
|
1048
|
+
declare function assertRequiresMFA(response: {
|
|
1049
|
+
requiresMFA?: boolean;
|
|
1050
|
+
mfaRequired?: boolean;
|
|
1051
|
+
mfaToken?: string;
|
|
1052
|
+
}, message?: string): void;
|
|
1053
|
+
/**
|
|
1054
|
+
* Assert that a login response does not require MFA.
|
|
1055
|
+
*/
|
|
1056
|
+
declare function assertNoMFARequired(response: {
|
|
1057
|
+
requiresMFA?: boolean;
|
|
1058
|
+
mfaRequired?: boolean;
|
|
1059
|
+
accessToken?: string;
|
|
1060
|
+
}, message?: string): void;
|
|
1061
|
+
/**
|
|
1062
|
+
* Assert that a user's email is verified.
|
|
1063
|
+
*/
|
|
1064
|
+
declare function assertEmailVerified(user: User, message?: string): void;
|
|
1065
|
+
/**
|
|
1066
|
+
* Assert that a user's email is not verified.
|
|
1067
|
+
*/
|
|
1068
|
+
declare function assertEmailNotVerified(user: User, message?: string): void;
|
|
1069
|
+
/**
|
|
1070
|
+
* Assert that a user is active.
|
|
1071
|
+
*/
|
|
1072
|
+
declare function assertUserActive(user: User, message?: string): void;
|
|
1073
|
+
/**
|
|
1074
|
+
* Assert that a user is inactive.
|
|
1075
|
+
*/
|
|
1076
|
+
declare function assertUserInactive(user: User, message?: string): void;
|
|
1077
|
+
/**
|
|
1078
|
+
* Assert that a user uses a specific auth method.
|
|
1079
|
+
*/
|
|
1080
|
+
declare function assertAuthMethod(user: User, method: 'password' | 'oauth' | 'both', message?: string): void;
|
|
1081
|
+
|
|
1082
|
+
export { type AssertApiCalledOptions, type AssertStoreMethodCalledOptions, type AuthScenario, type FetchCall, type JWTPayloadOptions, MockAuthStore, type MockAuthStoreOptions, MockFetchInstance, type MockFetchOptions, type MockRequest, type MockRoute, type MockRouteResponse, MockStorageAdapter, type MockStorageOptions, type ScenarioState, type SetupTestAuthOptions, type StorageCall, type StoreCall, type TestAuthContext, applyScenario, applyScenarios, assertApiCallOrder, assertApiCalled, assertApiNotCalled, assertAuthMethod, assertAuthenticated, assertEmailNotVerified, assertEmailVerified, assertHasPermissions, assertHasRoles, assertHasUser, assertLacksPermissions, assertLacksRoles, assertNoMFARequired, assertRequiresMFA, assertStoreMethodCalled, assertStoreMethodNotCalled, assertTokenExpired, assertTokenHasClaims, assertTokenSubject, assertTokenValid, assertUnauthenticated, assertUserActive, assertUserInactive, authScenarios, configureAuthFailure, configureMFAEnrollmentFlow, configureMFAFlow, configurePasswordResetFlow, configureRateLimiting, configureSSOLogout, configureSessionManagementFlow, configureTokenRefresh, createAuthenticatedMockStore, createExpiredMockJWT, createMockAuthActions, createMockAuthStore, createMockCurrentUser, createMockDevice, createMockFetch, createMockFetchWithRoutes, createMockIsAuthenticated, createMockJWT, createMockLoginSuccess, createMockMFARequired, createMockMFAToken, createMockSecurityEvent, createMockSession, createMockStorage, createMockStorageWithAuth, createMockTokenPair, createMockUser, createMockUserWithAuthMethod, createMockUserWithRoles, createTestAdminUser, createTestAuthHelpers, createTestSSOUser, createTestUserWithPermissions, getScenarioState, initAuthWithMocks, mockAccessToken, mockAdminLoginSuccess, mockAdminToken, mockAdminUser, mockApiKey, mockApiKeys, mockCurrentSession, mockDevices, mockExpiredToken, mockInactiveUser, mockLinkedAccount, mockLoginSuccess, mockLogoutSuccess, mockMFARequired, mockMFARequiredLegacy, mockMFASetup, mockMFAStatusDisabled, mockMFAStatusEnabled, mockMFAToken, mockMFAUser, mockOtherSession, mockRefreshToken, mockRegisterRequiresVerification, mockRegisterSuccess, mockSSOLoginSuccess, mockSSOLogoutResponse, mockSSOUser, mockSecurityEventLogin, mockSecurityEventPasswordChange, mockSecurityEventSuspicious, mockSecurityEvents, mockSessionToken, mockSessions, mockTrustedDevice, mockUntrustedDevice, mockUnverifiedUser, mockUser, mockUserPreferences, quickSetupAuth, resetTestAuth, setupTestAuth, simulateLogin, simulateLogout, simulateProfileUpdate, simulateTokenRefresh, withTestAuth, withTestAuthEach };
|