Search in sources :

Example 31 with User

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());
}
Also used : Owner(org.candlepin.model.Owner) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) LinkedList(java.util.LinkedList) Role(org.candlepin.model.Role) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 32 with User

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");
}
Also used : User(org.candlepin.model.User) NotFoundException(org.candlepin.common.exceptions.NotFoundException) Test(org.junit.Test)

Example 33 with User

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());
}
Also used : User(org.candlepin.model.User) Test(org.junit.Test)

Example 34 with User

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));
}
Also used : User(org.candlepin.model.User) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with User

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());
}
Also used : Role(org.candlepin.model.Role) User(org.candlepin.model.User) Test(org.junit.Test)

Aggregations

User (org.candlepin.model.User)49 Test (org.junit.Test)33 Role (org.candlepin.model.Role)14 Owner (org.candlepin.model.Owner)13 HashSet (java.util.HashSet)11 UserPrincipal (org.candlepin.auth.UserPrincipal)10 Principal (org.candlepin.auth.Principal)7 OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)6 PermissionBlueprint (org.candlepin.model.PermissionBlueprint)6 Consumer (org.candlepin.model.Consumer)5 Before (org.junit.Before)5 ApiOperation (io.swagger.annotations.ApiOperation)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 LinkedList (java.util.LinkedList)3 Permission (org.candlepin.auth.permissions.Permission)3 ConsumerType (org.candlepin.model.ConsumerType)3 Ignore (org.junit.Ignore)3 ApiResponses (io.swagger.annotations.ApiResponses)2 Method (java.lang.reflect.Method)2