ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/servlets/ServletOptionsBaseTest.java

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

      
    
Rootfs path

      
    
Size
5783 (5.6 KB)
MD5
dc010a042e8932aab8798a9d0c7dcba0
SHA1
25a0f66b719e73d36c44d32c0bd44bffbbc75bb0
SHA256
4a3046f924e4b5748a5c37e3699e69d72a260fabae7ab04a6a8f8ca032a1c115
SHA512

      
    
SHA1_git
28264052edb3b482110f57ea965b9106ddcd5806
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ServletOptionsBaseTest.java | 5.6 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.servlets; import java.io.File; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import jakarta.servlet.Servlet; import org.junit.Assert; import org.junit.Test; import org.junit.runners.Parameterized.Parameter; import static org.apache.catalina.startup.SimpleHttpClient.CRLF; import org.apache.catalina.Wrapper; import org.apache.catalina.startup.SimpleHttpClient; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; import org.apache.tomcat.util.scan.StandardJarScanner; public abstract class ServletOptionsBaseTest extends TomcatBaseTest { protected static final String COLLECTION_NAME = "collection"; protected static final String FILE_NAME = "file"; protected static final String UNKNOWN_NAME = "unknown"; @Parameter(0) public boolean listings; @Parameter(1) public boolean readonly; @Parameter(2) public boolean trace; @Parameter(3) public String url; @Parameter(4) public String method; /* * Check that methods returned by OPTIONS are consistent with the return * http status code. * Method not present in options response -> 405 expected * Method present in options response -> anything other than 405 expected */ @Test public void testOptions() throws Exception { Tomcat tomcat = getTomcatInstance(); tomcat.getConnector().setAllowTrace(trace); File docBase = new File(getTemporaryDirectory(), "webdav"); File collection = new File(docBase, COLLECTION_NAME); Assert.assertTrue(collection.mkdirs()); File file = new File(docBase, FILE_NAME); Assert.assertTrue(file.createNewFile()); addDeleteOnTearDown(docBase); // app dir is relative to server home org.apache.catalina.Context ctx = tomcat.addWebapp(null, "/webdav", docBase.getAbsolutePath()); Wrapper w = Tomcat.addServlet(ctx, "servlet", createServlet()); w.addInitParameter("listings", Boolean.toString(listings)); w.addInitParameter("readonly", Boolean.toString(readonly)); ctx.addServletMappingDecoded("/*", "servlet"); // Disable class path scanning - it slows the tests down by almost an order of magnitude ((StandardJarScanner) ctx.getJarScanner()).setScanClassPath(false); tomcat.start(); OptionsHttpClient client = new OptionsHttpClient(); client.setPort(getPort()); // @formatter:off client.setRequest(new String[] { "OPTIONS /webdav/" + url + " HTTP/1.1" + CRLF + "Host: localhost:" + getPort() + CRLF + "Connection: close" + CRLF + CRLF }); // @formatter:on client.connect(); client.processRequest(); Assert.assertTrue(client.getResponseLine(), client.isResponse200()); Set<String> allowed = client.getAllowedMethods(); client.disconnect(); client.reset(); // @formatter:off client.setRequest(new String[] { method + " /webdav/" + url + " HTTP/1.1" + CRLF + "Host: localhost:" + getPort() + CRLF + "Connection: close" + CRLF + CRLF }); // @formatter:on client.connect(); client.processRequest(); String msg = "Listings[" + listings + "], readonly [" + readonly + "], trace[ " + trace + "], url[" + url + "], method[" + method + "]"; Assert.assertNotNull(client.getResponseLine()); if (allowed.contains(method)) { Assert.assertFalse(msg, client.isResponse405()); } else { Assert.assertTrue(msg, client.isResponse405()); allowed = client.getAllowedMethods(); Assert.assertFalse(msg, allowed.contains(method)); } } protected abstract Servlet createServlet(); private static class OptionsHttpClient extends SimpleHttpClient { @Override public boolean isResponseBodyOK() { return true; } public Set<String> getAllowedMethods() { String valueList = null; for (String header : getResponseHeaders()) { if (header.startsWith("Allow:")) { valueList = header.substring(6).trim(); break; } } Assert.assertNotNull(valueList); String[] values = valueList.split(","); for (int i = 0; i < values.length; i++) { values[i] = values[i].trim(); } Set<String> allowed = new HashSet<>(Arrays.asList(values)); return allowed; } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
21.06
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