/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6449574
* @summary Invalid ldap filter is accepted and processed
*/
public class BalancedParentheses {
// Should we run the client or server in a separate thread?
//
// Both sides can throw exceptions, but do you have a preference
// as to which side should be the main thread.
static boolean separateServerThread = true;
// use any free port by default
// Is the server ready to serve?
volatile static boolean serverReady = false;
// Define the server side of the test.
//
// If the server prematurely exits, serverReady will be set to true
// to avoid infinite hangs.
// signal client, it's ready to accecpt connection
serverReady = true;
// accept a connection
// read the bindRequest
// ignore
break;
}
0x01, 0x00, 0x04, 0x00, 0x04, 0x00};
// write bindResponse
// ignore any more request.
// ignore
}
serverSock.close();
}
// Define the client side of the test.
//
// If the server prematurely exits, serverReady will be set to true
// to avoid infinite hangs.
// Wait for server to get started.
while (!serverReady) {
}
// set up the environment for creating the initial context
"com.sun.jndi.ldap.LdapCtxFactory");
// env.put(Context.SECURITY_AUTHENTICATION, "simple");
// env.put(Context.SECURITY_PRINCIPAL,"cn=root");
// env.put(Context.SECURITY_CREDENTIALS,"root");
// create initial context
// searching
try {
} catch (InvalidSearchFilterException isfe) {
// ignore, it is the expected filter exception.
} catch (NamingException ne) {
// maybe a read timeout exception, as the server does not response.
}
try {
} catch (InvalidSearchFilterException isfe) {
// ignore, it is the expected filter exception.
} catch (NamingException ne) {
// maybe a read timeout exception, as the server does not response.
}
try {
} catch (InvalidSearchFilterException isfe) {
// ignore, it is the expected filter exception.
} catch (NamingException ne) {
// maybe a read timeout exception, as the server does not response.
}
}
/*
* ============================================================
* The remainder is just support stuff
*/
// client and server thread
// client and server exceptions
if (newThread) {
serverThread = new Thread() {
public void run() {
try {
doServerSide();
} catch (Exception e) {
/*
* Our server thread just died.
*
* Release the client, if not active already...
*/
serverReady = true;
serverException = e;
}
}
};
} else {
doServerSide();
}
}
if (newThread) {
clientThread = new Thread() {
public void run() {
try {
doClientSide();
} catch (Exception e) {
/*
* Our client thread just died.
*/
clientException = e;
}
}
};
} else {
doClientSide();
}
}
// Primary constructor, used to drive remainder of the test.
if (separateServerThread) {
startServer(true);
startClient(false);
} else {
startClient(true);
startServer(false);
}
/*
* Wait for other side to close down.
*/
if (separateServerThread) {
serverThread.join();
} else {
clientThread.join();
}
/*
* When we get here, the test is pretty much over.
*
* If the main thread excepted, that propagates back
* immediately. If the other thread threw an exception, we
* should report back.
*/
if (serverException != null) {
throw serverException;
}
if (clientException != null) {
throw clientException;
}
}
// start the test
new BalancedParentheses();
}
}