changeset 5840:7e49c6f7507e

7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout Reviewed-by: xuelei
author weijun
date Sat, 21 Jul 2012 19:56:55 +0800
parents 5dc3f32c0d26
children 11d5ddc6a6d4
files test/sun/security/krb5/auto/BadKdc.java test/sun/security/krb5/auto/BadKdc1.java test/sun/security/krb5/auto/BadKdc2.java test/sun/security/krb5/auto/BadKdc3.java test/sun/security/krb5/auto/BadKdc4.java
diffstat 5 files changed, 42 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/security/krb5/auto/BadKdc.java	Sat Jul 21 19:56:53 2012 +0800
+++ b/test/sun/security/krb5/auto/BadKdc.java	Sat Jul 21 19:56:55 2012 +0800
@@ -67,7 +67,7 @@
      *       This is tough.
      *    c. Feed the KDC a UDP packet first. The current "solution".
      */
-    public static void go(int[]... expected)
+    public static void go(String... expected)
             throws Exception {
         try {
             go0(expected);
@@ -83,7 +83,7 @@
         }
     }
 
-    public static void go0(int[]... expected)
+    public static void go0(String... expected)
             throws Exception {
         System.setProperty("sun.security.krb5.debug", "true");
 
@@ -148,8 +148,9 @@
         return k;
     }
 
-    private static void test(int... expected) throws Exception {
+    private static void test(String expected) throws Exception {
         ByteArrayOutputStream bo = new ByteArrayOutputStream();
+        System.out.println("----------------- TEST -----------------");
         try {
             test0(bo, expected);
         } catch (Exception e) {
@@ -164,31 +165,34 @@
      * One round of test for max_retries and timeout.
      * @param expected the expected kdc# timeout kdc# timeout...
      */
-    private static void test0(ByteArrayOutputStream bo, int... expected)
+    private static void test0(ByteArrayOutputStream bo, String expected)
             throws Exception {
         PrintStream oldout = System.out;
+        boolean failed = false;
         System.setOut(new PrintStream(bo));
         try {
             Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
+        } catch (Exception e) {
+            failed = true;
         } finally {
             System.setOut(oldout);
         }
 
         String[] lines = new String(bo.toByteArray()).split("\n");
-        System.out.println("----------------- TEST -----------------");
-        int count = 0;
+        StringBuilder sb = new StringBuilder();
         for (String line: lines) {
             Matcher m = re.matcher(line);
             if (m.find()) {
                 System.out.println(line);
-                if (Integer.parseInt(m.group(1)) != expected[count++] ||
-                        Integer.parseInt(m.group(2)) != expected[count++]) {
-                    throw new Exception("Fail here");
-                }
+                sb.append(m.group(1)).append(m.group(2));
             }
         }
-        if (count != expected.length) {
-            throw new Exception("Less rounds");
+        if (failed) sb.append('-');
+
+        String output = sb.toString();
+        System.out.println("Expected: " + expected + ", actual " + output);
+        if (!output.matches(expected)) {
+            throw new Exception("Does not match");
         }
     }
 }
--- a/test/sun/security/krb5/auto/BadKdc1.java	Sat Jul 21 19:56:53 2012 +0800
+++ b/test/sun/security/krb5/auto/BadKdc1.java	Sat Jul 21 19:56:55 2012 +0800
@@ -37,16 +37,16 @@
            throws Exception {
        Security.setProperty("krb5.kdc.bad.policy", "tryLess");
        BadKdc.go(
-               new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,1,2,2,2,3,2}, // 1, 2
-               // The above line means try kdc1 for 2 seconds, then kdc1
-               // for 2 seconds,..., finally kdc3 for 2 seconds.
-               new int[]{1,2,2,2,3,2,1,2,2,2,3,2}, // 1, 2
+               "121212222222(32){1,2}1222(32){1,2}", // 1 2
+               // The above line means try kdc1 for 2 seconds then kdc1
+               // for 2 seconds... finally kdc3 for 2 seconds.
+               "1222(32){1,2}1222(32){1,2}",    // 1 2
                // refresh
-               new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,1,2,2,2,3,2}, // 1, 2
-               // k3 off, k2 on
-               new int[]{1,2,2,2,1,2,2,2}, // 1
+               "121212222222(32){1,2}1222(32){1,2}",  // 1 2
+               // k3 off k2 on
+               "(122212(22){1,2}|1222323232-)", // 1
                // k1 on
-               new int[]{1,2,1,2}  // empty
+               "(12(12){1,2}|122232-)"  // empty
        );
    }
 }
--- a/test/sun/security/krb5/auto/BadKdc2.java	Sat Jul 21 19:56:53 2012 +0800
+++ b/test/sun/security/krb5/auto/BadKdc2.java	Sat Jul 21 19:56:55 2012 +0800
@@ -37,14 +37,14 @@
             throws Exception {
         Security.setProperty("krb5.kdc.bad.policy", "tryLess:2,1000");
         BadKdc.go(
-                new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,1,1,1,1,2,1,2,1,3,2}, // 1, 2
-                new int[]{1,1,1,1,2,1,2,1,3,2,1,1,1,1,2,1,2,1,3,2}, // 1, 2
+                "121212222222(32){1,2}11112121(32){1,2}", // 1 2
+                "11112121(32){1,2}11112121(32){1,2}", // 1 2
                 // refresh
-                new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,1,1,1,1,2,1,2,1,3,2}, // 1, 2
-                // k3 off, k2 on
-                new int[]{1,1,1,1,2,1,1,1,1,1,2,2}, // 1
+                "121212222222(32){1,2}11112121(32){1,2}", // 1 2
+                // k3 off k2 on
+                "1111(21){1,2}1111(22){1,2}", // 1
                 // k1 on
-                new int[]{1,1,1,2}  // empty
+                "(11){1,2}(12){1,2}"  // empty
         );
     }
 }
--- a/test/sun/security/krb5/auto/BadKdc3.java	Sat Jul 21 19:56:53 2012 +0800
+++ b/test/sun/security/krb5/auto/BadKdc3.java	Sat Jul 21 19:56:55 2012 +0800
@@ -37,14 +37,14 @@
             throws Exception {
         Security.setProperty("krb5.kdc.bad.policy", "tryLast");
         BadKdc.go(
-                new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,3,2}, // 1, 2
-                new int[]{3,2,3,2}, // 1, 2
+                "121212222222(32){2,4}", // 1 2
+                "(32){2,4}", // 1 2
                 // refresh
-                new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,3,2}, // 1, 2
-                // k3 off, k2 on
-                new int[]{3,2,3,2,3,2,1,2,1,2,1,2,2,2,2,2}, // 1, 3
+                "121212222222(32){2,4}", // 1 2
+                // k3 off k2 on
+                "323232121212(22){2,4}", // 1 3
                 // k1 on
-                new int[]{2,2,2,2}  // 1, 3
+                "(22){2,4}"  // 1 3
         );
     }
 }
--- a/test/sun/security/krb5/auto/BadKdc4.java	Sat Jul 21 19:56:53 2012 +0800
+++ b/test/sun/security/krb5/auto/BadKdc4.java	Sat Jul 21 19:56:55 2012 +0800
@@ -37,14 +37,14 @@
             throws Exception {
         Security.setProperty("krb5.kdc.bad.policy", "");
         BadKdc.go(
-            new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,1,2,1,2,1,2,2,2,2,2,2,2,3,2},
-            new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,1,2,1,2,1,2,2,2,2,2,2,2,3,2},
+            "121212222222(32){1,2}121212222222(32){1,2}",
+            "121212222222(32){1,2}121212222222(32){1,2}",
             // refresh
-            new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,1,2,1,2,1,2,2,2,2,2,2,2,3,2},
-            // k3 off, k2 on
-            new int[]{1,2,1,2,1,2,2,2,1,2,1,2,1,2,2,2},
+            "121212222222(32){1,2}121212222222(32){1,2}",
+            // k3 off k2 on
+            "121212(22){1,2}121212(22){1,2}",
             // k1 on
-            new int[]{1,2,1,2}
+            "(12){2,4}"
         );
     }
 }