@@ -207,27 +207,32 @@ describe("SessionHandler", () => {
207
207
expect ( res . cookie ) . to . be . undefined ;
208
208
} ) ;
209
209
it ( "JWT cookie is present but invalid" , async ( ) => {
210
- const res = await handle ( existingUser , "_gitpod_dev_jwt_=invalid" ) ;
210
+ const res = await handle ( undefined , "__Host- _gitpod_dev_jwt_=invalid" ) ;
211
211
expect ( res . status ) . to . equal ( 401 ) ;
212
- expect ( res . value ) . to . equal ( "JWT Session is invalid " ) ;
212
+ expect ( res . value ) . to . equal ( "User has no valid session. " ) ;
213
213
expect ( res . cookie ) . to . be . undefined ;
214
214
} ) ;
215
215
216
- it ( "old JWT cookie is present, is accepted (!), and we get a new one " , async ( ) => {
216
+ it ( "old JWT cookie is ignored, new one is outdated and refreshed " , async ( ) => {
217
217
const oldExpiredCookie = await sessionHandler . createJWTSessionCookie ( existingUser . id , {
218
218
issuedAtMs : Date . now ( ) - SessionHandler . JWT_REFRESH_THRESHOLD - 1 ,
219
219
} ) ;
220
220
oldExpiredCookie . name = "_gitpod_dev_jwt_" ;
221
- const newCookie = await sessionHandler . createJWTSessionCookie ( existingUser . id ) ;
221
+ const newCookie = await sessionHandler . createJWTSessionCookie ( existingUser . id , {
222
+ issuedAtMs : Date . now ( ) - SessionHandler . JWT_REFRESH_THRESHOLD - 1 ,
223
+ } ) ;
222
224
223
- const res = await handle ( existingUser , `${ oldExpiredCookie . name } =${ oldExpiredCookie . value } ` ) ;
225
+ const res = await handle (
226
+ existingUser ,
227
+ `${ oldExpiredCookie . name } =${ oldExpiredCookie . value } ; ${ newCookie . name } =${ newCookie . value } ` ,
228
+ ) ;
224
229
expect ( res . status ) . to . equal ( 200 ) ;
225
230
expect ( res . value ) . to . equal ( "Refreshed JWT cookie issued." ) ;
226
231
expect ( res . cookie ) . to . not . be . undefined ;
227
232
expect ( res . cookie ?. split ( "=" ) [ 0 ] ) . to . equal ( newCookie . name ) ;
228
233
} ) ;
229
234
230
- it ( "old expired AND new one JWT cookies are present , new one is accepted" , async ( ) => {
235
+ it ( "ld JWT cookie is ignored , new one is accepted" , async ( ) => {
231
236
const oldExpiredCookie = await sessionHandler . createJWTSessionCookie ( existingUser . id , {
232
237
issuedAtMs : Date . now ( ) - SessionHandler . JWT_REFRESH_THRESHOLD - 1 ,
233
238
} ) ;
0 commit comments