Commit f7559c36 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Not empty context path bugfix

parent a438587d
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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()));
+16 −1
Original line number Diff line number Diff line
@@ -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"))