author | weijun |
Mon, 28 Mar 2011 18:04:10 +0800 | |
changeset 9007 | 05f25362fb76 |
parent 5506 | 202f599c92aa |
child 20175 | a65ad0a49e3c |
permissions | -rw-r--r-- |
2064 | 1 |
/* |
9007
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
2064 | 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. |
|
2064 | 22 |
*/ |
23 |
/* |
|
24 |
* @test |
|
25 |
* @bug 6789935 |
|
9007
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
26 |
* @run main/othervm ParseCAPaths |
2064 | 27 |
* @summary cross-realm capath search error |
28 |
*/ |
|
29 |
||
30 |
import java.util.Arrays; |
|
31 |
import sun.security.krb5.Realm; |
|
32 |
||
33 |
public class ParseCAPaths { |
|
9007
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
34 |
static Exception failed = null; |
2064 | 35 |
public static void main(String[] args) throws Exception { |
9007
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
36 |
System.setProperty("java.security.krb5.conf", |
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
37 |
System.getProperty("test.src", ".") +"/krb5-capaths.conf"); |
2064 | 38 |
//System.setProperty("sun.security.krb5.debug", "true"); |
39 |
||
40 |
// Standard example |
|
41 |
check("ANL.GOV", "TEST.ANL.GOV", "ANL.GOV"); |
|
42 |
check("ANL.GOV", "ES.NET", "ANL.GOV"); |
|
43 |
check("ANL.GOV", "PNL.GOV", "ANL.GOV", "ES.NET"); |
|
44 |
check("ANL.GOV", "NERSC.GOV", "ANL.GOV", "ES.NET"); |
|
45 |
// Hierachical |
|
46 |
check("N1.N.COM", "N2.N.COM", "N1.N.COM", "N.COM"); // 2 common |
|
47 |
check("N1.N.COM", "N2.N3.COM", "N1.N.COM", "N.COM", // 1 common |
|
48 |
"COM", "N3.COM"); |
|
49 |
check("N1.COM", "N2.COM", "N1.COM", "COM"); // 1 common |
|
50 |
check("N1", "N2", "N1"); // 0 common |
|
51 |
// Extra garbages |
|
52 |
check("A1.COM", "A4.COM", "A1.COM", "A2.COM"); |
|
53 |
check("B1.COM", "B3.COM", "B1.COM", "B2.COM"); |
|
54 |
// Missing is "." |
|
55 |
check("C1.COM", "C3.COM", "C1.COM", "C2.COM"); |
|
56 |
// Multiple path |
|
57 |
check("D1.COM", "D4.COM", "D1.COM", "D2.COM"); |
|
58 |
check("E1.COM", "E4.COM", "E1.COM", "E2.COM"); |
|
59 |
check("F1.COM", "F4.COM", "F1.COM", "F9.COM"); |
|
60 |
// Infinite loop |
|
61 |
check("G1.COM", "G3.COM", "G1.COM", "COM"); |
|
62 |
check("H1.COM", "H3.COM", "H1.COM"); |
|
63 |
check("I1.COM", "I4.COM", "I1.COM", "I5.COM"); |
|
9007
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
64 |
// J2=J1 is the same as J2=. |
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
65 |
check("J1.COM", "J2.COM", "J1.COM"); |
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
66 |
// 7019384 |
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
67 |
check("A9.PRAGUE.XXX.CZ", "SERVIS.XXX.CZ", |
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
68 |
"A9.PRAGUE.XXX.CZ", "PRAGUE.XXX.CZ", "ROOT.XXX.CZ"); |
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
69 |
if (failed != null) { |
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
70 |
throw failed; |
2064 | 71 |
} |
72 |
} |
|
73 |
||
74 |
static void check(String from, String to, String... paths) { |
|
75 |
try { |
|
76 |
check2(from, to, paths); |
|
77 |
} catch (Exception e) { |
|
9007
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
78 |
failed = e; |
2064 | 79 |
} |
80 |
} |
|
9007
05f25362fb76
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents:
5506
diff
changeset
|
81 |
|
2064 | 82 |
static void check2(String from, String to, String... paths) |
83 |
throws Exception { |
|
84 |
System.out.println(from + " -> " + to); |
|
85 |
System.out.println(" expected: " + Arrays.toString(paths)); |
|
86 |
String[] result = Realm.getRealmsList(from, to); |
|
87 |
System.out.println(" result: " + Arrays.toString(result)); |
|
88 |
if (result == null) { |
|
89 |
if (paths.length == 0) { |
|
90 |
// OK |
|
91 |
} else { |
|
92 |
throw new Exception("Shouldn't have a valid path."); |
|
93 |
} |
|
94 |
} else if(result.length != paths.length) { |
|
95 |
throw new Exception("Length of path not correct"); |
|
96 |
} else { |
|
97 |
for (int i=0; i<result.length; i++) { |
|
98 |
if (!result[i].equals(paths[i])) { |
|
99 |
throw new Exception("Path not same"); |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
} |