3434import static org .junit .Assert .assertTrue ;
3535import static org .mockito .Mockito .*;
3636
37-
3837import javax .servlet .ServletInputStream ;
3938import java .io .ByteArrayInputStream ;
4039import java .io .IOException ;
@@ -210,70 +209,41 @@ public void testMultipartPostWithShorterFilename() throws Exception {
210209 }
211210 }
212211
213- @ Test (expected = IOException .class )
212+ @ Test (expected = IOException .class )
214213 public void testMultipartPostWithExtremelyLongFilename () throws Exception {
215- buildRequestWithFilenameOfVaryingLength (1000 );
214+ // header bytes ~= filename length + ~107; at 5000 chars this far exceeds the 4096 default
215+ buildRequestWithFilenameOfVaryingLength (5000 );
216216 File testTmpDir = tempFolder .newFolder ("jackrabbit_long_filename" );
217+ new RequestData (mockRequest , testTmpDir ); // must throw IOException
218+ }
219+
220+ @ Test
221+ public void testMultipartPostWithLongFilenameUnderNewDefault () throws Exception {
222+ buildRequestWithFilenameOfVaryingLength (3800 ); // above 512, below 4096
223+ File testTmpDir = tempFolder .newFolder ("jackrabbit_medium_filename" );
217224 RequestData requestData = new RequestData (mockRequest , testTmpDir );
218225 try {
219- assertTrue (
220- requestData .getParameter ("fileUpload" ).length () > 950 );
226+ assertTrue (requestData .getParameter ("fileUpload" ).length () > 3800 );
221227 } finally {
222228 requestData .dispose ();
223229 }
224230 }
225231
226232 @ Test
227- public void testMultipartPostWithExtremelyLongFilenameNButHigherConfig () throws Exception {
233+ public void testMultipartPostWithExtremelyLongFilenameWithHigherConfig () throws Exception {
228234 try {
229- System .setProperty ("jackrabbit-server-PartHeaderSizeMax" , "2048 " );
230- buildRequestWithFilenameOfVaryingLength (1000 );
235+ System .setProperty ("jackrabbit-server-PartHeaderSizeMax" , "8192 " );
236+ buildRequestWithFilenameOfVaryingLength (7500 );
231237 File testTmpDir = tempFolder .newFolder ("jackrabbit_long_filename" );
232238 RequestData requestData = new RequestData (mockRequest , testTmpDir );
233239 try {
234240 assertTrue (
235- requestData .getParameter ("fileUpload" ).length () > 950 );
241+ requestData .getParameter ("fileUpload" ).length () > 7500 );
236242 } finally {
237243 requestData .dispose ();
238244 }
239245 } finally {
240246 System .clearProperty ("jackrabbit-server-PartHeaderSizeMax" );
241247 }
242248 }
243-
244- /**
245- * Assures special Unicode (Non-ASCII) symbols preserve structural state during text decoding.
246- */
247- // @Test
248- public void testMultipartPostWithNonAsciiCharacters () throws Exception {
249- File testTmpDir = tempFolder .newFolder ("jackrabbit_non_ascii" );
250- String boundary = "----MockBoundaryNonAscii" ;
251- String nonAsciiValue = "テスト_ü_é_ñ_value" ;
252- String nonAsciiFilename = "マニュアル_doc.pdf" ;
253-
254- String body = "--" + boundary + "\r \n " +
255- "Content-Disposition: form-data; name=\" unicodeField\" \r \n \r \n " +
256- nonAsciiValue + "\r \n " +
257- "--" + boundary + "\r \n " +
258- "Content-Disposition: form-data; name=\" unicodeFile\" ; filename=\" " + nonAsciiFilename + "\" \r \n " +
259- "Content-Type: application/pdf\r \n \r \n " +
260- "%PDF-Mock-Bytes\r \n " +
261- "--" + boundary + "--\r \n " ;
262-
263- byte [] payloadBytes = body .getBytes (StandardCharsets .UTF_8 );
264-
265- when (mockRequest .getMethod ()).thenReturn ("POST" );
266- when (mockRequest .getContentType ()).thenReturn ("multipart/form-data; boundary=" + boundary );
267- lenient ().when (mockRequest .getCharacterEncoding ()).thenReturn ("UTF-8" );
268- when (mockRequest .getInputStream ()).thenReturn (createServletInputStream (payloadBytes ));
269-
270- RequestData requestData = new RequestData (mockRequest , testTmpDir );
271- try {
272- String parsedValue = requestData .getParameter ("unicodeField" );
273- assertEquals ("Unicode decoding was corrupted inside the parsing sequence" , nonAsciiValue , parsedValue );
274- assertNotNull ("Non-ASCII file part metadata parsing must complete successfully" , requestData .getParameter ("unicodeFile" ));
275- } finally {
276- requestData .dispose ();
277- }
278- }
279249}
0 commit comments