Search in sources :

Example 1 with AuthKmsKeyMetadata

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));
}
Also used : AuthKmsKeyMetadata(com.nike.cerberus.domain.AuthKmsKeyMetadata) AuthKmsKeyMetadataResult(com.nike.cerberus.domain.AuthKmsKeyMetadataResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with AuthKmsKeyMetadata

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());
}
Also used : AuthKmsKeyMetadata(com.nike.cerberus.domain.AuthKmsKeyMetadata) OffsetDateTime(java.time.OffsetDateTime) AwsIamRoleKmsKeyRecord(com.nike.cerberus.record.AwsIamRoleKmsKeyRecord) AwsIamRoleRecord(com.nike.cerberus.record.AwsIamRoleRecord) Test(org.junit.Test)

Example 3 with AuthKmsKeyMetadata

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;
}
Also used : AuthKmsKeyMetadata(com.nike.cerberus.domain.AuthKmsKeyMetadata) AwsIamRoleKmsKeyRecord(com.nike.cerberus.record.AwsIamRoleKmsKeyRecord)

Aggregations

AuthKmsKeyMetadata (com.nike.cerberus.domain.AuthKmsKeyMetadata)3 AwsIamRoleKmsKeyRecord (com.nike.cerberus.record.AwsIamRoleKmsKeyRecord)2 Test (org.junit.Test)2 AuthKmsKeyMetadataResult (com.nike.cerberus.domain.AuthKmsKeyMetadataResult)1 AwsIamRoleRecord (com.nike.cerberus.record.AwsIamRoleRecord)1 OffsetDateTime (java.time.OffsetDateTime)1 ArrayList (java.util.ArrayList)1