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
import java .util .Locale ;
@@ -415,12 +417,17 @@ void setCookieHeader() {
415
417
* @since 5.1.11
416
418
*/
417
419
@ Test
418
- void setCookieHeaderWithExpiresAttribute () {
419
- String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires= Tue, 8 Oct 2019 19:50:00 GMT; Secure; " +
420
- " HttpOnly; SameSite=Lax" ;
420
+ void setCookieHeaderWithMaxAgeAndExpiresAttributes () {
421
+ String expiryDate = "Tue, 8 Oct 2019 19:50:00 GMT" ;
422
+ String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=" + expiryDate + "; Secure; HttpOnly; SameSite=Lax" ;
421
423
response .setHeader (SET_COOKIE , cookieValue );
422
- assertNumCookies (1 );
423
424
assertThat (response .getHeader (SET_COOKIE )).isEqualTo (cookieValue );
425
+
426
+ assertNumCookies (1 );
427
+ assertThat (response .getCookies ()[0 ]).isInstanceOf (MockCookie .class );
428
+ MockCookie mockCookie = (MockCookie ) response .getCookies ()[0 ];
429
+ assertThat (mockCookie .getMaxAge ()).isEqualTo (100 );
430
+ assertThat (mockCookie .getExpires ()).isEqualTo (ZonedDateTime .parse (expiryDate , DateTimeFormatter .RFC_1123_DATE_TIME ));
424
431
}
425
432
426
433
/**
@@ -454,18 +461,24 @@ void addCookieHeader() {
454
461
* @since 5.1.11
455
462
*/
456
463
@ Test
457
- void addCookieHeaderWithExpiresAttribute () {
458
- String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires= Tue, 8 Oct 2019 19:50:00 GMT; Secure; " +
459
- " HttpOnly; SameSite=Lax" ;
464
+ void addCookieHeaderWithMaxAgeAndExpiresAttributes () {
465
+ String expiryDate = "Tue, 8 Oct 2019 19:50:00 GMT" ;
466
+ String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=" + expiryDate + "; Secure; HttpOnly; SameSite=Lax" ;
460
467
response .addHeader (SET_COOKIE , cookieValue );
461
468
assertThat (response .getHeader (SET_COOKIE )).isEqualTo (cookieValue );
469
+
470
+ assertNumCookies (1 );
471
+ assertThat (response .getCookies ()[0 ]).isInstanceOf (MockCookie .class );
472
+ MockCookie mockCookie = (MockCookie ) response .getCookies ()[0 ];
473
+ assertThat (mockCookie .getMaxAge ()).isEqualTo (100 );
474
+ assertThat (mockCookie .getExpires ()).isEqualTo (ZonedDateTime .parse (expiryDate , DateTimeFormatter .RFC_1123_DATE_TIME ));
462
475
}
463
476
464
477
/**
465
478
* @since 5.1.12
466
479
*/
467
480
@ Test
468
- void addCookieHeaderWithZeroExpiresAttribute () {
481
+ void addCookieHeaderWithMaxAgeAndZeroExpiresAttributes () {
469
482
String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=0" ;
470
483
response .addHeader (SET_COOKIE , cookieValue );
471
484
assertNumCookies (1 );
@@ -476,14 +489,24 @@ void addCookieHeaderWithZeroExpiresAttribute() {
476
489
}
477
490
478
491
/**
479
- * @since 5.1.12
492
+ * @since 5.2.14
480
493
*/
481
494
@ Test
482
- void addCookieHeaderWithOnlyExpiresAttribute () {
483
- String cookieValue = "SESSION=123; Path=/; Expires=Tue, 8 Oct 2019 19:50:00 GMT" ;
495
+ void addCookieHeaderWithExpiresAttributeWithoutMaxAgeAttribute () {
496
+ String expiryDate = "Tue, 8 Oct 2019 19:50:00 GMT" ;
497
+ String cookieValue = "SESSION=123; Path=/; Expires=" + expiryDate ;
484
498
response .addHeader (SET_COOKIE , cookieValue );
485
- assertNumCookies ( 1 );
499
+ System . err . println ( response . getCookie ( "SESSION" ) );
486
500
assertThat (response .getHeader (SET_COOKIE )).isEqualTo (cookieValue );
501
+
502
+ assertNumCookies (1 );
503
+ assertThat (response .getCookies ()[0 ]).isInstanceOf (MockCookie .class );
504
+ MockCookie mockCookie = (MockCookie ) response .getCookies ()[0 ];
505
+ assertThat (mockCookie .getName ()).isEqualTo ("SESSION" );
506
+ assertThat (mockCookie .getValue ()).isEqualTo ("123" );
507
+ assertThat (mockCookie .getPath ()).isEqualTo ("/" );
508
+ assertThat (mockCookie .getMaxAge ()).isEqualTo (-1 );
509
+ assertThat (mockCookie .getExpires ()).isEqualTo (ZonedDateTime .parse (expiryDate , DateTimeFormatter .RFC_1123_DATE_TIME ));
487
510
}
488
511
489
512
@ Test
0 commit comments