Skip to content

Commit

Permalink
Fix issue with zip files being disallowed with fileServer (#501)
Browse files Browse the repository at this point in the history
* Add test for downloading zip files using fileServer

* Use default test name (test index)

* Add partial content test for zip files

* Allow zip files to be downloaded with fileServer

* Fix test expected length
  • Loading branch information
tdrwenski authored May 23, 2024
1 parent 0265ff3 commit 750304c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public static List<Object[]> getTestParameters() {
result.add(new Object[] {"fileServer/scanCdmUnitTests/formats/netcdf3/files/ctest0.nc",
ContentType.netcdf.toString(), "4b514d280c034222e8e5b8401fee268c"});

result
.add(new Object[] {"fileServer/scanLocal/oneFile.zip", "application/zip", "088e88fe16b8cd4ac73b5ef540393439"});
result
.add(new Object[] {"fileServer/scanLocal/twoFiles.zip", "application/zip", "a9d6538c628654e2840de4afa5d85aad"});

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class TestPartialContent {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

@Parameterized.Parameters(name = "{0}")
@Parameterized.Parameters
static public List<long[]> getTestParameters() {
final List<long[]> result = new ArrayList<>();

Expand All @@ -38,13 +38,25 @@ public void shouldReturnPartialContent() {
final String path = "fileServer/scanLocal/mydata1.nc";
final long maxSize = 66832;
final String contentType = ContentType.netcdf.toString();
checkPartialContent(path, maxSize, contentType);
}

@Test
public void shouldReturnPartialContentOfZip() {
final String path = "fileServer/scanLocal/twoFiles.zip";
final long maxSize = 667;
final String contentType = "application/zip";
checkPartialContent(path, maxSize, contentType);
}

private void checkPartialContent(String path, long maxSize, String contentType) {
final String endpoint = TestOnLocalServer.withHttpPath(path);

final byte[] content = TestOnLocalServer.getContent(null, endpoint,
new int[] {HttpServletResponse.SC_PARTIAL_CONTENT}, contentType, byteRange);
assertThat(content).isNotNull();

final long expectedLength = Math.min(byteRange[1] - byteRange[0] + 1, maxSize);
final long expectedLength = Math.min(byteRange[1] - byteRange[0] + 1, maxSize - byteRange[0]);
assertThat(content.length).isEqualTo(expectedLength);
}
}
2 changes: 1 addition & 1 deletion tds/src/main/java/thredds/servlet/ServletUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public static void writeMFileToResponse(HttpServletRequest request, HttpServletR
return;
}

if (file.isDirectory()) {
if (file.isDirectory() && !file.isZipFile()) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Expected a file name instead of a directory for URL path: " + requestPath);
return;
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 750304c

Please sign in to comment.