Search in sources :

Example 1 with MockJwtsSigningKeyResolver

use of com.yahoo.athenz.auth.token.jwts.MockJwtsSigningKeyResolver in project athenz by yahoo.

the class AccessTokenTest method testAccessTokenSignedTokenServerKeys.

@Test
public void testAccessTokenSignedTokenServerKeys() {
    long now = System.currentTimeMillis() / 1000;
    AccessToken accessToken = createAccessToken(now);
    // now get the signed token
    PrivateKey privateKey = Crypto.loadPrivateKey(ecPrivateKey);
    String accessJws = accessToken.getSignedToken(privateKey, "eckey1", SignatureAlgorithm.ES256);
    assertNotNull(accessJws);
    // now verify our signed token
    final String oldConf = System.setProperty(JwtsSigningKeyResolver.ZTS_PROP_ATHENZ_CONF, "src/test/resources/athenz-no-keys.conf");
    MockJwtsSigningKeyResolver.setResponseBody(JWT_KEYS);
    MockJwtsSigningKeyResolver resolver = new MockJwtsSigningKeyResolver("https://localhost:4443", null);
    AccessToken checkToken = new AccessToken(accessJws, resolver);
    validateAccessToken(checkToken, now);
    resetConfProperty(oldConf);
}
Also used : PrivateKey(java.security.PrivateKey) MockJwtsSigningKeyResolver(com.yahoo.athenz.auth.token.jwts.MockJwtsSigningKeyResolver) Test(org.testng.annotations.Test)

Example 2 with MockJwtsSigningKeyResolver

use of com.yahoo.athenz.auth.token.jwts.MockJwtsSigningKeyResolver in project athenz by yahoo.

the class AccessTokenTest method testAccessTokenSignedTokenServerKeysFailure.

@Test
public void testAccessTokenSignedTokenServerKeysFailure() {
    long now = System.currentTimeMillis() / 1000;
    AccessToken accessToken = createAccessToken(now);
    // now get the signed token
    PrivateKey privateKey = Crypto.loadPrivateKey(ecPrivateKey);
    String accessJws = accessToken.getSignedToken(privateKey, "eckey1", SignatureAlgorithm.ES256);
    assertNotNull(accessJws);
    // now verify our signed token
    final String oldConf = System.setProperty(JwtsSigningKeyResolver.ZTS_PROP_ATHENZ_CONF, "src/test/resources/athenz-no-keys.conf");
    MockJwtsSigningKeyResolver.setResponseBody("");
    SSLContext sslContext = Mockito.mock(SSLContext.class);
    MockJwtsSigningKeyResolver resolver = new MockJwtsSigningKeyResolver("https://localhost:4443", sslContext);
    try {
        new AccessToken(accessJws, resolver);
        fail();
    } catch (Exception ex) {
        assertTrue(ex instanceof IllegalArgumentException, ex.getMessage());
    }
    resetConfProperty(oldConf);
}
Also used : PrivateKey(java.security.PrivateKey) SSLContext(javax.net.ssl.SSLContext) MockJwtsSigningKeyResolver(com.yahoo.athenz.auth.token.jwts.MockJwtsSigningKeyResolver) IOException(java.io.IOException) CryptoException(com.yahoo.athenz.auth.util.CryptoException) CertificateEncodingException(java.security.cert.CertificateEncodingException) Test(org.testng.annotations.Test)

Aggregations

MockJwtsSigningKeyResolver (com.yahoo.athenz.auth.token.jwts.MockJwtsSigningKeyResolver)2 PrivateKey (java.security.PrivateKey)2 Test (org.testng.annotations.Test)2 CryptoException (com.yahoo.athenz.auth.util.CryptoException)1 IOException (java.io.IOException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 SSLContext (javax.net.ssl.SSLContext)1