65 * b. Read the output carefully, if there is a timeout, it's OK. |
65 * b. Read the output carefully, if there is a timeout, it's OK. |
66 * Just make sure the retries times and KDCs are correct. |
66 * Just make sure the retries times and KDCs are correct. |
67 * This is tough. |
67 * This is tough. |
68 * c. Feed the KDC a UDP packet first. The current "solution". |
68 * c. Feed the KDC a UDP packet first. The current "solution". |
69 */ |
69 */ |
70 public static void go(int[]... expected) |
70 public static void go(String... expected) |
71 throws Exception { |
71 throws Exception { |
72 try { |
72 try { |
73 go0(expected); |
73 go0(expected); |
74 } catch (BindException be) { |
74 } catch (BindException be) { |
75 System.out.println("The random port is used by another process"); |
75 System.out.println("The random port is used by another process"); |
81 } |
81 } |
82 throw le; |
82 throw le; |
83 } |
83 } |
84 } |
84 } |
85 |
85 |
86 public static void go0(int[]... expected) |
86 public static void go0(String... expected) |
87 throws Exception { |
87 throws Exception { |
88 System.setProperty("sun.security.krb5.debug", "true"); |
88 System.setProperty("sun.security.krb5.debug", "true"); |
89 |
89 |
90 // Idle UDP sockets will trigger a SocketTimeoutException, without it, |
90 // Idle UDP sockets will trigger a SocketTimeoutException, without it, |
91 // a PortUnreachableException will be thrown. |
91 // a PortUnreachableException will be thrown. |
146 new DatagramPacket("Hello".getBytes(), 5, |
146 new DatagramPacket("Hello".getBytes(), 5, |
147 InetAddress.getByName(OneKDC.KDCHOST), p)); |
147 InetAddress.getByName(OneKDC.KDCHOST), p)); |
148 return k; |
148 return k; |
149 } |
149 } |
150 |
150 |
151 private static void test(int... expected) throws Exception { |
151 private static void test(String expected) throws Exception { |
152 ByteArrayOutputStream bo = new ByteArrayOutputStream(); |
152 ByteArrayOutputStream bo = new ByteArrayOutputStream(); |
|
153 System.out.println("----------------- TEST -----------------"); |
153 try { |
154 try { |
154 test0(bo, expected); |
155 test0(bo, expected); |
155 } catch (Exception e) { |
156 } catch (Exception e) { |
156 System.out.println("----------------- ERROR -----------------"); |
157 System.out.println("----------------- ERROR -----------------"); |
157 System.out.println(new String(bo.toByteArray())); |
158 System.out.println(new String(bo.toByteArray())); |
162 |
163 |
163 /** |
164 /** |
164 * One round of test for max_retries and timeout. |
165 * One round of test for max_retries and timeout. |
165 * @param expected the expected kdc# timeout kdc# timeout... |
166 * @param expected the expected kdc# timeout kdc# timeout... |
166 */ |
167 */ |
167 private static void test0(ByteArrayOutputStream bo, int... expected) |
168 private static void test0(ByteArrayOutputStream bo, String expected) |
168 throws Exception { |
169 throws Exception { |
169 PrintStream oldout = System.out; |
170 PrintStream oldout = System.out; |
|
171 boolean failed = false; |
170 System.setOut(new PrintStream(bo)); |
172 System.setOut(new PrintStream(bo)); |
171 try { |
173 try { |
172 Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); |
174 Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); |
|
175 } catch (Exception e) { |
|
176 failed = true; |
173 } finally { |
177 } finally { |
174 System.setOut(oldout); |
178 System.setOut(oldout); |
175 } |
179 } |
176 |
180 |
177 String[] lines = new String(bo.toByteArray()).split("\n"); |
181 String[] lines = new String(bo.toByteArray()).split("\n"); |
178 System.out.println("----------------- TEST -----------------"); |
182 StringBuilder sb = new StringBuilder(); |
179 int count = 0; |
|
180 for (String line: lines) { |
183 for (String line: lines) { |
181 Matcher m = re.matcher(line); |
184 Matcher m = re.matcher(line); |
182 if (m.find()) { |
185 if (m.find()) { |
183 System.out.println(line); |
186 System.out.println(line); |
184 if (Integer.parseInt(m.group(1)) != expected[count++] || |
187 sb.append(m.group(1)).append(m.group(2)); |
185 Integer.parseInt(m.group(2)) != expected[count++]) { |
|
186 throw new Exception("Fail here"); |
|
187 } |
|
188 } |
188 } |
189 } |
189 } |
190 if (count != expected.length) { |
190 if (failed) sb.append('-'); |
191 throw new Exception("Less rounds"); |
191 |
|
192 String output = sb.toString(); |
|
193 System.out.println("Expected: " + expected + ", actual " + output); |
|
194 if (!output.matches(expected)) { |
|
195 throw new Exception("Does not match"); |
192 } |
196 } |
193 } |
197 } |
194 } |
198 } |