use of ee.ria.xroad.proxy.conf.KeyConfProvider in project X-Road by nordic-institute.
the class HealthChecksTest method createMockProviderWithOcspStatus.
private static KeyConfProvider createMockProviderWithOcspStatus(int status) throws Exception {
X509Certificate mockCertificate = mock(X509Certificate.class);
when(mockCertificate.getSubjectX500Principal()).thenReturn(new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"));
CertChain mockCertChain = mock(CertChain.class);
when(mockCertChain.getEndEntityCert()).thenReturn(mockCertificate);
AuthKey authKey = new AuthKey(mockCertChain, null);
KeyConfProvider mockKeyConfProvider = mock(KeyConfProvider.class);
when(mockKeyConfProvider.getAuthKey()).thenReturn(authKey);
OCSPResp mockResponse = mock(OCSPResp.class);
when(mockResponse.getStatus()).thenReturn(status);
when(mockKeyConfProvider.getOcspResponse((X509Certificate) notNull())).thenReturn(mockResponse);
return mockKeyConfProvider;
}
use of ee.ria.xroad.proxy.conf.KeyConfProvider in project X-Road by nordic-institute.
the class HealthChecksTest method checkAuthKeyOcspStatusShouldFailWhenEndEntityCertNotAvailable.
@Test
public void checkAuthKeyOcspStatusShouldFailWhenEndEntityCertNotAvailable() {
// prepare
CertChain mockCertChain = mock(CertChain.class);
when(mockCertChain.getEndEntityCert()).thenReturn(null);
AuthKey authKey = new AuthKey(mockCertChain, null);
KeyConfProvider mockKeyConfProvider = mock(KeyConfProvider.class);
when(mockKeyConfProvider.getAuthKey()).thenReturn(authKey);
KeyConf.reload(mockKeyConfProvider);
// execute
HealthCheckProvider testedProvider = HealthChecks.checkAuthKeyOcspStatus();
HealthCheckResult checkedResult = testedProvider.get();
// verify
assertTrue("health check result should be a failure", !checkedResult.isOk());
assertThat(checkedResult.getErrorMessage(), containsString("No end entity certificate available"));
}
use of ee.ria.xroad.proxy.conf.KeyConfProvider in project X-Road by nordic-institute.
the class HealthChecksTest method checkAuthKeyOcspStatusShouldFailWhenAuthKeyNotAvailable.
@Test
public void checkAuthKeyOcspStatusShouldFailWhenAuthKeyNotAvailable() {
// prepare
KeyConfProvider mockKeyConfProvider = mock(KeyConfProvider.class);
when(mockKeyConfProvider.getAuthKey()).thenReturn(null);
KeyConf.reload(mockKeyConfProvider);
// execute
HealthCheckProvider testedProvider = HealthChecks.checkAuthKeyOcspStatus();
HealthCheckResult checkedResult = testedProvider.get();
// verify
assertTrue("health check result should be a failure", !checkedResult.isOk());
assertThat(checkedResult.getErrorMessage(), containsString("No authentication key available"));
}
use of ee.ria.xroad.proxy.conf.KeyConfProvider in project X-Road by nordic-institute.
the class HealthChecksTest method checkAuthKeyOcspStatusShouldFailWhenCertChainNotAvailable.
@Test
public void checkAuthKeyOcspStatusShouldFailWhenCertChainNotAvailable() {
// prepare
AuthKey authKey = new AuthKey(null, null);
KeyConfProvider mockKeyConfProvider = mock(KeyConfProvider.class);
when(mockKeyConfProvider.getAuthKey()).thenReturn(authKey);
KeyConf.reload(mockKeyConfProvider);
// execute
HealthCheckProvider testedProvider = HealthChecks.checkAuthKeyOcspStatus();
HealthCheckResult checkedResult = testedProvider.get();
// verify
assertTrue("health check result should be a failure", !checkedResult.isOk());
assertThat(checkedResult.getErrorMessage(), containsString("No certificate chain available"));
}
use of ee.ria.xroad.proxy.conf.KeyConfProvider in project X-Road by nordic-institute.
the class HealthChecksTest method checkAuthKeyOcspStatusShouldBeOkWhenOcspStatusIsGood.
@Test
public void checkAuthKeyOcspStatusShouldBeOkWhenOcspStatusIsGood() throws Exception {
// prepare
KeyConfProvider mockKeyConfProvider = createMockProviderWithOcspStatus(OCSPResp.SUCCESSFUL);
KeyConf.reload(mockKeyConfProvider);
// execute
HealthCheckProvider testedProvider = HealthChecks.checkAuthKeyOcspStatus();
HealthCheckResult checkedResult = testedProvider.get();
// verify
assertTrue("health check should pass", checkedResult.isOk());
}
Aggregations