Search in sources :

Example 11 with User

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

the class DefaultUserServiceAdapterTest method testFindAllUsers.

@Test
public void testFindAllUsers() {
    User user = new User("test_user", "mypassword");
    this.service.createUser(user);
    List<User> users = this.service.listUsers();
    assertTrue("The size of the list should be 1", users.size() == 1);
    assertEquals("test_user", users.get(0).getUsername());
}
Also used : User(org.candlepin.model.User) Test(org.junit.Test)

Example 12 with User

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

the class DefaultUserServiceAdapterTest method testUpdating.

@Test
public void testUpdating() {
    User user = TestUtil.createUser(null, null, true);
    user = this.userCurator.create(user);
    user.setUsername("JarJar");
    user.setHashedPassword("Binks");
    user.setSuperAdmin(false);
    User updated = service.updateUser(user);
    assertEquals("JarJar", updated.getUsername());
    assertEquals("Binks", updated.getHashedPassword());
    assertFalse(updated.isSuperAdmin());
}
Also used : User(org.candlepin.model.User) Test(org.junit.Test)

Example 13 with User

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

the class DefaultUserServiceAdapterTest method findOwner.

@Test
@Ignore("Find a way to do this with permissions")
public void findOwner() {
    User user = new User("test_name", "password");
    this.service.createUser(user);
    Role adminRole = createAdminRole(owner);
    adminRole.addUser(user);
    roleCurator.create(adminRole);
// List<Owner> owners = this.service.getOwners("test_name");
// Assert.assertEquals(1, owners.size());
// Assert.assertEquals(owner, owners.get(0));
}
Also used : Role(org.candlepin.model.Role) User(org.candlepin.model.User) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with User

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

the class BasicAuthViaUserServiceTest method correctPrincipalNoPassword.

@Test
public void correctPrincipalNoPassword() throws Exception {
    Owner owner = new Owner("user", "user");
    setUserNoPassword("user");
    when(userService.validateUser("user", null)).thenReturn(true);
    Set<OwnerPermission> permissions = new HashSet<>();
    permissions.add(new OwnerPermission(owner, Access.ALL));
    when(userService.findByLogin("user")).thenReturn(new User());
    UserPrincipal expected = new UserPrincipal("user", new ArrayList<>(permissions), false);
    assertEquals(expected, this.auth.getPrincipal(request));
}
Also used : Owner(org.candlepin.model.Owner) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) User(org.candlepin.model.User) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with User

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

the class BasicAuthViaUserServiceTest method correctPrincipal.

/**
 * Valid credentials are given - checks if the correct principal is created.
 *
 * @throws Exception
 */
@Test
public void correctPrincipal() throws Exception {
    Owner owner = new Owner("user", "user");
    setUserAndPassword("user", "redhat");
    when(userService.validateUser("user", "redhat")).thenReturn(true);
    // TODO: test will fail, need to mock the permissions setup
    Set<OwnerPermission> permissions = new HashSet<>();
    permissions.add(new OwnerPermission(owner, Access.ALL));
    when(userService.findByLogin("user")).thenReturn(new User());
    UserPrincipal expected = new UserPrincipal("user", new ArrayList<>(permissions), false);
    assertEquals(expected, this.auth.getPrincipal(request));
}
Also used : Owner(org.candlepin.model.Owner) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) User(org.candlepin.model.User) HashSet(java.util.HashSet) 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