Search in sources :

Example 6 with ResourceException

use of com.yahoo.athenz.instance.provider.ResourceException in project athenz by yahoo.

the class InstanceAWSProviderTest method testConfirmInstanceEmptyDocument.

@Test
public void testConfirmInstanceEmptyDocument() {
    System.setProperty(InstanceAWSProvider.AWS_PROP_DNS_SUFFIX, "athenz.cloud");
    MockInstanceAWSProvider provider = new MockInstanceAWSProvider();
    System.setProperty(InstanceAWSProvider.AWS_PROP_PUBLIC_CERT, "src/test/resources/aws_public.cert");
    provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", null);
    InstanceConfirmation confirmation = new InstanceConfirmation().setAttestationData("{\"document\": \"\",\"signature\": \"signature\",\"role\": \"athenz.service\"}").setDomain("athenz").setProvider("provider").setService("service");
    HashMap<String, String> attributes = new HashMap<>();
    attributes.put("cloudAccount", "1234");
    attributes.put("sanDNS", "service.athenz.athenz.cloud,i-1234.instanceid.athenz.athenz.cloud");
    confirmation.setAttributes(attributes);
    try {
        provider.confirmInstance(confirmation);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 403);
    }
    System.clearProperty(InstanceAWSProvider.AWS_PROP_DNS_SUFFIX);
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HashMap(java.util.HashMap) ResourceException(com.yahoo.athenz.instance.provider.ResourceException) Test(org.testng.annotations.Test)

Example 7 with ResourceException

use of com.yahoo.athenz.instance.provider.ResourceException in project athenz by yahoo.

the class InstanceAWSECSProviderTest method testEmptyRefreshAttestationData.

@Test
public void testEmptyRefreshAttestationData() {
    InstanceAWSECSProvider provider = new InstanceAWSECSProvider();
    provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSECSProvider", null);
    InstanceConfirmation confirmation = new InstanceConfirmation();
    try {
        provider.refreshInstance(confirmation);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.FORBIDDEN);
    }
    confirmation.setAttestationData("");
    try {
        provider.refreshInstance(confirmation);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.FORBIDDEN);
    }
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) ResourceException(com.yahoo.athenz.instance.provider.ResourceException) Test(org.testng.annotations.Test)

Example 8 with ResourceException

use of com.yahoo.athenz.instance.provider.ResourceException in project athenz by yahoo.

the class InstanceAWSProviderTest method testConfirmInstanceInvalidHostnames.

@Test
public void testConfirmInstanceInvalidHostnames() {
    MockInstanceAWSProvider provider = new MockInstanceAWSProvider();
    System.setProperty(InstanceAWSProvider.AWS_PROP_PUBLIC_CERT, "src/test/resources/aws_public.cert");
    provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", null);
    InstanceConfirmation confirmation = new InstanceConfirmation().setAttestationData("{\"document\": \"document\",\"signature\": \"signature\",\"role\": \"athenz.service\"}").setDomain("athenz").setProvider("provider").setService("service");
    HashMap<String, String> attributes = new HashMap<>();
    attributes.put("cloudAccount", "1234");
    confirmation.setAttributes(attributes);
    try {
        provider.confirmInstance(confirmation);
        fail();
    } catch (ResourceException ex) {
    }
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HashMap(java.util.HashMap) ResourceException(com.yahoo.athenz.instance.provider.ResourceException) Test(org.testng.annotations.Test)

Example 9 with ResourceException

use of com.yahoo.athenz.instance.provider.ResourceException in project athenz by yahoo.

the class InstanceAWSProviderTest method testRefreshInstanceServiceMismatch.

@Test
public void testRefreshInstanceServiceMismatch() {
    MockInstanceAWSProvider provider = new MockInstanceAWSProvider();
    System.setProperty(InstanceAWSProvider.AWS_PROP_PUBLIC_CERT, "src/test/resources/aws_public.cert");
    provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", null);
    InstanceConfirmation confirmation = new InstanceConfirmation().setAttestationData("{\"document\": \"document\",\"signature\": \"signature\",\"role\": \"athenz2.service\"}").setDomain("athenz").setProvider("provider").setService("service");
    HashMap<String, String> attributes = new HashMap<>();
    attributes.put("cloudAccount", "1234");
    confirmation.setAttributes(attributes);
    try {
        provider.refreshInstance(confirmation);
        fail();
    } catch (ResourceException ex) {
    }
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HashMap(java.util.HashMap) ResourceException(com.yahoo.athenz.instance.provider.ResourceException) Test(org.testng.annotations.Test)

Example 10 with ResourceException

use of com.yahoo.athenz.instance.provider.ResourceException in project athenz by yahoo.

the class InstanceAWSProviderTest method testConfirmInstanceInvalidVerifyIdentity.

@Test
public void testConfirmInstanceInvalidVerifyIdentity() {
    MockInstanceAWSProvider provider = new MockInstanceAWSProvider();
    System.setProperty(InstanceAWSProvider.AWS_PROP_PUBLIC_CERT, "src/test/resources/aws_public.cert");
    provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", null);
    provider.setIdentityResult(false);
    String bootTime = Timestamp.fromMillis(System.currentTimeMillis() - 100).toString();
    InstanceConfirmation confirmation = new InstanceConfirmation().setAttestationData("{\"document\": \"{\\\"accountId\\\": \\\"1234\\\",\\\"pendingTime\\\": \\\"" + bootTime + "\\\",\\\"region\\\": \\\"us-west-2\\\",\\\"instanceId\\\": \\\"i-1234\\\"}\"," + "\"signature\": \"signature\",\"role\": \"athenz.service\"}").setDomain("athenz").setProvider("athenz.aws.us-west-2").setService("service");
    HashMap<String, String> attributes = new HashMap<>();
    attributes.put("cloudAccount", "1234");
    attributes.put("sanDNS", "service.athenz.athenz.cloud,i-1234.instanceid.athenz.athenz.cloud");
    confirmation.setAttributes(attributes);
    try {
        provider.confirmInstance(confirmation);
        fail();
    } catch (ResourceException ex) {
    }
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HashMap(java.util.HashMap) ResourceException(com.yahoo.athenz.instance.provider.ResourceException) Test(org.testng.annotations.Test)

Aggregations

ResourceException (com.yahoo.athenz.instance.provider.ResourceException)14 Test (org.testng.annotations.Test)14 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)12 HashMap (java.util.HashMap)8 AWSSecurityTokenServiceClient (com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient)1