diff --git a/jdk/test/sun/security/krb5/auto/BadKdc.java b/jdk/test/sun/security/krb5/auto/BadKdc.java index 86a464a4fe6..be8259d3538 100644 --- a/jdk/test/sun/security/krb5/auto/BadKdc.java +++ b/jdk/test/sun/security/krb5/auto/BadKdc.java @@ -67,7 +67,7 @@ public class BadKdc { * 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 class BadKdc { } } - 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 @@ public class BadKdc { 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 @@ public class BadKdc { * 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"); } } } diff --git a/jdk/test/sun/security/krb5/auto/BadKdc1.java b/jdk/test/sun/security/krb5/auto/BadKdc1.java index a4f52b490e2..bc96d056d71 100644 --- a/jdk/test/sun/security/krb5/auto/BadKdc1.java +++ b/jdk/test/sun/security/krb5/auto/BadKdc1.java @@ -37,16 +37,16 @@ public class BadKdc1 { 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 ); } } diff --git a/jdk/test/sun/security/krb5/auto/BadKdc2.java b/jdk/test/sun/security/krb5/auto/BadKdc2.java index 9a556429293..26e001bcc70 100644 --- a/jdk/test/sun/security/krb5/auto/BadKdc2.java +++ b/jdk/test/sun/security/krb5/auto/BadKdc2.java @@ -37,14 +37,14 @@ public class BadKdc2 { 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 ); } } diff --git a/jdk/test/sun/security/krb5/auto/BadKdc3.java b/jdk/test/sun/security/krb5/auto/BadKdc3.java index c9ce4db3827..83816027a55 100644 --- a/jdk/test/sun/security/krb5/auto/BadKdc3.java +++ b/jdk/test/sun/security/krb5/auto/BadKdc3.java @@ -37,14 +37,14 @@ public class BadKdc3 { 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 ); } } diff --git a/jdk/test/sun/security/krb5/auto/BadKdc4.java b/jdk/test/sun/security/krb5/auto/BadKdc4.java index eef77f282c4..bbd40471fb1 100644 --- a/jdk/test/sun/security/krb5/auto/BadKdc4.java +++ b/jdk/test/sun/security/krb5/auto/BadKdc4.java @@ -37,14 +37,14 @@ public class BadKdc4 { 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}" ); } }