@@ -58,6 +58,15 @@ describe("AuthorizeProject", () => {
58
58
allowedRedirects : [ "https://test-app.com/callback" ] ,
59
59
allowImplicitFlow : true ,
60
60
} ,
61
+ "test-subdomain-client" : {
62
+ name : "Test App With Any Subdomain Allowed" ,
63
+ allowedRedirects : [ ] ,
64
+ allowedRedirectsAnySubdomain : [
65
+ "https://a.pages.dev/foo" ,
66
+ "http://b.com/bar" ,
67
+ ] ,
68
+ allowImplicitFlow : true ,
69
+ } ,
61
70
} ,
62
71
} ;
63
72
@@ -333,4 +342,84 @@ describe("AuthorizeProject", () => {
333
342
screen . getByText ( "Authorize access to your project" ) ,
334
343
) ;
335
344
} ) ;
345
+
346
+ describe ( "allowedRedirectsAnySubdomain" , ( ) => {
347
+ test ( "accepts a subdomain of an allowed domain with matching path" , ( ) => {
348
+ mockRouter . setCurrentUrl (
349
+ "/?client_id=test-subdomain-client&redirect_uri=https://b.a.pages.dev/foo&response_type=token" ,
350
+ ) ;
351
+
352
+ render ( < AuthorizeProject /> ) ;
353
+ expect (
354
+ screen . getByText ( "Authorize access to your project" ) ,
355
+ ) . toBeInTheDocument ( ) ;
356
+ } ) ;
357
+
358
+ test ( "accepts multiple levels of subdomains with matching path" , ( ) => {
359
+ mockRouter . setCurrentUrl (
360
+ "/?client_id=test-subdomain-client&redirect_uri=https://c.b.a.pages.dev/foo&response_type=token" ,
361
+ ) ;
362
+
363
+ render ( < AuthorizeProject /> ) ;
364
+ expect (
365
+ screen . getByText ( "Authorize access to your project" ) ,
366
+ ) . toBeInTheDocument ( ) ;
367
+ } ) ;
368
+
369
+ test ( "rejects if domain structure is changed" , ( ) => {
370
+ mockRouter . setCurrentUrl (
371
+ "/?client_id=test-subdomain-client&redirect_uri=https://b.a.c.pages.dev/foo&response_type=token" ,
372
+ ) ;
373
+
374
+ render ( < AuthorizeProject /> ) ;
375
+ expect ( screen . getByTestId ( "invalid-redirect-uri" ) ) . toBeInTheDocument ( ) ;
376
+ } ) ;
377
+
378
+ test ( "rejects if path is different" , ( ) => {
379
+ mockRouter . setCurrentUrl (
380
+ "/?client_id=test-subdomain-client&redirect_uri=https://b.a.pages.dev/foo/bar&response_type=token" ,
381
+ ) ;
382
+
383
+ render ( < AuthorizeProject /> ) ;
384
+ expect ( screen . getByTestId ( "invalid-redirect-uri" ) ) . toBeInTheDocument ( ) ;
385
+ } ) ;
386
+
387
+ test ( "rejects if protocol is different" , ( ) => {
388
+ mockRouter . setCurrentUrl (
389
+ "/?client_id=test-subdomain-client&redirect_uri=http://b.a.pages.dev/foo&response_type=token" ,
390
+ ) ;
391
+
392
+ render ( < AuthorizeProject /> ) ;
393
+ expect ( screen . getByTestId ( "invalid-redirect-uri" ) ) . toBeInTheDocument ( ) ;
394
+ } ) ;
395
+
396
+ test ( "accepts a subdomain for second allowed domain with matching path" , ( ) => {
397
+ mockRouter . setCurrentUrl (
398
+ "/?client_id=test-subdomain-client&redirect_uri=http://sub.b.com/bar&response_type=token" ,
399
+ ) ;
400
+
401
+ render ( < AuthorizeProject /> ) ;
402
+ expect (
403
+ screen . getByText ( "Authorize access to your project" ) ,
404
+ ) . toBeInTheDocument ( ) ;
405
+ } ) ;
406
+
407
+ test ( "rejects if port is different" , ( ) => {
408
+ mockRouter . setCurrentUrl (
409
+ "/?client_id=test-subdomain-client&redirect_uri=https://b.a.pages.dev:8080/foo&response_type=token" ,
410
+ ) ;
411
+
412
+ render ( < AuthorizeProject /> ) ;
413
+ expect ( screen . getByTestId ( "invalid-redirect-uri" ) ) . toBeInTheDocument ( ) ;
414
+ } ) ;
415
+
416
+ test ( "rejects query parameters" , ( ) => {
417
+ mockRouter . setCurrentUrl (
418
+ "/?client_id=test-subdomain-client&redirect_uri=https://b.a.pages.dev/foo?query=param&response_type=token" ,
419
+ ) ;
420
+
421
+ render ( < AuthorizeProject /> ) ;
422
+ expect ( screen . getByTestId ( "invalid-redirect-uri" ) ) . toBeInTheDocument ( ) ;
423
+ } ) ;
424
+ } ) ;
336
425
} ) ;
0 commit comments