directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1237689 - in /directory: apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/ shared/trunk/ldap/codec/core/...
Date Mon, 30 Jan 2012 14:49:54 GMT
Author: elecharny
Date: Mon Jan 30 14:49:54 2012
New Revision: 1237689

URL: http://svn.apache.org/viewvc?rev=1237689&view=rev
Log:
o Fixed DIRAPI-70 : the encoding of the value in a filter was not done properly. HR attributes
were considered as binary, and non HR were considered as String, due to a wrong If.
o Added some test to demonstrate the issue

Modified:
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/search/AttributeValueAssertionFilter.java

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java?rev=1237689&r1=1237688&r2=1237689&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
(original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
Mon Jan 30 14:49:54 2012
@@ -23,6 +23,8 @@ package org.apache.directory.shared.clie
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 
 import java.util.concurrent.TimeUnit;
 
@@ -37,7 +39,6 @@ import org.apache.directory.shared.clien
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
 import org.apache.directory.shared.ldap.model.entry.Entry;
-import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.model.message.Response;
 import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
@@ -62,7 +63,11 @@ import org.junit.runner.RunWith;
 @CreateLdapServer(transports =
     { @CreateTransport(protocol = "LDAP"), @CreateTransport(protocol = "LDAPS") })
 @ApplyLdifs(
-    { "dn: cn=user1,ou=users,ou=system", "objectClass: person", "objectClass: top", "sn:
user1 sn",
+    {
+        "dn: cn=user1,ou=users,ou=system",
+        "objectClass: person",
+        "objectClass: top",
+        "sn: user1 sn",
         "cn: user1",
 
         // alias to the above entry
@@ -75,209 +80,230 @@ import org.junit.runner.RunWith;
 
         // Another user
         "dn: cn=elecharny,ou=users,ou=system",
-        "objectClass: person",
         "objectClass: top",
+        "objectClass: person",
+        "objectClass: extensibleObject",
         "sn:: RW1tYW51ZWwgTMOpY2hhcm55",
-        "cn: elecharny"
-
+        "cn: elecharny",
+        "publicKey:: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKbHnLFs5N2PHk0gkyI/g3XeIdjxnWOAW5RVap4zWZuNY4gNGH1MhfHPVHcy6WEMoo+zaxU0Xh+Iv6BzrIa70IUCAwEAAQ=="
 })
 public class ClientSearchRequestTest extends AbstractLdapTestUnit
 {
-private LdapNetworkConnection connection;
-
-
-@Before
-public void setup() throws Exception
-{
-    connection = LdapApiIntegrationUtils.getPooledAdminConnection( getLdapServer() );
-}
-
-
-@After
-public void shutdown() throws Exception
-{
-    LdapApiIntegrationUtils.releasePooledAdminConnection( connection, getLdapServer() );
-}
-
-
-@Test
-public void testSimpleSearch() throws Exception
-{
-    EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL
);
-    int count = 0;
-
-    while ( cursor.next() )
+    private LdapNetworkConnection connection;
+    
+    
+    @Before
+    public void setup() throws Exception
     {
-        Entry entry = cursor.get();
-        assertNotNull( entry );
-        count++;
+        connection = LdapApiIntegrationUtils.getPooledAdminConnection( getLdapServer() );
     }
-
-    SearchResultDone done = cursor.getSearchResultDone();
-
-    assertNotNull( done );
-    assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
-    assertEquals( 5, count );
-    cursor.close();
-}
-
-
-@Test
-public void testSimpleSearchWithControl() throws Exception
-{
-    SearchRequest searchRequest = new SearchRequestImpl().setBase( new Dn( "ou=system" )
)
-        .setFilter( "(objectclass=*)" )
-        .setScope( SearchScope.ONELEVEL ).addControl( new ManageDsaITImpl() );
-    EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL
);
-    int count = 0;
-
-    while ( cursor.next() )
+    
+    
+    @After
+    public void shutdown() throws Exception
     {
-        Entry entry = cursor.get();
-        assertNotNull( entry );
-        count++;
+        LdapApiIntegrationUtils.releasePooledAdminConnection( connection, getLdapServer()
);
     }
-
-    SearchResultDone done = cursor.getSearchResultDone();
-
-    assertNotNull( done );
-    assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
-    assertEquals( 5, count );
-    cursor.close();
-}
-
-
-@Test
-public void testSearch() throws Exception
-{
-    EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)",
-        SearchScope.ONELEVEL,
-        "*", "+" );
-    int count = 0;
-
-    while ( cursor.next() )
+    
+    
+    @Test
+    public void testSimpleSearch() throws Exception
     {
-        assertNotNull( cursor.get() );
-        count++;
+        EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL
);
+        int count = 0;
+    
+        while ( cursor.next() )
+        {
+            Entry entry = cursor.get();
+            assertNotNull( entry );
+            count++;
+        }
+    
+        SearchResultDone done = cursor.getSearchResultDone();
+    
+        assertNotNull( done );
+        assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
+        assertEquals( 5, count );
+        cursor.close();
     }
-
-    SearchResultDone done = cursor.getSearchResultDone();
-
-    assertNotNull( done );
-    assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
-    assertEquals( 5, count );
-    cursor.close();
-}
-
-
-@Test
-public void testSearchEquality() throws Exception
-{
-    EntryCursor cursor = connection.search( "ou=system", "(objectclass=organizationalUnit)",
-        SearchScope.ONELEVEL, "*", "+" );
-    int count = 0;
-
-    while ( cursor.next() )
+    
+    
+    @Test
+    public void testSimpleSearchWithControl() throws Exception
     {
-        Entry entry = cursor.get();
-        assertNotNull( entry );
-        count++;
+        SearchRequest searchRequest = new SearchRequestImpl().setBase( new Dn( "ou=system"
) )
+            .setFilter( "(objectclass=*)" )
+            .setScope( SearchScope.ONELEVEL ).addControl( new ManageDsaITImpl() );
+        EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL
);
+        int count = 0;
+    
+        while ( cursor.next() )
+        {
+            Entry entry = cursor.get();
+            assertNotNull( entry );
+            count++;
+        }
+    
+        SearchResultDone done = cursor.getSearchResultDone();
+    
+        assertNotNull( done );
+        assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
+        assertEquals( 5, count );
+        cursor.close();
     }
-
-    assertEquals( 4, count );
-    cursor.close();
-}
-
-
-@Test
-public void testAsyncSearch() throws Exception
-{
-    SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL,
"*",
-        "+" );
-    int count = 0;
-    Response searchResponse = null;
-
-    do
+    
+    
+    @Test
+    public void testSearch() throws Exception
     {
-        searchResponse = ( Response ) searchFuture.get( 1000, TimeUnit.MILLISECONDS );
-        assertNotNull( searchResponse );
-        if ( !( searchResponse instanceof SearchResultDone ) )
+        EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)",
+            SearchScope.ONELEVEL,
+            "*", "+" );
+        int count = 0;
+    
+        while ( cursor.next() )
         {
+            assertNotNull( cursor.get() );
             count++;
         }
+    
+        SearchResultDone done = cursor.getSearchResultDone();
+    
+        assertNotNull( done );
+        assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
+        assertEquals( 5, count );
+        cursor.close();
     }
-    while ( !( searchResponse instanceof SearchResultDone ) );
-
-    assertEquals( 5, count );
-}
-
-
-/**
- * Test a search with a Substring filter
- * @throws Exception
- */
-@Test
-public void testSearchPersonSubstring() throws Exception
-{
-    SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*ers*)",
SearchScope.SUBTREE,
-        "*", "+" );
-    int count = 0;
-    Response searchResponse = null;
-
-    do
+    
+    
+    @Test
+    public void testSearchEquality() throws Exception
     {
-        searchResponse = ( Response ) searchFuture.get( 100000, TimeUnit.MILLISECONDS );
-        assertNotNull( searchResponse );
-
-        if ( !( searchResponse instanceof SearchResultDone ) )
+        EntryCursor cursor = connection.search( "ou=system", "(objectclass=organizationalUnit)",
+            SearchScope.ONELEVEL, "*", "+" );
+        int count = 0;
+    
+        while ( cursor.next() )
         {
+            Entry entry = cursor.get();
+            assertNotNull( entry );
             count++;
         }
+    
+        assertEquals( 4, count );
+        cursor.close();
     }
-    while ( !( searchResponse instanceof SearchResultDone ) );
-
-    assertEquals( 3, count );
-}
-
-
-@Test
-public void testSearchWithDerefAlias() throws Exception
-{
-    SearchRequest searchRequest = new SearchRequestImpl();
-    searchRequest.setBase( new Dn( "ou=users,ou=system" ) );
-    searchRequest.setFilter( "(objectClass=*)" );
-    searchRequest.setScope( SearchScope.ONELEVEL );
-    searchRequest.addAttributes( "*" );
-
-    int count = 0;
-    Cursor<Response> cursor = connection.search( searchRequest );
-
-    while ( cursor.next() )
+    
+    
+    @Test
+    public void testAsyncSearch() throws Exception
     {
-        count++;
+        SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*)",
SearchScope.ONELEVEL, "*",
+            "+" );
+        int count = 0;
+        Response searchResponse = null;
+    
+        do
+        {
+            searchResponse = searchFuture.get( 1000, TimeUnit.MILLISECONDS );
+            assertNotNull( searchResponse );
+            if ( !( searchResponse instanceof SearchResultDone ) )
+            {
+                count++;
+            }
+        }
+        while ( !( searchResponse instanceof SearchResultDone ) );
+    
+        assertEquals( 5, count );
     }
-    cursor.close();
-
-    // due to dereferencing of aliases we get only one entry
-    assertEquals( 2, count );
-
-    count = 0;
-    searchRequest.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );
-    cursor = connection.search( searchRequest );
-
-    while ( cursor.next() )
+    
+    
+    /**
+     * Test a search with a Substring filter
+     * @throws Exception
+     */
+    @Test
+    public void testSearchPersonSubstring() throws Exception
     {
-        count++;
+        SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*ers*)",
SearchScope.SUBTREE,
+            "*", "+" );
+        int count = 0;
+        Response searchResponse = null;
+    
+        do
+        {
+            searchResponse = searchFuture.get( 100000, TimeUnit.MILLISECONDS );
+            assertNotNull( searchResponse );
+    
+            if ( !( searchResponse instanceof SearchResultDone ) )
+            {
+                count++;
+            }
+        }
+        while ( !( searchResponse instanceof SearchResultDone ) );
+    
+        assertEquals( 3, count );
     }
-    cursor.close();
-
-    assertEquals( 3, count );
-}
+    
+    
+    @Test
+    public void testSearchWithDerefAlias() throws Exception
+    {
+        SearchRequest searchRequest = new SearchRequestImpl();
+        searchRequest.setBase( new Dn( "ou=users,ou=system" ) );
+        searchRequest.setFilter( "(objectClass=*)" );
+        searchRequest.setScope( SearchScope.ONELEVEL );
+        searchRequest.addAttributes( "*" );
+    
+        int count = 0;
+        Cursor<Response> cursor = connection.search( searchRequest );
+    
+        while ( cursor.next() )
+        {
+            count++;
+        }
+        cursor.close();
+    
+        // due to dereferencing of aliases we get only one entry
+        assertEquals( 2, count );
+    
+        count = 0;
+        searchRequest.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );
+        cursor = connection.search( searchRequest );
+    
+        while ( cursor.next() )
+        {
+            count++;
+        }
+        cursor.close();
+    
+        assertEquals( 3, count );
+    }
+    
+    
+    @Test
+    public void testSearchUTF8() throws Exception
+    {
+        EntryCursor cursor = connection.search( "ou=users,ou=system", "(sn=Emmanuel L\u00E9charny)",
SearchScope.ONELEVEL, "*", "+" );
 
+        assertFalse (cursor.next() );
+        
+        cursor.close();
+    }
+    
 
-@Test(expected = LdapException.class)
-public void testSearchUTF8() throws Exception
-{
-    connection.search( "ou=system", "(sn=Emmanuel L\u00e9charny)", SearchScope.ONELEVEL,
"*", "+" );
-}
+    
+    @Test
+    public void testSearchBinary() throws Exception
+    {
+        connection.loadSchema();
+        EntryCursor cursor = connection.search( "ou=system", "(publicKey=\\30\\5C\\30\\0D\\06\\09\\2A\\86\\48\\86\\F7\\0D\\01\\01\\01\\05\\00\\03\\4B\\00\\30\\48\\02\\41\\00\\A6\\C7\\9C\\B1\\6C\\E4\\DD\\8F\\1E\\4D\\20\\93\\22\\3F\\83\\75\\DE\\21\\D8\\F1\\9D\\63\\80\\5B\\94\\55\\6A\\9E\\33\\59\\9B\\8D\\63\\88\\0D\\18\\7D\\4C\\85\\F1\\CF\\54\\77\\32\\E9\\61\\0C\\A2\\8F\\B3\\6B\\15\\34\\5E\\1F\\88\\BF\\A0\\73\\AC\\86\\BB\\D0\\85\\02\\03\\01\\00\\01)",
SearchScope.SUBTREE, "publicKey" );
+        
+        assertTrue( cursor.next() );
+        
+        Entry entry = cursor.get();
+        assertNotNull( entry.get( "publicKey" ) );
+        
+        cursor.close();
+    }
 }

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1237689&r1=1237688&r2=1237689&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Mon Jan 30 14:49:54 2012
@@ -1670,7 +1670,7 @@ public class LdapNetworkConnection exten
         // Check that the future hasn't be canceled
         if ( searchFuture.isCancelled() )
         {
-            // Thow an exception here
+            // Throw an exception here
             throw new LdapException( searchFuture.getCause() );
         }
 

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/search/AttributeValueAssertionFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/search/AttributeValueAssertionFilter.java?rev=1237689&r1=1237688&r2=1237689&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/search/AttributeValueAssertionFilter.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/search/AttributeValueAssertionFilter.java
Mon Jan 30 14:49:54 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.codec.search;
 
@@ -134,16 +134,16 @@ public class AttributeValueAssertionFilt
      *  |
      *  +--> 0x04 L2 attributeDesc
      *  +--> 0x04 L3 assertionValue
-     *  
+     * 
      * 
      * L2 = Length(attributeDesc)
      * L3 = Length(assertionValue)
-     * L1 = 1 + Length(L2) + L2 
+     * L1 = 1 + Length(L2) + L2
      *      + 1 + Length(L3) + L3
      * 
      * Length(AttributeValueFilter) = Length(0xA?) + Length(L1)
-     *                                + 1 + Length(L2) + L2 
-     *                                + 1 + Length(L3) + L3 
+     *                                + 1 + Length(L2) + L2
+     *                                + 1 + Length(L3) + L3
      */
     public int computeLength()
     {
@@ -165,16 +165,16 @@ public class AttributeValueAssertionFilt
 
 
     /**
-     * Encode the AttributeValueAssertion Filters to a PDU. The 
+     * Encode the AttributeValueAssertion Filters to a PDU. The
      * following filters are to be encoded :
-     *  - equality match 
+     *  - equality match
      *  - greater or equal
      *  - less or equal
-     *  - approx match 
+     *  - approx match
      * 
      * AttributeValueAssertion filters :
      * 
-     * 0xA[3, 5, 6, 8] LL 
+     * 0xA[3, 5, 6, 8] LL
      * 0x04 LL attributeDesc
      * 0x04 LL assertionValue
      * 
@@ -223,11 +223,11 @@ public class AttributeValueAssertionFilt
         // The assertion desc
         if ( assertion.getAssertionValue().isHumanReadable() )
         {
-            Value.encode( buffer, assertion.getAssertionValue().getBytes() );
+            Value.encode( buffer, assertion.getAssertionValue().getString() );
         }
         else
         {
-            Value.encode( buffer, assertion.getAssertionValue().getString() );
+            Value.encode( buffer, assertion.getAssertionValue().getBytes() );
         }
 
         return buffer;



Mime
View raw message