Search in sources :

Example 6 with HttpsJwks

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();
    }
}
Also used : HttpsJwks(org.jose4j.jwk.HttpsJwks) MockTime(org.apache.kafka.common.utils.MockTime) Time(org.apache.kafka.common.utils.Time) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Example 7 with HttpsJwks

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));
    }
}
Also used : HttpsJwks(org.jose4j.jwk.HttpsJwks) MockTime(org.apache.kafka.common.utils.MockTime) Time(org.apache.kafka.common.utils.Time) Test(org.junit.jupiter.api.Test)

Aggregations

HttpsJwks (org.jose4j.jwk.HttpsJwks)7 MockTime (org.apache.kafka.common.utils.MockTime)5 Time (org.apache.kafka.common.utils.Time)5 Test (org.junit.jupiter.api.Test)4 URL (java.net.URL)1 Path (java.nio.file.Path)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1 SASL_OAUTHBEARER_JWKS_ENDPOINT_URL (org.apache.kafka.common.config.SaslConfigs.SASL_OAUTHBEARER_JWKS_ENDPOINT_URL)1 Get (org.jose4j.http.Get)1 SimpleResponse (org.jose4j.http.SimpleResponse)1