use of com.yahoo.athenz.auth.oauth.token.OAuthJwtAccessToken in project athenz by yahoo.
the class OAuthJwtAccessTokenValidatorTest method testValidateCertificateBinding.
@Test
public void testValidateCertificateBinding() throws Exception {
final OAuthJwtAccessTokenValidator mock = Mockito.mock(OAuthJwtAccessTokenValidator.class, Mockito.CALLS_REAL_METHODS);
// on CertificateEncodingException
Mockito.doThrow(new CertificateEncodingException()).when(mock).getX509CertificateThumbprint(null);
assertThrows(OAuthJwtAccessTokenException.class, () -> mock.validateCertificateBinding(null, (X509Certificate) null));
// on CryptoException
Mockito.doThrow(new CryptoException()).when(mock).getX509CertificateThumbprint(null);
assertThrows(OAuthJwtAccessTokenException.class, () -> mock.validateCertificateBinding(null, (X509Certificate) null));
// actual call
OAuthJwtAccessTokenValidator validator = Mockito.mock(OAuthJwtAccessTokenValidator.class, Mockito.CALLS_REAL_METHODS);
X509Certificate cert = this.readCert("jwt_ui.athenz.io.pem");
Mockito.doReturn("zlkxyoX95le-Nv7OI0BxcjTOogvy9PGH-v_CBr_DsEk").when(validator).getX509CertificateThumbprint(cert);
ArgumentCaptor<OAuthJwtAccessToken> tokenArg = ArgumentCaptor.forClass(OAuthJwtAccessToken.class);
ArgumentCaptor<String> thumbprintArg = ArgumentCaptor.forClass(String.class);
validator.validateCertificateBinding(null, cert);
Mockito.verify(validator, Mockito.times(1)).validateCertificateBinding(tokenArg.capture(), thumbprintArg.capture());
assertNull(tokenArg.getValue());
assertEquals(thumbprintArg.getValue(), "zlkxyoX95le-Nv7OI0BxcjTOogvy9PGH-v_CBr_DsEk");
}
Aggregations