|
1 /* |
|
2 * Copyright 2001 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /* @test |
|
25 * @bug 4451522 4460484 |
|
26 * @summary URI and URL getHost() methods don't comform to RFC 2732 |
|
27 */ |
|
28 import java.net.*; |
|
29 |
|
30 public class TestIPv6Addresses { |
|
31 public static void main(String[] args) { |
|
32 try { |
|
33 // testing InetAddress static constructors |
|
34 InetAddress ia1 = InetAddress.getByName("fe80::a00:20ff:feae:45c9"); |
|
35 InetAddress ia2 = InetAddress.getByName("[fe80::a00:20ff:feae:45c9]"); |
|
36 System.out.println("InetAddress: "+ia1+" , "+ia2); |
|
37 if (!ia1.equals(ia2)) { |
|
38 throw new RuntimeException("InetAddress.getByName failed for"+ |
|
39 "literal IPv6 addresses"); |
|
40 } |
|
41 // testing URL constructor, getHost and getAuthority |
|
42 URL u1 = new URL("http", "fe80::a00:20ff:feae:45c9", 80, "/index.html"); |
|
43 URL u2 = new URL("http", "[fe80::a00:20ff:feae:45c9]", 80, "/index.html"); |
|
44 if (!u1.equals(u2)) { |
|
45 throw new RuntimeException("URL constructor failed for"+ |
|
46 "literal IPv6 addresses"); |
|
47 } |
|
48 if (!u1.getHost().equals(u2.getHost()) || |
|
49 !u1.getHost().equals("[fe80::a00:20ff:feae:45c9]")) { |
|
50 throw new RuntimeException("URL.getHost() failed for"+ |
|
51 "literal IPv6 addresses"); |
|
52 } |
|
53 if (!u1.getAuthority().equals("[fe80::a00:20ff:feae:45c9]:80")) { |
|
54 throw new RuntimeException("URL.getAuthority() failed for"+ |
|
55 "literal IPv6 addresses"); |
|
56 } |
|
57 |
|
58 // need to test URI as well |
|
59 |
|
60 // testing SocketPermission to see whether it handles unambiguous cases |
|
61 // testing getIP and getHost etc |
|
62 SocketPermission sp1 = |
|
63 new SocketPermission(u1.getHost()+":80-", "resolve"); |
|
64 SocketPermission sp2 = |
|
65 new SocketPermission(ia1.getHostAddress()+":8080", "resolve"); |
|
66 |
|
67 if (!sp1.implies(sp2)) { |
|
68 throw new RuntimeException("SocketPermission implies doesn't work"+ |
|
69 " for literal IPv6 addresses"); |
|
70 } |
|
71 } catch (Exception e) { |
|
72 throw new RuntimeException(e.getMessage()); |
|
73 } |
|
74 // bug 4460484 |
|
75 |
|
76 SecurityManager sm = new SecurityManager(); |
|
77 String strAddr = "::FFFF:127.0.0.1.2"; |
|
78 |
|
79 try { |
|
80 InetAddress addr = InetAddress.getByName(strAddr); |
|
81 } catch (UnknownHostException e) { |
|
82 // expected |
|
83 } |
|
84 System.setSecurityManager(sm); |
|
85 |
|
86 try { |
|
87 InetAddress addr = InetAddress.getByName(strAddr); |
|
88 } catch (java.security.AccessControlException e) { |
|
89 // expected |
|
90 } catch (UnknownHostException e) { |
|
91 // expected |
|
92 } |
|
93 |
|
94 } |
|
95 } |