use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testGrantIamPermissionIfRoleIsNotPresentByRoleId.
@Test(expected = ApiException.class)
public void testGrantIamPermissionIfRoleIsNotPresentByRoleId() {
IamPrincipalPermission iamPrincipalPermission = new IamPrincipalPermission();
iamPrincipalPermission.setIamPrincipalArn("arn");
iamPrincipalPermission.setRoleId("roleId");
Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.empty());
Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.empty());
iamPrincipalPermissionService.grantIamPrincipalPermission("boxId", iamPrincipalPermission, "user", OffsetDateTime.MAX);
}
use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testIamPrincipalPermissionUpdateWhenIamRoleIsNotPresent.
@Test(expected = ApiException.class)
public void testIamPrincipalPermissionUpdateWhenIamRoleIsNotPresent() {
IamPrincipalPermission iamPrincipalPermission = new IamPrincipalPermission();
iamPrincipalPermission.setIamPrincipalArn("arn");
Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.empty());
iamPrincipalPermissionService.updateIamPrincipalPermission("boxId", iamPrincipalPermission, "user", OffsetDateTime.MAX);
}
use of com.nike.cerberus.domain.IamPrincipalPermission 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.domain.IamPrincipalPermission 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.domain.IamPrincipalPermission in project cerberus by Nike-Inc.
the class IamPrincipalPermissionService method getIamPrincipalPermissions.
public Set<IamPrincipalPermission> getIamPrincipalPermissions(final String safeDepositBoxId) {
final Set<IamPrincipalPermission> iamPrincipalPermissionSet = Sets.newHashSet();
final List<AwsIamRolePermissionRecord> permissionRecords = awsIamRoleDao.getIamRolePermissions(safeDepositBoxId);
permissionRecords.forEach(r -> {
final Optional<AwsIamRoleRecord> iamRoleRecord = awsIamRoleDao.getIamRoleById(r.getAwsIamRoleId());
if (iamRoleRecord.isPresent()) {
final IamPrincipalPermission permission = new IamPrincipalPermission();
permission.setId(r.getId());
permission.setIamPrincipalArn(iamRoleRecord.get().getAwsIamRoleArn());
permission.setRoleId(r.getRoleId());
permission.setCreatedBy(r.getCreatedBy());
permission.setLastUpdatedBy(r.getLastUpdatedBy());
permission.setCreatedTs(r.getCreatedTs());
permission.setLastUpdatedTs(r.getLastUpdatedTs());
iamPrincipalPermissionSet.add(permission);
}
});
return iamPrincipalPermissionSet;
}
Aggregations