Search in sources :

Example 6 with ExpectValidationException

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

the class UsersServiceTest method mustRetainAccess.

@Test
@ExpectValidationException({ "readPermission", "editPermission" })
public void mustRetainAccess() {
    Role otherRole = createRole(randomXid(), "Some other role").getRole();
    User otherUser = insertUser();
    User user = insertUser(editRole, readRole);
    runAs.runAs(user, () -> {
        otherUser.setReadPermission(MangoPermission.requireAnyRole(otherRole));
        otherUser.setEditPermission(MangoPermission.requireAnyRole(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 7 with ExpectValidationException

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

the class UsersServiceTest method cantCreateUserYouCantRead.

@Test
@ExpectValidationException("readPermission")
public void cantCreateUserYouCantRead() {
    Role createRole = createUsersRole();
    User createUser = insertUser(editRole, createRole);
    // noinspection Convert2MethodRef
    runAs.runAs(createUser, () -> insertUser());
}
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 8 with ExpectValidationException

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

the class UsersServiceTest method cantChangeCreatedTimeOfSelf.

@Test
@ExpectValidationException("created")
public void cantChangeCreatedTimeOfSelf() {
    User user = insertUser();
    runAs.runAs(user, () -> {
        User self = service.get(user.getId());
        Date differentDate = new Date(self.getCreated().getTime() + 1);
        self.setCreated(differentDate);
        service.update(self.getId(), self);
    });
}
Also used : User(com.serotonin.m2m2.vo.User) Date(java.util.Date) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 9 with ExpectValidationException

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

the class UsersServiceTest method cantAddRolesToSelfWithExplicitEditPermission.

@Test
@ExpectValidationException("roles")
public void cantAddRolesToSelfWithExplicitEditPermission() {
    setEditSelfPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
    User vo = insertUser(editRole);
    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 10 with ExpectValidationException

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

the class UsersServiceTest method cantDisableSelf.

@Test
@ExpectValidationException("disabled")
public void cantDisableSelf() {
    setEditSelfPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
    User vo = insertUser();
    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)

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