Issue #8462 - Adding testcase to prove out behavior

This commit is contained in:
Joakim Erdfelt 2022-09-08 13:32:48 -05:00
parent efddb23969
commit 3d1150fd60
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
1 changed files with 62 additions and 0 deletions

View File

@ -165,6 +165,68 @@ public class DefaultServletTest
assertThat(response.toString(), response.getContent(), is("How now brown cow"));
}
@Test
public void testGetPercent2F() throws Exception
{
Path file = docRoot.resolve("file.txt");
Files.writeString(file, "How now brown cow", UTF_8);
context.addServlet(DefaultServlet.class, "/");
String rawResponse;
HttpTester.Response response;
// Access normally, in root of context
rawResponse = connector.getResponse("""
GET /context/file.txt HTTP/1.1\r
Host: local\r
Connection: close\r
\r
""");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.OK_200));
assertThat(response.toString(), response.getContent(), is("How now brown cow"));
// Attempt access using "%2F" instead of "/", should be a 404 (mainly because context isn't found)
rawResponse = connector.getResponse("""
GET /context%2Ffile.txt HTTP/1.1\r
Host: local\r
Connection: close\r
\r
""");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.NOT_FOUND_404));
Path dir = docRoot.resolve("dirFoo");
Files.createDirectory(dir);
Path other = dir.resolve("other.txt");
Files.writeString(other, "In a while", UTF_8);
// Access normally, in sub-dir of context
rawResponse = connector.getResponse("""
GET /context/dirFoo/other.txt HTTP/1.1\r
Host: local\r
Connection: close\r
\r
""");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.OK_200));
assertThat(response.toString(), response.getContent(), is("In a while"));
// Attempt access of content in sub-dir of context, using "%2F" instead of "/", should be a 404
rawResponse = connector.getResponse("""
GET /context/dirFoo%2Fother.txt HTTP/1.1\r
Host: local\r
Connection: close\r
\r
""");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.NOT_FOUND_404));
}
@Test
public void testListingWithSession() throws Exception
{