Search in sources :

Example 31 with ExpectValidationException

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

the class UsersServiceTest method cantAddAdditionalRolesWhenUpdating.

@Test
@ExpectValidationException("roles")
public void cantAddAdditionalRolesWhenUpdating() {
    Role roleToAdd = createRole(randomXid(), "Some other role").getRole();
    Role createRole = createUsersRole();
    User createUser = insertUser(createRole, editRole, readRole);
    User otherUser = insertUser();
    runAs.runAs(createUser, () -> {
        otherUser.setRoles(Collections.singleton(roleToAdd));
        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 32 with ExpectValidationException

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

the class DataPointServiceTest method testSetRolesCannotBeNull.

@Test
@ExpectValidationException("setPermission")
public void testSetRolesCannotBeNull() {
    DataPointVO vo = newVO(editUser);
    setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    vo.setSetPermission(null);
    service.insert(vo);
    runAs.runAs(readUser, () -> {
        DataPointVO fromDb = service.get(vo.getId());
        assertVoEqual(vo, fromDb);
        fromDb.setName("read user edited me");
        fromDb.setSetPermission(new MangoPermission());
        service.update(fromDb.getXid(), fromDb);
    });
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 33 with ExpectValidationException

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

the class EmailEventHandlerServiceTest method testCannotUpdateUnauthorizedScriptRole.

@Test
@ExpectValidationException("scriptRoles")
public void testCannotUpdateUnauthorizedScriptRole() {
    addRoleToCreatePermission(editRole);
    EmailEventHandlerVO vo = newVO(editUser);
    vo.setReadPermission(MangoPermission.requireAnyRole(editRole));
    vo.setEditPermission(MangoPermission.requireAnyRole(editRole));
    ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(editRole));
    vo.setScriptRoles(permissions);
    runAs.runAs(editUser, () -> {
        EmailEventHandlerVO fromDb = (EmailEventHandlerVO) service.insert(vo);
        ScriptPermissions newPermissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
        fromDb.setScriptRoles(newPermissions);
        service.update(fromDb.getId(), fromDb);
    });
}
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)

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