Search in sources :

Example 6 with CloudStore

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

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

the class CloudStoreTest method testParseInstanceProfileArnInvalidProfile.

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

Example 8 with CloudStore

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

the class CloudStoreTest method testParseIamRoleInfoInvalid.

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

Example 9 with CloudStore

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

the class CloudStoreTest method testGetS3ClientNullCreds.

@Test
public void testGetS3ClientNullCreds() {
    CloudStore store = new CloudStore(null);
    store.awsEnabled = true;
    store.credentials = null;
    try {
        store.getS3Client();
        fail();
    } catch (ResourceException ex) {
        assertEquals(500, ex.getCode());
    }
    store.close();
}
Also used : CloudStore(com.yahoo.athenz.zts.store.CloudStore) ResourceException(com.yahoo.athenz.zts.ResourceException) Test(org.testng.annotations.Test)

Example 10 with CloudStore

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

the class CloudStoreTest method testGetS3Client.

@Test
public void testGetS3Client() {
    System.setProperty(ZTSConsts.ZTS_PROP_AWS_PUBLIC_CERT, "src/test/resources/aws_public.crt");
    CloudStore store = new CloudStore(null);
    store.credentials = new BasicSessionCredentials("accessKey", "secretKey", "token");
    store.awsEnabled = true;
    assertNotNull(store.getS3Client());
    store.awsRegion = "us-west-2";
    assertNotNull(store.getS3Client());
    store.close();
}
Also used : CloudStore(com.yahoo.athenz.zts.store.CloudStore) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) 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