use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.
the class UsersServiceTest method cantAddAdditionalRolesWhenCreating.
@Test
@ExpectValidationException("roles")
public void cantAddAdditionalRolesWhenCreating() {
Role roleToAdd = createRole(randomXid(), "Some other role").getRole();
Role createRole = createUsersRole();
User createUser = insertUser(createRole, editRole, readRole);
runAs.runAs(createUser, () -> {
insertUser(roleToAdd);
});
}
use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.
the class UsersServiceTest method cannotAllowAccessToRoleWeDontHold.
@Test
@ExpectValidationException({ "readPermission", "editPermission" })
public void cannotAllowAccessToRoleWeDontHold() {
Role otherRole = createRole(randomXid(), "Some other role").getRole();
User otherUser = insertUser();
User user = insertUser(editRole, readRole);
runAs.runAs(user, () -> {
otherUser.setReadPermission(MangoPermission.requireAnyRole(readRole, otherRole));
otherUser.setEditPermission(MangoPermission.requireAnyRole(editRole, otherRole));
service.update(otherUser.getId(), otherUser);
});
}
use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.
the class EmailEventHandlerServiceTest method testCannotInsertUnauthorizedScriptRole.
@Test
@ExpectValidationException("scriptRoles")
public void testCannotInsertUnauthorizedScriptRole() {
addRoleToCreatePermission(editRole);
EmailEventHandlerVO 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);
});
}
use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.
the class UsersServiceTest method testRemoveRolesFails.
@Test
@ExpectValidationException("roles")
public void testRemoveRolesFails() {
User vo = newVO(null);
vo.setRoles(Collections.singleton(readRole));
service.insert(vo);
runAs.runAs(vo, () -> {
User self = service.get(vo.getId());
self.setRoles(Collections.emptySet());
service.update(self.getId(), self);
});
}
use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.
the class UsersServiceTest method cantRemoveRolesFromSelfWithExplicitEditPermission.
@Test
@ExpectValidationException("roles")
public void cantRemoveRolesFromSelfWithExplicitEditPermission() {
setEditSelfPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
User vo = insertUser(editRole, readRole);
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);
});
}
Aggregations