Skip to content

Commit

Permalink
Re-enable ResourceHandlerTest for range requests and fix. (#12418)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbartel authored Oct 24, 2024
1 parent 2d9ef61 commit 1e9aca4
Showing 1 changed file with 34 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -461,7 +460,6 @@ public static Stream<Arguments> rangeScenarios()
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
Expand Down Expand Up @@ -489,7 +487,6 @@ public static Stream<Arguments> rangeScenarios()
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
Expand Down Expand Up @@ -519,7 +516,6 @@ public static Stream<Arguments> rangeScenarios()
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
Expand All @@ -537,7 +533,6 @@ public static Stream<Arguments> rangeScenarios()
);

// test a range request with a file with no suffix, therefore no mimetype

scenarios.addScenario(
"No mimetype resource - no range requested",
"""
Expand Down Expand Up @@ -574,57 +569,55 @@ public static Stream<Arguments> rangeScenarios()
Range: bytes=0-9,20-29,40-49\r
\r
""",
HttpStatus.PARTIAL_CONTENT_206,
(response) ->
{
String body = response.getContent();
HttpStatus.PARTIAL_CONTENT_206,
(response) ->
{
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);

assertThat("Boundary expected: " + contentType.getValue(), boundary, notNullValue());
assertThat("Boundary expected: " + contentType.getValue(), boundary, notNullValue());

assertThat(body, containsString("Content-Range: bytes 0-9/80"));
assertThat(body, containsString("Content-Range: bytes 20-29/80"));
assertThat(body, containsString("Content-Range: bytes 0-9/80"));
assertThat(body, containsString("Content-Range: bytes 20-29/80"));

assertThat(response.getContent(), startsWith("--" + boundary));
assertThat(response.getContent(), endsWith(boundary + "--\r\n"));
}
assertThat(response.getContent(), startsWith("--" + boundary));
assertThat(response.getContent(), endsWith(boundary + "--\r\n"));
}
);

scenarios.addScenario(
"No mimetype resource - multiple ranges (x5) with empty range request",
"""
GET /context/nofilesuffix HTTP/1.1\r
Host: localhost\r
Range: bytes=0-9,20-29,40-49,60-60,70-79\r
\r
""",
HttpStatus.PARTIAL_CONTENT_206,
(response) ->
{
String body = response.getContent();
"No mimetype resource - multiple ranges (x5) with empty range request",
"""
GET /context/nofilesuffix HTTP/1.1\r
Host: localhost\r
Range: bytes=0-9,20-29,40-49,60-60,70-79\r
\r
""",
HttpStatus.PARTIAL_CONTENT_206,
(response) ->
{
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);

assertThat("Boundary expected: " + contentType.getValue(), boundary, notNullValue());
assertThat("Boundary expected: " + contentType.getValue(), boundary, notNullValue());

assertThat(body, containsString("Content-Range: bytes 0-9/80"));
assertThat(body, containsString("Content-Range: bytes 20-29/80"));
assertThat(body, containsString("Content-Range: bytes 40-49/80"));
assertThat(body, containsString("Content-Range: bytes 60-60/80")); // empty range
assertThat(body, containsString("Content-Range: bytes 70-79/80"));
assertThat(body, containsString("Content-Range: bytes 0-9/80"));
assertThat(body, containsString("Content-Range: bytes 20-29/80"));
assertThat(body, containsString("Content-Range: bytes 40-49/80"));
assertThat(body, containsString("Content-Range: bytes 60-60/80")); // empty range
assertThat(body, containsString("Content-Range: bytes 70-79/80"));

assertThat(response.getContent(), startsWith("--" + boundary));
assertThat(response.getContent(), endsWith(boundary + "--\r\n"));
}
assertThat(response.getContent(), startsWith("--" + boundary));
assertThat(response.getContent(), endsWith(boundary + "--\r\n"));
}
);

return scenarios.stream();
Expand Down Expand Up @@ -3115,7 +3108,6 @@ public void testProgrammaticCustomCompressionFormats() throws Exception

@ParameterizedTest
@MethodSource("rangeScenarios")
@Disabled
public void testRangeRequests(ResourceHandlerTest.Scenario scenario) throws Exception
{
FS.ensureDirExists(docRoot);
Expand Down

0 comments on commit 1e9aca4

Please sign in to comment.