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 2009/01/05 14:24:34 UTC

svn commit: r731560 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationGrammar.java test/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationRequestTest.java

Author: elecharny
Date: Mon Jan  5 05:24:34 2009
New Revision: 731560

URL: http://svn.apache.org/viewvc?rev=731560&view=rev
Log:
o Removed the grammarEndAllowed( true ) lines in the codec
o Added a test for emtpy sequences
o Fixed a test

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationGrammar.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationRequestTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationGrammar.java?rev=731560&r1=731559&r2=731560&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationGrammar.java Mon Jan  5 05:24:34 2009
@@ -91,7 +91,6 @@
                     CertGenerationContainer certGenContainer = ( CertGenerationContainer ) container;
                     CertGenerationObject certGenerationObject = new CertGenerationObject();
                     certGenContainer.setCertGenerationObject( certGenerationObject );
-                    certGenContainer.grammarEndAllowed( true );
                 }
             } );
 
@@ -120,7 +119,7 @@
                         LOG.debug( "Target DN = " + targetDN );
                     }
 
-                    if ( targetDN != null && ( targetDN.trim().length() > 0 ) )
+                    if ( ( targetDN != null ) && ( targetDN.trim().length() > 0 ) )
                     {
                         CertGenContainer.getCertGenerationObject().setTargetDN( targetDN );
                     }
@@ -131,8 +130,6 @@
                         LOG.error( msg );
                         throw new DecoderException( msg );
                     }
-
-                    CertGenContainer.grammarEndAllowed( true );
                 }
             } );
 
@@ -162,11 +159,10 @@
                         LOG.debug( "Issuer DN = " + issuerDN );
                     }
 
-                    if ( issuerDN != null && ( issuerDN.trim().length() > 0 ) )
+                    if ( ( issuerDN != null ) && ( issuerDN.trim().length() > 0 ) )
                     {
                         CertGenContainer.getCertGenerationObject().setIssuerDN( issuerDN );
                     }
-                    CertGenContainer.grammarEndAllowed( true );
                 }
             } );
 
@@ -196,12 +192,10 @@
                         LOG.debug( "subject DN = " + subjectDN );
                     }
 
-                    if ( subjectDN != null && ( subjectDN.trim().length() > 0 ) )
+                    if ( ( subjectDN != null ) && ( subjectDN.trim().length() > 0 ) )
                     {
                         CertGenContainer.getCertGenerationObject().setSubjectDN( subjectDN );
                     }
-
-                    CertGenContainer.grammarEndAllowed( true );
                 }
             } );
 
@@ -210,7 +204,7 @@
          *
          * CertGenerationObject ::= SEQUENCE { 
          *     ...
-         *     issuerDN IA5String
+         *     keyAlgorithm IA5String
          *     
          * Set the key algorithm value into the CertGenerationObject instance.
          */

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationRequestTest.java?rev=731560&r1=731559&r2=731560&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationRequestTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/CertGenerationRequestTest.java Mon Jan  5 05:24:34 2009
@@ -20,7 +20,10 @@
 package org.apache.directory.shared.ldap.codec.extended.operations;
 
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 
 import java.nio.ByteBuffer;
 
@@ -94,7 +97,6 @@
         }
         catch ( DecoderException e )
         {
-            e.printStackTrace();
             fail( e.getMessage() );
         }
 
@@ -145,7 +147,6 @@
         }
         catch ( DecoderException e )
         {
-            e.printStackTrace();
             assertTrue( true );
         }
                 
@@ -169,18 +170,75 @@
         try
         {
             decoder.decode( bb, container );
+            fail();
         }
         catch ( DecoderException e )
         {
-            e.printStackTrace();
-            fail( e.getMessage() );
+            assertTrue( true );
         }
 
+        /*
         CertGenerationObject certGenObj = container.getCertGenerationObject();
         
         assertEquals( "x", certGenObj.getTargetDN() );
         assertNull( certGenObj.getIssuerDN() );
         assertNull( certGenObj.getSubjectDN() );
         assertNull( certGenObj.getKeyAlgorithm() );
+        */
+    }
+
+
+    @Test
+    public void testCertGenerationDecodeWithoutTargetDN()
+    {
+        Asn1Decoder decoder = new LdapDecoder();
+
+        ByteBuffer bb = ByteBuffer.allocate( 5 );
+
+        bb.put( new byte[]
+            { 0x30, 0x03, // CertGenerateObject ::= SEQUENCE {
+              0x04, 0x01, ' ' } ); // empty targetDN value
+
+        String decodedPdu = StringTools.dumpBytes( bb.array() );
+        bb.flip();
+
+        CertGenerationContainer container = new CertGenerationContainer();
+
+        try
+        {
+            decoder.decode( bb, container );
+            fail( "shouldn't accept the empty targetDN" );
+        }
+        catch ( DecoderException e )
+        {
+            assertTrue( true );
+        }
+                
+    }
+    
+    
+    @Test
+    public void testDecodeEmptySequence()
+    {
+        Asn1Decoder decoder = new LdapDecoder();
+        
+        ByteBuffer bb = ByteBuffer.allocate( 2 );
+
+        bb.put( new byte[]
+            { 0x30, 0x00 }); // CertGenerateObject ::= SEQUENCE {
+
+        CertGenerationContainer container = new CertGenerationContainer();
+        bb.flip();
+
+        try
+        {
+            decoder.decode( bb, container );
+            // The PDU with an empty sequence is not allowed
+            fail();
+        }
+        catch ( DecoderException e )
+        {
+            assertTrue( true );
+        }
     }
 }