author | stefank |
Mon, 04 Apr 2016 09:15:01 +0200 | |
changeset 37241 | b9961c99c356 |
parent 23339 | d66b18f52418 |
permissions | -rw-r--r-- |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
13362
diff
changeset
|
2 |
* Copyright (c) 2009, 2012, 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)...., " + |
23339
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
42 |
"timeout=(\\d+),"); |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
43 |
|
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
44 |
// Ratio for timeout values of all timeout tests. Not final so that |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
45 |
// each test can choose their own. |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
46 |
static float ratio = 2f; |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
47 |
|
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
48 |
static void setRatio(float ratio) { |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
49 |
BadKdc.ratio = ratio; |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
50 |
} |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
51 |
|
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
52 |
static float getRatio() { |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
53 |
return ratio; |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
54 |
} |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
55 |
|
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
56 |
// Gets real timeout value. This method is called when writing krb5.conf |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
57 |
static int toReal(int from) { |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
58 |
return (int)(from * ratio + .5); |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
59 |
} |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
60 |
|
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
61 |
// De-ratio a millisecond value to second |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
62 |
static int toSymbolicSec(int from) { |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
63 |
return (int)(from / ratio / 1000f + 0.5); |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
64 |
} |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
65 |
|
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
66 |
/* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
67 |
* 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
|
68 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
69 |
* 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
|
70 |
* 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
|
71 |
* 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
|
72 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
73 |
* 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
|
74 |
* 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
|
75 |
* 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
|
76 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
77 |
* 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
|
78 |
* 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
|
79 |
* 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
|
80 |
* 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
|
81 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
82 |
* To avoid them: |
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 |
* 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
|
85 |
* |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
86 |
* 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
|
87 |
* 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
|
88 |
* 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
|
89 |
* This is tough. |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
90 |
* 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
|
91 |
*/ |
13362
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
92 |
public static void go(String... expected) |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
93 |
throws Exception { |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
94 |
try { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
95 |
go0(expected); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
96 |
} catch (BindException be) { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
97 |
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
|
98 |
} catch (LoginException le) { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
99 |
Throwable cause = le.getCause(); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
100 |
if (cause instanceof Asn1Exception) { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
101 |
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
|
102 |
return; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
103 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
104 |
throw le; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
105 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
106 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
107 |
|
13362
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
108 |
public static void go0(String... expected) |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
109 |
throws Exception { |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
110 |
System.setProperty("sun.security.krb5.debug", "true"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
111 |
|
12842 | 112 |
// Idle UDP sockets will trigger a SocketTimeoutException, without it, |
113 |
// a PortUnreachableException will be thrown. |
|
114 |
DatagramSocket d1 = null, d2 = null, d3 = null; |
|
115 |
||
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
116 |
// 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
|
117 |
// useful for checking debug output. |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
122 |
FileWriter fw = new FileWriter("alternative-krb5.conf"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
123 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
124 |
fw.write("[libdefaults]\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
125 |
"default_realm = " + OneKDC.REALM + "\n" + |
23339
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
126 |
"kdc_timeout = " + toReal(2000) + "\n"); |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
127 |
fw.write("[realms]\n" + OneKDC.REALM + " = {\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
128 |
"kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
129 |
"kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
130 |
"kdc = " + OneKDC.KDCHOST + ":" + p3 + "\n" + |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
131 |
"}\n"); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
132 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
133 |
fw.close(); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
134 |
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
|
135 |
Config.refresh(); |
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 |
// Turn on k3 only |
12842 | 138 |
d1 = new DatagramSocket(p1); |
139 |
d2 = new DatagramSocket(p2); |
|
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
140 |
KDC k3 = on(p3); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
141 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
142 |
test(expected[0]); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
143 |
test(expected[1]); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
144 |
Config.refresh(); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
145 |
test(expected[2]); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
146 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
147 |
k3.terminate(); // shutdown k3 |
12842 | 148 |
d3 = new DatagramSocket(p3); |
149 |
||
150 |
d2.close(); |
|
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
151 |
on(p2); // k2 is on |
12842 | 152 |
|
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
153 |
test(expected[3]); |
12842 | 154 |
d1.close(); |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
155 |
on(p1); // k1 and k2 is on |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
156 |
test(expected[4]); |
12842 | 157 |
|
158 |
d3.close(); |
|
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
159 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
160 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
161 |
private static KDC on(int p) throws Exception { |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
162 |
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
|
163 |
k.addPrincipal(OneKDC.USER, OneKDC.PASS); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
164 |
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
|
165 |
// 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
|
166 |
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
|
167 |
new DatagramSocket().send( |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
168 |
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
|
169 |
InetAddress.getByName(OneKDC.KDCHOST), p)); |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
170 |
return k; |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
171 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
172 |
|
13362
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
173 |
private static void test(String expected) throws Exception { |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
174 |
ByteArrayOutputStream bo = new ByteArrayOutputStream(); |
13362
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
175 |
System.out.println("----------------- TEST -----------------"); |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
176 |
try { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
177 |
test0(bo, expected); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
178 |
} catch (Exception e) { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
179 |
System.out.println("----------------- ERROR -----------------"); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
throw e; |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
183 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
184 |
} |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
185 |
|
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
186 |
/** |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
187 |
* 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
|
188 |
* @param expected the expected kdc# timeout kdc# timeout... |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
189 |
*/ |
13362
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
190 |
private static void test0(ByteArrayOutputStream bo, String expected) |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
191 |
throws Exception { |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
192 |
PrintStream oldout = System.out; |
13362
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
193 |
boolean failed = false; |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
194 |
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
|
195 |
try { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
196 |
Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); |
13362
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
197 |
} catch (Exception e) { |
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
198 |
failed = true; |
9522
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
199 |
} finally { |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
200 |
System.setOut(oldout); |
38e96027251b
6950929: Failures on Solaris sparc 64bit sun/security/krb5/auto/BadKdc4.java (and linux?)
weijun
parents:
5506
diff
changeset
|
201 |
} |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
202 |
|
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
203 |
String[] lines = new String(bo.toByteArray()).split("\n"); |
13362
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
204 |
StringBuilder sb = new StringBuilder(); |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
205 |
for (String line: lines) { |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
206 |
Matcher m = re.matcher(line); |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
207 |
if (m.find()) { |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
208 |
System.out.println(line); |
23339
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
209 |
sb.append(m.group(1)) |
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
210 |
.append(toSymbolicSec(Integer.parseInt(m.group(2)))); |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
211 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
212 |
} |
13362
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
213 |
if (failed) sb.append('-'); |
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
214 |
|
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
215 |
String output = sb.toString(); |
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
216 |
System.out.println("Expected: " + expected + ", actual " + output); |
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
217 |
if (!output.matches(expected)) { |
ff59dd695fc0
7178649: TEST BUG: BadKdc3.java needs improvement to ignore the unlikely but possible timeout
weijun
parents:
12842
diff
changeset
|
218 |
throw new Exception("Does not match"); |
4531
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
219 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
220 |
} |
3a9206343ab2
6843127: krb5 should not try to access unavailable kdc too often
weijun
parents:
diff
changeset
|
221 |
} |