use of com.yahoo.athenz.instance.provider.ResourceException in project athenz by yahoo.
the class InstanceAWSProviderTest method testConfirmInstanceInvalidDocument.
@Test
public void testConfirmInstanceInvalidDocument() {
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");
attributes.put("sanDNS", "service.athenz.athenz.cloud,i-1234.instanceid.athenz.athenz.cloud");
confirmation.setAttributes(attributes);
try {
provider.confirmInstance(confirmation);
fail();
} catch (ResourceException ex) {
}
}
use of com.yahoo.athenz.instance.provider.ResourceException in project athenz by yahoo.
the class InstanceAWSProviderTest method testVerifyInstanceIdentityException.
@Test
public void testVerifyInstanceIdentityException() {
MockInstanceAWSProvider provider = new MockInstanceAWSProvider();
provider.setIdentitySuper(true);
AWSSecurityTokenServiceClient mockClient = Mockito.mock(AWSSecurityTokenServiceClient.class);
Mockito.when(mockClient.getCallerIdentity(ArgumentMatchers.any())).thenThrow(new ResourceException(101));
provider.setStsClient(mockClient);
AWSAttestationData info = new AWSAttestationData();
assertFalse(provider.verifyInstanceIdentity(info, "1234"));
}
use of com.yahoo.athenz.instance.provider.ResourceException in project athenz by yahoo.
the class InstanceAWSProviderTest method testConfirmInstanceNullDocument.
@Test
public void testConfirmInstanceNullDocument() {
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("{\"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);
}
use of com.yahoo.athenz.instance.provider.ResourceException 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) {
}
}
use of com.yahoo.athenz.instance.provider.ResourceException 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) {
}
}
Aggregations