Search in sources :

Example 21 with ExpectValidationException

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

the class MailingListServiceTest method testAddMissingEditRole.

@Test
@ExpectValidationException("editPermission")
public void testAddMissingEditRole() {
    MailingList vo = newVO(readUser);
    Role role = new Role(10000, "new-role");
    Set<Role> editRoles = Collections.singleton(role);
    vo.setEditPermission(MangoPermission.requireAnyRole(editRoles));
    service.insert(vo);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 22 with ExpectValidationException

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

the class RoleServiceTest method cannotInsertNewUserRole.

@Test
@ExpectValidationException("xid")
public void cannotInsertNewUserRole() {
    RoleVO vo = new RoleVO(Common.NEW_ID, PermissionHolder.USER_ROLE_XID, "user default");
    service.insert(vo);
}
Also used : RoleVO(com.serotonin.m2m2.vo.role.RoleVO) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 23 with ExpectValidationException

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

the class UsersServiceTest method testAddEditRoleUserDoesNotHave.

@Test
@Override
@ExpectValidationException("roles")
public void testAddEditRoleUserDoesNotHave() {
    User vo = newVO(readUser);
    vo.setRoles(Collections.singleton(readRole));
    service.insert(vo);
    // Ensure the ability to edit self
    setEditSelfPermission(MangoPermission.requireAnyRole(readRole));
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        Set<Role> newRoles = new HashSet<>(self.getRoles());
        newRoles.add(editRole);
        self.setRoles(newRoles);
        service.update(self.getId(), self);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) User(com.serotonin.m2m2.vo.User) HashSet(java.util.HashSet) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 24 with ExpectValidationException

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

the class RoleServiceTest method cannotModifySuperadminRole.

@Test
@ExpectValidationException("xid")
public void cannotModifySuperadminRole() {
    RoleVO vo = service.get(PermissionHolder.SUPERADMIN_ROLE_XID);
    RoleVO updated = new RoleVO(Common.NEW_ID, vo.getXid(), "Superadmin default changed");
    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 25 with ExpectValidationException

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

the class UsersServiceTest method cantRemoveRolesFromSelf.

@Test
@ExpectValidationException("roles")
public void cantRemoveRolesFromSelf() {
    setEditSelfPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
    User vo = newVO(null);
    vo.setRoles(new HashSet<>(Arrays.asList(editRole, readRole)));
    vo.setEditPermission(MangoPermission.superadminOnly());
    service.insert(vo);
    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