Search in sources :

Example 11 with CloudStore

use of com.yahoo.athenz.zts.store.CloudStore in project athenz by yahoo.

the class CloudStoreTest method testParseInstanceInfoInvalid.

@Test
public void testParseInstanceInfoInvalid() {
    CloudStore store = new CloudStore(null);
    assertFalse(store.parseInstanceInfo("some_invalid_doc"));
    store.close();
}
Also used : CloudStore(com.yahoo.athenz.zts.store.CloudStore) Test(org.testng.annotations.Test)

Example 12 with CloudStore

use of com.yahoo.athenz.zts.store.CloudStore 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 13 with CloudStore

use of com.yahoo.athenz.zts.store.CloudStore in project athenz by yahoo.

the class CloudStoreTest method testParseInstanceProfileArn.

@Test
public void testParseInstanceProfileArn() {
    CloudStore store = new CloudStore(null);
    assertTrue(store.parseInstanceProfileArn("arn:aws:iam::111111111111:instance-profile/athenz.zts,athenz"));
    assertEquals(store.awsRole, "athenz.zts");
    store.close();
}
Also used : CloudStore(com.yahoo.athenz.zts.store.CloudStore) Test(org.testng.annotations.Test)

Example 14 with CloudStore

use of com.yahoo.athenz.zts.store.CloudStore 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)

Example 15 with CloudStore

use of com.yahoo.athenz.zts.store.CloudStore in project athenz by yahoo.

the class CloudStoreTest method testInitializeAwsSupportInvalidDocument.

@Test
public void testInitializeAwsSupportInvalidDocument() 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("invalid-document");
    store.setHttpClient(httpClient);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/dynamic/instance-identity/document")).thenReturn(responseDoc);
    try {
        store.awsEnabled = true;
        store.initializeAwsSupport();
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 500);
    }
    store.close();
}
Also used : CloudStore(com.yahoo.athenz.zts.store.CloudStore) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) ResourceException(com.yahoo.athenz.zts.ResourceException) Test(org.testng.annotations.Test)

Aggregations

CloudStore (com.yahoo.athenz.zts.store.CloudStore)45 Test (org.testng.annotations.Test)44 HttpClient (org.eclipse.jetty.client.HttpClient)17 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)16 MockCloudStore (com.yahoo.athenz.zts.store.MockCloudStore)6 Principal (com.yahoo.athenz.auth.Principal)5 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)5 SignedDomain (com.yahoo.athenz.zms.SignedDomain)5 ResourceException (com.yahoo.athenz.zts.ResourceException)5 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)2 File (java.io.File)2 AssumeRoleRequest (com.amazonaws.services.securitytoken.model.AssumeRoleRequest)1 CertSigner (com.yahoo.athenz.common.server.cert.CertSigner)1 SelfCertSigner (com.yahoo.athenz.zts.cert.impl.SelfCertSigner)1 ChangeLogStore (com.yahoo.athenz.zts.store.ChangeLogStore)1 DataStore (com.yahoo.athenz.zts.store.DataStore)1 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)1 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)1 PrivateKey (java.security.PrivateKey)1 X509Certificate (java.security.cert.X509Certificate)1