@@ -75,6 +75,7 @@ private void testGetSpecials(boolean allowSpecialPaths, boolean useSubpathWebdav
7575
7676 // Create a temp webapp that can be safely written to
7777 File tempWebapp = new File (getTemporaryDirectory (), "webdav-specialpath" +UUID .randomUUID ());
78+ tempWebapp .deleteOnExit ();
7879 Assert .assertTrue ("Failed to mkdirs on " +tempWebapp .getCanonicalPath (),tempWebapp .mkdirs ());
7980 Assert .assertTrue (new File (tempWebapp ,"WEB-INF" ).mkdir ());
8081 Assert .assertTrue (new File (tempWebapp ,"META-INF" ).mkdir ());
@@ -297,6 +298,7 @@ public void testBasicProperties() throws Exception {
297298
298299 // Create a temp webapp that can be safely written to
299300 File tempWebapp = new File (getTemporaryDirectory (), "webdav-properties" );
301+ tempWebapp .deleteOnExit ();
300302 Assert .assertTrue (tempWebapp .mkdirs ());
301303 Context ctxt = tomcat .addContext ("" , tempWebapp .getAbsolutePath ());
302304 Wrapper webdavServlet = Tomcat .addServlet (ctxt , "webdav" , new WebdavServlet ());
@@ -441,6 +443,7 @@ public void testBasicOperations() throws Exception {
441443
442444 // Create a temp webapp that can be safely written to
443445 File tempWebapp = new File (getTemporaryDirectory (), "webdav-webapp" );
446+ tempWebapp .deleteOnExit ();
444447 Assert .assertTrue (tempWebapp .mkdirs ());
445448 Context ctxt = tomcat .addContext ("" , tempWebapp .getAbsolutePath ());
446449 Wrapper webdavServlet = Tomcat .addServlet (ctxt , "webdav" , new WebdavServlet ());
@@ -922,6 +925,7 @@ public void testCopyOutsideSubpath() throws Exception {
922925
923926 // Create a temp webapp that can be safely written to
924927 File tempWebapp = new File (getTemporaryDirectory (), "webdav-subpath" );
928+ tempWebapp .deleteOnExit ();
925929 File subPath = new File (tempWebapp , "aaa" );
926930 Assert .assertTrue (subPath .mkdirs ());
927931
@@ -1018,6 +1022,7 @@ public void testSharedLocks() throws Exception {
10181022
10191023 // Create a temp webapp that can be safely written to
10201024 File tempWebapp = new File (getTemporaryDirectory (), "webdav-lock" );
1025+ tempWebapp .deleteOnExit ();
10211026 Assert .assertTrue (tempWebapp .mkdirs ());
10221027 Context ctxt = tomcat .addContext ("" , tempWebapp .getAbsolutePath ());
10231028 Wrapper webdavServlet = Tomcat .addServlet (ctxt , "webdav" , new WebdavServlet ());
@@ -1405,6 +1410,7 @@ public void testIfHeader() throws Exception {
14051410
14061411 // Create a temp webapp that can be safely written to
14071412 File tempWebapp = new File (getTemporaryDirectory (), "webdav-if" );
1413+ tempWebapp .deleteOnExit ();
14081414 File folder = new File (tempWebapp , "/myfolder/myfolder2/myfolder4/myfolder5" );
14091415 Assert .assertTrue (folder .mkdirs ());
14101416 File file = new File (folder , "myfile.txt" );
@@ -1535,6 +1541,7 @@ public void testPropertyStore() throws Exception {
15351541
15361542 // Create a temp webapp that can be safely written to
15371543 File tempWebapp = new File (getTemporaryDirectory (), "webdav-store" );
1544+ tempWebapp .deleteOnExit ();
15381545 Assert .assertTrue (tempWebapp .mkdirs ());
15391546 Context ctxt = tomcat .addContext ("" , tempWebapp .getAbsolutePath ());
15401547 Wrapper webdavServlet = Tomcat .addServlet (ctxt , "webdav" , new WebdavServlet ());
@@ -1566,6 +1573,82 @@ public void testPropertyStore() throws Exception {
15661573 validateXml (client .getResponseBody ());
15671574 }
15681575
1576+
1577+ /*
1578+ * Only tests LOCK bodies exceeding limit. Other tests cover valid LOCK bodies.
1579+ */
1580+ @ Test
1581+ public void testLockBodyLimit () throws Exception {
1582+ doTestLimit ("LOCK" , LOCK_BODY );
1583+ }
1584+
1585+
1586+ /*
1587+ * Only tests PROPFIND bodies exceeding limit. Other tests cover valid PROPFIND bodies.
1588+ */
1589+ @ Test
1590+ public void testPropFindBodyLimit () throws Exception {
1591+ doTestLimit ("PROPFIND" , PROPFIND_PROP );
1592+ }
1593+
1594+
1595+ private void doTestLimit (String method , String requestBody ) throws Exception {
1596+
1597+ Tomcat tomcat = getTomcatInstance ();
1598+
1599+ File appDir = new File ("test/webapp" );
1600+ Context ctxt = tomcat .addContext ("" , appDir .getAbsolutePath ());
1601+
1602+ Wrapper webdavServlet = Tomcat .addServlet (ctxt , "webdav" , new WebdavServlet ());
1603+ webdavServlet .addInitParameter ("listings" , "true" );
1604+ webdavServlet .addInitParameter ("secret" , "foo" );
1605+ webdavServlet .addInitParameter ("readonly" , "false" );
1606+ webdavServlet .addInitParameter ("useStrongETags" , "true" );
1607+ webdavServlet .addInitParameter ("maxRequestBodySize" , "10" );
1608+
1609+ ctxt .addServletMappingDecoded ("/*" , "webdav" );
1610+ tomcat .start ();
1611+
1612+ // With content length
1613+ Client client = new Client ();
1614+ client .setPort (getPort ());
1615+
1616+ // @formatter:off
1617+ client .setRequest (new String [] {
1618+ method + " / HTTP/1.1" + CRLF +
1619+ "Host: localhost:" + getPort () + CRLF +
1620+ "Content-Length: " + requestBody .length () + CRLF +
1621+ "Connection: Close" + CRLF +
1622+ CRLF +
1623+ requestBody
1624+ });
1625+ // @formatter:on
1626+ client .connect ();
1627+ client .processRequest (true );
1628+ Assert .assertEquals (WebdavStatus .SC_REQUEST_TOO_LONG , client .getStatusCode ());
1629+
1630+ // Without content length
1631+ client .reset ();
1632+
1633+ // @formatter:off
1634+ client .setRequest (new String [] {
1635+ method + " / HTTP/1.1" + CRLF +
1636+ "Host: localhost:" + getPort () + CRLF +
1637+ "Transfer-Encoding: chunked" + CRLF +
1638+ "Connection: Close" + CRLF +
1639+ CRLF +
1640+ Integer .toHexString (requestBody .length ()) + CRLF +
1641+ requestBody + CRLF +
1642+ "0" + CRLF +
1643+ CRLF
1644+ });
1645+ // @formatter:on
1646+ client .connect ();
1647+ client .processRequest (true );
1648+ Assert .assertEquals (WebdavStatus .SC_REQUEST_TOO_LONG , client .getStatusCode ());
1649+ }
1650+
1651+
15691652 public static class CustomPropertyStore implements PropertyStore {
15701653
15711654 private String propertyName = null ;
0 commit comments