jdk/test/sun/security/krb5/DnsFallback.java
changeset 23310 dfbe9ff289c6
parent 23306 679ac7841e8d
parent 22999 8212fb968f9b
child 23311 fd976b9703f1
equal deleted inserted replaced
23306:679ac7841e8d 23310:dfbe9ff289c6
     1 /*
       
     2  * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 /*
       
    24  * @test
       
    25  * @bug 6673164
       
    26  * @bug 6552334
       
    27  * @run main/othervm DnsFallback
       
    28  * @summary fix dns_fallback parse error, and use dns by default
       
    29  */
       
    30 
       
    31 import java.io.*;
       
    32 import java.lang.reflect.Method;
       
    33 import sun.security.krb5.Config;
       
    34 
       
    35 public class DnsFallback {
       
    36 
       
    37     static Method useDNS_Realm;
       
    38 
       
    39     public static void main(String[] args) throws Exception {
       
    40 
       
    41         useDNS_Realm = Config.class.getDeclaredMethod("useDNS_Realm");
       
    42         useDNS_Realm.setAccessible(true);
       
    43 
       
    44 
       
    45         // for 6673164
       
    46         check("true", "true", true);
       
    47         check("false", "true", false);
       
    48         check("true", "false", true);
       
    49         check("false", "false", false);
       
    50         check("true", null, true);
       
    51         check("false", null, false);
       
    52         check(null, "true", true);
       
    53         check(null, "false", false);
       
    54 
       
    55         // for 6552334
       
    56         check(null, null, true);
       
    57     }
       
    58 
       
    59     static void check(String realm, String fallback, boolean output)
       
    60             throws Exception {
       
    61 
       
    62         try (PrintStream ps =
       
    63                 new PrintStream(new FileOutputStream("dnsfallback.conf"))) {
       
    64             ps.println("[libdefaults]\n");
       
    65             if (realm != null) {
       
    66                 ps.println("dns_lookup_realm=" + realm);
       
    67             }
       
    68             if (fallback != null) {
       
    69                 ps.println("dns_fallback=" + fallback);
       
    70             }
       
    71         }
       
    72 
       
    73         System.setProperty("java.security.krb5.conf", "dnsfallback.conf");
       
    74         Config.refresh();
       
    75         System.out.println("Testing " + realm + ", " + fallback + ", " + output);
       
    76 
       
    77         if (!useDNS_Realm.invoke(Config.getInstance()).equals(output)) {
       
    78             throw new Exception("Fail");
       
    79         }
       
    80     }
       
    81 }
       
    82