use of com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory in project athenz by yahoo.
the class HttpCertSignerTest method testGenerateX509CertificateException.
@Test
public void testGenerateX509CertificateException() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
Request request = Mockito.mock(Request.class);
Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);
Mockito.when(request.send()).thenThrow(new TimeoutException());
assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
use of com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory in project athenz by yahoo.
the class HttpCertSignerTest method testGetCACertificateResponseEmpty.
@Test
public void testGetCACertificateResponseEmpty() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
ContentResponse response = Mockito.mock(ContentResponse.class);
Mockito.when(httpClient.GET("https://localhost:443/certsign/v2/x509")).thenReturn(response);
Mockito.when(response.getStatus()).thenReturn(200);
Mockito.when(response.getContentAsString()).thenReturn("");
assertNull(certSigner.getCACertificate());
}
use of com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory in project athenz by yahoo.
the class HttpCertSignerTest method testGenerateX509CertificateResponseNull.
@Test
public void testGenerateX509CertificateResponseNull() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
Request request = Mockito.mock(Request.class);
Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);
ContentResponse response = Mockito.mock(ContentResponse.class);
Mockito.when(request.send()).thenReturn(response);
Mockito.when(response.getStatus()).thenReturn(201);
Mockito.when(response.getContentAsString()).thenReturn(null);
assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
use of com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory in project athenz by yahoo.
the class HttpCertSignerTest method testGenerateX509Certificate.
@Test
public void testGenerateX509Certificate() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
Request request = Mockito.mock(Request.class);
Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);
ContentResponse response = Mockito.mock(ContentResponse.class);
Mockito.when(request.send()).thenReturn(response);
Mockito.when(response.getStatus()).thenReturn(201);
Mockito.when(response.getContentAsString()).thenReturn("{\"pem\": \"pem-value\"}");
String pem = certSigner.generateX509Certificate("csr", null, 0);
assertEquals(pem, "pem-value");
}
use of com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory in project athenz by yahoo.
the class HttpCertSignerTest method testGenerateX509CertificateInvalidData.
@Test
public void testGenerateX509CertificateInvalidData() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
Request request = Mockito.mock(Request.class);
Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);
ContentResponse response = Mockito.mock(ContentResponse.class);
Mockito.when(request.send()).thenReturn(response);
Mockito.when(response.getStatus()).thenReturn(201);
Mockito.when(response.getContentAsString()).thenReturn("{\"pem2\": \"pem-value\"}");
assertNull(certSigner.generateX509Certificate("csr", null, 0));
Mockito.when(response.getContentAsString()).thenReturn("invalid-json");
assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
Aggregations