@@ -4,3 +4,52 @@ test('app returns 200', async ({ page }) => {
44 const response = await page . goto ( '/' ) ;
55 expect ( response ?. status ( ) ) . toBe ( 200 ) ;
66} ) ;
7+
8+ test ( 'GET /auth/logout/callback clears authjs.* and logout_state' , async ( {
9+ request,
10+ baseURL,
11+ } ) => {
12+ const res = await request . get (
13+ `${ baseURL } /auth/logout/callback?state=teststate123` ,
14+ {
15+ headers : {
16+ Cookie : [
17+ 'logout_state=teststate123' ,
18+ 'authjs.session-token=fakesession' ,
19+ 'authjs.csrf-token=fakecsrf' ,
20+ 'authjs.callback-url=http://example.com' ,
21+ ] . join ( '; ' ) ,
22+ } ,
23+ maxRedirects : 0 ,
24+ } ,
25+ ) ;
26+
27+ const status = res . status ( ) ;
28+ const location = res . headers ( ) [ 'location' ] ;
29+ const setCookies = res
30+ . headersArray ( )
31+ . filter ( ( h ) => h . name . toLowerCase ( ) === 'set-cookie' )
32+ . map ( ( h ) => h . value ) as string [ ] ;
33+
34+ expect ( status ) . toBe ( 302 ) ;
35+ expect ( location ) . toMatch ( / \/ ( a u t h \/ ) ? l o g o u t \/ s u c c e s s $ / ) ;
36+ expect ( setCookies ) . toBeDefined ( ) ;
37+ expect ( Array . isArray ( setCookies ) ) . toBe ( true ) ;
38+
39+ const wasCleared = ( name : string ) =>
40+ setCookies . some (
41+ ( sc ) =>
42+ sc . startsWith ( `${ name } =` ) &&
43+ ( sc . includes ( 'Max-Age=0' ) || / E x p i r e s = T h u , 0 1 J a n 1 9 7 0 / i. test ( sc ) ) ,
44+ ) ;
45+
46+ expect ( wasCleared ( 'authjs.session-token' ) ) . toBe ( true ) ;
47+ expect ( wasCleared ( 'authjs.csrf-token' ) ) . toBe ( true ) ;
48+ expect ( wasCleared ( 'authjs.callback-url' ) ) . toBe ( true ) ;
49+ expect ( wasCleared ( 'logout_state' ) ) . toBe ( true ) ;
50+
51+ const logoutStateCookie = setCookies . find ( ( sc ) =>
52+ sc . startsWith ( 'logout_state=' ) ,
53+ ) ;
54+ expect ( logoutStateCookie ) . toMatch ( / P a t h = \/ a u t h \/ l o g o u t \/ c a l l b a c k / ) ;
55+ } ) ;
0 commit comments