|
20 | 20 | import okio.Buffer;
|
21 | 21 | import org.gridsuite.explore.server.dto.CaseAlertThresholdMessage;
|
22 | 22 | import org.gridsuite.explore.server.dto.ElementAttributes;
|
| 23 | +import org.gridsuite.explore.server.dto.PermissionDTO; |
| 24 | +import org.gridsuite.explore.server.dto.PermissionType; |
23 | 25 | import org.gridsuite.explore.server.services.*;
|
24 | 26 | import org.gridsuite.explore.server.utils.ContingencyListType;
|
25 | 27 | import org.gridsuite.explore.server.utils.ParametersType;
|
@@ -205,6 +207,11 @@ void setup(final MockWebServer server) throws Exception {
|
205 | 207 | String newElementUuidAsString = mapper.writeValueAsString(ELEMENT_COPY_UUID);
|
206 | 208 | String newElementAttributesAsString = mapper.writeValueAsString(new ElementAttributes(ELEMENT_UUID, STUDY1, "STUDY", USER1, 0, null));
|
207 | 209 | String listElementsAsString = "[" + newElementAttributesAsString + "," + publicStudyAttributesAsString + "]";
|
| 210 | + String parentDirectoryPermissions = mapper.writeValueAsString(List.of( |
| 211 | + new PermissionDTO(false, List.of(UUID.randomUUID(), UUID.randomUUID()), PermissionType.READ), |
| 212 | + new PermissionDTO(false, List.of(UUID.randomUUID()), PermissionType.WRITE), |
| 213 | + new PermissionDTO(false, List.of(), PermissionType.MANAGE) |
| 214 | + )); |
208 | 215 |
|
209 | 216 | final Dispatcher dispatcher = new Dispatcher() {
|
210 | 217 | @SneakyThrows(JsonProcessingException.class)
|
@@ -381,6 +388,18 @@ public MockResponse dispatch(RecordedRequest request) {
|
381 | 388 | return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), invalidElementAsString);
|
382 | 389 | } else if (path.matches("/v1/cases-alert-threshold")) {
|
383 | 390 | return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), "40");
|
| 391 | + } else if (path.matches("/v1/directories/" + PARENT_DIRECTORY_UUID + "/permissions")) { |
| 392 | + return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), parentDirectoryPermissions); |
| 393 | + } else if (path.matches("/v1/directories/" + PARENT_DIRECTORY_UUID_FORBIDDEN + "/permissions") && |
| 394 | + USER_NOT_ALLOWED.equals(request.getHeaders().get("userId"))) { |
| 395 | + return new MockResponse(403); |
| 396 | + } |
| 397 | + } else if ("PUT".equals(request.getMethod())) { |
| 398 | + if (path.matches("/v1/directories/" + PARENT_DIRECTORY_UUID + "/permissions")) { |
| 399 | + return new MockResponse(200); |
| 400 | + } else if (path.matches("/v1/directories/" + PARENT_DIRECTORY_UUID_FORBIDDEN + "/permissions") && |
| 401 | + USER_NOT_ALLOWED.equals(request.getHeaders().get("userId"))) { |
| 402 | + return new MockResponse(403); |
384 | 403 | }
|
385 | 404 | } else if ("DELETE".equals(request.getMethod())) {
|
386 | 405 | if (path.matches("/v1/filters/" + FILTER_UUID)) {
|
@@ -945,6 +964,45 @@ void testModifyCompositeModifications(final MockWebServer server) throws Excepti
|
945 | 964 | ).andExpect(status().isOk());
|
946 | 965 | }
|
947 | 966 |
|
| 967 | + @Test |
| 968 | + void testGetDirectoryPermissions() throws Exception { |
| 969 | + MvcResult result = mockMvc.perform(get("/v1/explore/directories/{directoryUuid}/permissions", PARENT_DIRECTORY_UUID) |
| 970 | + .header("userId", USER1)) |
| 971 | + .andExpect(status().isOk()) |
| 972 | + .andReturn(); |
| 973 | + String responseJson = result.getResponse().getContentAsString(); |
| 974 | + List<PermissionDTO> returnedPermissions = mapper.readValue(responseJson, new TypeReference<List<PermissionDTO>>() { }); |
| 975 | + assertEquals(3, returnedPermissions.size()); |
| 976 | + |
| 977 | + // Execute the test with a forbidden directory ID |
| 978 | + mockMvc.perform(get("/v1/explore/directories/{directoryUuid}/permissions", PARENT_DIRECTORY_UUID_FORBIDDEN) |
| 979 | + .header("userId", USER_NOT_ALLOWED)) |
| 980 | + .andExpect(status().isForbidden()); |
| 981 | + } |
| 982 | + |
| 983 | + @Test |
| 984 | + void testSetDirectoryPermissions() throws Exception { |
| 985 | + List<PermissionDTO> permissions = List.of( |
| 986 | + new PermissionDTO(false, List.of(UUID.randomUUID(), UUID.randomUUID()), PermissionType.READ), |
| 987 | + new PermissionDTO(false, List.of(UUID.randomUUID()), PermissionType.WRITE), |
| 988 | + new PermissionDTO(false, List.of(), PermissionType.MANAGE) |
| 989 | + ); |
| 990 | + String permissionsJson = mapper.writeValueAsString(permissions); |
| 991 | + |
| 992 | + mockMvc.perform(put("/v1/explore/directories/{directoryUuid}/permissions", PARENT_DIRECTORY_UUID) |
| 993 | + .header("userId", USER1) |
| 994 | + .contentType(MediaType.APPLICATION_JSON) |
| 995 | + .content(permissionsJson)) |
| 996 | + .andExpect(status().isOk()); |
| 997 | + |
| 998 | + // Execute the test with a forbidden directory ID |
| 999 | + mockMvc.perform(put("/v1/explore/directories/{directoryUuid}/permissions", PARENT_DIRECTORY_UUID_FORBIDDEN) |
| 1000 | + .header("userId", USER_NOT_ALLOWED) |
| 1001 | + .contentType(MediaType.APPLICATION_JSON) |
| 1002 | + .content(permissionsJson)) |
| 1003 | + .andExpect(status().isForbidden()); |
| 1004 | + } |
| 1005 | + |
948 | 1006 | @Test
|
949 | 1007 | void testGetModificationMetadata() throws Exception {
|
950 | 1008 | final String expectedResult = mapper.writeValueAsString(new ElementAttributes(MODIFICATION_UUID, "one modif", "MODIFICATION", USER1, 0L, null, modificationSpecificMetadata));
|
|
0 commit comments