Search in sources :

Example 1 with JWK

use of io.gravitee.am.model.jose.JWK in project gravitee-access-management by gravitee-io.

the class JWKServiceTest method testFilter_AES_256_keys.

@Test
public void testFilter_AES_256_keys() {
    TestObserver testObserver = jwkService.filter(JWK_SET, JWKFilter.OCT_KEY_ENCRYPTION(JWEAlgorithm.A256KW)).test();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertValue(jwk -> ((JWK) jwk).getKid().equals("octEnc256"));
    testObserver = jwkService.filter(JWK_SET, JWKFilter.OCT_KEY_ENCRYPTION(JWEAlgorithm.A256GCMKW)).test();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertValue(jwk -> ((JWK) jwk).getKid().equals("octEnc256"));
}
Also used : TestObserver(io.reactivex.observers.TestObserver) JWK(io.gravitee.am.model.jose.JWK) Test(org.junit.Test)

Example 2 with JWK

use of io.gravitee.am.model.jose.JWK in project gravitee-access-management by gravitee-io.

the class JWKServiceTest method testFilter_OKP.

@Test
public void testFilter_OKP() {
    OKPKey okpEnc = new OKPKey();
    okpEnc.setKty("OKP");
    okpEnc.setKid("okpEnc");
    okpEnc.setCrv("X25519");
    OKPKey okpSig = new OKPKey();
    okpSig.setKty("OKP");
    okpSig.setKid("okpSig");
    okpSig.setCrv("Ed25519");
    JWKSet okpSet = new JWKSet();
    okpSet.setKeys(Arrays.asList(okpEnc, okpSig));
    TestObserver testObserver = jwkService.filter(okpSet, JWKFilter.CURVE_KEY_ENCRYPTION()).test();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertValue(jwk -> ((JWK) jwk).getKid().equals("okpEnc"));
}
Also used : JWKSet(io.gravitee.am.model.oidc.JWKSet) OKPKey(io.gravitee.am.model.jose.OKPKey) TestObserver(io.reactivex.observers.TestObserver) JWK(io.gravitee.am.model.jose.JWK) Test(org.junit.Test)

Example 3 with JWK

use of io.gravitee.am.model.jose.JWK in project gravitee-access-management by gravitee-io.

the class JWKServiceTest method testGetKey_noKFound.

@Test
public void testGetKey_noKFound() {
    JWK jwk = Mockito.mock(JWK.class);
    JWKSet jwkSet = new JWKSet();
    jwkSet.setKeys(Arrays.asList(jwk));
    when(jwk.getKid()).thenReturn("notTheExpectedOne");
    TestObserver testObserver = jwkService.getKey(jwkSet, "expectedKid").test();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    // Expect empty result
    testObserver.assertResult();
}
Also used : JWKSet(io.gravitee.am.model.oidc.JWKSet) TestObserver(io.reactivex.observers.TestObserver) JWK(io.gravitee.am.model.jose.JWK) Test(org.junit.Test)

Example 4 with JWK

use of io.gravitee.am.model.jose.JWK in project gravitee-access-management by gravitee-io.

the class ProviderJWKSetEndpointHandlerTest method shouldInvokeJWKSetEndpoint.

@Test
public void shouldInvokeJWKSetEndpoint() throws Exception {
    JWK jwk = new RSAKey();
    jwk.setKty("RSA");
    jwk.setKid("my-test-key");
    JWKSet jwkSet = new JWKSet();
    jwkSet.setKeys(Collections.singletonList(jwk));
    when(jwkService.getKeys()).thenReturn(Single.just(jwkSet));
    testRequest(HttpMethod.GET, "/.well-known/jwks.json", HttpStatusCode.OK_200, "OK", "{\n" + "  \"keys\" : [ {\n" + "    \"kty\" : \"RSA\",\n" + "    \"kid\" : \"my-test-key\"\n" + "  } ]\n" + "}");
}
Also used : RSAKey(io.gravitee.am.model.jose.RSAKey) JWKSet(io.gravitee.am.model.oidc.JWKSet) JWK(io.gravitee.am.model.jose.JWK) Test(org.junit.Test)

Example 5 with JWK

use of io.gravitee.am.model.jose.JWK in project gravitee-access-management by gravitee-io.

the class JWKServiceTest method testFilter_EC.

@Test
public void testFilter_EC() {
    TestObserver testObserver = jwkService.filter(JWK_SET, JWKFilter.CURVE_KEY_ENCRYPTION()).test();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertValue(jwk -> ((JWK) jwk).getKid().equals("ecEnc"));
}
Also used : TestObserver(io.reactivex.observers.TestObserver) JWK(io.gravitee.am.model.jose.JWK) Test(org.junit.Test)

Aggregations

JWK (io.gravitee.am.model.jose.JWK)22 Test (org.junit.Test)15 TestObserver (io.reactivex.observers.TestObserver)12 JWKSet (io.gravitee.am.model.oidc.JWKSet)7 Key (java.security.Key)6 CertificateMetadata (io.gravitee.am.certificate.api.CertificateMetadata)5 DefaultKey (io.gravitee.am.certificate.api.DefaultKey)5 Date (java.util.Date)5 SignatureAlgorithm (io.gravitee.am.common.jwt.SignatureAlgorithm)3 RSAKey (io.gravitee.am.model.jose.RSAKey)3 JWKSet (com.nimbusds.jose.jwk.JWKSet)2 KeyUse (com.nimbusds.jose.jwk.KeyUse)2 CertificateProvider (io.gravitee.am.gateway.certificate.CertificateProvider)2 Flowable (io.reactivex.Flowable)2 Single (io.reactivex.Single)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 KeyPair (java.security.KeyPair)2 KeyStore (java.security.KeyStore)2 PrivateKey (java.security.PrivateKey)2