Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/ParseCAPaths.java
38838 views
/*1* Copyright (c) 2009, 2013, 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* @run main/othervm ParseCAPaths26* @summary cross-realm capath search error27*/2829import java.util.Arrays;30import sun.security.krb5.Realm;3132public class ParseCAPaths {33static Exception failed = null;34public static void main(String[] args) throws Exception {35System.setProperty("java.security.krb5.conf",36System.getProperty("test.src", ".") +"/krb5-capaths.conf");3738// MIT39check("ANL.GOV", "TEST.ANL.GOV", "ANL.GOV");40check("ANL.GOV", "ES.NET", "ANL.GOV");41check("ANL.GOV", "PNL.GOV", "ANL.GOV", "ES.NET");42check("ANL.GOV", "NERSC.GOV", "ANL.GOV", "ES.NET");43check("NERSC.GOV", "TEST.ANL.GOV", "NERSC.GOV", "ES.NET", "ANL.GOV");4445// RedHat46// 3.6.2.1. Configuring a Shared Hierarchy of Names47check("AA.EXAMPLE.COM", "BB.EXAMPLE.COM",48"AA.EXAMPLE.COM", "EXAMPLE.COM");49check("SITE1.SALES.EXAMPLE.COM", "EVERYWHERE.EXAMPLE.COM",50"SITE1.SALES.EXAMPLE.COM", "SALES.EXAMPLE.COM",51"EXAMPLE.COM");52check("DEVEL.EXAMPLE.COM", "PROD.EXAMPLE.ORG",53"DEVEL.EXAMPLE.COM", "EXAMPLE.COM", "COM",54"ORG", "EXAMPLE.ORG");55// 3.6.2.2. Configuring Paths in krb5.conf56check("A.EXAMPLE.COM", "B.EXAMPLE.COM", "A.EXAMPLE.COM");57check("A.EXAMPLE.COM", "C.EXAMPLE.COM",58"A.EXAMPLE.COM", "B.EXAMPLE.COM");59check("A.EXAMPLE.COM", "D.EXAMPLE.COM",60"A.EXAMPLE.COM", "B.EXAMPLE.COM", "C.EXAMPLE.COM");6162// The original JDK example63check("TIVOLI.COM", "IBM.COM", "TIVOLI.COM", "LDAPCENTRAL.NET",64"IBM_LDAPCENTRAL.COM", "MOONLITE.ORG");6566// Hierachical67check("N1.N.COM", "N2.N.COM", "N1.N.COM", "N.COM");68check("N1.N.COM", "N2.N3.COM", "N1.N.COM", "N.COM",69"COM", "N3.COM");70check("N1.COM", "N2.COM", "N1.COM", "COM");71check("N1", "N2", "N1");72check("N1.COM", "N2.ORG", "N1.COM", "COM", "ORG");73check("N1.N.COM", "N.COM", "N1.N.COM");74check("X.N1.N.COM", "N.COM", "X.N1.N.COM", "N1.N.COM");75check("N.COM", "N1.N.COM", "N.COM");76check("N.COM", "X.N1.N.COM", "N.COM", "N1.N.COM");77check("A.B.C", "D.E.F", "A.B.C", "B.C", "C", "F", "E.F");7879// Full path80check("A1.COM", "A2.COM", "A1.COM");81check("A1.COM", "A3.COM", "A1.COM", "A2.COM");82check("A1.COM", "A4.COM", "A1.COM", "A2.COM", "A3.COM");8384// Shortest path85check("B1.COM", "B2.COM", "B1.COM");86check("B1.COM", "B3.COM", "B1.COM", "B2.COM");87check("B1.COM", "B4.COM", "B1.COM", "B2.COM", "B3.COM");8889// Missing is "."90check("C1.COM", "C2.COM", "C1.COM", "COM");91check("C1.COM", "C3.COM", "C1.COM", "C2.COM");9293// cRealm = .94check("D1.COM", "D2.COM", "D1.COM");9596// Bad cases97check("E1.COM", "E2.COM", "E1.COM");98check("E1.COM", "E3.COM", "E1.COM", "E4.COM");99check("G1.COM", "G3.COM", "G1.COM", "G2.COM");100check("I1.COM", "I4.COM", "I1.COM", "I5.COM");101102// 7019384103check("A9.PRAGUE.XXX.CZ", "SERVIS.XXX.CZ",104"A9.PRAGUE.XXX.CZ", "PRAGUE.XXX.CZ", "ROOT.XXX.CZ");105106if (failed != null) {107throw failed;108}109}110111static void check(String from, String to, String... paths) {112try {113check2(from, to, paths);114} catch (Exception e) {115System.out.println(" " + e.getMessage());116failed = e;117}118}119120static void check2(String from, String to, String... paths)121throws Exception {122System.out.println(from + " -> " + to);123System.out.println(" expected: " + Arrays.toString(paths));124String[] result = Realm.getRealmsList(from, to);125if (result == null || result.length == 0) {126throw new Exception("There is always a valid path.");127} else if(result.length != paths.length) {128throw new Exception("Length of path not correct");129} else {130for (int i=0; i<result.length; i++) {131if (!result[i].equals(paths[i])) {132System.out.println(" result: " + Arrays.toString(result));133throw new Exception("Path not same");134}135}136}137}138}139140141