Search in sources :

Example 6 with Role

use of com.nike.cerberus.domain.Role in project cerberus by Nike-Inc.

the class UserGroupPermissionServiceTest method mockRoleWithRoleId.

private Role mockRoleWithRoleId() {
    Role role = Mockito.mock(Role.class);
    Mockito.when(role.getId()).thenReturn("id");
    return role;
}
Also used : Role(com.nike.cerberus.domain.Role)

Example 7 with Role

use of com.nike.cerberus.domain.Role 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));
}
Also used : Role(com.nike.cerberus.domain.Role) AwsIamRoleRecord(com.nike.cerberus.record.AwsIamRoleRecord) AwsIamRolePermissionRecord(com.nike.cerberus.record.AwsIamRolePermissionRecord) IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission) Test(org.junit.Test)

Example 8 with Role

use of com.nike.cerberus.domain.Role 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));
}
Also used : Role(com.nike.cerberus.domain.Role) AwsIamRoleRecord(com.nike.cerberus.record.AwsIamRoleRecord) AwsIamRolePermissionRecord(com.nike.cerberus.record.AwsIamRolePermissionRecord) IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Role

use of com.nike.cerberus.domain.Role 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));
}
Also used : Role(com.nike.cerberus.domain.Role) AwsIamRoleRecord(com.nike.cerberus.record.AwsIamRoleRecord) AwsIamRolePermissionRecord(com.nike.cerberus.record.AwsIamRolePermissionRecord) IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Role

use of com.nike.cerberus.domain.Role in project cerberus by Nike-Inc.

the class IamPrincipalPermissionServiceTest method testGrantIamPermissionIfRoleIsPresentByRoleIdAndRoleRecordNotFound.

@Test
public void testGrantIamPermissionIfRoleIsPresentByRoleIdAndRoleRecordNotFound() {
    IamPrincipalPermission iamPrincipalPermission = new IamPrincipalPermission();
    iamPrincipalPermission.setIamPrincipalArn("arn");
    iamPrincipalPermission.setRoleId("roleId");
    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.grantIamPrincipalPermission("boxId", iamPrincipalPermission, "user", OffsetDateTime.MAX);
    Mockito.verify(awsIamRoleDao).createIamRole(Mockito.any(AwsIamRoleRecord.class));
    Mockito.verify(awsIamRoleDao).createIamRolePermission(Mockito.any(AwsIamRolePermissionRecord.class));
}
Also used : Role(com.nike.cerberus.domain.Role) AwsIamRoleRecord(com.nike.cerberus.record.AwsIamRoleRecord) AwsIamRolePermissionRecord(com.nike.cerberus.record.AwsIamRolePermissionRecord) IamPrincipalPermission(com.nike.cerberus.domain.IamPrincipalPermission) Test(org.junit.Test)

Aggregations

Role (com.nike.cerberus.domain.Role)19 Test (org.junit.Test)16 IamPrincipalPermission (com.nike.cerberus.domain.IamPrincipalPermission)5 UserGroupPermission (com.nike.cerberus.domain.UserGroupPermission)5 AwsIamRolePermissionRecord (com.nike.cerberus.record.AwsIamRolePermissionRecord)5 AwsIamRoleRecord (com.nike.cerberus.record.AwsIamRoleRecord)5 UserGroupPermissionRecord (com.nike.cerberus.record.UserGroupPermissionRecord)5 RoleRecord (com.nike.cerberus.record.RoleRecord)3 UserGroupRecord (com.nike.cerberus.record.UserGroupRecord)3 HashSet (java.util.HashSet)3 Transactional (org.springframework.transaction.annotation.Transactional)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SDBMetadata (com.nike.cerberus.domain.SDBMetadata)1 SafeDepositBoxV2 (com.nike.cerberus.domain.SafeDepositBoxV2)1 SafeDepositBoxRecord (com.nike.cerberus.record.SafeDepositBoxRecord)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1