Search in sources :

Example 31 with UserGroupPermission

use of com.nike.cerberus.domain.UserGroupPermission 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 32 with UserGroupPermission

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

the class UserGroupPermissionServiceTest method testUpdateUserGroupPermissionWhenGroupRecordIsNotPresentForGivenName.

@Test
public void testUpdateUserGroupPermissionWhenGroupRecordIsNotPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
    String exceptionMessage = "";
    List<ApiError> apiErrors = new ArrayList<>();
    try {
        userGroupPermissionService.updateUserGroupPermission("safeBoId", userGroupPermission, "user", OffsetDateTime.MAX);
    } catch (ApiException apiException) {
        apiErrors = apiException.getApiErrors();
        exceptionMessage = apiException.getMessage();
    }
    String expectedExceptionMessage = "Unable to update permissions for user group name that doesn't exist.";
    Assert.assertFalse(apiErrors.isEmpty());
    Assert.assertEquals(expectedExceptionMessage, exceptionMessage);
}
Also used : UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) DefaultApiError(com.nike.cerberus.error.DefaultApiError) ApiError(com.nike.backstopper.apierror.ApiError) ApiException(com.nike.backstopper.exception.ApiException) Test(org.junit.Test)

Example 33 with UserGroupPermission

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

the class UserGroupPermissionServiceTest method mockUserGroupPermissionWithNameAndRoleId.

private UserGroupPermission mockUserGroupPermissionWithNameAndRoleId(String name, String roleId) {
    UserGroupPermission userGroupPermission = Mockito.mock(UserGroupPermission.class);
    Mockito.when(userGroupPermission.getName()).thenReturn(name);
    Mockito.when(userGroupPermission.getRoleId()).thenReturn(roleId);
    return userGroupPermission;
}
Also used : UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission)

Example 34 with UserGroupPermission

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

the class UserGroupPermissionServiceTest method testUpdateUserGroupPermissionsWhenGroupRecordIsPresentForGivenName.

@Test
public void testUpdateUserGroupPermissionsWhenGroupRecordIsPresentForGivenName() {
    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.updateUserGroupPermissions("safeBoId", userGroupPermissions, "user", OffsetDateTime.MAX);
    Mockito.verify(userGroupDao).updateUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
Also used : UserGroupRecord(com.nike.cerberus.record.UserGroupRecord) UserGroupPermissionRecord(com.nike.cerberus.record.UserGroupPermissionRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 35 with UserGroupPermission

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

the class UserGroupPermissionServiceTest method testUpdateUserGroupPermissionsWhenGroupRecordIsNotPresentForGivenName.

@Test
public void testUpdateUserGroupPermissionsWhenGroupRecordIsNotPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
    userGroupPermissions.add(userGroupPermission);
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
    String exceptionMessage = "";
    List<ApiError> apiErrors = new ArrayList<>();
    try {
        userGroupPermissionService.updateUserGroupPermissions("safeBoId", userGroupPermissions, "user", OffsetDateTime.MAX);
    } catch (ApiException apiException) {
        apiErrors = apiException.getApiErrors();
        exceptionMessage = apiException.getMessage();
    }
    String expectedExceptionMessage = "Unable to update permissions for user group name that doesn't exist.";
    Assert.assertFalse(apiErrors.isEmpty());
    Assert.assertEquals(expectedExceptionMessage, exceptionMessage);
}
Also used : UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) DefaultApiError(com.nike.cerberus.error.DefaultApiError) ApiError(com.nike.backstopper.apierror.ApiError) ApiException(com.nike.backstopper.exception.ApiException) Test(org.junit.Test)

Aggregations

UserGroupPermission (com.nike.cerberus.domain.UserGroupPermission)38 Test (org.junit.Test)34 HashSet (java.util.HashSet)17 SafeDepositBoxV2 (com.nike.cerberus.domain.SafeDepositBoxV2)15 UserGroupPermissionRecord (com.nike.cerberus.record.UserGroupPermissionRecord)8 UserGroupRecord (com.nike.cerberus.record.UserGroupRecord)8 IamPrincipalPermission (com.nike.cerberus.domain.IamPrincipalPermission)6 ApiError (com.nike.backstopper.apierror.ApiError)5 ApiException (com.nike.backstopper.exception.ApiException)5 Role (com.nike.cerberus.domain.Role)5 DefaultApiError (com.nike.cerberus.error.DefaultApiError)5 SafeDepositBoxV1 (com.nike.cerberus.domain.SafeDepositBoxV1)4 CerberusPrincipal (com.nike.cerberus.security.CerberusPrincipal)4 OffsetDateTime (java.time.OffsetDateTime)3 IamRolePermission (com.nike.cerberus.domain.IamRolePermission)2 SDBMetadata (com.nike.cerberus.domain.SDBMetadata)2 SafeDepositBoxRecord (com.nike.cerberus.record.SafeDepositBoxRecord)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1