CloudStore { boolean loadBootMetaData() { String document = getMetaData("/dynamic/instance-identity/document"); if (document == null) { return false; } if (!parseInstanceInfo(document)) { LOGGER.error("CloudStore: unable to parse instance identity document: {}", document); return false; } String docSignature = getMetaData("/dynamic/instance-identity/pkcs7"); if (docSignature == null) { return false; } String iamRole = getMetaData("/meta-data/iam/info"); if (iamRole == null) { return false; } if (!parseIamRoleInfo(iamRole)) { LOGGER.error("CloudStore: unable to parse iam role data: {}", iamRole); return false; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("CloudStore: service meta information:"); LOGGER.debug("CloudStore: role: {}", awsRole); LOGGER.debug("CloudStore: region: {}", awsRegion); } return true; } CloudStore(); void close(); void setHttpClient(HttpClient client); boolean isAwsEnabled(); AmazonS3 getS3Client(); AWSTemporaryCredentials assumeAWSRole(String account, String roleName, String principal,
                                                 Integer durationSeconds, String externalId); String getCloudAccount(String domainName);  }
@Test public void testLoadBootMetaData() throws InterruptedException, ExecutionException, TimeoutException { CloudStore store = new CloudStore(); HttpClient httpClient = Mockito.mock(HttpClient.class); ContentResponse responseDoc = Mockito.mock(ContentResponse.class); Mockito.when(responseDoc.getStatus()).thenReturn(200); Mockito.when(responseDoc.getContentAsString()).thenReturn(AWS_INSTANCE_DOCUMENT); ContentResponse responseSig = Mockito.mock(ContentResponse.class); Mockito.when(responseSig.getStatus()).thenReturn(200); Mockito.when(responseSig.getContentAsString()).thenReturn("pkcs7-signature"); ContentResponse responseInfo = Mockito.mock(ContentResponse.class); Mockito.when(responseInfo.getStatus()).thenReturn(200); Mockito.when(responseInfo.getContentAsString()).thenReturn(AWS_IAM_ROLE_INFO); store.setHttpClient(httpClient); Mockito.when(httpClient.GET("http: Mockito.when(httpClient.GET("http: Mockito.when(httpClient.GET("http: assertTrue(store.loadBootMetaData()); assertEquals(store.awsRole, "athenz.zts"); assertEquals(store.awsRegion, "us-west-2"); store.close(); }