author | jboes |
Fri, 08 Nov 2019 11:15:16 +0000 | |
changeset 59029 | 3786a0962570 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
3864 | 1 |
/* |
40975
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
32427
diff
changeset
|
2 |
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. |
3864 | 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 |
* |
|
5506 | 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. |
|
3864 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
3944
e098e010b520
6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents:
3864
diff
changeset
|
26 |
* @bug 6877357 6885166 |
9008
1c23e333dd76
7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents:
7977
diff
changeset
|
27 |
* @run main/othervm IPv6 |
40975
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
32427
diff
changeset
|
28 |
* @modules jdk.security.auth |
3864 | 29 |
* @summary IPv6 address does not work |
30 |
*/ |
|
31 |
||
32 |
import com.sun.security.auth.module.Krb5LoginModule; |
|
40975
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
32427
diff
changeset
|
33 |
import java.io.BufferedReader; |
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
32427
diff
changeset
|
34 |
import java.io.ByteArrayOutputStream; |
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
32427
diff
changeset
|
35 |
import java.io.FileOutputStream; |
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
32427
diff
changeset
|
36 |
import java.io.PrintStream; |
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
32427
diff
changeset
|
37 |
import java.io.StringReader; |
3864 | 38 |
import java.util.HashMap; |
39 |
import java.util.Map; |
|
40 |
import java.util.regex.Matcher; |
|
41 |
import java.util.regex.Pattern; |
|
42 |
import javax.security.auth.Subject; |
|
43 |
||
44 |
public class IPv6 { |
|
45 |
||
46 |
public static void main(String[] args) throws Exception { |
|
47 |
||
48 |
String[][] kdcs = { |
|
49 |
{"simple.host", null}, // These are legal settings |
|
50 |
{"simple.host", ""}, |
|
51 |
{"simple.host", "8080"}, |
|
52 |
{"0.0.0.1", null}, |
|
53 |
{"0.0.0.1", ""}, |
|
54 |
{"0.0.0.1", "8080"}, |
|
55 |
{"1::1", null}, |
|
56 |
{"[1::1]", null}, |
|
57 |
{"[1::1]", ""}, |
|
58 |
{"[1::1]", "8080"}, |
|
59 |
{"[1::1", null}, // Two illegal settings |
|
60 |
{"[1::1]abc", null}, |
|
61 |
}; |
|
62 |
// Prepares a krb5.conf with every kind of KDC settings |
|
63 |
PrintStream out = new PrintStream(new FileOutputStream("ipv6.conf")); |
|
64 |
out.println("[libdefaults]"); |
|
65 |
out.println("default_realm = V6"); |
|
3944
e098e010b520
6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents:
3864
diff
changeset
|
66 |
out.println("kdc_timeout = 1"); |
3864 | 67 |
out.println("[realms]"); |
68 |
out.println("V6 = {"); |
|
69 |
for (String[] hp: kdcs) { |
|
70 |
if (hp[1] != null) out.println(" kdc = "+hp[0]+":"+hp[1]); |
|
71 |
else out.println(" kdc = " + hp[0]); |
|
72 |
} |
|
73 |
out.println("}"); |
|
74 |
out.close(); |
|
75 |
||
76 |
System.setProperty("sun.security.krb5.debug", "true"); |
|
77 |
System.setProperty("java.security.krb5.conf", "ipv6.conf"); |
|
78 |
||
79 |
ByteArrayOutputStream bo = new ByteArrayOutputStream(); |
|
80 |
PrintStream po = new PrintStream(bo); |
|
81 |
PrintStream oldout = System.out; |
|
82 |
System.setOut(po); |
|
83 |
||
84 |
try { |
|
85 |
Subject subject = new Subject(); |
|
86 |
Krb5LoginModule krb5 = new Krb5LoginModule(); |
|
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
5506
diff
changeset
|
87 |
Map<String, String> map = new HashMap<>(); |
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
5506
diff
changeset
|
88 |
Map<String, Object> shared = new HashMap<>(); |
3864 | 89 |
|
90 |
map.put("debug", "true"); |
|
91 |
map.put("doNotPrompt", "true"); |
|
92 |
map.put("useTicketCache", "false"); |
|
93 |
map.put("useFirstPass", "true"); |
|
94 |
shared.put("javax.security.auth.login.name", "any"); |
|
95 |
shared.put("javax.security.auth.login.password", "any".toCharArray()); |
|
96 |
krb5.initialize(subject, null, shared, map); |
|
97 |
krb5.login(); |
|
98 |
} catch (Exception e) { |
|
99 |
// Ignore |
|
100 |
} |
|
101 |
||
102 |
po.flush(); |
|
103 |
||
104 |
System.setOut(oldout); |
|
3944
e098e010b520
6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents:
3864
diff
changeset
|
105 |
BufferedReader br = new BufferedReader(new StringReader( |
e098e010b520
6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents:
3864
diff
changeset
|
106 |
new String(bo.toByteArray()))); |
3864 | 107 |
int cc = 0; |
108 |
Pattern r = Pattern.compile(".*KrbKdcReq send: kdc=(.*) UDP:(\\d+),.*"); |
|
3944
e098e010b520
6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents:
3864
diff
changeset
|
109 |
String line; |
e098e010b520
6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents:
3864
diff
changeset
|
110 |
while ((line = br.readLine()) != null) { |
3864 | 111 |
Matcher m = r.matcher(line.subSequence(0, line.length())); |
112 |
if (m.matches()) { |
|
113 |
System.out.println("------------------"); |
|
114 |
System.out.println(line); |
|
115 |
String h = m.group(1), p = m.group(2); |
|
116 |
String eh = kdcs[cc][0], ep = kdcs[cc][1]; |
|
117 |
if (eh.charAt(0) == '[') { |
|
118 |
eh = eh.substring(1, eh.length()-1); |
|
119 |
} |
|
120 |
System.out.println("Expected: " + eh + " : " + ep); |
|
121 |
System.out.println("Actual: " + h + " : " + p); |
|
122 |
if (!eh.equals(h) || |
|
123 |
(ep == null || ep.length() == 0) && !p.equals("88") || |
|
124 |
(ep != null && ep.length() > 0) && !p.equals(ep)) { |
|
125 |
throw new Exception("Mismatch"); |
|
126 |
} |
|
127 |
cc++; |
|
128 |
} |
|
129 |
} |
|
130 |
if (cc != kdcs.length - 2) { // 2 illegal settings at the end |
|
131 |
throw new Exception("Not traversed"); |
|
132 |
} |
|
133 |
} |
|
134 |
} |