Search in sources :

Example 81 with HttpClient

use of org.eclipse.jetty.client.HttpClient 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 82 with HttpClient

use of org.eclipse.jetty.client.HttpClient 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 83 with HttpClient

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

the class CloudStoreTest method testLoadBootMetaDataInvalidIamInfoParse.

@Test
public void testLoadBootMetaDataInvalidIamInfoParse() throws InterruptedException, ExecutionException, TimeoutException {
    CloudStore store = new CloudStore(null);
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    ContentResponse responseDoc = Mockito.mock(ContentResponse.class);
    Mockito.when(responseDoc.getStatus()).thenReturn(200);
    Mockito.when(responseDoc.getContentAsString()).thenReturn(AWS_INSTANCE_DOCUMENT);
    ContentResponse responseSig = Mockito.mock(ContentResponse.class);
    Mockito.when(responseSig.getStatus()).thenReturn(200);
    Mockito.when(responseSig.getContentAsString()).thenReturn("pkcs7-signature");
    ContentResponse responseInfo = Mockito.mock(ContentResponse.class);
    Mockito.when(responseInfo.getStatus()).thenReturn(200);
    Mockito.when(responseInfo.getContentAsString()).thenReturn("{\"accountId\":\"012345678901\",\"InstanceProfileArn\":\"invalid\"}");
    store.setHttpClient(httpClient);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/dynamic/instance-identity/document")).thenReturn(responseDoc);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/dynamic/instance-identity/pkcs7")).thenReturn(responseSig);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/meta-data/iam/info")).thenReturn(responseInfo);
    assertFalse(store.loadBootMetaData());
    store.close();
}
Also used : CloudStore(com.yahoo.athenz.zts.store.CloudStore) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) Test(org.testng.annotations.Test)

Example 84 with HttpClient

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

the class CloudStoreTest method testGetMetaDataExceptions.

@SuppressWarnings("unchecked")
@Test
public void testGetMetaDataExceptions() throws InterruptedException, ExecutionException, TimeoutException {
    CloudStore store = new CloudStore(null);
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    store.setHttpClient(httpClient);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/exc1")).thenThrow(InterruptedException.class);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/exc2")).thenThrow(ExecutionException.class);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/exc3")).thenThrow(TimeoutException.class);
    assertNull(store.getMetaData("/exc1"));
    assertNull(store.getMetaData("/exc2"));
    assertNull(store.getMetaData("/exc3"));
    store.close();
}
Also used : CloudStore(com.yahoo.athenz.zts.store.CloudStore) HttpClient(org.eclipse.jetty.client.HttpClient) Test(org.testng.annotations.Test)

Example 85 with HttpClient

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

the class CloudStoreTest method testLoadBootMetaDataInvalidSignature.

@Test
public void testLoadBootMetaDataInvalidSignature() throws InterruptedException, ExecutionException, TimeoutException {
    CloudStore store = new CloudStore(null);
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    ContentResponse responseDoc = Mockito.mock(ContentResponse.class);
    Mockito.when(responseDoc.getStatus()).thenReturn(200);
    Mockito.when(responseDoc.getContentAsString()).thenReturn(AWS_INSTANCE_DOCUMENT);
    ContentResponse responseSig = Mockito.mock(ContentResponse.class);
    Mockito.when(responseSig.getStatus()).thenReturn(404);
    store.setHttpClient(httpClient);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/dynamic/instance-identity/document")).thenReturn(responseDoc);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/dynamic/instance-identity/pkcs7")).thenReturn(responseSig);
    assertFalse(store.loadBootMetaData());
    store.close();
}
Also used : CloudStore(com.yahoo.athenz.zts.store.CloudStore) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) 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