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);
}
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);
}
Aggregations