2064
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2009, 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
|
|
26 |
* @summary cross-realm capath search error
|
|
27 |
*/
|
|
28 |
|
|
29 |
import java.util.Arrays;
|
|
30 |
import sun.security.krb5.Realm;
|
|
31 |
|
|
32 |
public class ParseCAPaths {
|
|
33 |
static boolean failed = false;
|
|
34 |
public static void main(String[] args) throws Exception {
|
|
35 |
System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") +"/krb5-capaths.conf");
|
|
36 |
//System.setProperty("sun.security.krb5.debug", "true");
|
|
37 |
|
|
38 |
// Standard example
|
|
39 |
check("ANL.GOV", "TEST.ANL.GOV", "ANL.GOV");
|
|
40 |
check("ANL.GOV", "ES.NET", "ANL.GOV");
|
|
41 |
check("ANL.GOV", "PNL.GOV", "ANL.GOV", "ES.NET");
|
|
42 |
check("ANL.GOV", "NERSC.GOV", "ANL.GOV", "ES.NET");
|
|
43 |
// Hierachical
|
|
44 |
check("N1.N.COM", "N2.N.COM", "N1.N.COM", "N.COM"); // 2 common
|
|
45 |
check("N1.N.COM", "N2.N3.COM", "N1.N.COM", "N.COM", // 1 common
|
|
46 |
"COM", "N3.COM");
|
|
47 |
check("N1.COM", "N2.COM", "N1.COM", "COM"); // 1 common
|
|
48 |
check("N1", "N2", "N1"); // 0 common
|
|
49 |
// Extra garbages
|
|
50 |
check("A1.COM", "A4.COM", "A1.COM", "A2.COM");
|
|
51 |
check("B1.COM", "B3.COM", "B1.COM", "B2.COM");
|
|
52 |
// Missing is "."
|
|
53 |
check("C1.COM", "C3.COM", "C1.COM", "C2.COM");
|
|
54 |
// Multiple path
|
|
55 |
check("D1.COM", "D4.COM", "D1.COM", "D2.COM");
|
|
56 |
check("E1.COM", "E4.COM", "E1.COM", "E2.COM");
|
|
57 |
check("F1.COM", "F4.COM", "F1.COM", "F9.COM");
|
|
58 |
// Infinite loop
|
|
59 |
check("G1.COM", "G3.COM", "G1.COM", "COM");
|
|
60 |
check("H1.COM", "H3.COM", "H1.COM");
|
|
61 |
check("I1.COM", "I4.COM", "I1.COM", "I5.COM");
|
|
62 |
|
|
63 |
if (failed) {
|
|
64 |
throw new Exception("Failed somewhere.");
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
static void check(String from, String to, String... paths) {
|
|
69 |
try {
|
|
70 |
check2(from, to, paths);
|
|
71 |
} catch (Exception e) {
|
|
72 |
failed = true;
|
|
73 |
e.printStackTrace();
|
|
74 |
}
|
|
75 |
}
|
|
76 |
static void check2(String from, String to, String... paths)
|
|
77 |
throws Exception {
|
|
78 |
System.out.println(from + " -> " + to);
|
|
79 |
System.out.println(" expected: " + Arrays.toString(paths));
|
|
80 |
String[] result = Realm.getRealmsList(from, to);
|
|
81 |
System.out.println(" result: " + Arrays.toString(result));
|
|
82 |
if (result == null) {
|
|
83 |
if (paths.length == 0) {
|
|
84 |
// OK
|
|
85 |
} else {
|
|
86 |
throw new Exception("Shouldn't have a valid path.");
|
|
87 |
}
|
|
88 |
} else if(result.length != paths.length) {
|
|
89 |
throw new Exception("Length of path not correct");
|
|
90 |
} else {
|
|
91 |
for (int i=0; i<result.length; i++) {
|
|
92 |
if (!result[i].equals(paths[i])) {
|
|
93 |
throw new Exception("Path not same");
|
|
94 |
}
|
|
95 |
}
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|