use of com.nike.cerberus.record.AwsIamRoleRecord 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.record.AwsIamRoleRecord in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testIamPrincipalPermissionsUpdateWhenIamRoleIsPresent.
@Test
public void testIamPrincipalPermissionsUpdateWhenIamRoleIsPresent() {
IamPrincipalPermission iamPrincipalPermission = new IamPrincipalPermission();
iamPrincipalPermission.setIamPrincipalArn("arn");
AwsIamRoleRecord awsIamRoleRecord = new AwsIamRoleRecord();
Set<IamPrincipalPermission> iamPrincipalPermissions = new HashSet<>();
iamPrincipalPermissions.add(iamPrincipalPermission);
Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.of(awsIamRoleRecord));
iamPrincipalPermissionService.updateIamPrincipalPermissions("boxId", iamPrincipalPermissions, "user", OffsetDateTime.MAX);
Mockito.verify(awsIamRoleDao).updateIamRolePermission(Mockito.any(AwsIamRolePermissionRecord.class));
}
use of com.nike.cerberus.record.AwsIamRoleRecord in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testRevokePermissionWhenIamRoleIsPresent.
@Test
public void testRevokePermissionWhenIamRoleIsPresent() {
IamPrincipalPermission iamPrincipalPermission = Mockito.mock(IamPrincipalPermission.class);
Mockito.when(iamPrincipalPermission.getIamPrincipalArn()).thenReturn("arn");
AwsIamRoleRecord awsIamRoleRecord = Mockito.mock(AwsIamRoleRecord.class);
Mockito.when(awsIamRoleRecord.getId()).thenReturn("id");
Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.of(awsIamRoleRecord));
iamPrincipalPermissionService.revokeIamPrincipalPermission("boxId", iamPrincipalPermission);
Mockito.verify(awsIamRoleDao).deleteIamRolePermission("boxId", "id");
}
use of com.nike.cerberus.record.AwsIamRoleRecord in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testGetIamPrincipalPermissionsWhenIamRoleIsPresent.
@Test
public void testGetIamPrincipalPermissionsWhenIamRoleIsPresent() {
List<AwsIamRolePermissionRecord> awsIamRolePermissionRecords = new ArrayList<>();
AwsIamRolePermissionRecord awsIamRolePermissionRecord = new AwsIamRolePermissionRecord().setId("id").setCreatedBy("createdBy").setLastUpdatedBy("lastUpdatedBy").setRoleId("roleId").setCreatedTs(OffsetDateTime.MAX).setLastUpdatedTs(OffsetDateTime.MAX);
awsIamRolePermissionRecords.add(awsIamRolePermissionRecord);
AwsIamRoleRecord awsIamRoleRecord = new AwsIamRoleRecord().setAwsIamRoleArn("awsIamRoleArn");
Mockito.when(awsIamRoleDao.getIamRolePermissions("boxId")).thenReturn(awsIamRolePermissionRecords);
Mockito.when(awsIamRoleDao.getIamRoleById(Mockito.anyString())).thenReturn(Optional.of(awsIamRoleRecord));
Set<IamPrincipalPermission> boxIds = iamPrincipalPermissionService.getIamPrincipalPermissions("boxId");
Assert.assertTrue(boxIds.size() == 1);
boxIds.forEach(iamPrincipalPermission -> {
Assert.assertEquals("id", iamPrincipalPermission.getId());
Assert.assertEquals("lastUpdatedBy", iamPrincipalPermission.getLastUpdatedBy());
Assert.assertEquals("createdBy", iamPrincipalPermission.getCreatedBy());
Assert.assertEquals("roleId", iamPrincipalPermission.getRoleId());
Assert.assertEquals("awsIamRoleArn", iamPrincipalPermission.getIamPrincipalArn());
Assert.assertEquals(OffsetDateTime.MAX, iamPrincipalPermission.getCreatedTs());
Assert.assertEquals(OffsetDateTime.MAX, iamPrincipalPermission.getLastUpdatedTs());
});
}
use of com.nike.cerberus.record.AwsIamRoleRecord in project cerberus by Nike-Inc.
the class AuthenticationServiceTest method test_that_findIamRoleAssociatedWithSdb_returns_generic_role_when_iam_principal_not_found.
@Test
public void test_that_findIamRoleAssociatedWithSdb_returns_generic_role_when_iam_principal_not_found() {
String accountId = "0000000000";
String roleName = "role/path";
String principalArn = String.format("arn:aws:iam::%s:instance-profile/%s", accountId, roleName);
String roleArn = String.format(AWS_IAM_ROLE_ARN_TEMPLATE, AWS_GLOBAL_PARTITION_NAME, accountId, roleName);
AwsIamRoleRecord awsIamRoleRecord = mock(AwsIamRoleRecord.class);
when(awsIamRoleDao.getIamRole(principalArn)).thenReturn(Optional.empty());
when(awsIamRoleDao.getIamRole(roleArn)).thenReturn(Optional.of(awsIamRoleRecord));
when(awsIamRoleArnParser.isRoleArn(principalArn)).thenReturn(false);
when(awsIamRoleArnParser.convertPrincipalArnToRoleArn(principalArn)).thenReturn(roleArn);
Optional<AwsIamRoleRecord> result = authenticationService.findIamRoleAssociatedWithSdb(principalArn);
assertEquals(awsIamRoleRecord, result.get());
}
Aggregations