test/jdk/java/net/ipv6tests/BadIPv6Addresses.java
author dfuchs
Wed, 10 Jul 2019 22:33:23 +0200
changeset 55649 ad8e3b295615
parent 47216 71c04702a3d5
permissions -rw-r--r--
8227539: Replace wildcard address with loopback or local host in tests - part 20 Summary: Update some tests to stop using the wildcard address. Reviewed-by: michaelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21630
diff changeset
     2
 * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
21630
58a025b37bff 8019834: InetAddress.getByName hangs for bad IPv6 literals
chegar
parents: 5506
diff changeset
    26
 * @bug 4742177 8019834
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class BadIPv6Addresses {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
        String[] badAddresses = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
            "0:1:2:3:4:5:6:7:8",        // too many :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
            "0:1:2:3:4:5:6",            // not enough :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
            "0:1:2:3:4:5:6:x",          // bad digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
            "0:1:2:3:4:5:6::7",         // adjacent :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
            "0:1:2:3:4:5:6:789abcdef",  // too many digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
            "0:1:2:3::x",               // compressed, bad digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
            "0:1:2:::3",                // compressed, too many adjacent :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            "0:1:2:3::abcde",           // compressed, too many digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            "0:1",                      // compressed, not enough :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
            "0:0:0:0:0:x:10.0.0.1",     // with embeded ipv4, bad ipv6 digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            "0:0:0:0:0:0:10.0.0.x",     // with embeded ipv4, bad ipv4 digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            "0:0:0:0:0::0:10.0.0.1",    // with embeded ipv4, adjacent :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            "0:0:0:0:0:fffff:10.0.0.1", // with embeded ipv4, too many ipv6 digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            "0:0:0:0:0:0:0:10.0.0.1",   // with embeded ipv4, too many :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            "0:0:0:0:0:10.0.0.1",       // with embeded ipv4, not enough :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            "0:0:0:0:0:0:10.0.0.0.1",   // with embeded ipv4, too many .
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            "0:0:0:0:0:0:10.0.1",       // with embeded ipv4, not enough .
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            "0:0:0:0:0:0:10..0.0.1",    // with embeded ipv4, adjacent .
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            "::fffx:192.168.0.1",       // with compressed ipv4, bad ipv6 digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            "::ffff:192.168.0.x",       // with compressed ipv4, bad ipv4 digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            ":::ffff:192.168.0.1",      // with compressed ipv4, too many adjacent :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            "::fffff:192.168.0.1",      // with compressed ipv4, too many ipv6 digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            "::ffff:1923.168.0.1",      // with compressed ipv4, too many ipv4 digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            ":ffff:192.168.0.1",        // with compressed ipv4, not enough :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            "::ffff:192.168.0.1.2",     // with compressed ipv4, too many .
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            "::ffff:192.168.0",         // with compressed ipv4, not enough .
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            "::ffff:192.168..0.1"       // with compressed ipv4, adjacent .
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        List<String> failedAddrs = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        for (String addrStr : badAddresses) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                InetAddress addr = InetAddress.getByName(addrStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                // it is an error if no exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                failedAddrs.add(addrStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                // expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (failedAddrs.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            System.out.println("We should reject following ipv6 addresses, but we didn't:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            for (String addr : failedAddrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                System.out.println("\t" + addr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throw new RuntimeException("Test failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
}