@@ -84,21 +84,6 @@ Object.defineProperty(window, "sessionStorage", {
84
84
value : sessionStorageMock ,
85
85
} ) ;
86
86
87
- // Try to mock window.location, but don't fail if it doesn't work (e.g., in CI)
88
- try {
89
- Object . defineProperty ( window , "location" , {
90
- value : {
91
- origin : "http://localhost:3000" ,
92
- } ,
93
- } ) ;
94
- } catch {
95
- // Ignore error - tests that depend on this will be skipped
96
- }
97
-
98
- // Skip location-dependent tests in CI where window.location mocking fails
99
- const isCI = process . env . CI === "true" ;
100
- const skipIfCI = isCI ? it . skip : it ;
101
-
102
87
describe ( "AuthDebugger" , ( ) => {
103
88
const defaultAuthState = EMPTY_DEBUGGER_STATE ;
104
89
@@ -113,7 +98,7 @@ describe("AuthDebugger", () => {
113
98
jest . clearAllMocks ( ) ;
114
99
sessionStorageMock . getItem . mockReturnValue ( null ) ;
115
100
116
- // Supress
101
+ // Suppress console errors in tests to avoid JSDOM navigation noise
117
102
jest . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
118
103
119
104
mockDiscoverOAuthMetadata . mockResolvedValue ( mockOAuthMetadata ) ;
@@ -453,65 +438,58 @@ describe("AuthDebugger", () => {
453
438
} ) ;
454
439
455
440
describe ( "OAuth State Persistence" , ( ) => {
456
- skipIfCI (
457
- "should store auth state to sessionStorage before redirect in Quick OAuth Flow" ,
458
- async ( ) => {
459
- const updateAuthState = jest . fn ( ) ;
460
-
461
- // This test depends on window.location being mocked at the top of the file
462
-
463
- // Setup mocks for OAuth flow
464
- mockStartAuthorization . mockResolvedValue ( {
465
- authorizationUrl : new URL (
466
- "https://oauth.example.com/authorize?client_id=test_client_id&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Foauth%2Fcallback%2Fdebug" ,
467
- ) ,
468
- codeVerifier : "test_verifier" ,
469
- } ) ;
441
+ it ( "should store auth state to sessionStorage before redirect in Quick OAuth Flow" , async ( ) => {
442
+ const updateAuthState = jest . fn ( ) ;
470
443
471
- await act ( async ( ) => {
472
- renderAuthDebugger ( {
473
- updateAuthState,
474
- authState : { ...defaultAuthState } ,
475
- } ) ;
476
- } ) ;
444
+ // Setup mocks for OAuth flow
445
+ mockStartAuthorization . mockResolvedValue ( {
446
+ authorizationUrl : new URL (
447
+ "https://oauth.example.com/authorize?client_id=test_client_id&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Foauth%2Fcallback%2Fdebug" ,
448
+ ) ,
449
+ codeVerifier : "test_verifier" ,
450
+ } ) ;
477
451
478
- // Click Quick OAuth Flow
479
- await act ( async ( ) => {
480
- fireEvent . click ( screen . getByText ( "Quick OAuth Flow" ) ) ;
452
+ await act ( async ( ) => {
453
+ renderAuthDebugger ( {
454
+ updateAuthState,
455
+ authState : { ...defaultAuthState } ,
481
456
} ) ;
457
+ } ) ;
482
458
483
- // Wait for the flow to reach the authorization step
484
- await waitFor ( ( ) => {
485
- expect ( sessionStorage . setItem ) . toHaveBeenCalledWith (
486
- SESSION_KEYS . AUTH_DEBUGGER_STATE ,
487
- expect . stringContaining ( '"oauthStep":"authorization_code"' ) ,
488
- ) ;
489
- } ) ;
459
+ // Click Quick OAuth Flow
460
+ await act ( async ( ) => {
461
+ fireEvent . click ( screen . getByText ( "Quick OAuth Flow" ) ) ;
462
+ } ) ;
490
463
491
- // Verify the stored state includes all the accumulated data
492
- const storedStateCall = (
493
- sessionStorage . setItem as jest . Mock
494
- ) . mock . calls . find (
495
- ( call ) => call [ 0 ] === SESSION_KEYS . AUTH_DEBUGGER_STATE ,
464
+ // Wait for the flow to reach the authorization step
465
+ await waitFor ( ( ) => {
466
+ expect ( sessionStorage . setItem ) . toHaveBeenCalledWith (
467
+ SESSION_KEYS . AUTH_DEBUGGER_STATE ,
468
+ expect . stringContaining ( '"oauthStep":"authorization_code"' ) ,
496
469
) ;
470
+ } ) ;
497
471
498
- expect ( storedStateCall ) . toBeDefined ( ) ;
499
- const storedState = JSON . parse ( storedStateCall ! [ 1 ] as string ) ;
472
+ // Verify the stored state includes all the accumulated data
473
+ const storedStateCall = (
474
+ sessionStorage . setItem as jest . Mock
475
+ ) . mock . calls . find ( ( call ) => call [ 0 ] === SESSION_KEYS . AUTH_DEBUGGER_STATE ) ;
500
476
501
- expect ( storedState ) . toMatchObject ( {
502
- oauthStep : "authorization_code" ,
503
- authorizationUrl : expect . stringMatching (
504
- / ^ h t t p s : \/ \/ o a u t h \. e x a m p l e \. c o m \/ a u t h o r i z e / ,
505
- ) ,
506
- oauthMetadata : expect . objectContaining ( {
507
- token_endpoint : "https://oauth.example.com/token" ,
508
- } ) ,
509
- oauthClientInfo : expect . objectContaining ( {
510
- client_id : "test_client_id" ,
511
- } ) ,
512
- } ) ;
513
- } ,
514
- ) ;
477
+ expect ( storedStateCall ) . toBeDefined ( ) ;
478
+ const storedState = JSON . parse ( storedStateCall ! [ 1 ] as string ) ;
479
+
480
+ expect ( storedState ) . toMatchObject ( {
481
+ oauthStep : "authorization_code" ,
482
+ authorizationUrl : expect . stringMatching (
483
+ / ^ h t t p s : \/ \/ o a u t h \. e x a m p l e \. c o m \/ a u t h o r i z e / ,
484
+ ) ,
485
+ oauthMetadata : expect . objectContaining ( {
486
+ token_endpoint : "https://oauth.example.com/token" ,
487
+ } ) ,
488
+ oauthClientInfo : expect . objectContaining ( {
489
+ client_id : "test_client_id" ,
490
+ } ) ,
491
+ } ) ;
492
+ } ) ;
515
493
} ) ;
516
494
517
495
describe ( "OAuth Protected Resource Metadata" , ( ) => {
0 commit comments