@@ -92,10 +92,15 @@ void creates_derived_jwt_for_delegation_token() {
92
92
@ Test
93
93
void creates_derived_jwt_for_oidc_user () {
94
94
var issuer = new SignedJwtIssuer (CLAIMS_SIGNER , JwtClaimsResolver .empty ());
95
+
96
+ var iat = Instant .now ().minus (3 , ChronoUnit .MINUTES );
97
+ var exp = Instant .now ().plus (1 , ChronoUnit .MINUTES );
95
98
var oidcUser = new DefaultOidcUser (
96
99
List .of (),
97
100
OidcIdToken .withTokenValue ("XXX" )
98
101
.subject ("my-user" )
102
+ .issuedAt (iat )
103
+ .expiresAt (exp )
99
104
.build ()
100
105
);
101
106
@@ -110,8 +115,8 @@ void creates_derived_jwt_for_oidc_user() {
110
115
assertThat (issuer .issueSubstitutionToken (exchange ).block ()).isInstanceOfSatisfying (Jwt .class , token -> {
111
116
assertThat (token .getIssuer ()).hasToString ("https://upstream-issuer.example" );
112
117
assertThat (token .getSubject ()).isEqualTo ("my-user" );
113
- assertThat (token .getIssuedAt ()).isBeforeOrEqualTo ( Instant . now ( ));
114
- assertThat (token .getExpiresAt ()).isBetween ( Instant . now (). plus ( 4 , ChronoUnit . MINUTES ), Instant . now (). plus ( 5 , ChronoUnit .MINUTES ));
118
+ assertThat (token .getIssuedAt ()).isCloseTo ( iat , within ( 1 , ChronoUnit . SECONDS ));
119
+ assertThat (token .getExpiresAt ()).isCloseTo ( exp , within ( 1 , ChronoUnit .SECONDS ));
115
120
assertThat (token .getTokenValue ()).satisfies (verifyJwtSignedBy (issuer ));
116
121
});
117
122
}
@@ -179,6 +184,33 @@ void new_jwt_with_expiry_shorter_than_max() {
179
184
});
180
185
}
181
186
187
+ @ Test
188
+ void derived_jwt_for_just_expired_jwt () {
189
+ var issuer = new SignedJwtIssuer (CLAIMS_SIGNER , JwtClaimsResolver .empty ());
190
+
191
+ var iat = Instant .now ().minus (5 , ChronoUnit .MINUTES );
192
+ var expiry = Instant .now ().minus (10 , ChronoUnit .SECONDS );
193
+
194
+ var exchange = createExchange (
195
+ new JwtAuthenticationToken (Jwt .withTokenValue ("XXXX" )
196
+ .header ("alg" , "RS256" )
197
+ .issuedAt (iat )
198
+ .expiresAt (expiry )
199
+ .build (),
200
+ List .of (new PrincipalAuthenticationDetailsGrantedAuthority (new Actor (
201
+ ActorType .USER ,
202
+ () -> Map .of ("iss" , "https://upstream-issuer.example" , "sub" , "my-user" ),
203
+ null
204
+ )))
205
+ )
206
+ );
207
+
208
+ assertThat (issuer .issueSubstitutionToken (exchange ).block ()).isInstanceOfSatisfying (Jwt .class , token -> {
209
+ assertThat (token .getIssuedAt ()).isCloseTo (iat , within (1 , ChronoUnit .SECONDS ));
210
+ assertThat (token .getExpiresAt ()).isCloseTo (expiry , within (1 , ChronoUnit .SECONDS ));
211
+ });
212
+ }
213
+
182
214
static ServerWebExchange createExchange (Authentication authentication ) {
183
215
var request = MockServerHttpRequest .get ("/" ).build ();
184
216
var securityContext = new SecurityContextImpl (authentication );
0 commit comments