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());
}
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());
}
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);
}
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));
}
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));
}
Aggregations