You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2023/01/03 10:44:52 UTC

[commons-fileupload] 01/07: PR: FILEUPLOAD-293 Attempt to reproduce the issue.

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 1.x
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git

commit 7800445d65298ccfce0bcca3f5aae57ab2276807
Author: Jochen Wiedmann (jwi) <jo...@softwareag.com>
AuthorDate: Sat Feb 23 17:23:59 2019 +0100

    PR: FILEUPLOAD-293 Attempt to reproduce the issue.
---
 .../commons/fileupload/DiskFileUploadTest.java     | 37 +++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/fileupload/DiskFileUploadTest.java b/src/test/java/org/apache/commons/fileupload/DiskFileUploadTest.java
index 49f65f0..a472c1c 100644
--- a/src/test/java/org/apache/commons/fileupload/DiskFileUploadTest.java
+++ b/src/test/java/org/apache/commons/fileupload/DiskFileUploadTest.java
@@ -16,10 +16,14 @@
  */
 package org.apache.commons.fileupload;
 
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.commons.fileupload.disk.DiskFileItem;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -64,4 +68,35 @@ public class DiskFileUploadTest {
         }
     }
 
+    /** Proposed test for FILEUPLOAD-293. As of yet, doesn't reproduce the problem.
+     */
+    @Test
+    public void testMoveFile() throws Exception {
+        DiskFileUpload myUpload = new DiskFileUpload();
+        myUpload.setSizeThreshold(0);
+    	final String content =
+                "-----1234\r\n" +
+                "Content-Disposition: form-data; name=\"file\";"
+                		+ "filename=\"foo.tab\"\r\n" +
+                "Content-Type: text/whatever\r\n" +
+                "\r\n" +
+                "This is the content of the file\n" +
+                "\r\n" +
+                "-----1234--\r\n";
+    	final byte[] contentBytes = content.getBytes("US-ASCII");
+        final HttpServletRequest request = new MockHttpServletRequest(contentBytes, Constants.CONTENT_TYPE);
+        final List<FileItem> items = myUpload.parseRequest(request);
+        assertNotNull(items);
+        assertFalse(items.isEmpty());
+        final DiskFileItem dfi = (DiskFileItem) items.get(0);
+        final File out = new File("target/unit-tests/DiskFileUpload/out.file");
+        if (out.isFile()) {
+        	out.delete();
+        }
+        final File outDir = out.getParentFile();
+        if (!outDir.isDirectory()) {
+        	outDir.mkdirs();
+        }
+        dfi.write(out);
+    }
 }