Skip to content

Commit

Permalink
Some changes after review.
Browse files Browse the repository at this point in the history
Add tests for special characters in directory path.

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
  • Loading branch information
FranckLecuyer committed Jul 31, 2024
1 parent a744864 commit c4886bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ public ResponseEntity<Page<DirectoryElementInfos>> searchElements(
.body(service.searchElements(userInput, directoryUuid));
}

@GetMapping(value = "/directories/uuid", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get uuid from directory described by the path")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "The directory uuid"),
})
@GetMapping(value = "/directories/uuid")
@Operation(summary = "Get directory uuid from given path")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The directory uuid"),
@ApiResponse(responseCode = "404", description = "The directory was not found")})
public ResponseEntity<UUID> getDirectoryUuidFromPath(@RequestParam("directoryPath") String directoryPath) {
return ResponseEntity.ok().body(service.getDirectoryUuidFromPath(directoryPath));
String decodedDirectoryPath = URLDecoder.decode(directoryPath, StandardCharsets.UTF_8);
return ResponseEntity.ok().body(service.getDirectoryUuidFromPath(decodedDirectoryPath));
}
}
27 changes: 25 additions & 2 deletions src/test/java/org/gridsuite/directory/server/DirectoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,8 @@ public void testGetDirectoryFromPath() throws Exception {
// dir1 (userId1) dir2 (userId2) dir3 (userId3)
// | |
// dir4 (userId1) dir5 (userId3)
// |
// &~#{[^repert (userId3)

ElementAttributes rootDirectory = retrieveInsertAndCheckRootDirectory("root", USERID_2);
UUID rootDirectoryUuid = rootDirectory.getElementUuid();
Expand All @@ -1819,14 +1821,19 @@ public void testGetDirectoryFromPath() throws Exception {
ElementAttributes subDirAttributes3 = toElementAttributes(subDirUuid3, "dir3", DIRECTORY, USERID_3);
UUID subDirUuid4 = UUID.randomUUID();
ElementAttributes subDirAttributes4 = toElementAttributes(subDirUuid4, "dir4", DIRECTORY, USERID_1);
UUID subDirUuid5 = UUID.randomUUID();
UUID subDirUuid5 = UUID.fromString("11111111-7977-4592-ba19-88027e4254e4");
ElementAttributes subDirAttributes5 = toElementAttributes(subDirUuid5, "dir5", DIRECTORY, USERID_3);
UUID subDirUuid6 = UUID.fromString("22222222-7977-4592-ba19-88027e4254e4");
String encodedPath = "%26~%23%7B%5B%5Erepert";
String decodedPath = "&~#{[^repert";
ElementAttributes subDirAttributes6 = toElementAttributes(subDirUuid6, decodedPath, DIRECTORY, USERID_3);

insertAndCheckSubElement(rootDirectoryUuid, subDirAttributes1);
insertAndCheckSubElement(rootDirectoryUuid, subDirAttributes2);
insertAndCheckSubElement(rootDirectoryUuid, subDirAttributes3);
insertAndCheckSubElement(subDirUuid1, subDirAttributes4);
insertAndCheckSubElement(subDirUuid3, subDirAttributes5);
insertSubElement(subDirUuid5, subDirAttributes6, false);

insertAndCheckSubElement(subDirUuid1, toElementAttributes(UUID.randomUUID(), RECOLLEMENT, TYPE_01, USERID_1, ""));
insertAndCheckSubElement(subDirUuid2, toElementAttributes(UUID.randomUUID(), RECOLLEMENT, TYPE_01, USERID_2, ""));
Expand All @@ -1842,7 +1849,7 @@ public void testGetDirectoryFromPath() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpectAll(status().isOk()).andReturn();
UUID resultUuid = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), UUID.class);
assertEquals(resultUuid, subDirAttributes4.getElementUuid());
assertEquals(subDirAttributes4.getElementUuid(), resultUuid);
output.clear();

// unexisting directory
Expand All @@ -1851,6 +1858,22 @@ public void testGetDirectoryFromPath() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpectAll(status().isNotFound()).andReturn();
output.clear();

// path to element (not a directory)
mockMvc
.perform(get("/v1/directories/uuid?directoryPath=" + "root/dir1/dir4/" + RECOLLEMENT)
.contentType(MediaType.APPLICATION_JSON))
.andExpectAll(status().isNotFound()).andReturn();
output.clear();

// existing directory with special characters in path
mvcResult = mockMvc
.perform(get("/v1/directories/uuid?directoryPath=root/dir3/dir5/" + encodedPath)
.contentType(MediaType.APPLICATION_JSON))
.andExpectAll(status().isOk()).andReturn();
resultUuid = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), UUID.class);
assertEquals(subDirAttributes6.getElementUuid(), resultUuid);
output.clear();
}

private <T> List<T> mvcResultToList(MvcResult mvcResult) throws Exception {
Expand Down

0 comments on commit c4886bc

Please sign in to comment.