Search in sources :

Example 76 with HttpClient

use of org.eclipse.jetty.client.HttpClient in project athenz by yahoo.

the class HttpCertSignerTest method testGetCACertificateResponseNull.

@Test
public void testGetCACertificateResponseNull() 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(null);
    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 77 with HttpClient

use of org.eclipse.jetty.client.HttpClient in project athenz by yahoo.

the class HttpCertSignerTest method testGetCACertificate.

@Test
public void testGetCACertificate() 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("{\"pem\": \"pem-value\"}");
    String pem = certSigner.getCACertificate();
    assertEquals(pem, "pem-value");
}
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 78 with HttpClient

use of org.eclipse.jetty.client.HttpClient in project athenz by yahoo.

the class HttpCertSignerTest method testGenerateX509CertificateInvalidStatus.

@Test
public void testGenerateX509CertificateInvalidStatus() 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(400);
    assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
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 79 with HttpClient

use of org.eclipse.jetty.client.HttpClient in project athenz by yahoo.

the class HttpCertSignerTest method testGetSSHCertificate.

@Test
public void testGetSSHCertificate() 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/ssh")).thenReturn(response);
    Mockito.when(response.getStatus()).thenReturn(200);
    Mockito.when(response.getContentAsString()).thenReturn("{\"certs\": [{\"type\":\"user\",\"opensshkey\":\"user-key\"},{\"type\":\"host\",\"opensshkey\":\"host-key\"}]}");
    String pem = certSigner.getSSHCertificate("user");
    assertNotNull(pem);
    assertEquals(pem, "user-key");
}
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 80 with HttpClient

use of org.eclipse.jetty.client.HttpClient in project athenz by yahoo.

the class HttpCertSignerTest method testGenerateX509CertificateResponseEmpty.

@Test
public void testGenerateX509CertificateResponseEmpty() 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("");
    assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
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)

Aggregations

HttpClient (org.eclipse.jetty.client.HttpClient)197 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)102 Test (org.junit.Test)94 Request (org.eclipse.jetty.client.api.Request)53 HttpServletRequest (javax.servlet.http.HttpServletRequest)42 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)40 Test (org.testng.annotations.Test)34 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)24 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)19 CloudStore (com.yahoo.athenz.zts.store.CloudStore)17 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)16 HttpCertSigner (com.yahoo.athenz.zts.cert.impl.HttpCertSigner)14 HttpCertSignerFactory (com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory)14 URI (java.net.URI)11 HTTP2Client (org.eclipse.jetty.http2.client.HTTP2Client)11 ExecutionException (java.util.concurrent.ExecutionException)8 HttpProxy (org.eclipse.jetty.client.HttpProxy)8 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)8 IOException (java.io.IOException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7