Search in sources :

Example 6 with HttpCertSigner

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());
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) HttpCertSigner(com.yahoo.athenz.zts.cert.impl.HttpCertSigner) HttpCertSignerFactory(com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory) Test(org.testng.annotations.Test)

Example 7 with HttpCertSigner

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());
}
Also used : HttpClient(org.eclipse.jetty.client.HttpClient) HttpCertSigner(com.yahoo.athenz.zts.cert.impl.HttpCertSigner) HttpCertSignerFactory(com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 8 with HttpCertSigner

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());
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) HttpCertSigner(com.yahoo.athenz.zts.cert.impl.HttpCertSigner) HttpCertSignerFactory(com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory) Test(org.testng.annotations.Test)

Example 9 with HttpCertSigner

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");
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) Request(org.eclipse.jetty.client.api.Request) HttpCertSigner(com.yahoo.athenz.zts.cert.impl.HttpCertSigner) HttpCertSignerFactory(com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory) Test(org.testng.annotations.Test)

Example 10 with HttpCertSigner

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));
}
Also used : HttpClient(org.eclipse.jetty.client.HttpClient) Request(org.eclipse.jetty.client.api.Request) HttpCertSigner(com.yahoo.athenz.zts.cert.impl.HttpCertSigner) HttpCertSignerFactory(com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Aggregations

HttpCertSigner (com.yahoo.athenz.zts.cert.impl.HttpCertSigner)14 HttpCertSignerFactory (com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory)14 HttpClient (org.eclipse.jetty.client.HttpClient)14 Test (org.testng.annotations.Test)14 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)12 Request (org.eclipse.jetty.client.api.Request)7 TimeoutException (java.util.concurrent.TimeoutException)2