Path: blob/master/test/jdk/sun/security/krb5/config/ParseCAPaths.java
41155 views
/*1* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 6789935 801261525* @modules java.security.jgss/sun.security.krb526* @run main/othervm ParseCAPaths27* @summary cross-realm capath search error28*/2930import java.util.Arrays;31import sun.security.krb5.Realm;3233public class ParseCAPaths {34static Exception failed = null;35public static void main(String[] args) throws Exception {36System.setProperty("java.security.krb5.conf",37System.getProperty("test.src", ".") +"/krb5-capaths.conf");3839// MIT40check("ANL.GOV", "TEST.ANL.GOV", "ANL.GOV");41check("ANL.GOV", "ES.NET", "ANL.GOV");42check("ANL.GOV", "PNL.GOV", "ANL.GOV", "ES.NET");43check("ANL.GOV", "NERSC.GOV", "ANL.GOV", "ES.NET");44check("NERSC.GOV", "TEST.ANL.GOV", "NERSC.GOV", "ES.NET", "ANL.GOV");4546// RedHat47// 3.6.2.1. Configuring a Shared Hierarchy of Names48check("AA.EXAMPLE.COM", "BB.EXAMPLE.COM",49"AA.EXAMPLE.COM", "EXAMPLE.COM");50check("SITE1.SALES.EXAMPLE.COM", "EVERYWHERE.EXAMPLE.COM",51"SITE1.SALES.EXAMPLE.COM", "SALES.EXAMPLE.COM",52"EXAMPLE.COM");53check("DEVEL.EXAMPLE.COM", "PROD.EXAMPLE.ORG",54"DEVEL.EXAMPLE.COM", "EXAMPLE.COM", "COM",55"ORG", "EXAMPLE.ORG");56// 3.6.2.2. Configuring Paths in krb5.conf57check("A.EXAMPLE.COM", "B.EXAMPLE.COM", "A.EXAMPLE.COM");58check("A.EXAMPLE.COM", "C.EXAMPLE.COM",59"A.EXAMPLE.COM", "B.EXAMPLE.COM");60check("A.EXAMPLE.COM", "D.EXAMPLE.COM",61"A.EXAMPLE.COM", "B.EXAMPLE.COM", "C.EXAMPLE.COM");6263// The original JDK example64check("TIVOLI.COM", "IBM.COM", "TIVOLI.COM", "LDAPCENTRAL.NET",65"IBM_LDAPCENTRAL.COM", "MOONLITE.ORG");6667// Hierachical68check("N1.N.COM", "N2.N.COM", "N1.N.COM", "N.COM");69check("N1.N.COM", "N2.N3.COM", "N1.N.COM", "N.COM",70"COM", "N3.COM");71check("N1.COM", "N2.COM", "N1.COM", "COM");72check("N1", "N2", "N1");73check("N1.COM", "N2.ORG", "N1.COM", "COM", "ORG");74check("N1.N.COM", "N.COM", "N1.N.COM");75check("X.N1.N.COM", "N.COM", "X.N1.N.COM", "N1.N.COM");76check("N.COM", "N1.N.COM", "N.COM");77check("N.COM", "X.N1.N.COM", "N.COM", "N1.N.COM");78check("A.B.C", "D.E.F", "A.B.C", "B.C", "C", "F", "E.F");7980// Full path81check("A1.COM", "A2.COM", "A1.COM");82check("A1.COM", "A3.COM", "A1.COM", "A2.COM");83check("A1.COM", "A4.COM", "A1.COM", "A2.COM", "A3.COM");8485// Shortest path86check("B1.COM", "B2.COM", "B1.COM");87check("B1.COM", "B3.COM", "B1.COM", "B2.COM");88check("B1.COM", "B4.COM", "B1.COM", "B2.COM", "B3.COM");8990// Missing is "."91check("C1.COM", "C2.COM", "C1.COM", "COM");92check("C1.COM", "C3.COM", "C1.COM", "C2.COM");9394// cRealm = .95check("D1.COM", "D2.COM", "D1.COM");9697// Bad cases98check("E1.COM", "E2.COM", "E1.COM");99check("E1.COM", "E3.COM", "E1.COM", "E4.COM");100check("G1.COM", "G3.COM", "G1.COM", "G2.COM");101check("I1.COM", "I4.COM", "I1.COM", "I5.COM");102103// 7019384104check("A9.PRAGUE.XXX.CZ", "SERVIS.XXX.CZ",105"A9.PRAGUE.XXX.CZ", "PRAGUE.XXX.CZ", "ROOT.XXX.CZ");106107if (failed != null) {108throw failed;109}110}111112static void check(String from, String to, String... paths) {113try {114check2(from, to, paths);115} catch (Exception e) {116System.out.println(" " + e.getMessage());117failed = e;118}119}120121static void check2(String from, String to, String... paths)122throws Exception {123System.out.println(from + " -> " + to);124System.out.println(" expected: " + Arrays.toString(paths));125String[] result = Realm.getRealmsList(from, to);126if (result == null || result.length == 0) {127throw new Exception("There is always a valid path.");128} else if(result.length != paths.length) {129throw new Exception("Length of path not correct");130} else {131for (int i=0; i<result.length; i++) {132if (!result[i].equals(paths[i])) {133System.out.println(" result: " + Arrays.toString(result));134throw new Exception("Path not same");135}136}137}138}139}140141142