ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/startup/TestMultipartConfig.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/startup/TestMultipartConfig.java
Status
scanned
Type
file
Name
TestMultipartConfig.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
7043 (6.9 KB)
MD5
42cb13e9c93659e0e5f1486100b8403e
SHA1
61c789ba439c1cc20599925fa6637606b397c8d8
SHA256
c31ae0ccf834e1ab77f8e458b511bd8dc114112032a937b70d4fb0d1fdd610f7
SHA512

      
    
SHA1_git
2f95c156c6f378fa9a4b4d5df3c928f48da81473
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestMultipartConfig.java | 6.9 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.startup; import java.lang.reflect.Method; import jakarta.servlet.MultipartConfigElement; import org.junit.Assert; import org.junit.Test; 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; 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 MultipartDef(); multipartDef.setMaxFileSize("1024"); StandardWrapper servlet = config(multipartDef); MultipartConfigElement mce = servlet.getMultipartConfigElement(); Assert.assertNotNull(mce); Assert.assertEquals("", mce.getLocation()); Assert.assertEquals(1024, mce.getMaxFileSize()); Assert.assertEquals(-1, mce.getMaxRequestSize()); Assert.assertEquals(0, mce.getFileSizeThreshold()); } @Test public void testPartialMultipartConfigMaxRequestSize() throws Exception { MultipartDef multipartDef = new MultipartDef(); multipartDef.setMaxRequestSize("10240"); StandardWrapper servlet = config(multipartDef); MultipartConfigElement mce = servlet.getMultipartConfigElement(); Assert.assertNotNull(mce); Assert.assertEquals("", mce.getLocation()); Assert.assertEquals(-1, mce.getMaxFileSize()); Assert.assertEquals(10240, mce.getMaxRequestSize()); Assert.assertEquals(0, mce.getFileSizeThreshold()); } @Test public void testPartialMultipartConfigFileSizeThreshold() throws Exception { MultipartDef multipartDef = new MultipartDef(); multipartDef.setFileSizeThreshold("24"); 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(24, mce.getFileSizeThreshold()); } @Test public void testCompleteMultipartConfig() throws Exception { MultipartDef multipartDef = new MultipartDef(); multipartDef.setMaxFileSize("1024"); multipartDef.setMaxRequestSize("10240"); multipartDef.setFileSizeThreshold("24"); multipartDef.setLocation("/tmp/foo"); StandardWrapper servlet = config(multipartDef); MultipartConfigElement mce = servlet.getMultipartConfigElement(); Assert.assertNotNull(mce); Assert.assertEquals("/tmp/foo", mce.getLocation()); Assert.assertEquals(1024, mce.getMaxFileSize()); Assert.assertEquals(10240, mce.getMaxRequestSize()); Assert.assertEquals(24, mce.getFileSizeThreshold()); } private StandardWrapper config(MultipartDef multipartDef) throws Exception { MyContextConfig config = new MyContextConfig(); WebXml webxml = new WebXml(); ServletDef servletDef = new ServletDef(); servletDef.setServletName("test"); servletDef.setServletClass("org.apache.catalina.startup.ParamServlet"); servletDef.setMultipartDef(multipartDef); webxml.addServlet(servletDef); Method m = ContextConfig.class.getDeclaredMethod("configureContext", WebXml.class); // Force our way in m.setAccessible(true); m.invoke(config, webxml); StandardWrapper servlet = (StandardWrapper)config.getContext().findChild("test"); return servlet; } private static class MyContextConfig extends ContextConfig { MyContextConfig() { CustomContext context = new CustomContext(); super.context = context; context.setConfigured(false); context.setState(LifecycleState.STARTING_PREP); context.setName("test"); Connector connector = new Connector(); StandardService service = new StandardService(); service.addConnector(connector); StandardEngine engine = new StandardEngine(); engine.setService(service); Container parent = new StandardHost(); parent.setParent(engine); super.context.setParent(parent); } public Context getContext() { return super.context; } } private static class CustomContext extends StandardContext { private volatile LifecycleState state; @Override public synchronized LifecycleState getState() { return state; } @Override public synchronized void setState(LifecycleState state) { this.state = state; } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
19.38
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9