Skip to content
Snippets Groups Projects
Commit 72b63e2d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

privilege checking for not admin fixed

parent bfbaeaf2
No related branches found
No related tags found
2 merge requests!115Resolve "admin panel should use API",!114Resolve "admin panel should use API"
...@@ -7,6 +7,8 @@ import static org.mockito.Matchers.any; ...@@ -7,6 +7,8 @@ import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
...@@ -159,6 +161,19 @@ public class ProjectRestImplTest extends RestTestFunctions { ...@@ -159,6 +161,19 @@ public class ProjectRestImplTest extends RestTestFunctions {
} }
} }
@Test
public void testGetProjects() throws Exception {
try {
ProjectRestImpl projectRest = createMockProjectRest("testFiles/model/sample.xml");
List<ProjectMetaData> result = projectRest.getProjects(token.getId());
Gson gson = new Gson();
assertNotNull(gson.toJson(result));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test @Test
public void testGetStatistics() throws Exception { public void testGetStatistics() throws Exception {
try { try {
...@@ -208,6 +223,9 @@ public class ProjectRestImplTest extends RestTestFunctions { ...@@ -208,6 +223,9 @@ public class ProjectRestImplTest extends RestTestFunctions {
IProjectService projectServiceMock = Mockito.mock(IProjectService.class); IProjectService projectServiceMock = Mockito.mock(IProjectService.class);
Mockito.when(projectServiceMock.getProjectByProjectId(anyString(), any())).thenReturn(project); Mockito.when(projectServiceMock.getProjectByProjectId(anyString(), any())).thenReturn(project);
List<Project> projects = new ArrayList<>();
projects.add(project);
Mockito.when(projectServiceMock.getAllProjects(any())).thenReturn(projects);
_projectRestImpl.setProjectService(projectServiceMock); _projectRestImpl.setProjectService(projectServiceMock);
return _projectRestImpl; return _projectRestImpl;
......
...@@ -291,7 +291,7 @@ public class ProjectService implements IProjectService { ...@@ -291,7 +291,7 @@ public class ProjectService implements IProjectService {
} }
List<Project> result = new ArrayList<>(); List<Project> result = new ArrayList<>();
for (Project project : projects) { for (Project project : projects) {
if (userService.userHasPrivilege(token, PrivilegeType.VIEW_PROJECT, result)) { if (userService.userHasPrivilege(token, PrivilegeType.VIEW_PROJECT, project)) {
result.add(project); result.add(project);
} }
} }
......
...@@ -82,6 +82,19 @@ public class ProjectServiceTest extends ServiceTestFunctions { ...@@ -82,6 +82,19 @@ public class ProjectServiceTest extends ServiceTestFunctions {
public void tearDown() throws Exception { public void tearDown() throws Exception {
} }
@Test
public void testGetProjectWithoutAccessToEverything() {
try {
createUser();
AuthenticationToken token = userService.login(user.getLogin(), "passwd");
List<Project> projects = projectService.getAllProjects(token);
assertNotNull(projects);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test @Test
public void test() { public void test() {
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment