7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
Reviewed-by: xuelei
This commit is contained in:
parent
53170d594f
commit
3db0a0443c
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user