use of com.yahoo.athenz.zts.cert.impl.HttpCertSigner in project athenz by yahoo.
the class HttpCertSignerTest method testGetCACertificateInvalidStatus.
@Test
public void testGetCACertificateInvalidStatus() 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(400);
assertNull(certSigner.getCACertificate());
}
use of com.yahoo.athenz.zts.cert.impl.HttpCertSigner in project athenz by yahoo.
the class HttpCertSignerTest method testGetCACertificateException.
@Test
public void testGetCACertificateException() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
Mockito.when(httpClient.GET("https://localhost:443/certsign/v2/x509")).thenThrow(new TimeoutException());
assertNull(certSigner.getCACertificate());
}
use of com.yahoo.athenz.zts.cert.impl.HttpCertSigner in project athenz by yahoo.
the class HttpCertSignerTest method testGetCACertificateInvalidData.
@Test
public void testGetCACertificateInvalidData() 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("{\"pem2\": \"pem-value\"}");
assertNull(certSigner.getCACertificate());
Mockito.when(response.getContentAsString()).thenReturn("invalid-json");
assertNull(certSigner.getCACertificate());
}
use of com.yahoo.athenz.zts.cert.impl.HttpCertSigner in project athenz by yahoo.
the class HttpCertSignerTest method testGenerateSSHCertificate.
@Test
public void testGenerateSSHCertificate() 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/ssh")).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("{\"type\":\"user\",\"opensshkey\": \"ssh-key\"}");
String pem = certSigner.generateSSHCertificate("ssh-key-req");
assertEquals(pem, "ssh-key");
}
use of com.yahoo.athenz.zts.cert.impl.HttpCertSigner 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));
}
Aggregations