Search in sources :

Example 1 with ResourceException

use of com.yahoo.athenz.zts.ResourceException in project athenz by yahoo.

the class JDBCCertRecordStore method getConnection.

@Override
public CertRecordStoreConnection getConnection() {
    try {
        JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(src.getConnection());
        jdbcConn.setOperationTimeout(opTimeout);
        return jdbcConn;
    } catch (SQLException ex) {
        LOG.error("getConnection: {}", ex.getMessage());
        throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, ex.getMessage());
    }
}
Also used : SQLException(java.sql.SQLException) ResourceException(com.yahoo.athenz.zts.ResourceException)

Example 2 with ResourceException

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

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

Example 4 with ResourceException

use of com.yahoo.athenz.zts.ResourceException in project athenz by yahoo.

the class CloudStoreTest method testInitializeAwsSupportInvalidCreds.

@Test
public void testInitializeAwsSupportInvalidCreds() 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(AWS_IAM_ROLE_INFO);
    ContentResponse responseCreds = Mockito.mock(ContentResponse.class);
    Mockito.when(responseCreds.getStatus()).thenReturn(200);
    Mockito.when(responseCreds.getContentAsString()).thenReturn("invalid-creds");
    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);
    Mockito.when(httpClient.GET("http://169.254.169.254/latest/meta-data/iam/security-credentials/athenz.zts")).thenReturn(responseCreds);
    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)

Example 5 with ResourceException

use of com.yahoo.athenz.zts.ResourceException in project athenz by yahoo.

the class CloudStoreTest method testGetS3ClientAWSNotEnabled.

@Test
public void testGetS3ClientAWSNotEnabled() {
    CloudStore store = new CloudStore(null);
    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)

Aggregations

ResourceException (com.yahoo.athenz.zts.ResourceException)8 Test (org.testng.annotations.Test)6 CloudStore (com.yahoo.athenz.zts.store.CloudStore)5 SQLException (java.sql.SQLException)2 HttpClient (org.eclipse.jetty.client.HttpClient)2 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)2 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 AWSSecurityTokenServiceClient (com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient)1 AssumeRoleRequest (com.amazonaws.services.securitytoken.model.AssumeRoleRequest)1 AssumeRoleResult (com.amazonaws.services.securitytoken.model.AssumeRoleResult)1 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1 AWSTemporaryCredentials (com.yahoo.athenz.zts.AWSTemporaryCredentials)1 SQLTimeoutException (java.sql.SQLTimeoutException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1