Path: blob/master/test/jdk/sun/security/krb5/config/DnsFallback.java
41155 views
/*1* Copyright (c) 2008, 2012, 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 6673164 6552334 807710225* @modules java.security.jgss/sun.security.krb5:+open26* @run main/othervm DnsFallback27* @summary fix dns_fallback parse error, and use dns by default28*/2930import java.io.*;31import java.lang.reflect.Method;32import sun.security.krb5.Config;3334public class DnsFallback {3536static Method useDNS_Realm;37static Method useDNS_KDC;3839public static void main(String[] args) throws Exception {4041useDNS_Realm = Config.class.getDeclaredMethod("useDNS_Realm");42useDNS_Realm.setAccessible(true);43useDNS_KDC = Config.class.getDeclaredMethod("useDNS_KDC");44useDNS_KDC.setAccessible(true);454647// for 667316448check("true", "true", true, true);49check("false", "true", false, false);50check("true", "false", true, true);51check("false", "false", false, false);52check("true", null, true, true);53check("false", null, false, false);54check(null, "true", true, true);55check(null, "false", false, false);5657// for 6552334, no longer true58//check(null, null, true, true);5960// 807710261check(null, null, false, true);62}6364/**65* Sets and checks.66*67* @param u dns_lookup_XXX value set, none if null68* @param f dns_fallback value set, none if null69* @param r expected useDNS_Realm70* @param k expected useDNS_KDC71*/72static void check(String u, String f, boolean r, boolean k)73throws Exception {7475try (PrintStream ps =76new PrintStream(new FileOutputStream("dnsfallback.conf"))) {77ps.println("[libdefaults]\n");78if (u != null) {79ps.println("dns_lookup_realm=" + u);80ps.println("dns_lookup_kdc=" + u);81}82if (f != null) {83ps.println("dns_fallback=" + f);84}85}8687System.setProperty("java.security.krb5.conf", "dnsfallback.conf");88Config.refresh();89System.out.println("Testing " + u + ", " + f + ", " + r + ", " + k);9091if (!useDNS_Realm.invoke(Config.getInstance()).equals(r)) {92throw new Exception("useDNS_Realm Fail");93}9495if (!useDNS_KDC.invoke(Config.getInstance()).equals(k)) {96throw new Exception("useDNS_KDC Fail");97}98}99}100101102103