Search in sources :

Example 6 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class UserResourceTest method testListOwnersForMySystemsAdmin.

@Test
public void testListOwnersForMySystemsAdmin() {
    User user = new User();
    user.setUsername("dummyuser" + TestUtil.randomInt());
    user.setPassword("password");
    userResource.createUser(user);
    Owner owner1 = createOwner();
    Role owner1Role = new Role(owner1.getKey() + " role");
    owner1Role.addPermission(new PermissionBlueprint(PermissionType.USERNAME_CONSUMERS, owner1, Access.ALL));
    owner1Role.addUser(user);
    roleCurator.create(owner1Role);
    Set<Permission> perms = new HashSet<>();
    perms.add(new UsernameConsumersPermission(user, owner1));
    Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);
    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) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) 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 7 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class UserResourceTest method testListAllUsers.

@Test
public void testListAllUsers() {
    User user = new User();
    user.setUsername("henri");
    user.setPassword("password");
    userResource.createUser(user);
    List<User> users = userResource.list();
    assertTrue("length should be 1", users.size() == 1);
}
Also used : User(org.candlepin.model.User) Test(org.junit.Test)

Example 8 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class DefaultUserServiceAdapterTest method superAdminRole.

@Test
@Ignore("Find a way to do this with permissions")
public void superAdminRole() {
    Set<Owner> owners = new HashSet<>();
    owners.add(owner);
    User user = new User("super_admin", "password", true);
    this.service.createUser(user);
    Assert.assertTrue(this.service.findByLogin("super_admin").getRoles().contains(Access.ALL));
}
Also used : Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class DefaultUserServiceAdapterTest method deleteUserRemovesUserFromRoles.

@Test
public void deleteUserRemovesUserFromRoles() {
    Role adminRole = createAdminRole(owner);
    roleCurator.create(adminRole);
    User user = new User("testuser", "password");
    service.createUser(user);
    service.addUserToRole(adminRole, user);
    service.deleteUser(user);
    adminRole = service.getRole(adminRole.getId());
    assertEquals(0, adminRole.getUsers().size());
}
Also used : Role(org.candlepin.model.Role) User(org.candlepin.model.User) Test(org.junit.Test)

Example 10 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class DefaultUserServiceAdapterTest method findByLogin.

@Test
public void findByLogin() {
    User u = mock(User.class);
    UserCurator curator = mock(UserCurator.class);
    RoleCurator roleCurator = mock(RoleCurator.class);
    UserServiceAdapter dusa = new DefaultUserServiceAdapter(curator, roleCurator);
    when(curator.findByLogin(anyString())).thenReturn(u);
    User foo = dusa.findByLogin("foo");
    assertNotNull(foo);
    assertEquals(foo, u);
}
Also used : User(org.candlepin.model.User) UserCurator(org.candlepin.model.UserCurator) UserServiceAdapter(org.candlepin.service.UserServiceAdapter) RoleCurator(org.candlepin.model.RoleCurator) 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