use of com.yahoo.athenz.auth.oauth.token.DefaultOAuthJwtAccessToken in project athenz by yahoo.
the class DefaultOAuthJwtAccessTokenParserTest method testParse.
@Test
@SuppressWarnings("rawtypes")
public void testParse() throws Exception {
// mock internal parser
DefaultOAuthJwtAccessTokenParser parser = new DefaultOAuthJwtAccessTokenParser(baseKeyStore, this.classLoader.getResource("jwt_jwks.json").toString());
JwtParser jwtParserMock = Mockito.mock(JwtParser.class);
Field f = parser.getClass().getDeclaredField("parser");
f.setAccessible(true);
f.set(parser, jwtParserMock);
// parse error
Mockito.when(jwtParserMock.parseClaimsJws(null)).thenThrow(new NullPointerException());
assertThrows(OAuthJwtAccessTokenException.class, () -> parser.parse(null));
// parse success
String jwtString = "dummy-jwt-string";
Jws<Claims> jws = new Jws<Claims>() {
public JwsHeader getHeader() {
return null;
}
public Claims getBody() {
return null;
}
@Override
public String getSignature() {
return "dummy-jwt-signature";
}
};
Mockito.when(jwtParserMock.parseClaimsJws(jwtString)).thenReturn(jws);
OAuthJwtAccessToken token = parser.parse(jwtString);
assertNotNull(token);
assertTrue(token instanceof DefaultOAuthJwtAccessToken);
assertEquals(token.getSignature(), "dummy-jwt-signature");
}
use of com.yahoo.athenz.auth.oauth.token.DefaultOAuthJwtAccessToken in project athenz by yahoo.
the class DefaultOAuthJwtAccessTokenParser method parse.
@Override
public OAuthJwtAccessToken parse(String jwtString) throws OAuthJwtAccessTokenException {
OAuthJwtAccessToken accessToken = null;
try {
Jws<Claims> jws = this.parser.parseClaimsJws(jwtString);
accessToken = new DefaultOAuthJwtAccessToken(jws);
} catch (Exception ex) {
throw new OAuthJwtAccessTokenException(ex);
}
return accessToken;
}
Aggregations