use of com.nike.cerberus.domain.AuthKmsKeyMetadata in project cerberus by Nike-Inc.
the class AdminActionsControllerTest method testGetAuthKmsKeyMetadataWhenKmsServiceReturnsListWithAuthenticationKmsData.
@Test
public void testGetAuthKmsKeyMetadataWhenKmsServiceReturnsListWithAuthenticationKmsData() {
AuthKmsKeyMetadata authKmsKeyMetadata = new AuthKmsKeyMetadata();
List<AuthKmsKeyMetadata> authKmsKeyMetadataList = new ArrayList<>();
authKmsKeyMetadataList.add(authKmsKeyMetadata);
Mockito.when(kmsService.getAuthenticationKmsMetadata()).thenReturn(authKmsKeyMetadataList);
AuthKmsKeyMetadataResult authKmsKeyMetadataResult = adminActionsController.getAuthKmsKeyMetadata();
Assert.assertNotNull(authKmsKeyMetadataResult);
Assert.assertSame(authKmsKeyMetadataList, authKmsKeyMetadataResult.getAuthenticationKmsKeyMetadata());
Assert.assertSame(authKmsKeyMetadata, authKmsKeyMetadataResult.getAuthenticationKmsKeyMetadata().get(0));
}
use of com.nike.cerberus.domain.AuthKmsKeyMetadata in project cerberus by Nike-Inc.
the class KmsServiceTest method test_that_getAuthenticationKmsMetadata_returns_AuthKmsKeyMetadata_from_dao_data.
@Test
public void test_that_getAuthenticationKmsMetadata_returns_AuthKmsKeyMetadata_from_dao_data() {
OffsetDateTime create = OffsetDateTime.now().plus(5, ChronoUnit.MINUTES);
OffsetDateTime update = OffsetDateTime.now().plus(3, ChronoUnit.MINUTES);
OffsetDateTime validate = OffsetDateTime.now().plus(7, ChronoUnit.MINUTES);
List<AwsIamRoleKmsKeyRecord> keyRecords = ImmutableList.of(new AwsIamRoleKmsKeyRecord().setAwsIamRoleId("iam-role-id").setAwsKmsKeyId("key-id").setAwsRegion("us-west-2").setCreatedTs(create).setLastUpdatedTs(update).setLastValidatedTs(validate));
List<AuthKmsKeyMetadata> expected = ImmutableList.of(new AuthKmsKeyMetadata().setAwsIamRoleArn("iam-role-arn").setAwsKmsKeyId("key-id").setAwsRegion("us-west-2").setCreatedTs(create).setLastUpdatedTs(update).setLastValidatedTs(validate));
when(awsIamRoleDao.getAllKmsKeys()).thenReturn(Optional.ofNullable(keyRecords));
when(awsIamRoleDao.getIamRoleById("iam-role-id")).thenReturn(Optional.of(new AwsIamRoleRecord().setAwsIamRoleArn("iam-role-arn")));
assertArrayEquals(expected.toArray(), kmsService.getAuthenticationKmsMetadata().toArray());
}
use of com.nike.cerberus.domain.AuthKmsKeyMetadata in project cerberus by Nike-Inc.
the class KmsService method getAuthenticationKmsMetadata.
public List<AuthKmsKeyMetadata> getAuthenticationKmsMetadata() {
List<AuthKmsKeyMetadata> result = new LinkedList<>();
Optional<List<AwsIamRoleKmsKeyRecord>> keysOptional = awsIamRoleDao.getAllKmsKeys();
List<AwsIamRoleKmsKeyRecord> keys = keysOptional.orElse(new LinkedList<>());
keys.forEach(key -> {
AuthKmsKeyMetadata metadata = new AuthKmsKeyMetadata().setAwsKmsKeyId(key.getAwsKmsKeyId()).setAwsRegion(key.getAwsRegion()).setCreatedTs(key.getCreatedTs()).setLastUpdatedTs(key.getLastUpdatedTs()).setLastValidatedTs(key.getLastValidatedTs());
awsIamRoleDao.getIamRoleById(key.getAwsIamRoleId()).ifPresent(awsIamRoleRecord -> metadata.setAwsIamRoleArn(awsIamRoleRecord.getAwsIamRoleArn()));
result.add(metadata);
});
return result;
}
Aggregations