package delete; import junit.framework.TestCase; import netscape.ldap.LDAPConnection; import netscape.ldap.LDAPException; /** * Testcase to demonstrate DIRSERVER-634 ("Delete with illegal DN causes client * to hang"). Uses Sun ONE Directory SDK for Java 4.1 , or comparable (Netscape, * Mozilla). */ public class DeletionWithIllegalNameTest extends TestCase { static final String HOST = "localhost"; static final int PORT = 10389; static final String USER = "uid=admin,ou=system"; static final String PASSWORD = "secret"; static final String BASE = "dc=example,dc=com"; private LDAPConnection con = null; protected void setUp() throws LDAPException { con = new LDAPConnection(); con.connect(3, HOST, PORT, USER, PASSWORD); } protected void tearDown() throws LDAPException { con.disconnect(); } /** * Try to delete a non existing entry. Expected result code is 32 * (NO_SUCH_OBJECT). */ public void testDeleteNotExisting() { try { con.delete("cn=This does not exist" + "," + BASE); fail("deletion should fail"); } catch (LDAPException e) { assertTrue(e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT); } } /** * Try to delete an entry with invalid DN. Expected result code is 32 * (NO_SUCH_OBJECT) or 34 (INVALID_DN_SYNTAX). */ public void testDeleteWithIllegalName() throws LDAPException { try { con.delete("This is an illegal name" + "," + BASE); fail("deletion should fail"); } catch (LDAPException e) { assertTrue(e.getLDAPResultCode() == LDAPException.INVALID_DN_SYNTAX || e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT); } } }