Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/URL/TestIPv6Addresses.java
41149 views
1
/*
2
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 4451522 4460484
26
* @run main/othervm -Djava.security.manager=allow TestIPv6Addresses
27
* @summary URI and URL getHost() methods don't comform to RFC 2732
28
*/
29
30
// Run in othervm -Djava.security.manager=allow because the tests sets a SecurityManager
31
32
import java.net.*;
33
34
public class TestIPv6Addresses {
35
public static void main(String[] args) {
36
try {
37
// testing InetAddress static constructors
38
InetAddress ia1 = InetAddress.getByName("fe80::a00:20ff:feae:45c9");
39
InetAddress ia2 = InetAddress.getByName("[fe80::a00:20ff:feae:45c9]");
40
System.out.println("InetAddress: "+ia1+" , "+ia2);
41
if (!ia1.equals(ia2)) {
42
throw new RuntimeException("InetAddress.getByName failed for"+
43
"literal IPv6 addresses");
44
}
45
// testing URL constructor, getHost and getAuthority
46
URL u1 = new URL("http", "fe80::a00:20ff:feae:45c9", 80, "/index.html");
47
URL u2 = new URL("http", "[fe80::a00:20ff:feae:45c9]", 80, "/index.html");
48
if (!u1.equals(u2)) {
49
throw new RuntimeException("URL constructor failed for"+
50
"literal IPv6 addresses");
51
}
52
if (!u1.getHost().equals(u2.getHost()) ||
53
!u1.getHost().equals("[fe80::a00:20ff:feae:45c9]")) {
54
throw new RuntimeException("URL.getHost() failed for"+
55
"literal IPv6 addresses");
56
}
57
if (!u1.getAuthority().equals("[fe80::a00:20ff:feae:45c9]:80")) {
58
throw new RuntimeException("URL.getAuthority() failed for"+
59
"literal IPv6 addresses");
60
}
61
62
// need to test URI as well
63
64
// testing SocketPermission to see whether it handles unambiguous cases
65
// testing getIP and getHost etc
66
SocketPermission sp1 =
67
new SocketPermission(u1.getHost()+":80-", "resolve");
68
SocketPermission sp2 =
69
new SocketPermission(ia1.getHostAddress()+":8080", "resolve");
70
71
if (!sp1.implies(sp2)) {
72
throw new RuntimeException("SocketPermission implies doesn't work"+
73
" for literal IPv6 addresses");
74
}
75
} catch (Exception e) {
76
throw new RuntimeException(e.getMessage());
77
}
78
// bug 4460484
79
80
SecurityManager sm = new SecurityManager();
81
String strAddr = "::FFFF:127.0.0.1.2";
82
83
try {
84
InetAddress addr = InetAddress.getByName(strAddr);
85
} catch (UnknownHostException e) {
86
// expected
87
}
88
System.setSecurityManager(sm);
89
90
try {
91
InetAddress addr = InetAddress.getByName(strAddr);
92
} catch (java.security.AccessControlException e) {
93
// expected
94
} catch (UnknownHostException e) {
95
// expected
96
}
97
98
}
99
}
100
101