@@ -88,13 +88,15 @@ public class OpenIdConnectAuthenticatorTests extends OpenIdConnectTestCase {
88
88
private Settings globalSettings ;
89
89
private Environment env ;
90
90
private ThreadContext threadContext ;
91
+ private int callsToReloadJwk ;
91
92
92
93
@ Before
93
94
public void setup () {
94
95
globalSettings = Settings .builder ().put ("path.home" , createTempDir ())
95
96
.put ("xpack.security.authc.realms.oidc.oidc-realm.ssl.verification_mode" , "certificate" ).build ();
96
97
env = TestEnvironment .newEnvironment (globalSettings );
97
98
threadContext = new ThreadContext (globalSettings );
99
+ callsToReloadJwk = 0 ;
98
100
}
99
101
100
102
@ After
@@ -278,6 +280,7 @@ public void testClockSkewIsHonored() throws Exception {
278
280
authenticator .authenticate (token , future );
279
281
JWTClaimsSet claimsSet = future .actionGet ();
280
282
assertThat (claimsSet .getSubject (), equalTo (subject ));
283
+ assertThat (callsToReloadJwk , equalTo (0 ));
281
284
}
282
285
283
286
public void testImplicitFlowFailsWithExpiredToken () throws Exception {
@@ -317,6 +320,7 @@ public void testImplicitFlowFailsWithExpiredToken() throws Exception {
317
320
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
318
321
assertThat (e .getCause (), instanceOf (BadJWTException .class ));
319
322
assertThat (e .getCause ().getMessage (), containsString ("Expired JWT" ));
323
+ assertThat (callsToReloadJwk , equalTo (0 ));
320
324
}
321
325
322
326
public void testImplicitFlowFailsNotYetIssuedToken () throws Exception {
@@ -356,6 +360,7 @@ public void testImplicitFlowFailsNotYetIssuedToken() throws Exception {
356
360
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
357
361
assertThat (e .getCause (), instanceOf (BadJWTException .class ));
358
362
assertThat (e .getCause ().getMessage (), containsString ("JWT issue time ahead of current time" ));
363
+ assertThat (callsToReloadJwk , equalTo (0 ));
359
364
}
360
365
361
366
public void testImplicitFlowFailsInvalidIssuer () throws Exception {
@@ -394,6 +399,7 @@ public void testImplicitFlowFailsInvalidIssuer() throws Exception {
394
399
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
395
400
assertThat (e .getCause (), instanceOf (BadJWTException .class ));
396
401
assertThat (e .getCause ().getMessage (), containsString ("Unexpected JWT issuer" ));
402
+ assertThat (callsToReloadJwk , equalTo (0 ));
397
403
}
398
404
399
405
public void testImplicitFlowFailsInvalidAudience () throws Exception {
@@ -432,6 +438,7 @@ public void testImplicitFlowFailsInvalidAudience() throws Exception {
432
438
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
433
439
assertThat (e .getCause (), instanceOf (BadJWTException .class ));
434
440
assertThat (e .getCause ().getMessage (), containsString ("Unexpected JWT audience" ));
441
+ assertThat (callsToReloadJwk , equalTo (0 ));
435
442
}
436
443
437
444
public void testAuthenticateImplicitFlowFailsWithForgedRsaIdToken () throws Exception {
@@ -456,6 +463,7 @@ public void testAuthenticateImplicitFlowFailsWithForgedRsaIdToken() throws Excep
456
463
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
457
464
assertThat (e .getCause (), instanceOf (BadJWSException .class ));
458
465
assertThat (e .getCause ().getMessage (), containsString ("Signed JWT rejected: Invalid signature" ));
466
+ assertThat (callsToReloadJwk , equalTo (1 ));
459
467
}
460
468
461
469
public void testAuthenticateImplicitFlowFailsWithForgedEcsdsaIdToken () throws Exception {
@@ -480,6 +488,7 @@ public void testAuthenticateImplicitFlowFailsWithForgedEcsdsaIdToken() throws Ex
480
488
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
481
489
assertThat (e .getCause (), instanceOf (BadJWSException .class ));
482
490
assertThat (e .getCause ().getMessage (), containsString ("Signed JWT rejected: Invalid signature" ));
491
+ assertThat (callsToReloadJwk , equalTo (1 ));
483
492
}
484
493
485
494
public void testAuthenticateImplicitFlowFailsWithForgedHmacIdToken () throws Exception {
@@ -503,6 +512,7 @@ public void testAuthenticateImplicitFlowFailsWithForgedHmacIdToken() throws Exce
503
512
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
504
513
assertThat (e .getCause (), instanceOf (BadJWSException .class ));
505
514
assertThat (e .getCause ().getMessage (), containsString ("Signed JWT rejected: Invalid signature" ));
515
+ assertThat (callsToReloadJwk , equalTo (0 ));
506
516
}
507
517
508
518
public void testAuthenticateImplicitFlowFailsWithForgedAccessToken () throws Exception {
@@ -532,6 +542,7 @@ public void testAuthenticateImplicitFlowFailsWithForgedAccessToken() throws Exce
532
542
assertThat (e .getMessage (), containsString ("Failed to verify access token" ));
533
543
assertThat (e .getCause (), instanceOf (InvalidHashException .class ));
534
544
assertThat (e .getCause ().getMessage (), containsString ("Access token hash (at_hash) mismatch" ));
545
+ assertThat (callsToReloadJwk , equalTo (0 ));
535
546
}
536
547
537
548
public void testImplicitFlowFailsWithNoneAlgorithm () throws Exception {
@@ -569,6 +580,7 @@ public void testImplicitFlowFailsWithNoneAlgorithm() throws Exception {
569
580
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
570
581
assertThat (e .getCause (), instanceOf (BadJOSEException .class ));
571
582
assertThat (e .getCause ().getMessage (), containsString ("Another algorithm expected, or no matching key(s) found" ));
583
+ assertThat (callsToReloadJwk , equalTo (0 ));
572
584
}
573
585
574
586
/**
@@ -599,6 +611,7 @@ public void testImplicitFlowFailsWithAlgorithmMixupAttack() throws Exception {
599
611
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
600
612
assertThat (e .getCause (), instanceOf (BadJOSEException .class ));
601
613
assertThat (e .getCause ().getMessage (), containsString ("Another algorithm expected, or no matching key(s) found" ));
614
+ assertThat (callsToReloadJwk , equalTo (0 ));
602
615
}
603
616
604
617
public void testImplicitFlowFailsWithUnsignedJwt () throws Exception {
@@ -635,6 +648,7 @@ public void testImplicitFlowFailsWithUnsignedJwt() throws Exception {
635
648
assertThat (e .getMessage (), containsString ("Failed to parse or validate the ID Token" ));
636
649
assertThat (e .getCause (), instanceOf (BadJWTException .class ));
637
650
assertThat (e .getCause ().getMessage (), containsString ("Signed ID token expected" ));
651
+ assertThat (callsToReloadJwk , equalTo (0 ));
638
652
}
639
653
640
654
public void testJsonObjectMerging () throws Exception {
@@ -832,6 +846,7 @@ private OpenIdConnectAuthenticator.ReloadableJWKSource mockSource(JWK jwk) {
832
846
Mockito .doAnswer (invocation -> {
833
847
@ SuppressWarnings ("unchecked" )
834
848
ActionListener <Void > listener = (ActionListener <Void >) invocation .getArguments ()[0 ];
849
+ callsToReloadJwk += 1 ;
835
850
listener .onResponse (null );
836
851
return null ;
837
852
}).when (jwkSource ).triggerReload (any (ActionListener .class ));
0 commit comments