use of org.candlepin.model.User in project candlepin by candlepin.
the class UserResourceTest method testListAllOwners.
@Test
public void testListAllOwners() {
User user = new User();
user.setUsername("dummyuser" + TestUtil.randomInt());
user.setPassword("password");
userResource.createUser(user);
Owner owner1 = createOwner();
Owner owner2 = createOwner();
Role owner1Role = new Role(owner1.getKey() + " role");
Role owner2Role = new Role(owner2.getKey() + " role");
owner1Role.addPermission(new PermissionBlueprint(PermissionType.OWNER, owner1, Access.ALL));
owner1Role.addPermission(new PermissionBlueprint(PermissionType.OWNER, owner2, Access.READ_ONLY));
owner1Role.addUser(user);
owner2Role.addUser(user);
roleCurator.create(owner1Role);
roleCurator.create(owner2Role);
Set<Permission> perms = new HashSet<>();
perms.add(new OwnerPermission(owner1, Access.ALL));
perms.add(new OwnerPermission(owner2, Access.READ_ONLY));
Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);
// Requesting the list of owners for this user should assume ALL, and not
// return owner2:
Iterable<Owner> response = userResource.listUsersOwners(user.getUsername(), userPrincipal);
List<Owner> owners = new LinkedList<>();
for (Object entity : response) {
owners.add((Owner) entity);
}
assertEquals(1, owners.size());
assertEquals(owner1.getKey(), owners.get(0).getKey());
}
use of org.candlepin.model.User in project candlepin by candlepin.
the class UserResourceTest method testUpdateUsersNoLogin.
@Test
public void testUpdateUsersNoLogin() {
try {
User user = new User();
user.setUsername("henri");
user.setPassword("password");
userResource.updateUser("JarJarIsMyCopilot", user);
} catch (NotFoundException e) {
// this is exptected
return;
}
fail("No exception was thrown");
}
use of org.candlepin.model.User in project candlepin by candlepin.
the class UserResourceTest method testUpdateUsers.
@Test
public void testUpdateUsers() {
User user = new User();
user.setUsername("henri");
user.setPassword("password");
userResource.createUser(user);
User update = new User();
update.setUsername("Luke");
update.setHashedPassword("Skywalker");
update.setSuperAdmin(true);
User updated = userResource.updateUser("henri", update);
assertEquals("Luke", updated.getUsername());
assertEquals("Skywalker", updated.getHashedPassword());
assertTrue(updated.isSuperAdmin());
}
use of org.candlepin.model.User in project candlepin by candlepin.
the class DefaultUserServiceAdapterTest method ownerAdminRole.
@Test
@Ignore("Find a way to do this with permissions")
public void ownerAdminRole() {
User user = new User("regular_user", "password");
this.service.createUser(user);
Assert.assertTrue(this.service.findByLogin("regular_user").getRoles().contains(Access.ALL));
}
use of org.candlepin.model.User in project candlepin by candlepin.
the class DefaultUserServiceAdapterTest method addUserToRole.
@Test
public void addUserToRole() {
Role adminRole = createAdminRole(owner);
roleCurator.create(adminRole);
User user = new User("testuser", "password");
service.createUser(user);
service.addUserToRole(adminRole, user);
adminRole = service.getRole(adminRole.getId());
assertEquals(1, adminRole.getUsers().size());
}
Aggregations