Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/DnsFallback.java
38839 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* @run main/othervm DnsFallback26* @summary fix dns_fallback parse error, and use dns by default27*/2829import java.io.*;30import java.lang.reflect.Method;31import sun.security.krb5.Config;3233public class DnsFallback {3435static Method useDNS_Realm;36static Method useDNS_KDC;3738public static void main(String[] args) throws Exception {3940useDNS_Realm = Config.class.getDeclaredMethod("useDNS_Realm");41useDNS_Realm.setAccessible(true);42useDNS_KDC = Config.class.getDeclaredMethod("useDNS_KDC");43useDNS_KDC.setAccessible(true);444546// for 667316447check("true", "true", true, true);48check("false", "true", false, false);49check("true", "false", true, true);50check("false", "false", false, false);51check("true", null, true, true);52check("false", null, false, false);53check(null, "true", true, true);54check(null, "false", false, false);5556// for 6552334, no longer true57//check(null, null, true, true);5859// 807710260check(null, null, false, true);61}6263/**64* Sets and checks.65*66* @param u dns_lookup_XXX value set, none if null67* @param f dns_fallback value set, none if null68* @param r expected useDNS_Realm69* @param k expected useDNS_KDC70*/71static void check(String u, String f, boolean r, boolean k)72throws Exception {7374try (PrintStream ps =75new PrintStream(new FileOutputStream("dnsfallback.conf"))) {76ps.println("[libdefaults]\n");77if (u != null) {78ps.println("dns_lookup_realm=" + u);79ps.println("dns_lookup_kdc=" + u);80}81if (f != null) {82ps.println("dns_fallback=" + f);83}84}8586System.setProperty("java.security.krb5.conf", "dnsfallback.conf");87Config.refresh();88System.out.println("Testing " + u + ", " + f + ", " + r + ", " + k);8990if (!useDNS_Realm.invoke(Config.getInstance()).equals(r)) {91throw new Exception("useDNS_Realm Fail");92}9394if (!useDNS_KDC.invoke(Config.getInstance()).equals(k)) {95throw new Exception("useDNS_KDC Fail");96}97}98}99100101102