Search in sources :

Example 16 with ExpectValidationException

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

the class UsersServiceTest method cantDisableSelfEvenWithExplicitEditPermission.

@Test
@ExpectValidationException("disabled")
public void cantDisableSelfEvenWithExplicitEditPermission() {
    User vo = insertUser(editRole, readRole);
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        self.setDisabled(true);
        service.update(self.getId(), self);
    });
}
Also used : User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 17 with ExpectValidationException

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

the class UsersServiceTest method cantAddRolesToSelf.

@Test
@ExpectValidationException("roles")
public void cantAddRolesToSelf() {
    setEditSelfPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
    User vo = newVO(null);
    vo.setRoles(Collections.singleton(editRole));
    vo.setEditPermission(MangoPermission.superadminOnly());
    service.insert(vo);
    runAs.runAs(vo, () -> {
        User self = service.get(vo.getId());
        self.setRoles(Stream.concat(self.getRoles().stream(), Stream.of(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)

Example 18 with ExpectValidationException

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

the class UsersServiceTest method testChangeUsernameWithoutPermission.

@Test
@ExpectValidationException("username")
public void testChangeUsernameWithoutPermission() {
    setEditSelfPermission(MangoPermission.requireAnyRole(readRole));
    PermissionDefinition def = ModuleRegistry.getPermissionDefinition(ChangeOwnUsernamePermissionDefinition.PERMISSION);
    Set<Set<Role>> roleSet = def.getPermission().getRoles();
    Set<Set<Role>> newRoles = new HashSet<>();
    newRoles.add(Collections.singleton(editRole));
    for (Set<Role> roles : roleSet) {
        if (roles.contains(PermissionHolder.USER_ROLE)) {
            // skip the user role
            continue;
        }
        newRoles.add(roles);
    }
    systemPermissionService.update(new MangoPermission(newRoles), def);
    User vo = newVO(readUser);
    vo.setRoles(Collections.singleton(readRole));
    service.insert(vo);
    User saved = service.get(vo.getId());
    runAs.runAs(saved, () -> {
        saved.setUsername(randomXid());
        service.update(saved.getId(), saved);
    });
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) ChangeOwnUsernamePermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.ChangeOwnUsernamePermissionDefinition) PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) HashSet(java.util.HashSet) Set(java.util.Set) User(com.serotonin.m2m2.vo.User) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 19 with ExpectValidationException

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

the class UsersServiceTest method cantChangeSessionExpirationOfSelf.

@Test
@ExpectValidationException({ "sessionExpirationOverride", "sessionExpirationPeriods", "sessionExpirationPeriodType" })
public void cantChangeSessionExpirationOfSelf() {
    User user = insertUser();
    runAs.runAs(user, () -> {
        User self = service.get(user.getId());
        self.setSessionExpirationOverride(true);
        self.setSessionExpirationPeriods(5);
        self.setSessionExpirationPeriodType("MINUTES");
        service.update(self.getId(), self);
    });
}
Also used : User(com.serotonin.m2m2.vo.User) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 20 with ExpectValidationException

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

the class MaintenanceEventsServiceTest method testCannotRemoveToggleAccess.

@Test
@ExpectValidationException("togglePermission")
public void testCannotRemoveToggleAccess() {
    MaintenanceEventVO vo = newVO(editUser);
    setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    service.insert(vo);
    runAs.runAs(readUser, () -> {
        MaintenanceEventVO fromDb = service.get(vo.getId());
        assertVoEqual(vo, fromDb);
        fromDb.setTogglePermission(MangoPermission.superadminOnly());
        service.update(fromDb.getId(), fromDb);
    });
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) 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