author | xyin |
Wed, 01 May 2019 00:06:22 -0700 | |
branch | JDK-8210696-branch |
changeset 57345 | ff884a2f247b |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
1 |
/* |
57345 | 2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
4 |
* |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
8 |
* |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
13 |
* accompanied this code). |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
14 |
* |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
18 |
* |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
21 |
* questions. |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
22 |
*/ |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
23 |
|
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
24 |
/** |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
25 |
* @test |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
26 |
* @bug 6748156 |
57345 | 27 |
* @library lib/ |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
28 |
* @summary add an new JNDI property to control the boolean flag WaitForReply |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
29 |
*/ |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
30 |
|
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
31 |
import javax.naming.*; |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
32 |
import javax.naming.directory.*; |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
33 |
import java.util.Hashtable; |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
34 |
|
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
35 |
public class NoWaitForReplyTest { |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
36 |
|
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
37 |
public static void main(String[] args) throws Exception { |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
38 |
|
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
39 |
boolean passed = false; |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
40 |
|
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
41 |
// start the LDAP server |
57345 | 42 |
BaseLdapServer ldapServer = new BaseLdapServer() |
43 |
.setDebugLevel(BaseLdapServer.DebugLevel.FULL).startServer(); |
|
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
44 |
|
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
45 |
// Set up the environment for creating the initial context |
57345 | 46 |
Hashtable<String, Object> env = new Hashtable<>(11); |
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
47 |
env.put(Context.PROVIDER_URL, "ldap://localhost:" + |
57345 | 48 |
ldapServer.getPort()); |
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
49 |
env.put(Context.INITIAL_CONTEXT_FACTORY, |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
50 |
"com.sun.jndi.ldap.LdapCtxFactory"); |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
51 |
|
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
52 |
// Wait up to 10 seconds for a response from the LDAP server |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
53 |
env.put("com.sun.jndi.ldap.read.timeout", "10000"); |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
54 |
|
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
55 |
// Don't wait until the first search reply is received |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
56 |
env.put("com.sun.jndi.ldap.search.waitForReply", "false"); |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
57 |
|
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
58 |
// Send the LDAP search request without first authenticating (no bind) |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
59 |
env.put("java.naming.ldap.version", "3"); |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
60 |
|
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
61 |
|
57345 | 62 |
try (ldapServer) { |
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
63 |
|
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
64 |
// Create initial context |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
65 |
System.out.println("Client: connecting to the server"); |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
66 |
DirContext ctx = new InitialDirContext(env); |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
67 |
|
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
68 |
SearchControls scl = new SearchControls(); |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
69 |
scl.setSearchScope(SearchControls.SUBTREE_SCOPE); |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
70 |
System.out.println("Client: performing search"); |
57345 | 71 |
NamingEnumeration<?> answer = |
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
72 |
ctx.search("ou=People,o=JNDITutorial", "(objectClass=*)", scl); |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
73 |
|
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
74 |
// Server will never reply: either we waited in the call above until |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
75 |
// the timeout (fail) or we did not wait and reached here (pass). |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
76 |
passed = true; |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
77 |
System.out.println("Client: did not wait until first reply"); |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
78 |
|
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
79 |
// Close the context when we're done |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
80 |
ctx.close(); |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
81 |
|
8574
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
82 |
} catch (NamingException e) { |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
83 |
// timeout (ignore) |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
84 |
} |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
85 |
|
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
86 |
if (!passed) { |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
87 |
throw new Exception( |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
88 |
"Test FAILED: should not have waited until first search reply"); |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
89 |
} |
8b25e0b1d00e
7025105: TEST_BUG test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
coffeys
parents:
8564
diff
changeset
|
90 |
System.out.println("Test PASSED"); |
8564
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
91 |
} |
d99f879a35ab
6750362: Very large LDAP requests throw a OOM on LDAP servers which aren't aware of Paged Results Controls
coffeys
parents:
diff
changeset
|
92 |
} |