You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/01/28 16:56:17 UTC

svn commit: r373169 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/search/SearchResultReferenceGrammar.java test/java/org/apache/ldap/common/codec/search/SearchResultReferenceTest.java

Author: elecharny
Date: Sat Jan 28 07:56:09 2006
New Revision: 373169

URL: http://svn.apache.org/viewcvs?rev=373169&view=rev
Log:
- Added a pop transition
- Added a test

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/SearchResultReferenceGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultReferenceTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/SearchResultReferenceGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/SearchResultReferenceGrammar.java?rev=373169&r1=373168&r2=373169&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/SearchResultReferenceGrammar.java (original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/search/SearchResultReferenceGrammar.java Sat Jan 28 07:56:09 2006
@@ -153,6 +153,9 @@
                         // We can have an END transition
                         ldapMessageContainer.grammarEndAllowed( true );
                         
+                        // We can have a Pop transition
+                        ldapMessageContainer.grammarPopAllowed( true );
+                        
                         return;
                     }
                 } );

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultReferenceTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultReferenceTest.java?rev=373169&r1=373168&r2=373169&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultReferenceTest.java (original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultReferenceTest.java Sat Jan 28 07:56:09 2006
@@ -19,6 +19,7 @@
 import java.nio.ByteBuffer;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 
 import javax.naming.NamingException;
 
@@ -26,6 +27,7 @@
 import org.apache.asn1.codec.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.IAsn1Container;
+import org.apache.ldap.common.codec.Control;
 import org.apache.ldap.common.codec.LdapDecoder;
 import org.apache.ldap.common.codec.LdapMessage;
 import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -154,6 +156,158 @@
         
         // Check the length
         assertEquals(0x3D8, message.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringTools.dumpBytes( bb.array() ); 
+            
+            assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+    /**
+     * Test the decoding of a SearchResultReference with controls
+     */
+    public void testDecodeSearchResultReferenceSuccessWithControls() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3F5 );
+        
+        String[] ldapUrls = new String[] 
+                                       {
+                                        "ldap:///",
+                                        "ldap://directory.apache.org:80/",
+                                        "ldap://d-a.org:80/",
+                                        "ldap://1.2.3.4/",
+                                        "ldap://1.2.3.4:80/",
+                                        "ldap://1.1.1.100000.a/",
+                                        "ldap://directory.apache.org:389/dc=example,dc=org/",
+                                        "ldap://directory.apache.org:389/dc=example",
+                                        "ldap://directory.apache.org:389/dc=example%202,dc=org",
+                                        "ldap://directory.apache.org:389/dc=example,dc=org?ou",
+                                        "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc",
+                                        "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou",
+                                        "ldap:///o=University%20of%20Michigan,c=US",
+                                        "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US",
+                                        "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress",
+                                        "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)",
+                                        "ldap://ldap.itd.umich.edu/c=GB?objectClass?one",
+                                        "ldap://ldap.question.com/o=Question%3f,c=US?mail",
+                                        "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)",
+                                        "ldap:///??sub??bindname=cn=Manager%2co=Foo",
+                                        "ldap:///??sub??!bindname=cn=Manager%2co=Foo"
+                                    };
+
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, (byte)0x82, 0x03, (byte)0xF1,   // LDAPMessage ::=SEQUENCE {
+                  0x02, 0x01, 0x01,                   //     messageID MessageID
+                  0x73, (byte)0x82, 0x03, (byte)0xcd, //     CHOICE { ..., searchResEntry  SearchResultEntry, ...
+                                                      // SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL
+            } );
+
+        
+        for (int i = 0; i < ldapUrls.length; i++)
+        {
+            stream.put((byte)0x04);
+            stream.put((byte)ldapUrls[i].getBytes().length);
+            
+            byte[] bytes = ldapUrls[i].getBytes();
+            
+            for (int j=0; j < bytes.length; j++)
+            {
+                stream.put(bytes[j]);
+            }
+        }
+        
+        byte[] controlBytes = new byte[] { 
+                (byte)0xA0, 0x1B,   // A control 
+                  0x30, 0x19, 
+                    0x04, 0x17, 
+                      0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 
+                      0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 
+                      0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
+        };
+
+        for (int i = 0; i < controlBytes.length; i++)
+        {
+            stream.put( controlBytes[i] );
+        }
+        
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        SearchResultReference searchResultReference      = message.getSearchResultReference();
+
+        assertEquals( 1, message.getMessageId() );
+        
+        HashSet ldapUrlsSet = new HashSet();
+        
+        try {
+            for (int i = 0; i < ldapUrls.length; i++)
+            {
+                ldapUrlsSet.add( new LdapURL( ldapUrls[i].getBytes() ).toString() );
+            }
+        } catch ( LdapURLEncodingException luee)
+        {
+            fail();
+        }
+        
+        Iterator iter = searchResultReference.getSearchResultReferences().iterator();
+        
+        while (iter.hasNext())
+        {
+            LdapURL ldapUrl = (LdapURL)iter.next();
+            
+            if (ldapUrlsSet.contains( ldapUrl.toString()) )
+            {
+                ldapUrlsSet.remove( ldapUrl.toString() );
+            }
+            else
+            {
+                fail(ldapUrl.toString() + " is not present");
+            }
+        }
+        
+        assertTrue( ldapUrlsSet.size() == 0 );
+        
+        // Check the Control
+        List controls = message.getControls();
+        
+        assertEquals( 1, controls.size() );
+        
+        Control control = message.getControls( 0 );
+        assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+        assertEquals( "", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
+
+        // Check the length
+        assertEquals(0x3F5, message.computeLength());
         
         // Check the encoding
         try