Search in sources :

Example 11 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cantAddAdditionalRolesWhenCreating.

@Test
@ExpectValidationException("roles")
public void cantAddAdditionalRolesWhenCreating() {
    Role roleToAdd = createRole(randomXid(), "Some other role").getRole();
    Role createRole = createUsersRole();
    User createUser = insertUser(createRole, editRole, readRole);
    runAs.runAs(createUser, () -> {
        insertUser(roleToAdd);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 12 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cannotAllowAccessToRoleWeDontHold.

@Test
@ExpectValidationException({ "readPermission", "editPermission" })
public void cannotAllowAccessToRoleWeDontHold() {
    Role otherRole = createRole(randomXid(), "Some other role").getRole();
    User otherUser = insertUser();
    User user = insertUser(editRole, readRole);
    runAs.runAs(user, () -> {
        otherUser.setReadPermission(MangoPermission.requireAnyRole(readRole, otherRole));
        otherUser.setEditPermission(MangoPermission.requireAnyRole(editRole, otherRole));
        service.update(otherUser.getId(), otherUser);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 13 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.

the class EmailEventHandlerServiceTest method testCannotInsertUnauthorizedScriptRole.

@Test
@ExpectValidationException("scriptRoles")
public void testCannotInsertUnauthorizedScriptRole() {
    addRoleToCreatePermission(editRole);
    EmailEventHandlerVO vo = newVO(editUser);
    vo.setReadPermission(MangoPermission.requireAnyRole(editRole));
    vo.setEditPermission(MangoPermission.requireAnyRole(editRole));
    ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
    vo.setScriptRoles(permissions);
    runAs.runAs(editUser, () -> {
        service.insert(vo);
    });
}
Also used : EmailEventHandlerVO(com.serotonin.m2m2.vo.event.EmailEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 14 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.

the class UsersServiceTest method testRemoveRolesFails.

@Test
@ExpectValidationException("roles")
public void testRemoveRolesFails() {
    User vo = newVO(null);
    vo.setRoles(Collections.singleton(readRole));
    service.insert(vo);
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        self.setRoles(Collections.emptySet());
        service.update(self.getId(), self);
    });
}
Also used : User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 15 with ExpectValidationException

use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.

the class UsersServiceTest method cantRemoveRolesFromSelfWithExplicitEditPermission.

@Test
@ExpectValidationException("roles")
public void cantRemoveRolesFromSelfWithExplicitEditPermission() {
    setEditSelfPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
    User vo = insertUser(editRole, readRole);
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        self.setRoles(self.getRoles().stream().filter(r -> !r.equals(readRole)).collect(Collectors.toSet()));
        service.update(self.getId(), self);
    });
}
Also used : User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Aggregations

ExpectValidationException (com.infiniteautomation.mango.rules.ExpectValidationException)33 Test (org.junit.Test)33 User (com.serotonin.m2m2.vo.User)21 Role (com.serotonin.m2m2.vo.role.Role)9 ScriptPermissions (com.infiniteautomation.mango.util.script.ScriptPermissions)4 RoleVO (com.serotonin.m2m2.vo.role.RoleVO)4 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)2 EmailEventHandlerVO (com.serotonin.m2m2.vo.event.EmailEventHandlerVO)2 SetPointEventHandlerVO (com.serotonin.m2m2.vo.event.SetPointEventHandlerVO)2 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)2 HashSet (java.util.HashSet)2 MaintenanceEventVO (com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO)1 PermissionDefinition (com.serotonin.m2m2.module.PermissionDefinition)1 ChangeOwnUsernamePermissionDefinition (com.serotonin.m2m2.module.definitions.permissions.ChangeOwnUsernamePermissionDefinition)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 MailingListEntry (com.serotonin.m2m2.vo.mailingList.MailingListEntry)1 MailingListRecipient (com.serotonin.m2m2.vo.mailingList.MailingListRecipient)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Set (java.util.Set)1