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