Search in sources :

Example 16 with InstanceConfirmation

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

the class InstanceAWSProviderTest method testConfirmInstanceServiceMismatch.

@Test
public void testConfirmInstanceServiceMismatch() {
    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.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 17 with InstanceConfirmation

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

the class InstanceAWSProviderTest method testRefreshInstanceInvalidVerifyIdentity.

@Test
public void testRefreshInstanceInvalidVerifyIdentity() {
    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.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 18 with InstanceConfirmation

use of com.yahoo.athenz.instance.provider.InstanceConfirmation 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 19 with InstanceConfirmation

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

the class InstanceAWSLambdaProviderTest method testConfirmInstanceNullDocument.

@Test
public void testConfirmInstanceNullDocument() {
    System.setProperty(InstanceAWSProvider.AWS_PROP_DNS_SUFFIX, "athenz.cloud");
    MockInstanceAWSLambdaProvider provider = new MockInstanceAWSLambdaProvider();
    System.setProperty(InstanceAWSProvider.AWS_PROP_PUBLIC_CERT, "src/test/resources/aws_public.cert");
    provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSLambdaProvider", null);
    InstanceConfirmation confirmation = new InstanceConfirmation().setAttestationData("{\"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);
    InstanceConfirmation result = provider.confirmInstance(confirmation);
    assertEquals(result.getAttributes().get("certUsage"), "client");
    assertEquals(result.getDomain(), "athenz");
    System.clearProperty(InstanceAWSProvider.AWS_PROP_DNS_SUFFIX);
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 20 with InstanceConfirmation

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

the class InstanceAWSLambdaProviderTest method testConfirmInstanceEmptyDocument.

@Test
public void testConfirmInstanceEmptyDocument() {
    System.setProperty(InstanceAWSProvider.AWS_PROP_DNS_SUFFIX, "athenz.cloud");
    MockInstanceAWSLambdaProvider provider = new MockInstanceAWSLambdaProvider();
    System.setProperty(InstanceAWSProvider.AWS_PROP_PUBLIC_CERT, "src/test/resources/aws_public.cert");
    provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSLambdaProvider", 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);
    InstanceConfirmation result = provider.confirmInstance(confirmation);
    assertEquals(result.getAttributes().get("certUsage"), "client");
    assertEquals(result.getDomain(), "athenz");
    System.clearProperty(InstanceAWSProvider.AWS_PROP_DNS_SUFFIX);
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Aggregations

InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)39 Test (org.testng.annotations.Test)36 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)20 SignedDomain (com.yahoo.athenz.zms.SignedDomain)18 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)18 ChangeLogStore (com.yahoo.athenz.zts.store.ChangeLogStore)18 DataStore (com.yahoo.athenz.zts.store.DataStore)18 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)18 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)18 Path (java.nio.file.Path)18 X509Certificate (java.security.cert.X509Certificate)14 HashMap (java.util.HashMap)14 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)13 CertificateAuthority (com.yahoo.athenz.auth.impl.CertificateAuthority)12 ResourceException (com.yahoo.athenz.instance.provider.ResourceException)12 X509CertRecord (com.yahoo.athenz.zts.cert.X509CertRecord)12 WebApplicationException (javax.ws.rs.WebApplicationException)3 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)2 CryptoException (com.yahoo.athenz.auth.util.CryptoException)2 AuditLogMsgBuilder (com.yahoo.athenz.common.server.log.AuditLogMsgBuilder)2