18
18
19
19
import java .io .IOException ;
20
20
import java .nio .charset .StandardCharsets ;
21
+ import java .time .ZonedDateTime ;
22
+ import java .time .format .DateTimeFormatter ;
21
23
import java .util .Arrays ;
22
24
import java .util .Collection ;
23
25
@@ -357,12 +359,17 @@ void setCookieHeader() {
357
359
* @since 5.1.11
358
360
*/
359
361
@ Test
360
- void setCookieHeaderWithExpiresAttribute () {
361
- String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires= Tue, 8 Oct 2019 19:50:00 GMT; Secure; " +
362
- " HttpOnly; SameSite=Lax" ;
362
+ void setCookieHeaderWithMaxAgeAndExpiresAttributes () {
363
+ String expiryDate = "Tue, 8 Oct 2019 19:50:00 GMT" ;
364
+ String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=" + expiryDate + "; Secure; HttpOnly; SameSite=Lax" ;
363
365
response .setHeader (SET_COOKIE , cookieValue );
364
- assertNumCookies (1 );
365
366
assertThat (response .getHeader (SET_COOKIE )).isEqualTo (cookieValue );
367
+
368
+ assertNumCookies (1 );
369
+ assertThat (response .getCookies ()[0 ]).isInstanceOf (MockCookie .class );
370
+ MockCookie mockCookie = (MockCookie ) response .getCookies ()[0 ];
371
+ assertThat (mockCookie .getMaxAge ()).isEqualTo (100 );
372
+ assertThat (mockCookie .getExpires ()).isEqualTo (ZonedDateTime .parse (expiryDate , DateTimeFormatter .RFC_1123_DATE_TIME ));
366
373
}
367
374
368
375
/**
@@ -396,18 +403,24 @@ void addCookieHeader() {
396
403
* @since 5.1.11
397
404
*/
398
405
@ Test
399
- void addCookieHeaderWithExpiresAttribute () {
400
- String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires= Tue, 8 Oct 2019 19:50:00 GMT; Secure; " +
401
- " HttpOnly; SameSite=Lax" ;
406
+ void addCookieHeaderWithMaxAgeAndExpiresAttributes () {
407
+ String expiryDate = "Tue, 8 Oct 2019 19:50:00 GMT" ;
408
+ String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=" + expiryDate + "; Secure; HttpOnly; SameSite=Lax" ;
402
409
response .addHeader (SET_COOKIE , cookieValue );
403
410
assertThat (response .getHeader (SET_COOKIE )).isEqualTo (cookieValue );
411
+
412
+ assertNumCookies (1 );
413
+ assertThat (response .getCookies ()[0 ]).isInstanceOf (MockCookie .class );
414
+ MockCookie mockCookie = (MockCookie ) response .getCookies ()[0 ];
415
+ assertThat (mockCookie .getMaxAge ()).isEqualTo (100 );
416
+ assertThat (mockCookie .getExpires ()).isEqualTo (ZonedDateTime .parse (expiryDate , DateTimeFormatter .RFC_1123_DATE_TIME ));
404
417
}
405
418
406
419
/**
407
420
* @since 5.1.12
408
421
*/
409
422
@ Test
410
- void addCookieHeaderWithZeroExpiresAttribute () {
423
+ void addCookieHeaderWithMaxAgeAndZeroExpiresAttributes () {
411
424
String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=0" ;
412
425
response .addHeader (SET_COOKIE , cookieValue );
413
426
assertNumCookies (1 );
@@ -418,14 +431,24 @@ void addCookieHeaderWithZeroExpiresAttribute() {
418
431
}
419
432
420
433
/**
421
- * @since 5.1.12
434
+ * @since 5.2.14
422
435
*/
423
436
@ Test
424
- void addCookieHeaderWithOnlyExpiresAttribute () {
425
- String cookieValue = "SESSION=123; Path=/; Expires=Tue, 8 Oct 2019 19:50:00 GMT" ;
437
+ void addCookieHeaderWithExpiresAttributeWithoutMaxAgeAttribute () {
438
+ String expiryDate = "Tue, 8 Oct 2019 19:50:00 GMT" ;
439
+ String cookieValue = "SESSION=123; Path=/; Expires=" + expiryDate ;
426
440
response .addHeader (SET_COOKIE , cookieValue );
427
- assertNumCookies ( 1 );
441
+ System . err . println ( response . getCookie ( "SESSION" ) );
428
442
assertThat (response .getHeader (SET_COOKIE )).isEqualTo (cookieValue );
443
+
444
+ assertNumCookies (1 );
445
+ assertThat (response .getCookies ()[0 ]).isInstanceOf (MockCookie .class );
446
+ MockCookie mockCookie = (MockCookie ) response .getCookies ()[0 ];
447
+ assertThat (mockCookie .getName ()).isEqualTo ("SESSION" );
448
+ assertThat (mockCookie .getValue ()).isEqualTo ("123" );
449
+ assertThat (mockCookie .getPath ()).isEqualTo ("/" );
450
+ assertThat (mockCookie .getMaxAge ()).isEqualTo (-1 );
451
+ assertThat (mockCookie .getExpires ()).isEqualTo (ZonedDateTime .parse (expiryDate , DateTimeFormatter .RFC_1123_DATE_TIME ));
429
452
}
430
453
431
454
@ Test
0 commit comments