Search in sources :

Example 11 with UserGroupPermission

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

the class UserGroupPermissionServiceTest method testRevokeUserGroupPermissionWhenGroupRecordIsNotPresentForGivenName.

@Test
public void testRevokeUserGroupPermissionWhenGroupRecordIsNotPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
    String exceptionMessage = "";
    List<ApiError> apiErrors = new ArrayList<>();
    try {
        userGroupPermissionService.revokeUserGroupPermission("safeBoxId", userGroupPermission);
    } catch (ApiException apiException) {
        exceptionMessage = apiException.getMessage();
        apiErrors = apiException.getApiErrors();
    }
    String expectedExceptionMessage = "Unable to revoke 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 12 with UserGroupPermission

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

the class UserGroupPermissionServiceTest method testRevokeUserGroupPermissionWhenGroupRecordIsPresentForGivenName.

@Test
public void testRevokeUserGroupPermissionWhenGroupRecordIsPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Optional<UserGroupRecord> userGroupRecord = getUserGroup();
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
    userGroupPermissionService.revokeUserGroupPermission("safeBoxId", userGroupPermission);
    Mockito.verify(userGroupDao).deleteUserGroupPermission("safeBoxId", userGroupRecord.get().getId());
}
Also used : UserGroupRecord(com.nike.cerberus.record.UserGroupRecord) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 13 with UserGroupPermission

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

the class UserGroupPermissionServiceTest method testRevokeUserGroupPermissionsWhenGroupRecordIsNotPresentForGivenName.

@Test
public void testRevokeUserGroupPermissionsWhenGroupRecordIsNotPresentForGivenName() {
    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.revokeUserGroupPermissions("safeBoxId", userGroupPermissions);
    } catch (ApiException apiException) {
        exceptionMessage = apiException.getMessage();
        apiErrors = apiException.getApiErrors();
    }
    String expectedExceptionMessage = "Unable to revoke 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 14 with UserGroupPermission

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

the class UserGroupPermissionServiceTest method testUpdateUserGroupPermissionWhenGroupRecordIsPresentForGivenName.

@Test
public void testUpdateUserGroupPermissionWhenGroupRecordIsPresentForGivenName() {
    UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
    Optional<UserGroupRecord> userGroupRecord = getUserGroup();
    Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
    userGroupPermissionService.updateUserGroupPermission("safeBoId", userGroupPermission, "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 15 with UserGroupPermission

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

the class UserGroupPermissionsValidator method isValid.

public boolean isValid(Set<UserGroupPermission> userGroupPermissionSet, ConstraintValidatorContext context) {
    if (userGroupPermissionSet == null || userGroupPermissionSet.isEmpty()) {
        return true;
    }
    boolean isValid = true;
    Set<String> userGroups = new HashSet<>();
    for (UserGroupPermission userGroupPermission : userGroupPermissionSet) {
        if (userGroups.contains(userGroupPermission.getName())) {
            isValid = false;
            break;
        } else {
            userGroups.add(userGroupPermission.getName());
        }
    }
    return isValid;
}
Also used : UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) HashSet(java.util.HashSet)

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