Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/jndi/ldap/NoWaitForReplyTest.java
41153 views
1
/*
2
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
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.
22
*/
23
24
/**
25
* @test
26
* @bug 6748156
27
* @summary add an new JNDI property to control the boolean flag WaitForReply
28
* @library lib/ /test/lib
29
*/
30
31
import javax.naming.*;
32
import javax.naming.directory.*;
33
import java.util.Hashtable;
34
import jdk.test.lib.net.URIBuilder;
35
36
public class NoWaitForReplyTest {
37
38
public static void main(String[] args) throws Exception {
39
40
boolean passed = false;
41
42
// start the LDAP server
43
var ldapServer = new BaseLdapServer().start();
44
45
// Set up the environment for creating the initial context
46
Hashtable<Object, Object> env = new Hashtable<>(11);
47
env.put(Context.PROVIDER_URL, URIBuilder.newBuilder()
48
.scheme("ldap")
49
.loopback()
50
.port(ldapServer.getPort())
51
.build().toString());
52
env.put(Context.INITIAL_CONTEXT_FACTORY,
53
"com.sun.jndi.ldap.LdapCtxFactory");
54
55
// Wait up to 10 seconds for a response from the LDAP server
56
env.put("com.sun.jndi.ldap.read.timeout", "10000");
57
58
// Don't wait until the first search reply is received
59
env.put("com.sun.jndi.ldap.search.waitForReply", "false");
60
61
// Send the LDAP search request without first authenticating (no bind)
62
env.put("java.naming.ldap.version", "3");
63
64
65
try (ldapServer) {
66
67
// Create initial context
68
System.out.println("Client: connecting to the server");
69
DirContext ctx = new InitialDirContext(env);
70
71
SearchControls scl = new SearchControls();
72
scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
73
System.out.println("Client: performing search");
74
NamingEnumeration<SearchResult> answer =
75
ctx.search("ou=People,o=JNDITutorial", "(objectClass=*)", scl);
76
77
// Server will never reply: either we waited in the call above until
78
// the timeout (fail) or we did not wait and reached here (pass).
79
passed = true;
80
System.out.println("Client: did not wait until first reply");
81
82
// Close the context when we're done
83
ctx.close();
84
85
} catch (NamingException e) {
86
// timeout (ignore)
87
}
88
89
if (!passed) {
90
throw new Exception(
91
"Test FAILED: should not have waited until first search reply");
92
}
93
System.out.println("Test PASSED");
94
}
95
}
96
97