@@ -148,6 +148,37 @@ describe('CookieStore', () => {
148148 await expect ( get ( baseURL , '/session' , { cookieJar } ) ) . rejects . toThrowError ( 'Unauthorized' ) ;
149149 } ) ;
150150
151+ it ( 'should clean up single cookie when switching to chunked' , async ( ) => {
152+ const baseURL = await setup ( defaultConfig ) ;
153+ const appSession = encrypted ( {
154+ big_claim : randomBytes ( 2000 ) . toString ( 'base64' )
155+ } ) ;
156+ expect ( appSession . length ) . toBeGreaterThan ( 4000 ) ;
157+ const cookieJar = toCookieJar ( { appSession } , baseURL ) ;
158+ const session = await get ( baseURL , '/session' , { cookieJar } ) ;
159+ expect ( session . claims ) . toHaveProperty ( 'big_claim' ) ;
160+ const cookies = fromCookieJar ( cookieJar , baseURL ) ;
161+ expect ( cookies ) . toHaveProperty ( [ 'appSession.0' ] ) ;
162+ expect ( cookies ) . not . toHaveProperty ( 'appSession' ) ;
163+ } ) ;
164+
165+ it ( 'should clean up chunked cookies when switching to a single cookie' , async ( ) => {
166+ const baseURL = await setup ( defaultConfig ) ;
167+ const appSession = encrypted ( { sub : 'foo' } ) ;
168+ const cookieJar = toCookieJar (
169+ {
170+ 'appSession.0' : appSession . slice ( 0 , 100 ) ,
171+ 'appSession.1' : appSession . slice ( 100 )
172+ } ,
173+ baseURL
174+ ) ;
175+ const session = await get ( baseURL , '/session' , { cookieJar } ) ;
176+ expect ( session . claims ) . toHaveProperty ( 'sub' ) ;
177+ const cookies = fromCookieJar ( cookieJar , baseURL ) ;
178+ expect ( cookies ) . toHaveProperty ( 'appSession' ) ;
179+ expect ( cookies ) . not . toHaveProperty ( [ 'appSession.0' ] ) ;
180+ } ) ;
181+
151182 it ( 'should set the default cookie options on http' , async ( ) => {
152183 const baseURL = await setup ( defaultConfig ) ;
153184 const appSession = encrypted ( ) ;
0 commit comments