ParseCAPaths.java revision 900
900N/A/*
900N/A * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
900N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
900N/A *
900N/A * This code is free software; you can redistribute it and/or modify it
900N/A * under the terms of the GNU General Public License version 2 only, as
900N/A * published by the Free Software Foundation.
900N/A *
900N/A * This code is distributed in the hope that it will be useful, but WITHOUT
900N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
900N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
900N/A * version 2 for more details (a copy is included in the LICENSE file that
900N/A * accompanied this code).
900N/A *
900N/A * You should have received a copy of the GNU General Public License version
900N/A * 2 along with this work; if not, write to the Free Software Foundation,
900N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
900N/A *
900N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
900N/A * CA 95054 USA or visit www.sun.com if you need additional information or
900N/A * have any questions.
900N/A */
900N/A/*
900N/A * @test
900N/A * @bug 6789935
900N/A * @summary cross-realm capath search error
900N/A */
900N/A
900N/Aimport java.util.Arrays;
900N/Aimport sun.security.krb5.Realm;
900N/A
900N/Apublic class ParseCAPaths {
900N/A static boolean failed = false;
900N/A public static void main(String[] args) throws Exception {
900N/A System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") +"/krb5-capaths.conf");
900N/A //System.setProperty("sun.security.krb5.debug", "true");
900N/A
900N/A // Standard example
900N/A check("ANL.GOV", "TEST.ANL.GOV", "ANL.GOV");
900N/A check("ANL.GOV", "ES.NET", "ANL.GOV");
900N/A check("ANL.GOV", "PNL.GOV", "ANL.GOV", "ES.NET");
900N/A check("ANL.GOV", "NERSC.GOV", "ANL.GOV", "ES.NET");
900N/A // Hierachical
900N/A check("N1.N.COM", "N2.N.COM", "N1.N.COM", "N.COM"); // 2 common
900N/A check("N1.N.COM", "N2.N3.COM", "N1.N.COM", "N.COM", // 1 common
900N/A "COM", "N3.COM");
900N/A check("N1.COM", "N2.COM", "N1.COM", "COM"); // 1 common
900N/A check("N1", "N2", "N1"); // 0 common
900N/A // Extra garbages
900N/A check("A1.COM", "A4.COM", "A1.COM", "A2.COM");
900N/A check("B1.COM", "B3.COM", "B1.COM", "B2.COM");
900N/A // Missing is "."
900N/A check("C1.COM", "C3.COM", "C1.COM", "C2.COM");
900N/A // Multiple path
900N/A check("D1.COM", "D4.COM", "D1.COM", "D2.COM");
900N/A check("E1.COM", "E4.COM", "E1.COM", "E2.COM");
900N/A check("F1.COM", "F4.COM", "F1.COM", "F9.COM");
900N/A // Infinite loop
900N/A check("G1.COM", "G3.COM", "G1.COM", "COM");
900N/A check("H1.COM", "H3.COM", "H1.COM");
900N/A check("I1.COM", "I4.COM", "I1.COM", "I5.COM");
900N/A
900N/A if (failed) {
900N/A throw new Exception("Failed somewhere.");
900N/A }
900N/A }
900N/A
900N/A static void check(String from, String to, String... paths) {
900N/A try {
900N/A check2(from, to, paths);
900N/A } catch (Exception e) {
900N/A failed = true;
900N/A e.printStackTrace();
900N/A }
900N/A }
900N/A static void check2(String from, String to, String... paths)
900N/A throws Exception {
900N/A System.out.println(from + " -> " + to);
900N/A System.out.println(" expected: " + Arrays.toString(paths));
900N/A String[] result = Realm.getRealmsList(from, to);
900N/A System.out.println(" result: " + Arrays.toString(result));
900N/A if (result == null) {
900N/A if (paths.length == 0) {
900N/A // OK
900N/A } else {
900N/A throw new Exception("Shouldn't have a valid path.");
900N/A }
900N/A } else if(result.length != paths.length) {
900N/A throw new Exception("Length of path not correct");
900N/A } else {
900N/A for (int i=0; i<result.length; i++) {
900N/A if (!result[i].equals(paths[i])) {
900N/A throw new Exception("Path not same");
900N/A }
900N/A }
900N/A }
900N/A }
900N/A}