Search in sources :

Example 11 with Role

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

the class RoleServiceTest method testGetAllRolesWhenRoleRecordsArePresent.

@Test
public void testGetAllRolesWhenRoleRecordsArePresent() {
    List<RoleRecord> roleRecords = new ArrayList<>();
    RoleRecord roleRecord = createRoleRecord();
    roleRecords.add(roleRecord);
    Mockito.when(roleDao.getAllRoles()).thenReturn(roleRecords);
    List<Role> allRoles = roleService.getAllRoles();
    Assert.assertFalse(allRoles.isEmpty());
    Assert.assertEquals(1, allRoles.size());
}
Also used : Role(com.nike.cerberus.domain.Role) RoleRecord(com.nike.cerberus.record.RoleRecord) Test(org.junit.Test)

Example 12 with Role

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

the class RoleServiceTest method testGetRoleByIdIfRoleIsPresentForGivenId.

@Test
public void testGetRoleByIdIfRoleIsPresentForGivenId() {
    RoleRecord roleRecord = createRoleRecord();
    Mockito.when(roleDao.getRoleById("id")).thenReturn(Optional.of(roleRecord));
    Optional<Role> roleById = roleService.getRoleById("id");
    Assert.assertTrue(roleById.isPresent());
}
Also used : Role(com.nike.cerberus.domain.Role) RoleRecord(com.nike.cerberus.record.RoleRecord) Test(org.junit.Test)

Example 13 with Role

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

the class SafeDepositBoxServiceTest method test_that_deleteSafeDepositBox_deletes_permissions_secrets_and_versions.

@Test
public void test_that_deleteSafeDepositBox_deletes_permissions_secrets_and_versions() {
    String sdbPathNoCategory = "safedepositbox-zzz-fake";
    String sdbPath = "category/" + sdbPathNoCategory;
    String sdbId = "sdb id";
    SafeDepositBoxRecord safeDepositBox = new SafeDepositBoxRecord().setId(sdbId).setPath(sdbPath);
    when(safeDepositBoxDao.getSafeDepositBox(sdbId)).thenReturn(Optional.of(safeDepositBox));
    when(roleService.getRoleByName(RoleRecord.ROLE_OWNER)).thenReturn(Optional.of(new Role()));
    safeDepositBoxService.deleteSafeDepositBox(sdbId);
    verify(iamPrincipalPermissionService).deleteIamPrincipalPermissions(sdbId);
    verify(userGroupPermissionService).deleteUserGroupPermissions(sdbId);
    verify(secureDataVersionDao).deleteAllVersionsThatStartWithPartialPath(sdbPathNoCategory);
    verify(secureDataService).deleteAllSecretsThatStartWithGivenPartialPath(sdbId, sdbPathNoCategory);
}
Also used : Role(com.nike.cerberus.domain.Role) SafeDepositBoxRecord(com.nike.cerberus.record.SafeDepositBoxRecord) Test(org.junit.Test)

Example 14 with Role

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

the class UserGroupPermissionServiceTest method testGrantUserGroupPermissionWhenUserGroupRecordIsPresentForGivenName.

@Test
public void testGrantUserGroupPermissionWhenUserGroupRecordIsPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Role role = Mockito.mock(Role.class);
    Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
    Optional<UserGroupRecord> userGroupRecord = getUserGroup();
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
    userGroupPermissionService.grantUserGroupPermission("safeBoxId", userGroupPermission, "user", OffsetDateTime.MAX);
    Mockito.verify(userGroupDao).createUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
Also used : Role(com.nike.cerberus.domain.Role) UserGroupRecord(com.nike.cerberus.record.UserGroupRecord) UserGroupPermissionRecord(com.nike.cerberus.record.UserGroupPermissionRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 15 with Role

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

the class UserGroupPermissionServiceTest method testGrantUserGroupPermissionsWhenUserGroupRecordIsNotPresentForGivenName.

@Test
public void testGrantUserGroupPermissionsWhenUserGroupRecordIsNotPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
    userGroupPermissions.add(userGroupPermission);
    Role role = Mockito.mock(Role.class);
    Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
    userGroupPermissionService.grantUserGroupPermissions("safeBoxId", userGroupPermissions, "user", OffsetDateTime.MAX);
    Mockito.verify(userGroupDao).createUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
Also used : Role(com.nike.cerberus.domain.Role) UserGroupPermissionRecord(com.nike.cerberus.record.UserGroupPermissionRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) 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