ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/webresources/TestCachedResource.java

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

      
    
Rootfs path

      
    
Size
5753 (5.6 KB)
MD5
348c9055fcd518a2487818bd22e8f836
SHA1
3ebd48acf303f34d563d5e3a0aa80a1690593a62
SHA256
bda15013417ce3bd0a85278c280514992c015cdd6ec08faa490efc1c53db5fb4
SHA512

      
    
SHA1_git
38cd7a81b281e7174b7b92a582b682821b411df8
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestCachedResource.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.webresources; import java.io.ByteArrayInputStream; import java.io.File; import java.io.InputStream; import java.net.JarURLConnection; import java.net.URL; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.Context; import org.apache.catalina.WebResourceRoot; import org.apache.catalina.core.StandardHost; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; public class TestCachedResource extends TomcatBaseTest { // https://bz.apache.org/bugzilla/show_bug.cgi?id=63872 @Test public void testUrlFileFromDirectory() throws Exception { Tomcat tomcat = getTomcatInstance(); File docBase = new File("test/webresources/dir1"); Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath()); tomcat.start(); WebResourceRoot root = ctx.getResources(); URL d1 = root.getResource("/d1").getURL(); URL d1f1 = d1.toURI().resolve("d1-f1.txt").toURL(); try (InputStream is = d1f1.openStream()) { Assert.assertNotNull(is); } } // https://bz.apache.org/bugzilla/show_bug.cgi?id=63970 @Test public void testCachedJarUrlConnection() throws Exception { Tomcat tomcat = getTomcatInstance(); File docBase = new File("test/webresources/war-url-connection.war"); Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath()); tomcat.start(); WebResourceRoot root = ctx.getResources(); // WAR contains a resources JAR so this should return a JAR URL URL webinf = root.getResource("/index.html").getURL(); Assert.assertEquals("jar", webinf.getProtocol()); JarURLConnection jarConn = null; try { jarConn = (JarURLConnection) webinf.openConnection(); } catch (ClassCastException e) { // Ignore } Assert.assertNotNull(jarConn); } @Test public void testDirectoryListingsPackedWar() throws Exception { Tomcat tomcat = getTomcatInstance(); File docBase = new File("test/webresources/war-url-connection.war"); Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath()); ((StandardHost) tomcat.getHost()).setUnpackWARs(false); tomcat.start(); WebResourceRoot root = ctx.getResources(); URL d1 = root.getResource("/").getURL(); try (InputStream is = d1.openStream()) { Assert.assertNotNull(is); } } @Test public void testDirectoryListingsWar() throws Exception { Tomcat tomcat = getTomcatInstance(); File docBase = new File("test/webresources/war-url-connection.war"); Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath()); tomcat.start(); WebResourceRoot root = ctx.getResources(); URL d1 = root.getResource("/").getURL(); try (InputStream is = d1.openStream()) { Assert.assertNotNull(is); } } @Test public void testDirectoryListingsDir() throws Exception { Tomcat tomcat = getTomcatInstance(); File docBase = new File("test/webresources/dir1"); Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath()); tomcat.start(); WebResourceRoot root = ctx.getResources(); URL d1 = root.getResource("/d1").getURL(); try (InputStream is = d1.openStream()) { Assert.assertNotNull(is); } } @Test public void testGetContentWebInfClasses() throws Exception { Tomcat tomcat = getTomcatInstance(); File docBase = new File("test/webapp"); Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath()); tomcat.start(); URL url = ctx.getLoader().getClassLoader().getResource("bug69623-a.mdd"); Object o = url.getContent(); /* * Could test the actual content but a non-null return without an exception is enough to demonstrate the bug has * not occurred. */ Assert.assertTrue(o instanceof ByteArrayInputStream); } @Test public void testGetContentWebInfLib() throws Exception { Tomcat tomcat = getTomcatInstance(); File docBase = new File("test/webapp"); Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath()); tomcat.start(); URL url = ctx.getLoader().getClassLoader().getResource("bug69623-b.mdd"); Object o = url.getContent(); /* * Could test the actual content but a non-null return without an exception is enough to demonstrate the bug has * not occurred. */ Assert.assertTrue(o instanceof ByteArrayInputStream); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
20.24
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
https://bz.apache.org/bugzilla/show_bug.cgi?id=63872 36 36
https://bz.apache.org/bugzilla/show_bug.cgi?id=63970 57 57