use of com.serotonin.m2m2.vo.role.Role 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());
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method testDeleteRoleUpdateVO.
@Test
@Override
public void testDeleteRoleUpdateVO() {
User vo = newVO(readUser);
vo.setRoles(Collections.singleton(readRole));
service.insert(vo);
User fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
roleService.delete(readRole.getId());
// Remove the read role from the local copy
Set<Role> roles = new HashSet<>(fromDb.getRoles());
roles.remove(readRole);
fromDb.setRoles(roles);
// Check database
User updated = service.get(fromDb.getId());
assertVoEqual(fromDb, updated);
// Check cache
updated = service.get(fromDb.getUsername());
assertVoEqual(fromDb, updated);
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method canChangePermissionsOfSelfWithExplicitPermission.
@Test
public void canChangePermissionsOfSelfWithExplicitPermission() {
Role otherRole = createRole(randomXid(), "Some other role").getRole();
User vo = insertUser(editRole, readRole, otherRole);
runAs.runAs(vo, () -> {
User self = service.get(vo.getId());
self.setReadPermission(MangoPermission.requireAnyRole(otherRole));
self.setEditPermission(MangoPermission.requireAnyRole(otherRole));
service.update(self.getId(), self);
});
}
use of com.serotonin.m2m2.vo.role.Role 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.serotonin.m2m2.vo.role.Role 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);
});
}
Aggregations