Search in sources :

Example 1 with KeyConfProvider

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;
}
Also used : CertChain(ee.ria.xroad.common.cert.CertChain) AuthKey(ee.ria.xroad.common.conf.globalconf.AuthKey) X500Principal(javax.security.auth.x500.X500Principal) KeyConfProvider(ee.ria.xroad.proxy.conf.KeyConfProvider) X509Certificate(java.security.cert.X509Certificate) OCSPResp(org.bouncycastle.cert.ocsp.OCSPResp)

Example 2 with KeyConfProvider

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"));
}
Also used : CertChain(ee.ria.xroad.common.cert.CertChain) AuthKey(ee.ria.xroad.common.conf.globalconf.AuthKey) KeyConfProvider(ee.ria.xroad.proxy.conf.KeyConfProvider) Test(org.junit.Test)

Example 3 with KeyConfProvider

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"));
}
Also used : KeyConfProvider(ee.ria.xroad.proxy.conf.KeyConfProvider) Test(org.junit.Test)

Example 4 with KeyConfProvider

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"));
}
Also used : AuthKey(ee.ria.xroad.common.conf.globalconf.AuthKey) KeyConfProvider(ee.ria.xroad.proxy.conf.KeyConfProvider) Test(org.junit.Test)

Example 5 with KeyConfProvider

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());
}
Also used : KeyConfProvider(ee.ria.xroad.proxy.conf.KeyConfProvider) Test(org.junit.Test)

Aggregations

KeyConfProvider (ee.ria.xroad.proxy.conf.KeyConfProvider)6 Test (org.junit.Test)5 AuthKey (ee.ria.xroad.common.conf.globalconf.AuthKey)3 CertChain (ee.ria.xroad.common.cert.CertChain)2 X509Certificate (java.security.cert.X509Certificate)1 X500Principal (javax.security.auth.x500.X500Principal)1 OCSPResp (org.bouncycastle.cert.ocsp.OCSPResp)1