Skip to content
Snippets Groups Projects
Commit f7559c36 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Not empty context path bugfix

parent a438587d
No related branches found
No related tags found
No related merge requests found
Pipeline #1037 passed
......@@ -13,7 +13,10 @@ public abstract class FileController {
protected HttpServletRequest request;
public String getPath() {
String[] parts = request.getRequestURI().split("/");
String uri = request.getRequestURI().substring(request.getContextPath().length());
String[] parts = uri.split("/");
return String.join("/", Arrays.stream(parts)
.map(p -> URLDecoder.decode(p, StandardCharsets.UTF_8))
.collect(Collectors.toList()));
......
......@@ -61,13 +61,28 @@ public class GetFileControllerTest {
fileInfo.setVirtualPath("/path/to/myfile");
fileInfo.setIsPublic(true);
when(fileDao.getFileInfo(any())).thenReturn(Optional.of(fileInfo));
when(fileDao.getFileInfo(eq("/path/to/myfile"))).thenReturn(Optional.of(fileInfo));
mockMvc.perform(get("/path/to/myfile"))
.andDo(print())
.andExpect(status().isOk());
}
@Test
public void testContextPathIsRemoved() throws Exception {
FileInfo fileInfo = new FileInfo();
fileInfo.setOsPath(tempFile.getAbsolutePath());
fileInfo.setVirtualPath("/path/to/myfile");
fileInfo.setIsPublic(true);
when(fileDao.getFileInfo(eq("/path/to/myfile"))).thenReturn(Optional.of(fileInfo));
mockMvc.perform(get("/context/path/to/myfile").contextPath("/context"))
.andDo(print())
.andExpect(status().isOk());
}
@Test
public void testFileNotFoundInDb() throws Exception {
mockMvc.perform(get("/path/to/myfile"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment