use of org.jose4j.jwk.HttpsJwks in project kafka by apache.
the class RefreshingHttpsJwksTest method testBasicScheduleRefresh.
/**
* Test that a key not previously scheduled for refresh will be scheduled without a refresh.
*/
@Test
public void testBasicScheduleRefresh() throws Exception {
String keyId = "abc123";
Time time = new MockTime();
HttpsJwks httpsJwks = spyHttpsJwks();
try (RefreshingHttpsJwks refreshingHttpsJwks = getRefreshingHttpsJwks(time, httpsJwks)) {
refreshingHttpsJwks.init();
verify(httpsJwks, times(1)).refresh();
assertTrue(refreshingHttpsJwks.maybeExpediteRefresh(keyId));
verify(httpsJwks, times(1)).refresh();
}
}
use of org.jose4j.jwk.HttpsJwks in project kafka by apache.
the class RefreshingHttpsJwksTest method testSecondaryRefreshAfterElapsedDelay.
/**
* Test that if we ask to load a missing key, and then we wait past the sleep time that it will
* call refresh to load the key.
*/
@Test
public void testSecondaryRefreshAfterElapsedDelay() throws Exception {
String keyId = "abc123";
// Unfortunately, we can't mock time here because the
Time time = MockTime.SYSTEM;
// scheduled executor doesn't respect it.
HttpsJwks httpsJwks = spyHttpsJwks();
try (RefreshingHttpsJwks refreshingHttpsJwks = getRefreshingHttpsJwks(time, httpsJwks)) {
refreshingHttpsJwks.init();
verify(httpsJwks, times(1)).refresh();
assertTrue(refreshingHttpsJwks.maybeExpediteRefresh(keyId));
time.sleep(REFRESH_MS + 1);
verify(httpsJwks, times(3)).refresh();
assertFalse(refreshingHttpsJwks.maybeExpediteRefresh(keyId));
}
}
Aggregations