@@ -3,13 +3,23 @@ import sinon from 'sinon';
3
3
4
4
import runtime from '../runtime' ;
5
5
import { jsonOk } from '../util/mockFetch' ;
6
- import { type AuthReason , type RequestState , AuthErrorReason , AuthStatus } from './authStatus' ;
6
+ import { AuthErrorReason , type AuthReason , AuthStatus , type RequestState } from './authStatus' ;
7
7
import { TokenVerificationErrorReason } from './errors' ;
8
8
import { mockInvalidSignatureJwt , mockJwks , mockJwt , mockJwtPayload , mockMalformedJwt } from './fixtures' ;
9
9
import type { AuthenticateRequestOptions } from './request' ;
10
10
import { authenticateRequest } from './request' ;
11
11
12
- function assertSignedOut ( assert , requestState : RequestState , reason : AuthReason , message = '' ) {
12
+ function assertSignedOut (
13
+ assert ,
14
+ requestState : RequestState ,
15
+ expectedState : {
16
+ reason : AuthReason ;
17
+ isSatellite ?: boolean ;
18
+ domain ?: string ;
19
+ signInUrl ?: string ;
20
+ message ?: string ;
21
+ } ,
22
+ ) {
13
23
assert . propEqual ( requestState , {
14
24
frontendApi : 'cafe.babe.clerk.ts' ,
15
25
publishableKey : '' ,
@@ -21,9 +31,9 @@ function assertSignedOut(assert, requestState: RequestState, reason: AuthReason,
21
31
isSatellite : false ,
22
32
signInUrl : '' ,
23
33
domain : '' ,
24
- message,
25
- reason,
34
+ message : '' ,
26
35
toAuth : { } ,
36
+ ...expectedState ,
27
37
} ) ;
28
38
}
29
39
@@ -174,7 +184,10 @@ export default (QUnit: QUnit) => {
174
184
175
185
const errMessage =
176
186
'The JWKS endpoint did not contain any signing keys. Contact support@clerk.com. Contact support@clerk.com (reason=jwk-remote-failed-to-load, token-carrier=header)' ;
177
- assertSignedOut ( assert , requestState , TokenVerificationErrorReason . RemoteJWKFailedToLoad , errMessage ) ;
187
+ assertSignedOut ( assert , requestState , {
188
+ reason : TokenVerificationErrorReason . RemoteJWKFailedToLoad ,
189
+ message : errMessage ,
190
+ } ) ;
178
191
assertSignedOutToAuth ( assert , requestState ) ;
179
192
} ) ;
180
193
@@ -204,7 +217,10 @@ export default (QUnit: QUnit) => {
204
217
205
218
const errMessage =
206
219
'Invalid JWT Authorized party claim (azp) "https://accounts.inspired.puma-74.lcl.dev". Expected "whatever". (reason=token-invalid-authorized-parties, token-carrier=header)' ;
207
- assertSignedOut ( assert , requestState , TokenVerificationErrorReason . TokenInvalidAuthorizedParties , errMessage ) ;
220
+ assertSignedOut ( assert , requestState , {
221
+ reason : TokenVerificationErrorReason . TokenInvalidAuthorizedParties ,
222
+ message : errMessage ,
223
+ } ) ;
208
224
assertSignedOutToAuth ( assert , requestState ) ;
209
225
} ) ;
210
226
@@ -228,7 +244,10 @@ export default (QUnit: QUnit) => {
228
244
} ) ;
229
245
230
246
const errMessage = 'JWT signature is invalid. (reason=token-invalid-signature, token-carrier=header)' ;
231
- assertSignedOut ( assert , requestState , TokenVerificationErrorReason . TokenInvalidSignature , errMessage ) ;
247
+ assertSignedOut ( assert , requestState , {
248
+ reason : TokenVerificationErrorReason . TokenInvalidSignature ,
249
+ message : errMessage ,
250
+ } ) ;
232
251
assertSignedOutToAuth ( assert , requestState ) ;
233
252
} ) ;
234
253
@@ -240,7 +259,10 @@ export default (QUnit: QUnit) => {
240
259
241
260
const errMessage =
242
261
'Invalid JWT form. A JWT consists of three parts separated by dots. (reason=token-invalid, token-carrier=header)' ;
243
- assertSignedOut ( assert , requestState , TokenVerificationErrorReason . TokenInvalid , errMessage ) ;
262
+ assertSignedOut ( assert , requestState , {
263
+ reason : TokenVerificationErrorReason . TokenInvalid ,
264
+ message : errMessage ,
265
+ } ) ;
244
266
assertSignedOutToAuth ( assert , requestState ) ;
245
267
} ) ;
246
268
@@ -256,7 +278,9 @@ export default (QUnit: QUnit) => {
256
278
cookieToken : mockJwt ,
257
279
} ) ;
258
280
259
- assertSignedOut ( assert , requestState , AuthErrorReason . HeaderMissingCORS ) ;
281
+ assertSignedOut ( assert , requestState , {
282
+ reason : AuthErrorReason . HeaderMissingCORS ,
283
+ } ) ;
260
284
assertSignedOutToAuth ( assert , requestState ) ;
261
285
} ) ;
262
286
@@ -270,7 +294,7 @@ export default (QUnit: QUnit) => {
270
294
cookieToken : mockJwt ,
271
295
} ) ;
272
296
273
- assertSignedOut ( assert , requestState , AuthErrorReason . HeaderMissingNonBrowser ) ;
297
+ assertSignedOut ( assert , requestState , { reason : AuthErrorReason . HeaderMissingNonBrowser } ) ;
274
298
assertSignedOutToAuth ( assert , requestState ) ;
275
299
} ) ;
276
300
@@ -292,6 +316,24 @@ export default (QUnit: QUnit) => {
292
316
assert . strictEqual ( requestState . toAuth ( ) , null ) ;
293
317
} ) ;
294
318
319
+ test ( 'cookieToken: returns signed out is satellite but a non-browser request [11y]' , async assert => {
320
+ const requestState = await authenticateRequest ( {
321
+ ...defaultMockAuthenticateRequestOptions ,
322
+ apiKey : 'deadbeef' ,
323
+ clientUat : '0' ,
324
+ isSatellite : true ,
325
+ domain : 'satellite.dev' ,
326
+ userAgent : '[some-agent]' ,
327
+ } ) ;
328
+
329
+ assertSignedOut ( assert , requestState , {
330
+ reason : AuthErrorReason . SatelliteCookieNeedsSyncing ,
331
+ isSatellite : true ,
332
+ domain : 'satellite.dev' ,
333
+ } ) ;
334
+ assertSignedOutToAuth ( assert , requestState ) ;
335
+ } ) ;
336
+
295
337
test ( 'returns interstitial when app is satellite, returns from primary and is dev instance [13y]' , async assert => {
296
338
const sp = new URLSearchParams ( ) ;
297
339
sp . set ( '__clerk_referrer_primary' , 'true' ) ;
@@ -339,7 +381,9 @@ export default (QUnit: QUnit) => {
339
381
apiKey : 'live_deadbeef' ,
340
382
} ) ;
341
383
342
- assertSignedOut ( assert , requestState , AuthErrorReason . CookieAndUATMissing ) ;
384
+ assertSignedOut ( assert , requestState , {
385
+ reason : AuthErrorReason . CookieAndUATMissing ,
386
+ } ) ;
343
387
assertSignedOutToAuth ( assert , requestState ) ;
344
388
} ) ;
345
389
@@ -430,7 +474,9 @@ export default (QUnit: QUnit) => {
430
474
clientUat : '0' ,
431
475
} ) ;
432
476
433
- assertSignedOut ( assert , requestState , AuthErrorReason . StandardSignedOut ) ;
477
+ assertSignedOut ( assert , requestState , {
478
+ reason : AuthErrorReason . StandardSignedOut ,
479
+ } ) ;
434
480
assertSignedOutToAuth ( assert , requestState ) ;
435
481
} ) ;
436
482
@@ -455,7 +501,10 @@ export default (QUnit: QUnit) => {
455
501
456
502
const errMessage =
457
503
'Subject claim (sub) is required and must be a string. Received undefined. Make sure that this is a valid Clerk generate JWT. (reason=token-verification-failed, token-carrier=cookie)' ;
458
- assertSignedOut ( assert , requestState , TokenVerificationErrorReason . TokenVerificationFailed , errMessage ) ;
504
+ assertSignedOut ( assert , requestState , {
505
+ reason : TokenVerificationErrorReason . TokenVerificationFailed ,
506
+ message : errMessage ,
507
+ } ) ;
459
508
assertSignedOutToAuth ( assert , requestState ) ;
460
509
} ) ;
461
510
0 commit comments