Search in sources :

Example 16 with UserGroupPermission

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

the class UniqueOwnerValidatorTest method owner_in_group_permissions_is_invalid.

@Test
public void owner_in_group_permissions_is_invalid() {
    UserGroupPermission userGroupPermission = new UserGroupPermission();
    userGroupPermission.setName("owner");
    SafeDepositBoxV1 safeDepositBox1 = new SafeDepositBoxV1();
    safeDepositBox1.setOwner("owner");
    safeDepositBox1.getUserGroupPermissions().add(userGroupPermission);
    SafeDepositBoxV2 safeDepositBox2 = new SafeDepositBoxV2();
    safeDepositBox2.setOwner("owner");
    safeDepositBox2.getUserGroupPermissions().add(userGroupPermission);
    Assert.assertFalse(subject.isValid(safeDepositBox1, mockConstraintValidatorContext));
    Assert.assertFalse(subject.isValid(safeDepositBox2, mockConstraintValidatorContext));
}
Also used : SafeDepositBoxV1(com.nike.cerberus.domain.SafeDepositBoxV1) SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 17 with UserGroupPermission

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

the class UniqueOwnerValidatorTest method unique_owner_is_valid.

@Test
public void unique_owner_is_valid() {
    UserGroupPermission userGroupPermission = new UserGroupPermission();
    userGroupPermission.setName("group");
    SafeDepositBoxV1 safeDepositBox1 = new SafeDepositBoxV1();
    safeDepositBox1.setOwner("owner");
    safeDepositBox1.getUserGroupPermissions().add(userGroupPermission);
    SafeDepositBoxV2 safeDepositBox2 = new SafeDepositBoxV2();
    safeDepositBox2.setOwner("owner");
    safeDepositBox2.getUserGroupPermissions().add(userGroupPermission);
    Assert.assertTrue(subject.isValid(safeDepositBox1, mockConstraintValidatorContext));
    Assert.assertTrue(subject.isValid(safeDepositBox2, mockConstraintValidatorContext));
}
Also used : SafeDepositBoxV1(com.nike.cerberus.domain.SafeDepositBoxV1) SafeDepositBoxV2(com.nike.cerberus.domain.SafeDepositBoxV2) UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 18 with UserGroupPermission

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

the class UserGroupPermissionsValidatorTest method unique_set_is_valid.

@Test
public void unique_set_is_valid() {
    UserGroupPermission a = new UserGroupPermission();
    a.setName("abc");
    UserGroupPermission b = new UserGroupPermission();
    b.setName("def");
    Assert.assertTrue(subject.isValid(Sets.newSet(a, b), mockConstraintValidatorContext));
}
Also used : UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) Test(org.junit.Test)

Example 19 with UserGroupPermission

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

the class PermissionValidationServiceTest method mockUserGroupPermissionWithName.

private Set<UserGroupPermission> mockUserGroupPermissionWithName() {
    UserGroupPermission userGroupPermission = Mockito.mock(UserGroupPermission.class);
    Mockito.when(userGroupPermission.getName()).thenReturn("userGroup1");
    Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
    userGroupPermissions.add(userGroupPermission);
    return userGroupPermissions;
}
Also used : UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) HashSet(java.util.HashSet)

Example 20 with UserGroupPermission

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

the class PermissionValidationServiceTest method testDoesPrincipalHaveReadPermissionWithPrincipalTypeAndGroupsCaseSensitiveHavingUserGroupsInUpperCase.

@Test
public void testDoesPrincipalHaveReadPermissionWithPrincipalTypeAndGroupsCaseSensitiveHavingUserGroupsInUpperCase() {
    PermissionValidationService permissionValidationService = createPermissionValidationServiceWithGroupCaseSensitive(true);
    Set<String> userGroups = new HashSet<>();
    userGroups.add("USERGROUP1");
    CerberusPrincipal cerberusPrincipal = mockCerberusPrincipalWithPrincipalTypeAndUserGroups(PrincipalType.USER, userGroups);
    Set<UserGroupPermission> userGroupPermissions = mockUserGroupPermissionWithName();
    Mockito.when(userGroupPermissionService.getUserGroupPermissions("sdbId")).thenReturn(userGroupPermissions);
    boolean hasPermission = permissionValidationService.doesPrincipalHaveReadPermission(cerberusPrincipal, "sdbId");
    Assert.assertFalse(hasPermission);
}
Also used : UserGroupPermission(com.nike.cerberus.domain.UserGroupPermission) CerberusPrincipal(com.nike.cerberus.security.CerberusPrincipal) HashSet(java.util.HashSet) 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