[tomcat] 01/04: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64384

2020-04-27 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 13de9aa412237a42512cc6e0ae57254665ae539f
Author: Christopher Schultz 
AuthorDate: Mon Apr 27 18:01:00 2020 -0400

Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64384

Respect partial multipart-config elements.
---
 .../org/apache/catalina/startup/ContextConfig.java |  30 ++--
 .../catalina/startup/TestMultipartConfig.java  | 171 +
 2 files changed, 189 insertions(+), 12 deletions(-)

diff --git a/java/org/apache/catalina/startup/ContextConfig.java 
b/java/org/apache/catalina/startup/ContextConfig.java
index fe8c87d..0f29773 100644
--- a/java/org/apache/catalina/startup/ContextConfig.java
+++ b/java/org/apache/catalina/startup/ContextConfig.java
@@ -1354,19 +1354,25 @@ public class ContextConfig implements LifecycleListener 
{
 wrapper.setServletClass(servlet.getServletClass());
 MultipartDef multipartdef = servlet.getMultipartDef();
 if (multipartdef != null) {
-if (multipartdef.getMaxFileSize() != null &&
-multipartdef.getMaxRequestSize()!= null &&
-multipartdef.getFileSizeThreshold() != null) {
-wrapper.setMultipartConfigElement(new 
MultipartConfigElement(
-multipartdef.getLocation(),
-Long.parseLong(multipartdef.getMaxFileSize()),
-Long.parseLong(multipartdef.getMaxRequestSize()),
-Integer.parseInt(
-multipartdef.getFileSizeThreshold(;
-} else {
-wrapper.setMultipartConfigElement(new 
MultipartConfigElement(
-multipartdef.getLocation()));
+long maxFileSize = -1;
+long maxRequestSize = -1;
+int fileSizeThreshold = 0;
+
+if(null != multipartdef.getMaxFileSize()) {
+maxFileSize = 
Long.parseLong(multipartdef.getMaxFileSize());
+}
+if(null != multipartdef.getMaxRequestSize()) {
+maxRequestSize = 
Long.parseLong(multipartdef.getMaxRequestSize());
 }
+if(null != multipartdef.getFileSizeThreshold()) {
+fileSizeThreshold = 
Integer.parseInt(multipartdef.getFileSizeThreshold());
+}
+
+wrapper.setMultipartConfigElement(new MultipartConfigElement(
+multipartdef.getLocation(),
+maxFileSize,
+maxRequestSize,
+fileSizeThreshold));
 }
 if (servlet.getAsyncSupported() != null) {
 wrapper.setAsyncSupported(
diff --git a/test/org/apache/catalina/startup/TestMultipartConfig.java 
b/test/org/apache/catalina/startup/TestMultipartConfig.java
new file mode 100644
index 000..d0ca905
--- /dev/null
+++ b/test/org/apache/catalina/startup/TestMultipartConfig.java
@@ -0,0 +1,171 @@
+package org.apache.catalina.startup;
+
+import java.lang.reflect.Method;
+
+import jakarta.servlet.MultipartConfigElement;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleState;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardEngine;
+import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardService;
+import org.apache.catalina.core.StandardWrapper;
+import org.apache.tomcat.util.descriptor.web.MultipartDef;
+import org.apache.tomcat.util.descriptor.web.ServletDef;
+import org.apache.tomcat.util.descriptor.web.WebXml;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestMultipartConfig {
+@Test
+public void testNoMultipartConfig() throws Exception {
+StandardWrapper servlet =  config(null);
+
+MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+Assert.assertNull(mce);
+}
+
+@Test
+public void testDefaultMultipartConfig() throws Exception {
+MultipartDef multipartDef = new MultipartDef();
+// Do not set any attributes on multipartDef: expect defaults
+
+StandardWrapper servlet =  config(multipartDef);
+MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+Assert.assertNotNull(mce);
+Assert.assertEquals("", mce.getLocation());
+Assert.assertEquals(-1, mce.getMaxFileSize());
+Assert.assertEquals(-1, mce.getMaxRequestSize());
+Assert.assertEquals(0, mce.getFileSizeThreshold());
+}
+
+@Test
+public void testPartialMultipartConfigMaxFileSize() throws Exception {
+MultipartDef multipartDef = new Mul

[tomcat] 01/04: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64384

2020-04-27 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 56f21b8654260291d1e088016ab1145779c3329c
Author: Christopher Schultz 
AuthorDate: Mon Apr 27 18:01:00 2020 -0400

Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64384

Respect partial multipart-config elements.
---
 .../org/apache/catalina/startup/ContextConfig.java |  30 ++--
 .../catalina/startup/TestMultipartConfig.java  | 171 +
 2 files changed, 189 insertions(+), 12 deletions(-)

diff --git a/java/org/apache/catalina/startup/ContextConfig.java 
b/java/org/apache/catalina/startup/ContextConfig.java
index 82db594..252912b 100644
--- a/java/org/apache/catalina/startup/ContextConfig.java
+++ b/java/org/apache/catalina/startup/ContextConfig.java
@@ -1362,19 +1362,25 @@ public class ContextConfig implements LifecycleListener 
{
 wrapper.setServletClass(servlet.getServletClass());
 MultipartDef multipartdef = servlet.getMultipartDef();
 if (multipartdef != null) {
-if (multipartdef.getMaxFileSize() != null &&
-multipartdef.getMaxRequestSize()!= null &&
-multipartdef.getFileSizeThreshold() != null) {
-wrapper.setMultipartConfigElement(new 
MultipartConfigElement(
-multipartdef.getLocation(),
-Long.parseLong(multipartdef.getMaxFileSize()),
-Long.parseLong(multipartdef.getMaxRequestSize()),
-Integer.parseInt(
-multipartdef.getFileSizeThreshold(;
-} else {
-wrapper.setMultipartConfigElement(new 
MultipartConfigElement(
-multipartdef.getLocation()));
+long maxFileSize = -1;
+long maxRequestSize = -1;
+int fileSizeThreshold = 0;
+
+if(null != multipartdef.getMaxFileSize()) {
+maxFileSize = 
Long.parseLong(multipartdef.getMaxFileSize());
+}
+if(null != multipartdef.getMaxRequestSize()) {
+maxRequestSize = 
Long.parseLong(multipartdef.getMaxRequestSize());
 }
+if(null != multipartdef.getFileSizeThreshold()) {
+fileSizeThreshold = 
Integer.parseInt(multipartdef.getFileSizeThreshold());
+}
+
+wrapper.setMultipartConfigElement(new MultipartConfigElement(
+multipartdef.getLocation(),
+maxFileSize,
+maxRequestSize,
+fileSizeThreshold));
 }
 if (servlet.getAsyncSupported() != null) {
 wrapper.setAsyncSupported(
diff --git a/test/org/apache/catalina/startup/TestMultipartConfig.java 
b/test/org/apache/catalina/startup/TestMultipartConfig.java
new file mode 100644
index 000..d0ca905
--- /dev/null
+++ b/test/org/apache/catalina/startup/TestMultipartConfig.java
@@ -0,0 +1,171 @@
+package org.apache.catalina.startup;
+
+import java.lang.reflect.Method;
+
+import jakarta.servlet.MultipartConfigElement;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleState;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardEngine;
+import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardService;
+import org.apache.catalina.core.StandardWrapper;
+import org.apache.tomcat.util.descriptor.web.MultipartDef;
+import org.apache.tomcat.util.descriptor.web.ServletDef;
+import org.apache.tomcat.util.descriptor.web.WebXml;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestMultipartConfig {
+@Test
+public void testNoMultipartConfig() throws Exception {
+StandardWrapper servlet =  config(null);
+
+MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+Assert.assertNull(mce);
+}
+
+@Test
+public void testDefaultMultipartConfig() throws Exception {
+MultipartDef multipartDef = new MultipartDef();
+// Do not set any attributes on multipartDef: expect defaults
+
+StandardWrapper servlet =  config(multipartDef);
+MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+Assert.assertNotNull(mce);
+Assert.assertEquals("", mce.getLocation());
+Assert.assertEquals(-1, mce.getMaxFileSize());
+Assert.assertEquals(-1, mce.getMaxRequestSize());
+Assert.assertEquals(0, mce.getFileSizeThreshold());
+}
+
+@Test
+public void testPartialMultipartConfigMaxFileSize() throws Exception {
+MultipartDef multipartDef = new Mul