Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BC0969A86 for ; Mon, 3 Oct 2011 14:59:49 +0000 (UTC) Received: (qmail 75129 invoked by uid 500); 3 Oct 2011 14:59:49 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 75074 invoked by uid 500); 3 Oct 2011 14:59:49 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 75067 invoked by uid 99); 3 Oct 2011 14:59:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Oct 2011 14:59:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Oct 2011 14:59:42 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 357832388A6C for ; Mon, 3 Oct 2011 14:59:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1178423 [2/2] - /directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/ Date: Mon, 03 Oct 2011 14:59:19 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111003145920.357832388A6C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/DeleteIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/DeleteIT.java?rev=1178423&view=auto ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/DeleteIT.java (added) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/DeleteIT.java Mon Oct 3 14:59:19 2011 @@ -0,0 +1,314 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.server.operations.ldapsdk; + + +import static org.apache.directory.server.integ.ServerIntegrationUtils.getAdminConnection; +import static org.apache.directory.server.integ.ServerIntegrationUtils.getNsdkWiredConnection; +import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import javax.naming.NameNotFoundException; +import javax.naming.ReferralException; +import javax.naming.ldap.LdapContext; + +import netscape.ldap.LDAPConnection; +import netscape.ldap.LDAPConstraints; +import netscape.ldap.LDAPControl; +import netscape.ldap.LDAPException; +import netscape.ldap.LDAPResponse; +import netscape.ldap.LDAPResponseListener; +import netscape.ldap.LDAPSearchConstraints; + +import org.apache.directory.ldap.client.api.LdapConnection; +import org.apache.directory.server.annotations.CreateLdapServer; +import org.apache.directory.server.annotations.CreateTransport; +import org.apache.directory.server.core.annotations.ApplyLdifs; +import org.apache.directory.server.core.integ.AbstractLdapTestUnit; +import org.apache.directory.server.core.integ.FrameworkRunner; +import org.apache.directory.shared.ldap.model.exception.LdapContextNotEmptyException; +import org.apache.directory.shared.ldap.model.exception.LdapNoSuchObjectException; +import org.apache.directory.shared.ldap.model.message.ResultCodeEnum; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Integration tests for delete operations. + * + * @author Apache Directory Project + */ +@RunWith(FrameworkRunner.class) +@CreateLdapServer(transports = + { @CreateTransport(protocol = "LDAP") }) +@ApplyLdifs( + { + // Entry # 1 + "dn: uid=akarasulu,ou=users,ou=system", "objectClass: uidObject", "objectClass: person", + "objectClass: top", + "uid: akarasulu", + "cn: Alex Karasulu", + "sn: karasulu", + + // Entry # 2 + "dn: ou=Computers,uid=akarasulu,ou=users,ou=system", "objectClass: organizationalUnit", "objectClass: top", + "ou: computers", + "description: Computers for Alex", + "seeAlso: ou=Machines,uid=akarasulu,ou=users,ou=system", + + // Entry # 3 + "dn: uid=akarasuluref,ou=users,ou=system", "objectClass: uidObject", "objectClass: referral", + "objectClass: top", "uid: akarasuluref", "ref: ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", + "ref: ldap://foo:10389/uid=akarasulu,ou=users,ou=system", + "ref: ldap://bar:10389/uid=akarasulu,ou=users,ou=system" }) +public class DeleteIT extends AbstractLdapTestUnit +{ + private static final Logger LOG = LoggerFactory.getLogger( DeleteIT.class ); + + + /** + * Tests normal delete operation on normal non-referral entries without + * the ManageDsaIT control. + */ + @Test + public void testNormalDeleteFailContextNotEmpty() throws Exception + { + LdapConnection conn = getAdminConnection( getLdapServer() ); + + // delete failure on non-leaf entry + try + { + conn.delete( "uid=akarasulu,ou=users,ou=system" ); + fail(); + } + catch ( LdapContextNotEmptyException lcnee ) + { + assertTrue( true ); + } + + conn.unBind(); + conn.close(); + } + + + /** + * Tests normal delete operation on normal non-referral entries without + * the ManageDsaIT control. + */ + @Test + public void testNormalDelete() throws Exception + { + LdapConnection conn = getAdminConnection( getLdapServer() ); + + // delete success + conn.delete( "ou=computers,uid=akarasulu,ou=users,ou=system" ); + + // delete failure non-existant entry + try + { + conn.delete( "uid=elecharny,ou=users,ou=system" ); + fail(); + } + catch ( LdapNoSuchObjectException lnsoe ) + { + assertTrue( true ); + } + + conn.unBind(); + conn.close(); + } + + + /** + * Tests normal delete operation on non-existent entries without + * the ManageDsaIT control. + */ + @Test + public void testDeleteNonExistent() throws Exception + { + LdapConnection conn = getAdminConnection( getLdapServer() ); + + // delete failure non-existent entry + try + { + conn.delete( "uid=elecharny,ou=users,ou=system" ); + fail(); + } + catch ( LdapNoSuchObjectException lnsoe ) + { + assertTrue( true ); + } + + conn.unBind(); + conn.close(); + } + + + /** + * Tests delete operation on referral entry with the ManageDsaIT control. + */ + @Test + public void testOnReferralWithManageDsaITControl() throws Exception + { + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPSearchConstraints(); + constraints.setClientControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) ); + constraints.setServerControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) ); + conn.setConstraints( constraints ); + + // delete success + conn.delete( "uid=akarasuluref,ou=users,ou=system", constraints ); + + try + { + conn.read( "uid=akarasuluref,ou=users,ou=system", ( LDAPSearchConstraints ) constraints ); + fail( "Should never get here." ); + } + catch ( LDAPException e ) + { + assertEquals( ResultCodeEnum.NO_SUCH_OBJECT.getValue(), e.getLDAPResultCode() ); + } + + conn.disconnect(); + } + + + /** + * Tests delete operation on normal and referral entries without the + * ManageDsaIT control. Referrals are sent back to the client with a + * non-success result code. + */ + @Test + public void testOnReferral() throws Exception + { + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPConstraints(); + constraints.setReferrals( false ); + conn.setConstraints( constraints ); + + // referrals failure + LDAPResponseListener listener = null; + LDAPResponse response = null; + + listener = conn.delete( "uid=akarasuluref,ou=users,ou=system", null, constraints ); + response = listener.getResponse(); + assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() ); + + assertEquals( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[0] ); + assertEquals( "ldap://foo:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[1] ); + assertEquals( "ldap://bar:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[2] ); + + conn.disconnect(); + } + + + /** + * Tests delete operation on normal and referral entries without the + * ManageDsaIT control using JNDI instead of the Netscape API. Referrals + * are sent back to the client with a non-success result code. + */ + @Test + public void testThrowOnReferralWithJndi() throws Exception + { + LdapContext ctx = getWiredContextThrowOnRefferal( getLdapServer() ); + + // delete success + ctx.destroySubcontext( "ou=computers,uid=akarasulu,ou=users,ou=system" ); + + try + { + ctx.lookup( "ou=computers,uid=akarasulu,ou=users,ou=system" ); + fail( "Should never get here." ); + } + catch ( NameNotFoundException e ) + { + } + + // referrals failure on delete + try + { + ctx.destroySubcontext( "uid=akarasuluref,ou=users,ou=system" ); + fail( "Should never get here" ); + } + catch ( ReferralException e ) + { + // seems JNDI only returns the first referral URL and not all so we test for it + assertEquals( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", e.getReferralInfo() ); + } + + ctx.close(); + } + + + /** + * Tests referral handling when an ancestor is a referral. + */ + @Test + public void testAncestorReferral() throws Exception + { + LOG.debug( "" ); + + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPConstraints(); + conn.setConstraints( constraints ); + + // referrals failure + LDAPResponseListener listener = null; + LDAPResponse response = null; + + listener = conn.delete( "ou=Computers,uid=akarasuluref,ou=users,ou=system", null, constraints ); + response = listener.getResponse(); + assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() ); + + assertEquals( "ldap://localhost:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", + response.getReferrals()[0] ); + assertEquals( "ldap://foo:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[1] ); + assertEquals( "ldap://bar:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[2] ); + + conn.disconnect(); + } + + + /** + * Try to delete an entry with invalid Dn. The operation fails + * during parsing the given Dn + */ + @Test + public void testDeleteWithIllegalName() throws Exception + { + LdapConnection conn = getAdminConnection( getLdapServer() ); + + try + { + conn.delete( "This is an illegal name,dc=example,dc=com" ); + fail( "deletion should fail" ); + } + catch ( Exception e ) + { + // expected + } + + conn.close(); + } +} Added: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/IllegalModificationIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/IllegalModificationIT.java?rev=1178423&view=auto ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/IllegalModificationIT.java (added) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/IllegalModificationIT.java Mon Oct 3 14:59:19 2011 @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.server.operations.ldapsdk; + +import static org.apache.directory.server.integ.ServerIntegrationUtils.getAdminConnection; +import static org.apache.directory.server.integ.ServerIntegrationUtils.getNsdkWiredConnection; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import netscape.ldap.LDAPAttribute; +import netscape.ldap.LDAPConnection; +import netscape.ldap.LDAPEntry; +import netscape.ldap.LDAPException; +import netscape.ldap.LDAPModification; + +import org.apache.directory.ldap.client.api.LdapConnection; +import org.apache.directory.server.annotations.CreateLdapServer; +import org.apache.directory.server.annotations.CreateTransport; +import org.apache.directory.server.core.annotations.ApplyLdifs; +import org.apache.directory.server.core.integ.AbstractLdapTestUnit; +import org.apache.directory.server.core.integ.FrameworkRunner; +import org.apache.directory.shared.ldap.model.entry.Entry; +import org.apache.directory.shared.ldap.model.message.ModifyRequest; +import org.apache.directory.shared.ldap.model.message.ModifyRequestImpl; +import org.apache.directory.shared.ldap.model.message.ModifyResponse; +import org.apache.directory.shared.ldap.model.message.ResultCodeEnum; +import org.apache.directory.shared.ldap.model.name.Dn; +import org.junit.Test; +import org.junit.runner.RunWith; + + +/** + * A test taken from DIRSERVER-630: If one tries to add an attribute to an + * entry, and does not provide a value, it is assumed that the server does + * not modify the entry. We have a situation here using Sun ONE Directory + * SDK for Java, where adding a description attribute without value to a + * person entry like this, + * + * dn: cn=Kate Bush,dc=example,dc=com + * objectclass: person + * objectclass: top + * sn: Bush + * cn: Kate Bush + * + * does not fail (modify call does not result in an exception). Instead, a + * description attribute is created within the entry. At least the new + * attribute is readable with Netscape SDK (it is not visible to most UIs, + * because it is invalid ...). + * + * @author Apache Directory Project + */ +@RunWith(FrameworkRunner.class) +//@CreateDS( name="IllegalModificationIT-class", enableChangeLog=false ) +@CreateLdapServer(transports = + { @CreateTransport(protocol = "LDAP") }) +@ApplyLdifs( + { + // Entry # 1 + "dn: cn=Kate Bush,ou=system", "objectClass: person", "objectClass: top", "cn: Kate Bush", "sn: Bush" }) +public class IllegalModificationIT extends AbstractLdapTestUnit +{ + private static final String DN = "cn=Kate Bush,ou=system"; + + + @Test + public void testIllegalModification() throws Exception + { + LdapConnection con = getAdminConnection( getLdapServer() ); + + ModifyRequest modReq = new ModifyRequestImpl(); + modReq.setName( new Dn( DN ) ); + modReq.add( "description", "" ); + + ModifyResponse resp = con.modify( modReq ); + assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, resp.getLdapResult().getResultCode() ); + + // Check whether entry is unmodified, i.e. no description + Entry entry = con.lookup( DN ); + assertEquals( "description exists?", null, entry.get( "description" ) ); + con.close(); + } + + + @Test + public void testIllegalModification2() throws Exception + { + LDAPConnection con = getNsdkWiredConnection( getLdapServer() ); + + // first a valid attribute + LDAPAttribute attr = new LDAPAttribute( "description", "The description" ); + LDAPModification mod = new LDAPModification( LDAPModification.ADD, attr ); + // then an invalid one without any value + attr = new LDAPAttribute( "displayName" ); + LDAPModification mod2 = new LDAPModification( LDAPModification.ADD, attr ); + + try + { + con.modify( "cn=Kate Bush,ou=system", new LDAPModification[] + { mod, mod2 } ); + fail( "error expected due to empty attribute value" ); + } + catch ( LDAPException e ) + { + // expected + } + + // Check whether entry is unmodified, i.e. no displayName + LDAPEntry entry = con.read( DN ); + assertEquals( "displayName exists?", null, entry.getAttribute( "displayName" ) ); + } +} Added: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/ModifyDnReferralIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/ModifyDnReferralIT.java?rev=1178423&view=auto ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/ModifyDnReferralIT.java (added) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/ModifyDnReferralIT.java Mon Oct 3 14:59:19 2011 @@ -0,0 +1,293 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.server.operations.ldapsdk; + +import static org.apache.directory.server.integ.ServerIntegrationUtils.getNsdkWiredConnection; +import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import javax.naming.ReferralException; +import javax.naming.ldap.LdapContext; + +import netscape.ldap.LDAPConnection; +import netscape.ldap.LDAPConstraints; +import netscape.ldap.LDAPControl; +import netscape.ldap.LDAPEntry; +import netscape.ldap.LDAPException; +import netscape.ldap.LDAPResponse; +import netscape.ldap.LDAPResponseListener; +import netscape.ldap.LDAPSearchConstraints; + +import org.apache.directory.server.annotations.CreateLdapServer; +import org.apache.directory.server.annotations.CreateTransport; +import org.apache.directory.server.core.annotations.ApplyLdifs; +import org.apache.directory.server.core.integ.AbstractLdapTestUnit; +import org.apache.directory.server.core.integ.FrameworkRunner; +import org.apache.directory.shared.ldap.model.message.ResultCodeEnum; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Tests the server to make sure standard compare operations work properly. + * + * @author Apache Directory Project + */ +@RunWith ( FrameworkRunner.class ) +@CreateLdapServer ( + transports = + { + @CreateTransport( protocol = "LDAP" ) + }) +@ApplyLdifs( { + // Entry # 1 + "dn: uid=akarasulu,ou=users,ou=system", + "objectClass: uidObject", + "objectClass: person", + "objectClass: top", + "uid: akarasulu", + "cn: Alex Karasulu", + "sn: karasulu", + + // Entry # 2 + "dn: ou=Computers,uid=akarasulu,ou=users,ou=system", + "objectClass: organizationalUnit", + "objectClass: top", + "ou: computers", + "description: Computers for Alex", + "seeAlso: ou=Machines,uid=akarasulu,ou=users,ou=system", + + // Entry # 3 + "dn: uid=akarasuluref,ou=users,ou=system", + "objectClass: uidObject", + "objectClass: referral", + "objectClass: top", + "uid: akarasuluref", + "ref: ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", + "ref: ldap://foo:10389/uid=akarasulu,ou=users,ou=system", + "ref: ldap://bar:10389/uid=akarasulu,ou=users,ou=system", + + // Entry # 4 + "dn: uid=elecharny,ou=users,ou=system", + "objectClass: uidObject", + "objectClass: person", + "objectClass: top", + "uid: elecharny", + "cn: Emmanuel Lecharny", + "sn: lecharny" + } +) +public class ModifyDnReferralIT extends AbstractLdapTestUnit +{ + private static final Logger LOG = LoggerFactory.getLogger( ModifyDnReferralIT.class ); + + + /** + * Tests ModifyDN operation on referral entry with the ManageDsaIT control. + */ + @Test + public void testOnReferralWithManageDsaITControl() throws Exception + { + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPSearchConstraints(); + constraints.setClientControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) ); + constraints.setServerControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) ); + conn.setConstraints( constraints ); + + // ModifyDN success + conn.rename( "uid=akarasuluref,ou=users,ou=system", "uid=ref", true, constraints ); + LDAPEntry entry = conn.read( "uid=ref,ou=users,ou=system", ( LDAPSearchConstraints ) constraints ); + assertNotNull( entry ); + assertEquals( "uid=ref,ou=users,ou=system", entry.getDN() ); + + conn.disconnect(); + } + + + /** + * Tests ModifyDN operation with newSuperior on referral entry with the + * ManageDsaIT control. + */ + @Test + public void testNewSuperiorOnReferralWithManageDsaITControl() throws Exception + { + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPSearchConstraints(); + constraints.setClientControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) ); + constraints.setServerControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) ); + conn.setConstraints( constraints ); + + // ModifyDN success + try + { + conn.rename( "uid=elecharny,ou=users,ou=system", "uid=newuser", + "uid=akarasuluref,ou=users,ou=system", true, constraints ); + } + catch ( LDAPException le ) + { + assertEquals ( LDAPException.AFFECTS_MULTIPLE_DSAS, le.getLDAPResultCode() ); + } + + conn.disconnect(); + } + + + /** + * Tests ModifyDN operation on normal and referral entries without the + * ManageDsaIT control. Referrals are sent back to the client with a + * non-success result code. + */ + @Test + public void testOnReferral() throws Exception + { + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPConstraints(); + constraints.setReferrals( false ); + conn.setConstraints( constraints ); + + // referrals failure + LDAPResponseListener listener = null; + LDAPResponse response = null; + + listener = conn.rename( "uid=akarasuluref,ou=users,ou=system", "uid=ref", true, null, constraints ); + response = listener.getResponse(); + assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() ); + + assertEquals( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[0] ); + assertEquals( "ldap://foo:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[1] ); + assertEquals( "ldap://bar:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[2] ); + + conn.disconnect(); + } + + + /** + * Tests ModifyDN operation on normal and referral entries without the + * ManageDsaIT control. Referrals are sent back to the client with a + * non-success result code. + */ + @Test + public void testNewSupierorOnReferral() throws Exception + { + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPConstraints(); + constraints.setReferrals( false ); + conn.setConstraints( constraints ); + + // referrals failure + try + { + conn.rename( "uid=elecharny,ou=users,ou=system", "uid=ref", + "uid=akarasuluref,ou=users,ou=system", true, constraints ); + } + catch ( LDAPException e ) + { + assertEquals( LDAPException.AFFECTS_MULTIPLE_DSAS, e.getLDAPResultCode() ); + } + + conn.disconnect(); + } + + + /** + * Tests ModifyDN operation on normal and referral entries without the + * ManageDsaIT control using JNDI instead of the Netscape API. Referrals + * are sent back to the client with a non-success result code. + */ + @Test + public void testThrowOnReferralWithJndi() throws Exception + { + LdapContext ctx = getWiredContextThrowOnRefferal( getLdapServer() ); + + // ModifyDN referrals failure + try + { + ctx.rename( "uid=akarasuluref,ou=users,ou=system", "uid=ref,ou=users,ou=system" ); + fail( "Should never get here due to ModifyDN failure on ReferralException" ); + } + catch ( ReferralException e ) + { + // seems JNDI only returns the first referral URL and not all so we test for it + assertEquals( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", e.getReferralInfo() ); + } + + ctx.close(); + } + + + /** + * Tests referral handling when an ancestor is a referral. + */ + @Test + public void testAncestorReferral() throws Exception + { + LOG.debug( "" ); + + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPConstraints(); + conn.setConstraints( constraints ); + + // referrals failure + LDAPResponseListener listener = null; + LDAPResponse response = null; + + listener = conn.rename( "ou=Computers,uid=akarasuluref,ou=users,ou=system", "ou=Machines", true, null, constraints ); + response = listener.getResponse(); + assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() ); + + assertEquals( "ldap://localhost:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[0] ); + assertEquals( "ldap://foo:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[1] ); + assertEquals( "ldap://bar:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[2] ); + + conn.disconnect(); + } + + + /** + * Tests referral handling when an ancestor is a referral. + */ + @Test + public void testNewSuperiorAncestorReferral() throws Exception + { + LOG.debug( "" ); + + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPConstraints(); + conn.setConstraints( constraints ); + + // referrals failure + try + { + conn.rename( "uid=elecharny,ou=users,ou=system", "ou=Machines", + "ou=Computers,uid=akarasuluref,ou=users,ou=system", true, constraints ); + fail( "Should never get here to affectsMultipleDSA error result code" ); + } + catch ( LDAPException e ) + { + assertEquals( LDAPException.AFFECTS_MULTIPLE_DSAS, e.getLDAPResultCode() ); + } + + conn.disconnect(); + } +} Added: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/ModifyReferralIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/ModifyReferralIT.java?rev=1178423&view=auto ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/ModifyReferralIT.java (added) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/ldapsdk/ModifyReferralIT.java Mon Oct 3 14:59:19 2011 @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.server.operations.ldapsdk; + +import static org.apache.directory.server.integ.ServerIntegrationUtils.getNsdkWiredConnection; +import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import javax.naming.ReferralException; +import javax.naming.directory.Attribute; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.DirContext; +import javax.naming.directory.ModificationItem; +import javax.naming.ldap.LdapContext; + +import netscape.ldap.LDAPAttribute; +import netscape.ldap.LDAPConnection; +import netscape.ldap.LDAPConstraints; +import netscape.ldap.LDAPControl; +import netscape.ldap.LDAPModification; +import netscape.ldap.LDAPResponse; +import netscape.ldap.LDAPResponseListener; + +import org.apache.directory.server.annotations.CreateLdapServer; +import org.apache.directory.server.annotations.CreateTransport; +import org.apache.directory.server.core.annotations.ApplyLdifs; +import org.apache.directory.server.core.integ.AbstractLdapTestUnit; +import org.apache.directory.server.core.integ.FrameworkRunner; +import org.apache.directory.server.operations.compare.CompareIT; +import org.apache.directory.shared.ldap.model.message.ResultCodeEnum; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * A test taken from DIRSERVER-630: If one tries to add an attribute to an + * entry, and does not provide a value, it is assumed that the server does + * not modify the entry. We have a situation here using Sun ONE Directory + * SDK for Java, where adding a description attribute without value to a + * person entry like this, + * + * dn: cn=Kate Bush,dc=example,dc=com + * objectclass: person + * objectclass: top + * sn: Bush + * cn: Kate Bush + * + * does not fail (modify call does not result in an exception). Instead, a + * description attribute is created within the entry. At least the new + * attribute is readable with Netscape SDK (it is not visible to most UIs, + * because it is invalid ...). + * + * @author Apache Directory Project + */ +@RunWith ( FrameworkRunner.class ) +//@CreateDS( name="ModifyReferralIT-class", enableChangeLog=false ) +@CreateLdapServer ( + transports = + { + @CreateTransport( protocol = "LDAP" ) + }) +@ApplyLdifs( { + // Entry # 1 + "dn: uid=akarasulu,ou=users,ou=system", + "objectClass: uidObject", + "objectClass: person", + "objectClass: top", + "uid: akarasulu", + "cn: Alex Karasulu", + "sn: karasulu", + // Entry # 2 + "dn: ou=Computers,uid=akarasulu,ou=users,ou=system", + "objectClass: organizationalUnit", + "objectClass: top", + "ou: computers", + "description: Computers for Alex", + "seeAlso: ou=Machines,uid=akarasulu,ou=users,ou=system", + // Entry # 3 + "dn: uid=akarasuluref,ou=users,ou=system", + "objectClass: extensibleObject", + "objectClass: referral", + "objectClass: top", + "uid: akarasuluref", + "ref: ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", + "ref: ldap://foo:10389/uid=akarasulu,ou=users,ou=system", + "ref: ldap://bar:10389/uid=akarasulu,ou=users,ou=system" + } +) +public class ModifyReferralIT extends AbstractLdapTestUnit +{ + private static final Logger LOG = LoggerFactory.getLogger( CompareIT.class ); + + + /** + * Tests modify operation on referral entry with the ManageDsaIT control. + */ + @Test + public void testOnReferralWithManageDsaITControl() throws Exception + { + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPConstraints(); + constraints.setClientControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) ); + constraints.setServerControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) ); + conn.setConstraints( constraints ); + + // modify success + LDAPAttribute attribute = new LDAPAttribute( "description", "referral to akarasulu" ); + LDAPModification mod = new LDAPModification( LDAPModification.ADD, attribute ); + conn.modify( "uid=akarasuluref,ou=users,ou=system", mod, constraints ); + + assertTrue( conn.compare( "uid=akarasuluref,ou=users,ou=system", attribute, constraints ) ); + + conn.disconnect(); + } + + + /** + * Tests modify operation on referral entries without the + * ManageDsaIT control. Referrals are sent back to the client with a + * non-success result code. + */ + @Test + public void testOnReferral() throws Exception + { + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPConstraints(); + constraints.setReferrals( false ); + conn.setConstraints( constraints ); + + // referrals failure + // modify success + LDAPAttribute attribute = new LDAPAttribute( "description", "referral to akarasulu" ); + LDAPModification mod = new LDAPModification( LDAPModification.ADD, attribute ); + LDAPResponseListener listener = conn.modify( "uid=akarasuluref,ou=users,ou=system", mod, null, constraints ); + LDAPResponse response = listener.getResponse(); + + assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() ); + + assertEquals( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[0] ); + assertEquals( "ldap://foo:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[1] ); + assertEquals( "ldap://bar:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[2] ); + + conn.disconnect(); + } + + + /** + * Tests modify operation on normal and referral entries without the + * ManageDsaIT control using JNDI instead of the Netscape API. Referrals + * are sent back to the client with a non-success result code. + */ + @Test + public void testThrowOnReferralWithJndi() throws Exception + { + LdapContext ctx = getWiredContextThrowOnRefferal( getLdapServer() ); + + // modify failure + Attribute attr = new BasicAttribute( "description", "referral to akarasulu" ); + ModificationItem mod = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr ); + + try + { + ctx.modifyAttributes( "uid=akarasuluref,ou=users,ou=system", new ModificationItem[] { mod } ); + } + catch ( ReferralException e ) + { + // seems JNDI only returns the first referral URL and not all so we test for it + assertEquals( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", e.getReferralInfo() ); + } + + ctx.close(); + } + + + /** + * Tests referral handling when an ancestor is a referral. + */ + @Test + public void testAncestorReferral() throws Exception + { + LOG.debug( "" ); + + LDAPConnection conn = getNsdkWiredConnection( getLdapServer() ); + LDAPConstraints constraints = new LDAPConstraints(); + conn.setConstraints( constraints ); + + // referrals failure + LDAPAttribute attribute = new LDAPAttribute( "ou", "Machines" ); + LDAPModification mod = new LDAPModification( LDAPModification.ADD, attribute ); + LDAPResponseListener listener = null; + LDAPResponse response = null; + + listener = conn.modify( "ou=Computers,uid=akarasuluref,ou=users,ou=system", mod, null, constraints ); + response = listener.getResponse(); + assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() ); + + assertEquals( "ldap://localhost:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[0] ); + assertEquals( "ldap://foo:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[1] ); + assertEquals( "ldap://bar:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[2] ); + + conn.disconnect(); + } +}