Search in sources :

Example 1 with UserRoleDaoService

use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testCreateUserUnauthorizedException.

@Test
public void testCreateUserUnauthorizedException() throws Exception {
    UserRoleDaoService mockService = mock(UserRoleDaoService.class);
    doThrow(new SecurityException()).when(mockService).createUser(any(User.class));
    UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
    try {
        resource.createUser(new User("not", "admin"));
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.FORBIDDEN.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 2 with UserRoleDaoService

use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testCreateRoleEmptyName.

@Test
public void testCreateRoleEmptyName() throws Exception {
    UserRoleDaoService mockService = mock(UserRoleDaoService.class);
    doThrow(new UserRoleDaoService.ValidationFailedException()).when(mockService).createRole(anyString());
    UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
    try {
        resource.createRole("");
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 3 with UserRoleDaoService

use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testCreateUserValidationFailed.

@Test
public void testCreateUserValidationFailed() throws Exception {
    UserRoleDaoService mockService = mock(UserRoleDaoService.class);
    doThrow(new UserRoleDaoService.ValidationFailedException()).when(mockService).createUser(any(User.class));
    UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
    try {
        resource.createUser(new User("\\/validation", "failed"));
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 4 with UserRoleDaoService

use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.

the class UserRoleDaoResource_RolesUpdatedTest method setUp.

@Before
public void setUp() {
    UserRoleDaoService service = mock(UserRoleDaoService.class);
    doReturn(new RoleListWrapper(allRoles)).when(service).getRolesForUser(eq(SESSION_USER_NAME));
    resource = new UserRoleDaoResource(mock(IRoleAuthorizationPolicyRoleBindingDao.class), mock(ITenantManager.class), new ArrayList<String>(), ROLE_NAME_ADMINISTRATOR, service);
    session = new StandaloneSession(SESSION_USER_NAME);
    resource = spy(resource);
    doReturn(session).when(resource).getSession();
    userRoleDao = mock(IUserRoleDao.class);
    doReturn(new ArrayList<IPentahoRole>()).when(userRoleDao).getRoles(any(ITenant.class));
    doReturn(mock(ITenant.class)).when(resource).getTenant(anyString());
    doReturn(userRoleDao).when(resource).getUserRoleDao();
    doReturn(true).when(resource).canAdminister();
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) ITenant(org.pentaho.platform.api.mt.ITenant) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Before(org.junit.Before)

Example 5 with UserRoleDaoService

use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method changePassException.

private void changePassException(Exception ex, int expectedStatus, String name, String newPass, String oldPass) throws Exception {
    UserRoleDaoService mockService = mock(UserRoleDaoService.class);
    doThrow(ex).when(mockService).changeUserPassword(anyString(), anyString(), anyString());
    UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
    try {
        resource.changeUserPassword(new ChangePasswordUser(name, newPass, oldPass));
    } catch (WebApplicationException exception) {
        assertEquals(expectedStatus, exception.getResponse().getStatus());
    }
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

UserRoleDaoService (org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService)8 WebApplicationException (javax.ws.rs.WebApplicationException)7 Test (org.junit.Test)6 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)4 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)1 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)1 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)1