use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class SafeDepositBoxServiceTest method test_that_validates_user_AD_group_name.
@Test
public void test_that_validates_user_AD_group_name() {
String id = "111";
String categoryId = "222";
String readId = "333";
String sdbName = "HEALTH CHECK BUCKET";
SafeDepositBoxV2 sdbObject = new SafeDepositBoxV2();
sdbObject.setId(id);
sdbObject.setPath("app/health-check-bucket/");
sdbObject.setCategoryId(categoryId);
sdbObject.setName(sdbName);
sdbObject.setOwner("app.mock.test");
sdbObject.setDescription("This SDB is read by the Health Check Lambda...");
sdbObject.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
sdbObject.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
sdbObject.setCreatedBy("foobar@nike.com");
sdbObject.setLastUpdatedBy("foobar@nike.com");
safeDepositBoxService.adGroupNamePrefix = "app.mock";
Set<UserGroupPermission> userPerms = new HashSet<>();
userPerms.add(new UserGroupPermission().withName("app.mock.foo").withRoleId(readId));
userPerms.add(new UserGroupPermission().withName("app.mock.blah").withRoleId(readId));
sdbObject.setUserGroupPermissions(userPerms);
safeDepositBoxService.validateUserGroupName(sdbObject);
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class SafeDepositBoxServiceTest method test_that_validates_user_group_sanitization.
@Test
public void test_that_validates_user_group_sanitization() {
String id = "111";
String categoryId = "222";
String readId = "333";
String sdbName = "HEALTH CHECK BUCKET";
SafeDepositBoxV2 sdbObject = new SafeDepositBoxV2();
sdbObject.setId(id);
sdbObject.setPath("app/health-check-bucket/");
sdbObject.setCategoryId(categoryId);
sdbObject.setName(sdbName);
sdbObject.setOwner("app.mock.test");
sdbObject.setDescription("This SDB is read by the Health Check Lambda...");
sdbObject.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
sdbObject.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
sdbObject.setCreatedBy("foobar@nike.com");
sdbObject.setLastUpdatedBy("foobar@nike.com");
Set<UserGroupPermission> userPerms = new HashSet<>();
userPerms.add(new UserGroupPermission().withName("app.Mock.blah").withRoleId(readId));
userPerms.add(new UserGroupPermission().withName("app.mock.blah").withRoleId(readId));
sdbObject.setUserGroupPermissions(userPerms);
safeDepositBoxService.sanitizeUserGroupPermissions(sdbObject);
assertEquals(sdbObject.getUserGroupPermissions().size(), 1);
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testGrantUserGroupPermissionsWhenUserGroupRecordIsPresentForGivenName.
@Test
public void testGrantUserGroupPermissionsWhenUserGroupRecordIsPresentForGivenName() {
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);
Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
userGroupPermissions.add(userGroupPermission);
userGroupPermissionService.grantUserGroupPermissions("safeBoxId", userGroupPermissions, "user", OffsetDateTime.MAX);
Mockito.verify(userGroupDao).createUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testGetUserGroupPermissionsForGivenSafeBoxIdWhenUserGroupPermissionRecordPresent.
@Test
public void testGetUserGroupPermissionsForGivenSafeBoxIdWhenUserGroupPermissionRecordPresent() {
UserGroupPermissionRecord userGroupPermissionRecord = getUserGroupPermissionRecord();
List<UserGroupPermissionRecord> userGroupPermissionRecords = new ArrayList<>();
userGroupPermissionRecords.add(userGroupPermissionRecord);
Mockito.when(userGroupDao.getUserGroupPermissions("safeBoxId")).thenReturn(userGroupPermissionRecords);
Optional<UserGroupRecord> userGroupRecord = getUserGroup();
Mockito.when(userGroupDao.getUserGroup("id")).thenReturn(userGroupRecord);
Set<UserGroupPermission> userGroupPermissions = userGroupPermissionService.getUserGroupPermissions("safeBoxId");
Assert.assertFalse(userGroupPermissions.isEmpty());
Assert.assertEquals(1, userGroupPermissions.size());
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testRevokeUserGroupPermissionsWhenGroupRecordIsPresentForGivenName.
@Test
public void testRevokeUserGroupPermissionsWhenGroupRecordIsPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
userGroupPermissions.add(userGroupPermission);
Optional<UserGroupRecord> userGroupRecord = getUserGroup();
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
userGroupPermissionService.revokeUserGroupPermissions("safeBoxId", userGroupPermissions);
Mockito.verify(userGroupDao).deleteUserGroupPermission("safeBoxId", userGroupRecord.get().getId());
}
Aggregations