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());
}
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());
}
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();
}
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();
}
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();
}
Aggregations