< prev index next >

test/sun/security/krb5/DnsFallback.java

Print this page
rev 10772 : imported patch 8077102-dns_lookup_realm-should-be-false-by-default


   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 


   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 6552334 8077102

  26  * @run main/othervm DnsFallback
  27  * @summary fix dns_fallback parse error, and use dns by default
  28  */
  29 
  30 import java.io.*;
  31 import java.lang.reflect.Method;
  32 import sun.security.krb5.Config;
  33 
  34 public class DnsFallback {
  35 
  36     static Method useDNS_Realm;
  37     static Method useDNS_KDC;
  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         useDNS_KDC = Config.class.getDeclaredMethod("useDNS_KDC");
  44         useDNS_KDC.setAccessible(true);
  45 
  46 
  47         // for 6673164
  48         check("true", "true", true, true);
  49         check("false", "true", false, false);
  50         check("true", "false", true, true);
  51         check("false", "false", false, false);
  52         check("true", null, true, true);
  53         check("false", null, false, false);
  54         check(null, "true", true, true);
  55         check(null, "false", false, false);
  56 
  57         // for 6552334, no longer true
  58         //check(null, null, true, true);
  59 
  60         // 8077102
  61         check(null, null, false, true);
  62     }
  63 
  64     /**
  65      * Sets and checks.
  66      *
  67      * @param u dns_lookup_XXX value set, none if null
  68      * @param f dns_fallback value set, none if null
  69      * @param r expected useDNS_Realm
  70      * @param k expected useDNS_KDC
  71      */
  72     static void check(String u, String f, boolean r, boolean k)
  73             throws Exception {
  74 
  75         try (PrintStream ps =
  76                 new PrintStream(new FileOutputStream("dnsfallback.conf"))) {
  77             ps.println("[libdefaults]\n");
  78             if (u != null) {
  79                 ps.println("dns_lookup_realm=" + u);
  80                 ps.println("dns_lookup_kdc=" + u);
  81             }
  82             if (f != null) {
  83                 ps.println("dns_fallback=" + f);
  84             }
  85         }
  86 
  87         System.setProperty("java.security.krb5.conf", "dnsfallback.conf");
  88         Config.refresh();
  89         System.out.println("Testing " + u + ", " + f + ", " + r + ", " + k);
  90 
  91         if (!useDNS_Realm.invoke(Config.getInstance()).equals(r)) {
  92             throw new Exception("useDNS_Realm Fail");
  93         }
  94 
  95         if (!useDNS_KDC.invoke(Config.getInstance()).equals(k)) {
  96             throw new Exception("useDNS_KDC Fail");
  97         }
  98     }
  99 }
 100 
< prev index next >