480764 Add extra tests for empty multipart.
This commit is contained in:
parent
9f430ae7f7
commit
6f6ccdf061
|
@ -64,6 +64,17 @@ public class MultipartFilterTest
|
||||||
private ServletTester tester;
|
private ServletTester tester;
|
||||||
FilterHolder multipartFilter;
|
FilterHolder multipartFilter;
|
||||||
|
|
||||||
|
|
||||||
|
public static class NullServlet extends HttpServlet
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
resp.setStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class FilenameServlet extends TestServlet
|
public static class FilenameServlet extends TestServlet
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -143,6 +154,70 @@ public class MultipartFilterTest
|
||||||
tester.stop();
|
tester.stop();
|
||||||
tester=null;
|
tester=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFinalBoundaryOnly() throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
tester.addServlet(NullServlet.class,"/null");
|
||||||
|
HttpTester.Request request = HttpTester.newRequest();
|
||||||
|
HttpTester.Response response;
|
||||||
|
|
||||||
|
// test GET
|
||||||
|
request.setMethod("POST");
|
||||||
|
request.setVersion("HTTP/1.0");
|
||||||
|
request.setHeader("Host","tester");
|
||||||
|
request.setURI("/context/null");
|
||||||
|
|
||||||
|
String delimiter = "\r\n";
|
||||||
|
final String boundary = "MockMultiPartTestBoundary";
|
||||||
|
String content =
|
||||||
|
delimiter +
|
||||||
|
"Hello world" +
|
||||||
|
delimiter + // Two delimiter markers, which make an empty line.
|
||||||
|
delimiter +
|
||||||
|
"--" + boundary + "--" + delimiter;
|
||||||
|
|
||||||
|
request.setHeader("Content-Type","multipart/form-data; boundary="+boundary);
|
||||||
|
request.setContent(content);
|
||||||
|
|
||||||
|
try(StacklessLogging stackless = new StacklessLogging(ServletHandler.class))
|
||||||
|
{
|
||||||
|
response = HttpTester.parseResponse(tester.getResponses(request.generate()));
|
||||||
|
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmpty() throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
tester.addServlet(NullServlet.class,"/null");
|
||||||
|
|
||||||
|
HttpTester.Request request = HttpTester.newRequest();
|
||||||
|
HttpTester.Response response;
|
||||||
|
|
||||||
|
// test GET
|
||||||
|
request.setMethod("POST");
|
||||||
|
request.setVersion("HTTP/1.0");
|
||||||
|
request.setHeader("Host","tester");
|
||||||
|
request.setURI("/context/null");
|
||||||
|
|
||||||
|
String delimiter = "\r\n";
|
||||||
|
final String boundary = "MockMultiPartTestBoundary";
|
||||||
|
String content =
|
||||||
|
delimiter +
|
||||||
|
"--" + boundary + "--" + delimiter;
|
||||||
|
|
||||||
|
request.setHeader("Content-Type","multipart/form-data; boundary="+boundary);
|
||||||
|
request.setContent(content);
|
||||||
|
|
||||||
|
try(StacklessLogging stackless = new StacklessLogging(ServletHandler.class))
|
||||||
|
{
|
||||||
|
response = HttpTester.parseResponse(tester.getResponses(request.generate()));
|
||||||
|
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBadPost() throws Exception
|
public void testBadPost() throws Exception
|
||||||
|
|
|
@ -63,6 +63,7 @@ public class MultiPartInputStreamTest
|
||||||
_tmpDir.deleteOnExit();
|
_tmpDir.deleteOnExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBadMultiPartRequest()
|
public void testBadMultiPartRequest()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -72,12 +73,12 @@ public class MultiPartInputStreamTest
|
||||||
"Content-Type: application/octet-stream\r\n\r\n"+
|
"Content-Type: application/octet-stream\r\n\r\n"+
|
||||||
"How now brown cow."+
|
"How now brown cow."+
|
||||||
"\r\n--" + boundary + "-\r\n\r\n";
|
"\r\n--" + boundary + "-\r\n\r\n";
|
||||||
|
|
||||||
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||||
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(str.getBytes()),
|
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(str.getBytes()),
|
||||||
"multipart/form-data, boundary="+boundary,
|
"multipart/form-data, boundary="+boundary,
|
||||||
config,
|
config,
|
||||||
_tmpDir);
|
_tmpDir);
|
||||||
mpis.setDeleteOnExit(true);
|
mpis.setDeleteOnExit(true);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -90,7 +91,56 @@ public class MultiPartInputStreamTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFinalBoundaryOnly()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String delimiter = "\r\n";
|
||||||
|
final String boundary = "MockMultiPartTestBoundary";
|
||||||
|
|
||||||
|
|
||||||
|
// Malformed multipart request body containing only an arbitrary string of text, followed by the final boundary marker, delimited by empty lines.
|
||||||
|
String str =
|
||||||
|
delimiter +
|
||||||
|
"Hello world" +
|
||||||
|
delimiter + // Two delimiter markers, which make an empty line.
|
||||||
|
delimiter +
|
||||||
|
"--" + boundary + "--" + delimiter;
|
||||||
|
|
||||||
|
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||||
|
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(str.getBytes()),
|
||||||
|
"multipart/form-data, boundary="+boundary,
|
||||||
|
config,
|
||||||
|
_tmpDir);
|
||||||
|
mpis.setDeleteOnExit(true);
|
||||||
|
Collection<Part> parts = mpis.getParts();
|
||||||
|
assertTrue(mpis.getParts().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmpty()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String delimiter = "\r\n";
|
||||||
|
final String boundary = "MockMultiPartTestBoundary";
|
||||||
|
|
||||||
|
String str =
|
||||||
|
delimiter +
|
||||||
|
"--" + boundary + "--" + delimiter;
|
||||||
|
|
||||||
|
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||||
|
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(str.getBytes()),
|
||||||
|
"multipart/form-data, boundary="+boundary,
|
||||||
|
config,
|
||||||
|
_tmpDir);
|
||||||
|
mpis.setDeleteOnExit(true);
|
||||||
|
assertTrue(mpis.getParts().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNoBoundaryRequest()
|
public void testNoBoundaryRequest()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue