author | weijun |
Wed, 27 Apr 2011 17:11:06 +0800 | |
changeset 9522 | 38e96027251b |
parent 5506 | 202f599c92aa |
child 12842 | f6f9cb8f6b97 |
permissions | -rw-r--r-- |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
1 |
/* |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
4 |
* |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
8 |
* |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
14 |
* |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
22 |
*/ |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
23 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
24 |
import java.io.*; |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
25 |
import java.net.BindException; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
26 |
import java.net.DatagramPacket; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
27 |
import java.net.DatagramSocket; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
28 |
import java.net.InetAddress; |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
29 |
import java.util.regex.Matcher; |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
30 |
import java.util.regex.Pattern; |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
31 |
import javax.security.auth.login.LoginException; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
32 |
import sun.security.krb5.Asn1Exception; |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
33 |
import sun.security.krb5.Config; |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
34 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
35 |
public class BadKdc { |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
36 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
37 |
// Matches the krb5 debug output: |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
38 |
// >>> KDCCommunication: kdc=kdc.rabbit.hole UDP:14319, timeout=2000,... |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
39 |
// ^ kdc# ^ timeout |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
40 |
static final Pattern re = Pattern.compile( |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
41 |
">>> KDCCommunication: kdc=kdc.rabbit.hole UDP:(\\d)...., " + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
42 |
"timeout=(\\d)000,"); |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
43 |
|
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
44 |
/* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
45 |
* There are several cases this test fails: |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
46 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
47 |
* 1. The random selected port is used by another process. No good way to |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
48 |
* prevent this happening, coz krb5.conf must be written before KDC starts. |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
49 |
* There are two different outcomes: |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
50 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
51 |
* a. Cannot start the KDC. A BindException thrown. |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
52 |
* b. When trying to access a non-existing KDC, a response is received! |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
53 |
* Most likely a Asn1Exception thrown |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
54 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
55 |
* 2. Even if a KDC is started, and more than 20 seconds pass by, a timeout |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
56 |
* can still happens for the first UDP request. In fact, the KDC did not |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
57 |
* received it at all. This happens on almost all platforms, especially |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
58 |
* solaris-i586 and solaris-x64. |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
59 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
60 |
* To avoid them: |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
61 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
62 |
* 1. Catch those exceptions and ignore |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
63 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
64 |
* 2. a. Make the timeout longer? useless |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
65 |
* b. Read the output carefully, if there is a timeout, it's OK. |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
66 |
* Just make sure the retries times and KDCs are correct. |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
67 |
* This is tough. |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
68 |
* c. Feed the KDC a UDP packet first. The current "solution". |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
69 |
*/ |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
70 |
public static void go(int[]... expected) |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
71 |
throws Exception { |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
72 |
try { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
73 |
go0(expected); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
74 |
} catch (BindException be) { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
75 |
System.out.println("The random port is used by another process"); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
76 |
} catch (LoginException le) { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
77 |
Throwable cause = le.getCause(); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
78 |
if (cause instanceof Asn1Exception) { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
79 |
System.out.println("Bad packet possibly from another process"); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
80 |
return; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
81 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
82 |
throw le; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
83 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
84 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
85 |
|
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
86 |
public static void go0(int[]... expected) |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
87 |
throws Exception { |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
88 |
System.setProperty("sun.security.krb5.debug", "true"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
89 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
90 |
// Make sure KDCs' ports starts with 1 and 2 and 3, |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
91 |
// useful for checking debug output. |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
92 |
int p1 = 10000 + new java.util.Random().nextInt(10000); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
93 |
int p2 = 20000 + new java.util.Random().nextInt(10000); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
94 |
int p3 = 30000 + new java.util.Random().nextInt(10000); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
95 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
96 |
FileWriter fw = new FileWriter("alternative-krb5.conf"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
97 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
98 |
fw.write("[libdefaults]\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
99 |
"default_realm = " + OneKDC.REALM + "\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
100 |
"kdc_timeout = 2000\n"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
101 |
fw.write("[realms]\n" + OneKDC.REALM + " = {\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
102 |
"kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
103 |
"kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
104 |
"kdc = " + OneKDC.KDCHOST + ":" + p3 + "\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
105 |
"}\n"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
106 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
107 |
fw.close(); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
108 |
System.setProperty("java.security.krb5.conf", "alternative-krb5.conf"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
109 |
Config.refresh(); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
110 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
111 |
// Turn on k3 only |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
112 |
KDC k3 = on(p3); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
113 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
114 |
test(expected[0]); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
115 |
test(expected[1]); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
116 |
Config.refresh(); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
117 |
test(expected[2]); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
118 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
119 |
k3.terminate(); // shutdown k3 |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
120 |
on(p2); // k2 is on |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
121 |
test(expected[3]); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
122 |
on(p1); // k1 and k2 is on |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
123 |
test(expected[4]); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
124 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
125 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
126 |
private static KDC on(int p) throws Exception { |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
127 |
KDC k = new KDC(OneKDC.REALM, OneKDC.KDCHOST, p, true); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
128 |
k.addPrincipal(OneKDC.USER, OneKDC.PASS); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
129 |
k.addPrincipalRandKey("krbtgt/" + OneKDC.REALM); |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
130 |
// Feed a packet to newly started KDC to warm it up |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
131 |
System.err.println("-------- IGNORE THIS ERROR MESSAGE --------"); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
132 |
new DatagramSocket().send( |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
133 |
new DatagramPacket("Hello".getBytes(), 5, |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
134 |
InetAddress.getByName(OneKDC.KDCHOST), p)); |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
135 |
return k; |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
136 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
137 |
|
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
138 |
private static void test(int... expected) throws Exception { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
139 |
ByteArrayOutputStream bo = new ByteArrayOutputStream(); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
140 |
try { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
141 |
test0(bo, expected); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
142 |
} catch (Exception e) { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
143 |
System.out.println("----------------- ERROR -----------------"); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
144 |
System.out.println(new String(bo.toByteArray())); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
145 |
System.out.println("--------------- ERROR END ---------------"); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
146 |
throw e; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
147 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
148 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
149 |
|
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
150 |
/** |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
151 |
* One round of test for max_retries and timeout. |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
152 |
* @param expected the expected kdc# timeout kdc# timeout... |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
153 |
*/ |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
154 |
private static void test0(ByteArrayOutputStream bo, int... expected) |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
155 |
throws Exception { |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
156 |
PrintStream oldout = System.out; |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
157 |
System.setOut(new PrintStream(bo)); |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
158 |
try { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
159 |
Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
160 |
} finally { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
161 |
System.setOut(oldout); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
162 |
} |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
163 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
164 |
String[] lines = new String(bo.toByteArray()).split("\n"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
165 |
System.out.println("----------------- TEST -----------------"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
166 |
int count = 0; |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
167 |
for (String line: lines) { |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
168 |
Matcher m = re.matcher(line); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
169 |
if (m.find()) { |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
170 |
System.out.println(line); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
171 |
if (Integer.parseInt(m.group(1)) != expected[count++] || |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
172 |
Integer.parseInt(m.group(2)) != expected[count++]) { |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
173 |
throw new Exception("Fail here"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
174 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
175 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
176 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
177 |
if (count != expected.length) { |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
178 |
throw new Exception("Less rounds"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
179 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
180 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
181 |
} |