jdk/test/sun/security/krb5/ParseCAPaths.java
author weijun
Mon, 28 Mar 2011 18:04:10 +0800
changeset 9007 05f25362fb76
parent 5506 202f599c92aa
child 20175 a65ad0a49e3c
permissions -rw-r--r--
7019384: Realm.getRealmsList returns realms list in wrong (reverse) order Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2064
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
     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
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
     4
 *
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
     8
 *
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    13
 * accompanied this code).
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    14
 *
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2064
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2064
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2064
diff changeset
    21
 * questions.
2064
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    22
 */
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    23
/*
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    24
 * @test
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    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
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    27
 * @summary cross-realm capath search error
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    28
 */
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    29
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    30
import java.util.Arrays;
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    31
import sun.security.krb5.Realm;
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    32
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    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
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    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
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    38
        //System.setProperty("sun.security.krb5.debug", "true");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    39
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    40
        // Standard example
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    41
        check("ANL.GOV", "TEST.ANL.GOV", "ANL.GOV");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    42
        check("ANL.GOV", "ES.NET", "ANL.GOV");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    43
        check("ANL.GOV", "PNL.GOV", "ANL.GOV", "ES.NET");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    44
        check("ANL.GOV", "NERSC.GOV", "ANL.GOV", "ES.NET");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    45
        // Hierachical
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    46
        check("N1.N.COM", "N2.N.COM", "N1.N.COM", "N.COM");     // 2 common
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    47
        check("N1.N.COM", "N2.N3.COM", "N1.N.COM", "N.COM",     // 1 common
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    48
                "COM", "N3.COM");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    49
        check("N1.COM", "N2.COM", "N1.COM", "COM");             // 1 common
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    50
        check("N1", "N2", "N1");                                // 0 common
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    51
        // Extra garbages
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    52
        check("A1.COM", "A4.COM", "A1.COM", "A2.COM");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    53
        check("B1.COM", "B3.COM", "B1.COM", "B2.COM");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    54
        // Missing is "."
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    55
        check("C1.COM", "C3.COM", "C1.COM", "C2.COM");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    56
        // Multiple path
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    57
        check("D1.COM", "D4.COM", "D1.COM", "D2.COM");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    58
        check("E1.COM", "E4.COM", "E1.COM", "E2.COM");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    59
        check("F1.COM", "F4.COM", "F1.COM", "F9.COM");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    60
        // Infinite loop
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    61
        check("G1.COM", "G3.COM", "G1.COM", "COM");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    62
        check("H1.COM", "H3.COM", "H1.COM");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    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
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    71
        }
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    72
    }
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    73
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    74
    static void check(String from, String to, String... paths) {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    75
        try {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    76
            check2(from, to, paths);
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    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
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    79
        }
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    80
    }
9007
05f25362fb76 7019384: Realm.getRealmsList returns realms list in wrong (reverse) order
weijun
parents: 5506
diff changeset
    81
2064
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    82
    static void check2(String from, String to, String... paths)
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    83
            throws Exception {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    84
        System.out.println(from + " -> " + to);
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    85
        System.out.println("    expected: " + Arrays.toString(paths));
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    86
        String[] result = Realm.getRealmsList(from, to);
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    87
        System.out.println("    result:   " + Arrays.toString(result));
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    88
        if (result == null) {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    89
            if (paths.length == 0) {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    90
                // OK
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    91
            } else {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    92
                throw new Exception("Shouldn't have a valid path.");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    93
            }
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    94
        } else if(result.length != paths.length) {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    95
            throw new Exception("Length of path not correct");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    96
        } else {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    97
            for (int i=0; i<result.length; i++) {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    98
                if (!result[i].equals(paths[i])) {
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
    99
                    throw new Exception("Path not same");
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
   100
                }
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
   101
            }
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
   102
        }
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
   103
    }
d690c8a2acea 6789935: cross-realm capath search error
weijun
parents:
diff changeset
   104
}