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

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

      
    
Rootfs path

      
    
Size
3646 (3.6 KB)
MD5
ef658c39648c1dd4273ab331e0b5b3ee
SHA1
348fe43e0e0a9b869c45f439ac6303d089385e8f
SHA256
16fce5cb3c53ed1f7cf9409dd2fc4b09887b7027babb73e09426808b7fecae72
SHA512

      
    
SHA1_git
9e227b97168189c1a77a1ec14ebc23491c5148b5
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestXmlValidationUsingContext.java | 3.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.startup; import java.io.File; import java.io.FileWriter; import java.io.IOException; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.Context; /** * Tests XML validation works on the Context. */ public class TestXmlValidationUsingContext extends TomcatBaseTest { @Test public void contextValidationWithInvalidWebXml() throws Exception { File appDir = getTemporaryDirectory(); File webInf = new File(appDir, "WEB-INF"); Assert.assertTrue(webInf.isDirectory() || webInf.mkdirs()); writeInvalidXml(new File(webInf, "web.xml")); Tomcat tomcat = getTomcatInstance(); Context ctx = tomcat.addWebapp(null, "", appDir.getAbsolutePath()); ctx.setXmlValidation(true); ctx.setXmlNamespaceAware(true); tomcat.start(); Assert.assertFalse("Context should not be available when web.xml is invalid and validation is enabled", ctx.getState().isAvailable()); } @Test public void contextValidationWithValidWebXml() throws Exception { File appDir = getTemporaryDirectory(); File webInf = new File(appDir, "WEB-INF"); Assert.assertTrue(webInf.isDirectory() || webInf.mkdirs()); writeValidXml(new File(webInf, "web.xml")); Tomcat tomcat = getTomcatInstance(); Context ctx = tomcat.addWebapp(null, "", appDir.getAbsolutePath()); ctx.setXmlValidation(true); ctx.setXmlNamespaceAware(true); tomcat.start(); Assert.assertTrue("Context should be available when web.xml is valid and validation is enabled", ctx.getState().isAvailable()); } private void writeValidXml(File webXml) throws IOException { try (FileWriter fw = new FileWriter(webXml)) { fw.write( """ <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" version="6.0"> </web-app> """); } } private void writeInvalidXml(File webXml) throws IOException { try (FileWriter fw = new FileWriter(webXml)) { fw.write( """ <?xml version="1.0" encoding="UTF-8"?> <web-app> </web-app> """); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
31.4
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://jakarta.ee/xml/ns/jakartaee 68 68
https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd 71 71