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

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

      
    
Rootfs path

      
    
Size
6126 (6.0 KB)
MD5
a819cc169f67d166e0c91971ddd48fbc
SHA1
b162e4de61009937a2944aa09aee8a1834d2f22b
SHA256
9558f67ff0eaca9dfc18e77ec955b289b12f8573ca57839331ffa3a07c138aa9
SHA512

      
    
SHA1_git
9cfa33821f6186b0c30ba9faa075b3a951cbb1eb
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestStartupIPv6Connectors.java | 6.0 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.net.HttpURLConnection; import java.net.Inet6Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.URI; import java.net.URL; import java.util.Enumeration; import jakarta.servlet.http.HttpServletResponse; import org.junit.Assert; import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Test; import org.apache.catalina.Context; public class TestStartupIPv6Connectors extends TomcatBaseTest { private static String linklocalAddress; private static String globalAddress; @Test public void testIPv6Localhost() throws Exception { assertHttpOkOnAddress("::1"); } @Test public void testIPv6LinkLocal() throws Exception { Assume.assumeTrue("No IPv6 link-local present", linklocalAddress != null); assertHttpOkOnAddress(linklocalAddress); } @Test public void testIPv6Global() throws Exception { Assume.assumeTrue("No IPv6 global-unicast present", globalAddress != null); assertHttpOkOnAddress(globalAddress); } @Test public void testIPv6MappedIPv4() throws Exception { assertHttpOkOnAddress("::ffff:127.0.0.1"); } @BeforeClass public static void initializeTestIpv6Addresses() throws Exception { Inet6Address possibleLinkLocalLoopback = null; Inet6Address possibleLinkLocalOnGlobal = null; Inet6Address possibleLinkLocalAny = null; Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface interf = interfaces.nextElement(); if (!interf.isUp() || interf.isVirtual() || interf.isPointToPoint() || !interf.supportsMulticast()) { continue; } Enumeration<InetAddress> addresses = interf.getInetAddresses(); boolean globalOnInterface = false; while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (address instanceof Inet6Address inet6Address) { if (!inet6Address.isAnyLocalAddress() && !inet6Address.isLoopbackAddress() && !inet6Address.isLinkLocalAddress() && !inet6Address.isMulticastAddress()) { globalOnInterface = true; if (!interf.isLoopback()) { globalAddress = inet6Address.getHostAddress(); break; } } } } // Second pass to get link-local results with specific order addresses = interf.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (address instanceof Inet6Address inet6Address) { if (inet6Address.isLinkLocalAddress()) { if (interf.isLoopback()) { // Best option for mac possibleLinkLocalLoopback = inet6Address; } else if (globalOnInterface && possibleLinkLocalOnGlobal == null) { // link-local on an interface that also has a global IPv6 (e.g. en0) possibleLinkLocalOnGlobal = inet6Address; } else if (possibleLinkLocalAny == null) { possibleLinkLocalAny = inet6Address; } } } } } if (possibleLinkLocalLoopback != null) { linklocalAddress = possibleLinkLocalLoopback.getHostAddress(); } else if (possibleLinkLocalOnGlobal != null) { linklocalAddress = possibleLinkLocalOnGlobal.getHostAddress(); } else if (possibleLinkLocalAny != null) { linklocalAddress = possibleLinkLocalAny.getHostAddress(); } } private void assertHttpOkOnAddress(String address) throws Exception { Tomcat tomcat = getTomcatInstance(); tomcat.getConnector().setProperty("address", address); File baseDir = new File(getTemporaryDirectory(), "ipv6"); addDeleteOnTearDown(baseDir); Assert.assertTrue(baseDir.mkdirs() && baseDir.isDirectory()); tomcat.setBaseDir(baseDir.getAbsolutePath()); Context context = tomcat.addContext("", null); Tomcat.addServlet(context, "simple", new HelloWorldServlet()); context.addServletMappingDecoded("/", "simple"); try { tomcat.start(); } catch (Exception e) { Assume.assumeNoException("Can't bind to " + address, e); } if (address.contains(":")) { address = "[" + address + "]"; } URL url = new URI("http://" + address + ":" + getPort() + "/").toURL(); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); Assert.assertEquals(HttpServletResponse.SC_OK, connection.getResponseCode()); tomcat.stop(); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
23.94
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