Path: blob/master/test/jdk/com/sun/jndi/ldap/NoWaitForReplyTest.java
41153 views
/*1* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 674815626* @summary add an new JNDI property to control the boolean flag WaitForReply27* @library lib/ /test/lib28*/2930import javax.naming.*;31import javax.naming.directory.*;32import java.util.Hashtable;33import jdk.test.lib.net.URIBuilder;3435public class NoWaitForReplyTest {3637public static void main(String[] args) throws Exception {3839boolean passed = false;4041// start the LDAP server42var ldapServer = new BaseLdapServer().start();4344// Set up the environment for creating the initial context45Hashtable<Object, Object> env = new Hashtable<>(11);46env.put(Context.PROVIDER_URL, URIBuilder.newBuilder()47.scheme("ldap")48.loopback()49.port(ldapServer.getPort())50.build().toString());51env.put(Context.INITIAL_CONTEXT_FACTORY,52"com.sun.jndi.ldap.LdapCtxFactory");5354// Wait up to 10 seconds for a response from the LDAP server55env.put("com.sun.jndi.ldap.read.timeout", "10000");5657// Don't wait until the first search reply is received58env.put("com.sun.jndi.ldap.search.waitForReply", "false");5960// Send the LDAP search request without first authenticating (no bind)61env.put("java.naming.ldap.version", "3");626364try (ldapServer) {6566// Create initial context67System.out.println("Client: connecting to the server");68DirContext ctx = new InitialDirContext(env);6970SearchControls scl = new SearchControls();71scl.setSearchScope(SearchControls.SUBTREE_SCOPE);72System.out.println("Client: performing search");73NamingEnumeration<SearchResult> answer =74ctx.search("ou=People,o=JNDITutorial", "(objectClass=*)", scl);7576// Server will never reply: either we waited in the call above until77// the timeout (fail) or we did not wait and reached here (pass).78passed = true;79System.out.println("Client: did not wait until first reply");8081// Close the context when we're done82ctx.close();8384} catch (NamingException e) {85// timeout (ignore)86}8788if (!passed) {89throw new Exception(90"Test FAILED: should not have waited until first search reply");91}92System.out.println("Test PASSED");93}94}959697