@@ -478,19 +478,30 @@ public void shouldThrowOnNegativeNotBeforeLeeway() throws Exception {
478478 .acceptNotBefore (-1 );
479479 }
480480
481- // Issued At
481+ // Issued At with future date
482+ @ Test (expected = InvalidClaimException .class )
483+ public void shouldThrowOnFutureIssuedAt () throws Exception {
484+ Clock clock = mock (Clock .class );
485+ when (clock .getToday ()).thenReturn (new Date (DATE_TOKEN_MS_VALUE - 1000 ));
486+
487+ String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE0Nzc1OTJ9.CWq-6pUXl1bFg81vqOUZbZrheO2kUBd2Xr3FUZmvudE" ;
488+ JWTVerifier .BaseVerification verification = (JWTVerifier .BaseVerification ) JWTVerifier .init (Algorithm .HMAC256 ("secret" ));
489+
490+ DecodedJWT jwt = verification .build (clock ).verify (token );
491+ assertThat (jwt , is (notNullValue ()));
492+ }
493+
494+ // Issued At with future date and ignore flag
482495 @ Test
483- public void shouldValidateIssuedAtWithLeeway () throws Exception {
496+ public void shouldSkipIssuedAtVerificationWhenFlagIsPassed () throws Exception {
484497 Clock clock = mock (Clock .class );
485498 when (clock .getToday ()).thenReturn (new Date (DATE_TOKEN_MS_VALUE - 1000 ));
486499
487- String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0Nzc1OTJ9.0WJky9eLN7kuxLyZlmbcXRL3Wy8hLoNCEk5CCl2M4lo" ;
488- JWTVerifier .BaseVerification verification = (JWTVerifier .BaseVerification ) JWTVerifier .init (Algorithm .HMAC256 ("secret" ))
489- .acceptIssuedAt (2 );
490- DecodedJWT jwt = verification
491- .build (clock )
492- .verify (token );
500+ String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE0Nzc1OTJ9.CWq-6pUXl1bFg81vqOUZbZrheO2kUBd2Xr3FUZmvudE" ;
501+ JWTVerifier .BaseVerification verification = (JWTVerifier .BaseVerification ) JWTVerifier .init (Algorithm .HMAC256 ("secret" ));
502+ verification .ignoreIssuedAt ();
493503
504+ DecodedJWT jwt = verification .build (clock ).verify (token );
494505 assertThat (jwt , is (notNullValue ()));
495506 }
496507
@@ -508,6 +519,20 @@ public void shouldThrowOnInvalidIssuedAtIfPresent() throws Exception {
508519 .verify (token );
509520 }
510521
522+ @ Test
523+ public void shouldOverrideAcceptIssuedAtWhenIgnoreIssuedAtFlagPassedAndSkipTheVerification () throws Exception {
524+ Clock clock = mock (Clock .class );
525+ when (clock .getToday ()).thenReturn (new Date (DATE_TOKEN_MS_VALUE - 1000 ));
526+
527+ String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0Nzc1OTJ9.0WJky9eLN7kuxLyZlmbcXRL3Wy8hLoNCEk5CCl2M4lo" ;
528+ JWTVerifier .BaseVerification verification = (JWTVerifier .BaseVerification ) JWTVerifier .init (Algorithm .HMAC256 ("secret" ));
529+ DecodedJWT jwt = verification .acceptIssuedAt (20 ).ignoreIssuedAt ()
530+ .build ()
531+ .verify (token );
532+
533+ assertThat (jwt , is (notNullValue ()));
534+ }
535+
511536 @ Test
512537 public void shouldValidateIssuedAtIfPresent () throws Exception {
513538 Clock clock = mock (Clock .class );
0 commit comments