6761072: new krb5 tests fail on multiple platforms
authorweijun
Mon, 20 Oct 2008 10:32:33 +0800
changeset 1456 1d3c6724de2f
parent 1455 79b6d4798fa3
child 1457 8a9b53004f38
6761072: new krb5 tests fail on multiple platforms Reviewed-by: xuelei
jdk/test/sun/security/krb5/auto/BasicKrb5Test.java
jdk/test/sun/security/krb5/auto/KDC.java
jdk/test/sun/security/krb5/auto/OneKDC.java
--- a/jdk/test/sun/security/krb5/auto/BasicKrb5Test.java	Fri Oct 17 00:51:59 2008 -0700
+++ b/jdk/test/sun/security/krb5/auto/BasicKrb5Test.java	Mon Oct 20 10:32:33 2008 +0800
@@ -49,14 +49,17 @@
         if (args.length > 0) {
             etype = args[0];
         }
+
+        // Creates and starts the KDC. This line must be put ahead of etype check
+        // since the check needs a krb5.conf.
+        new OneKDC(etype).writeJAASConf();
+
         System.out.println("Testing etype " + etype);
         if (etype != null && !EType.isSupported(Config.getInstance().getType(etype))) {
             System.out.println("Not supported.");
             System.exit(0);
         }
 
-        // Creates and starts the KDC
-        new OneKDC(etype).writeJAASConf();
         new BasicKrb5Test().go(OneKDC.SERVER, OneKDC.BACKEND);
     }
 
--- a/jdk/test/sun/security/krb5/auto/KDC.java	Fri Oct 17 00:51:59 2008 -0700
+++ b/jdk/test/sun/security/krb5/auto/KDC.java	Mon Oct 20 10:32:33 2008 +0800
@@ -152,12 +152,19 @@
                 return;
             }
         }
+        String localhost = "localhost";
+        try {
+            localhost = InetAddress.getByName(localhost)
+                    .getCanonicalHostName();
+        } catch (UnknownHostException uhe) {
+            ;   // Ignore, localhost is still "localhost"
+        }
         KDC kdc = create("RABBIT.HOLE", 8888, false);
         kdc.addPrincipal("dummy", "bogus".toCharArray());
         kdc.addPrincipal("foo", "bar".toCharArray());
         kdc.addPrincipalRandKey("krbtgt/" + kdc.realm);
-        kdc.addPrincipalRandKey("server/localhost");
-        kdc.addPrincipalRandKey("backend/localhost");
+        kdc.addPrincipalRandKey("server/" + localhost);
+        kdc.addPrincipalRandKey("backend/" + localhost);
     }
 
     /**
--- a/jdk/test/sun/security/krb5/auto/OneKDC.java	Fri Oct 17 00:51:59 2008 -0700
+++ b/jdk/test/sun/security/krb5/auto/OneKDC.java	Mon Oct 20 10:32:33 2008 +0800
@@ -24,6 +24,8 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.security.Security;
 import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
@@ -44,10 +46,23 @@
  */
 public class OneKDC extends KDC {
 
+    // The krb5 codes would try to canonicalize hostnames before creating
+    // a service principal name, so let's find out the canonicalized form
+    // of localhost first. The following codes mimic the process inside
+    // PrincipalName.java.
+    static String localhost = "localhost";
+    static {
+        try {
+            localhost = InetAddress.getByName(localhost)
+                    .getCanonicalHostName();
+        } catch (UnknownHostException uhe) {
+            ;   // Ignore, localhost is still "localhost"
+        }
+    }
     public static final String USER = "dummy";
     public static final char[] PASS = "bogus".toCharArray();
-    public static final String SERVER = "server/localhost";
-    public static final String BACKEND = "backend/localhost";
+    public static String SERVER = "server/" + localhost;
+    public static String BACKEND = "backend/" + localhost;
     public static final String KRB5_CONF = "localkdc-krb5.conf";
     public static final String KTAB = "localkdc.ktab";
     public static final String JAAS_CONF = "localkdc-jaas.conf";