Search in sources :

Example 1 with ExpectValidationException

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

the class SetPointEventHandlerServiceTest method testCannotInsertUnauthorizedScriptRole.

@Test
@ExpectValidationException("scriptRoles")
public void testCannotInsertUnauthorizedScriptRole() {
    addRoleToCreatePermission(editRole);
    SetPointEventHandlerVO 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 : SetPointEventHandlerVO(com.serotonin.m2m2.vo.event.SetPointEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 2 with ExpectValidationException

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

the class SetPointEventHandlerServiceTest method testCannotUpdateUnauthorizedScriptRole.

@Test
@ExpectValidationException("scriptRoles")
public void testCannotUpdateUnauthorizedScriptRole() {
    addRoleToCreatePermission(editRole);
    SetPointEventHandlerVO 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, () -> {
        SetPointEventHandlerVO fromDb = (SetPointEventHandlerVO) service.insert(vo);
        ScriptPermissions newPermissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
        fromDb.setScriptRoles(newPermissions);
        service.update(fromDb.getId(), fromDb);
    });
}
Also used : SetPointEventHandlerVO(com.serotonin.m2m2.vo.event.SetPointEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 3 with ExpectValidationException

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

the class MailingListServiceTest method testRecursiveMailingListsAreInvalid.

@Test
@ExpectValidationException("recipients[0]")
public void testRecursiveMailingListsAreInvalid() {
    MailingList recursiveMailingList = service.insert(newVO(readUser));
    List<MailingListRecipient> entries = new ArrayList<>();
    recursiveMailingList.setEntries(entries);
    MailingListEntry ml = new MailingListEntry();
    ml.setMailingListId(recursiveMailingList.getId());
    entries.add(ml);
    service.update(recursiveMailingList.getId(), recursiveMailingList);
}
Also used : MailingListEntry(com.serotonin.m2m2.vo.mailingList.MailingListEntry) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ArrayList(java.util.ArrayList) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 4 with ExpectValidationException

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

the class RoleServiceTest method cannotModifyUserRole.

@Test
@ExpectValidationException("xid")
public void cannotModifyUserRole() {
    RoleVO vo = service.get(PermissionHolder.USER_ROLE_XID);
    RoleVO updated = new RoleVO(Common.NEW_ID, vo.getXid(), vo.getName());
    service.update(vo.getXid(), updated);
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 5 with ExpectValidationException

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

the class RoleServiceTest method cannotInsertSuperadminRole.

@Test
@ExpectValidationException("xid")
public void cannotInsertSuperadminRole() {
    RoleVO vo = new RoleVO(Common.NEW_ID, PermissionHolder.SUPERADMIN_ROLE_XID, "Superadmin default");
    service.insert(vo);
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) 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