7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout

Reviewed-by: xuelei
This commit is contained in:
Weijun Wang 2012-07-21 19:56:55 +08:00
parent 53170d594f
commit 3db0a0443c
5 changed files with 42 additions and 38 deletions

View File

@ -67,7 +67,7 @@ public class BadKdc {
* This is tough. * This is tough.
* c. Feed the KDC a UDP packet first. The current "solution". * 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 { throws Exception {
try { try {
go0(expected); go0(expected);
@ -83,7 +83,7 @@ public class BadKdc {
} }
} }
public static void go0(int[]... expected) public static void go0(String... expected)
throws Exception { throws Exception {
System.setProperty("sun.security.krb5.debug", "true"); System.setProperty("sun.security.krb5.debug", "true");
@ -148,8 +148,9 @@ public class BadKdc {
return k; return k;
} }
private static void test(int... expected) throws Exception { private static void test(String expected) throws Exception {
ByteArrayOutputStream bo = new ByteArrayOutputStream(); ByteArrayOutputStream bo = new ByteArrayOutputStream();
System.out.println("----------------- TEST -----------------");
try { try {
test0(bo, expected); test0(bo, expected);
} catch (Exception e) { } catch (Exception e) {
@ -164,31 +165,34 @@ public class BadKdc {
* One round of test for max_retries and timeout. * One round of test for max_retries and timeout.
* @param expected the expected kdc# timeout kdc# 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 { throws Exception {
PrintStream oldout = System.out; PrintStream oldout = System.out;
boolean failed = false;
System.setOut(new PrintStream(bo)); System.setOut(new PrintStream(bo));
try { try {
Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
} catch (Exception e) {
failed = true;
} finally { } finally {
System.setOut(oldout); System.setOut(oldout);
} }
String[] lines = new String(bo.toByteArray()).split("\n"); String[] lines = new String(bo.toByteArray()).split("\n");
System.out.println("----------------- TEST -----------------"); StringBuilder sb = new StringBuilder();
int count = 0;
for (String line: lines) { for (String line: lines) {
Matcher m = re.matcher(line); Matcher m = re.matcher(line);
if (m.find()) { if (m.find()) {
System.out.println(line); System.out.println(line);
if (Integer.parseInt(m.group(1)) != expected[count++] || sb.append(m.group(1)).append(m.group(2));
Integer.parseInt(m.group(2)) != expected[count++]) {
throw new Exception("Fail here");
}
} }
} }
if (count != expected.length) { if (failed) sb.append('-');
throw new Exception("Less rounds");
String output = sb.toString();
System.out.println("Expected: " + expected + ", actual " + output);
if (!output.matches(expected)) {
throw new Exception("Does not match");
} }
} }
} }

View File

@ -37,16 +37,16 @@ public class BadKdc1 {
throws Exception { throws Exception {
Security.setProperty("krb5.kdc.bad.policy", "tryLess"); Security.setProperty("krb5.kdc.bad.policy", "tryLess");
BadKdc.go( 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 "121212222222(32){1,2}1222(32){1,2}", // 1 2
// The above line means try kdc1 for 2 seconds, then kdc1 // The above line means try kdc1 for 2 seconds then kdc1
// for 2 seconds,..., finally kdc3 for 2 seconds. // for 2 seconds... finally kdc3 for 2 seconds.
new int[]{1,2,2,2,3,2,1,2,2,2,3,2}, // 1, 2 "1222(32){1,2}1222(32){1,2}", // 1 2
// refresh // 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 "121212222222(32){1,2}1222(32){1,2}", // 1 2
// k3 off, k2 on // k3 off k2 on
new int[]{1,2,2,2,1,2,2,2}, // 1 "(122212(22){1,2}|1222323232-)", // 1
// k1 on // k1 on
new int[]{1,2,1,2} // empty "(12(12){1,2}|122232-)" // empty
); );
} }
} }

View File

@ -37,14 +37,14 @@ public class BadKdc2 {
throws Exception { throws Exception {
Security.setProperty("krb5.kdc.bad.policy", "tryLess:2,1000"); Security.setProperty("krb5.kdc.bad.policy", "tryLess:2,1000");
BadKdc.go( 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 "121212222222(32){1,2}11112121(32){1,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 "11112121(32){1,2}11112121(32){1,2}", // 1 2
// refresh // 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 "121212222222(32){1,2}11112121(32){1,2}", // 1 2
// k3 off, k2 on // k3 off k2 on
new int[]{1,1,1,1,2,1,1,1,1,1,2,2}, // 1 "1111(21){1,2}1111(22){1,2}", // 1
// k1 on // k1 on
new int[]{1,1,1,2} // empty "(11){1,2}(12){1,2}" // empty
); );
} }
} }

View File

@ -37,14 +37,14 @@ public class BadKdc3 {
throws Exception { throws Exception {
Security.setProperty("krb5.kdc.bad.policy", "tryLast"); Security.setProperty("krb5.kdc.bad.policy", "tryLast");
BadKdc.go( BadKdc.go(
new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,3,2}, // 1, 2 "121212222222(32){2,4}", // 1 2
new int[]{3,2,3,2}, // 1, 2 "(32){2,4}", // 1 2
// refresh // refresh
new int[]{1,2,1,2,1,2,2,2,2,2,2,2,3,2,3,2}, // 1, 2 "121212222222(32){2,4}", // 1 2
// k3 off, k2 on // k3 off k2 on
new int[]{3,2,3,2,3,2,1,2,1,2,1,2,2,2,2,2}, // 1, 3 "323232121212(22){2,4}", // 1 3
// k1 on // k1 on
new int[]{2,2,2,2} // 1, 3 "(22){2,4}" // 1 3
); );
} }
} }

View File

@ -37,14 +37,14 @@ public class BadKdc4 {
throws Exception { throws Exception {
Security.setProperty("krb5.kdc.bad.policy", ""); Security.setProperty("krb5.kdc.bad.policy", "");
BadKdc.go( 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}, "121212222222(32){1,2}121212222222(32){1,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}",
// refresh // 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}, "121212222222(32){1,2}121212222222(32){1,2}",
// k3 off, k2 on // k3 off k2 on
new int[]{1,2,1,2,1,2,2,2,1,2,1,2,1,2,2,2}, "121212(22){1,2}121212(22){1,2}",
// k1 on // k1 on
new int[]{1,2,1,2} "(12){2,4}"
); );
} }
} }