InstanceAWSECSProvider extends InstanceAWSProvider { @Override public void initialize(String provider, String providerEndpoint, SSLContext sslcontext, KeyStore keyStore) { super.initialize(provider, providerEndpoint, sslcontext, keyStore); bootTimeOffset = 0; supportRefresh = true; }  @Override void initialize(String provider, String providerEndpoint, SSLContext sslcontext,
            KeyStore keyStore);  }
@Test public void testInitializeDefaults() { InstanceAWSECSProvider provider = new InstanceAWSECSProvider(); provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSECSProvider", null, null); assertNull(provider.awsPublicKey); assertEquals(provider.bootTimeOffset, 0); provider.close(); }
@Test public void testValidateAWSDocumentInvalidBootTime() { StringBuilder errMsg = new StringBuilder(256); StringBuilder privateIp = new StringBuilder(64); MockInstanceAWSECSProvider provider = new MockInstanceAWSECSProvider(); System.setProperty(InstanceAWSProvider.AWS_PROP_PUBLIC_CERT, "src/test/resources/aws_public.cert"); provider.initialize("athenz.aws-ecs.us-west-2", "com.yahoo.athenz.instance.provider.impl.InstanceAWSECSProvider", null, null); String bootTime = Timestamp.fromMillis(System.currentTimeMillis() - 1000000).toString(); AWSAttestationData data = new AWSAttestationData(); data.setDocument("{\"accountId\": \"1234\",\"pendingTime\": \"" + bootTime + "\",\"region\": \"us-west-2\",\"instanceId\": \"i-1234\"}"); data.setSignature("signature"); assertTrue(provider.validateAWSDocument("athenz.aws-ecs.us-west-2", data, "1234", "i-1234", true, privateIp, errMsg)); }
@Test public void testEmptyRefreshAttestationData() { InstanceAWSECSProvider provider = new InstanceAWSECSProvider(); provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSECSProvider", null, 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); } }