use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testGrantIamPermissionIfRoleIsPresentByRoleIdAndRoleRecordFound.
@Test
public void testGrantIamPermissionIfRoleIsPresentByRoleIdAndRoleRecordFound() {
IamPrincipalPermission iamPrincipalPermission = new IamPrincipalPermission();
iamPrincipalPermission.setIamPrincipalArn("arn");
iamPrincipalPermission.setRoleId("roleId");
Role role = new Role();
AwsIamRoleRecord awsIamRoleRecord = new AwsIamRoleRecord();
Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.of(awsIamRoleRecord));
Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
Mockito.when(uuidSupplier.get()).thenReturn("uuid");
iamPrincipalPermissionService.grantIamPrincipalPermission("boxId", iamPrincipalPermission, "user", OffsetDateTime.MAX);
Mockito.verify(awsIamRoleDao, Mockito.never()).createIamRole(Mockito.any(AwsIamRoleRecord.class));
Mockito.verify(awsIamRoleDao).createIamRolePermission(Mockito.any(AwsIamRolePermissionRecord.class));
}
use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testRevokePermissionsWhenIamRoleIsPresent.
@Test
public void testRevokePermissionsWhenIamRoleIsPresent() {
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));
Set<IamPrincipalPermission> iamPrincipalPermissions = new HashSet<>();
iamPrincipalPermissions.add(iamPrincipalPermission);
iamPrincipalPermissionService.revokeIamPrincipalPermissions("boxId", iamPrincipalPermissions);
Mockito.verify(awsIamRoleDao).deleteIamRolePermission("boxId", "id");
}
use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testRevokePermissionsWhenIamRoleIsNotPresent.
@Test(expected = ApiException.class)
public void testRevokePermissionsWhenIamRoleIsNotPresent() {
IamPrincipalPermission iamPrincipalPermission = Mockito.mock(IamPrincipalPermission.class);
Mockito.when(iamPrincipalPermission.getIamPrincipalArn()).thenReturn("arn");
Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.empty());
Set<IamPrincipalPermission> iamPrincipalPermissions = new HashSet<>();
iamPrincipalPermissions.add(iamPrincipalPermission);
iamPrincipalPermissionService.revokeIamPrincipalPermissions("boxId", iamPrincipalPermissions);
}
use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testGrantIamPermissionsIfRoleIsPresentByRoleIdAndRoleRecordFound.
@Test
public void testGrantIamPermissionsIfRoleIsPresentByRoleIdAndRoleRecordFound() {
IamPrincipalPermission iamPrincipalPermission = new IamPrincipalPermission();
iamPrincipalPermission.setIamPrincipalArn("arn");
iamPrincipalPermission.setRoleId("roleId");
Set<IamPrincipalPermission> iamPrincipalPermissions = new HashSet<>();
iamPrincipalPermissions.add(iamPrincipalPermission);
Role role = new Role();
AwsIamRoleRecord awsIamRoleRecord = new AwsIamRoleRecord();
Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.of(awsIamRoleRecord));
Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
Mockito.when(uuidSupplier.get()).thenReturn("uuid");
iamPrincipalPermissionService.grantIamPrincipalPermissions("boxId", iamPrincipalPermissions, "user", OffsetDateTime.MAX);
Mockito.verify(awsIamRoleDao, Mockito.never()).createIamRole(Mockito.any(AwsIamRoleRecord.class));
Mockito.verify(awsIamRoleDao).createIamRolePermission(Mockito.any(AwsIamRolePermissionRecord.class));
}
use of com.nike.cerberus.domain.IamPrincipalPermission in project cerberus by Nike-Inc.
the class IamPrincipalPermissionServiceTest method testGrantIamPermissionsIfRoleIsPresentByRoleIdAndRoleRecordNotFound.
@Test
public void testGrantIamPermissionsIfRoleIsPresentByRoleIdAndRoleRecordNotFound() {
IamPrincipalPermission iamPrincipalPermission = new IamPrincipalPermission();
iamPrincipalPermission.setIamPrincipalArn("arn");
iamPrincipalPermission.setRoleId("roleId");
Set<IamPrincipalPermission> iamPrincipalPermissions = new HashSet<>();
iamPrincipalPermissions.add(iamPrincipalPermission);
Role role = new Role();
Mockito.when(awsIamRoleDao.getIamRole("arn")).thenReturn(Optional.empty());
Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
Mockito.when(uuidSupplier.get()).thenReturn("uuid");
iamPrincipalPermissionService.grantIamPrincipalPermissions("boxId", iamPrincipalPermissions, "user", OffsetDateTime.MAX);
Mockito.verify(awsIamRoleDao).createIamRole(Mockito.any(AwsIamRoleRecord.class));
Mockito.verify(awsIamRoleDao).createIamRolePermission(Mockito.any(AwsIamRolePermissionRecord.class));
}
Aggregations