use of com.yahoo.athenz.instance.provider.InstanceConfirmation in project athenz by yahoo.
the class InstanceHttpProviderTest method testInstanceHttpProviderConfirmInstance.
@Test
public void testInstanceHttpProviderConfirmInstance() {
InstanceHttpProvider provider = new InstanceHttpProvider();
provider.initialize("provider", "https://localhost:4443/instance", null);
InstanceProviderClient client = Mockito.mock(InstanceProviderClient.class);
provider.client = client;
InstanceConfirmation confirmation = new InstanceConfirmation().setAttestationData("data").setDomain("athenz").setProvider("provider").setService("service");
Mockito.when(client.postInstanceConfirmation(confirmation)).thenReturn(confirmation);
InstanceConfirmation result = provider.confirmInstance(confirmation);
assertEquals(result.getAttestationData(), "data");
assertEquals(result.getDomain(), "athenz");
assertEquals(result.getProvider(), "provider");
assertEquals(result.getService(), "service");
provider.close();
}
use of com.yahoo.athenz.instance.provider.InstanceConfirmation in project athenz by yahoo.
the class InstanceHttpProviderTest method testInstanceHttpProviderRefreshInstance.
@Test
public void testInstanceHttpProviderRefreshInstance() {
InstanceHttpProvider provider = new InstanceHttpProvider();
provider.initialize("provider", "https://localhost:4443/instance", null);
InstanceProviderClient client = Mockito.mock(InstanceProviderClient.class);
provider.client = client;
InstanceConfirmation confirmation = new InstanceConfirmation().setAttestationData("data").setDomain("athenz").setProvider("provider").setService("service");
Mockito.when(client.postRefreshConfirmation(confirmation)).thenReturn(confirmation);
InstanceConfirmation result = provider.refreshInstance(confirmation);
assertEquals(result.getAttestationData(), "data");
assertEquals(result.getDomain(), "athenz");
assertEquals(result.getProvider(), "provider");
assertEquals(result.getService(), "service");
provider.close();
}
use of com.yahoo.athenz.instance.provider.InstanceConfirmation in project athenz by yahoo.
the class InstanceAWSProviderTest method testRefreshInstance.
@Test
public void testRefreshInstance() {
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);
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);
InstanceConfirmation result = provider.refreshInstance(confirmation);
assertEquals(result.getDomain(), "athenz");
System.clearProperty(InstanceAWSProvider.AWS_PROP_DNS_SUFFIX);
}
use of com.yahoo.athenz.instance.provider.InstanceConfirmation 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) {
}
}
use of com.yahoo.athenz.instance.provider.InstanceConfirmation 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) {
}
}
Aggregations