You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/06/15 10:54:33 UTC

svn commit: r954764 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/ test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/

Author: kayyagari
Date: Tue Jun 15 08:54:33 2010
New Revision: 954764

URL: http://svn.apache.org/viewvc?rev=954764&view=rev
Log:
o fixed the encode method
o updated tag vaues
o fixed ignored test and added few more test cases

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java?rev=954764&r1=954763&r2=954764&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java Tue Jun 15 08:54:33 2010
@@ -25,6 +25,7 @@ import java.nio.ByteBuffer;
 
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.controls.AbstractControl;
@@ -88,25 +89,31 @@ public class PasswordPolicyResponseContr
         // Encode the Control envelop
         super.encode( buffer );
 
-        // Encode the OCTET_STRING tag
-        buffer.put( UniversalTag.OCTET_STRING_TAG );
-        buffer.put( TLV.getBytes( valueLength ) );
+        if( controlLen > 0 )
+        {
+            // Encode the OCTET_STRING tag
+            buffer.put( UniversalTag.OCTET_STRING_TAG );
+            buffer.put( TLV.getBytes( valueLength ) );
+        }
 
         if ( timeBeforeExpiration >= 0 )
         {
             buffer.put( ( byte ) PasswordPolicyResponseControlTags.TIME_BEFORE_EXPIRATION_TAG.getValue() );
             buffer.put( TLV.getBytes( timeBeforeExpiration ) );
+            buffer.put( Value.getBytes( timeBeforeExpiration ) );
         }
         else if ( graceAuthNsRemaining >= 0 )
         {
             buffer.put( ( byte ) PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG.getValue() );
             buffer.put( TLV.getBytes( graceAuthNsRemaining ) );
+            buffer.put( Value.getBytes( graceAuthNsRemaining ) );
         }
 
         if ( ppolicyError != null )
         {
             buffer.put( UniversalTag.ENUMERATED_TAG );
             buffer.put( TLV.getBytes( ppolicyError.getValue() ) );
+            buffer.put( Value.getBytes( ppolicyError.getValue() ) );
         }
 
         return buffer;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java?rev=954764&r1=954763&r2=954764&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java Tue Jun 15 08:54:33 2010
@@ -27,7 +27,7 @@ package org.apache.directory.shared.ldap
  */
 public enum PasswordPolicyResponseControlTags
 {
-    TIME_BEFORE_EXPIRATION_TAG(0x0080), GRACE_AUTHNS_REMAINING_TAG(0x00A1);
+    TIME_BEFORE_EXPIRATION_TAG(0x0080), GRACE_AUTHNS_REMAINING_TAG(0x0081);
 
     /** Internal value for each tag */
     private int value;

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.java?rev=954764&r1=954763&r2=954764&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.java Tue Jun 15 08:54:33 2010
@@ -21,12 +21,14 @@
 package org.apache.directory.shared.ldap.codec.controls.ppolicy;
 
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import java.nio.ByteBuffer;
 
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
-import org.junit.Ignore;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
-import static org.junit.Assert.*;
 
 
 /**
@@ -36,9 +38,95 @@ import static org.junit.Assert.*;
  */
 public class PasswordPolicyResponseControlTest
 {
+
+    @Test
+    public void testDecodeRespWithExpiryWarningAndError() throws Exception
+    {
+        Asn1Decoder decoder = new PasswordPolicyResponseControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 8 );
+
+        bb.put( new byte[]
+            { 
+             0x30, 0x06,
+              (byte)0x80, 1, 1, //  
+              0x0A, 0x01, 1 
+            } );
+
+        bb.flip();
+
+        PasswordPolicyResponseControlContainer container = new PasswordPolicyResponseControlContainer();
+        container.setPasswordPolicyResponseControl( new PasswordPolicyResponseControl() );
+
+        decoder.decode( bb, container );
+
+        PasswordPolicyResponseControl control = container.getPasswordPolicyResponseControl();
+        assertEquals( 1, control.getTimeBeforeExpiration() );
+        assertEquals( 1, control.getPasswordPolicyError().getValue() );
+        
+        ByteBuffer buffer = ByteBuffer.allocate( 0x25 );
+        buffer.put( new byte[]
+               {
+                 0x30, 0x23,
+                  0x04, 0x19,
+                   '1','.', '3', '.', '6', '.', '1', '.', '4',
+                   '.', '1', '.', '4', '2', '.', '2', '.', '2',
+                   '7', '.', '8', '.', '5', '.', '1',
+                   0x04, 0x06,
+                   (byte)0x80, 1, 0x01, //  
+                   0x0A, 0x01, 0x01
+               } );
+        buffer.flip();
+        
+        ByteBuffer encoded = control.encode( ByteBuffer.allocate( control.computeLength() ) );
+        assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes( encoded.array() ) );
+    }
+    
+
+    @Test
+    public void testDecodeRespWithGraceAuthWarningAndError() throws Exception
+    {
+        Asn1Decoder decoder = new PasswordPolicyResponseControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 8 );
+
+        bb.put( new byte[]
+            { 
+             0x30, 0x06,
+              (byte)0x81, 1, 1, //  
+              0x0A, 0x01, 1 
+            } );
+
+        bb.flip();
+
+        PasswordPolicyResponseControlContainer container = new PasswordPolicyResponseControlContainer();
+        container.setPasswordPolicyResponseControl( new PasswordPolicyResponseControl() );
+
+        decoder.decode( bb, container );
+
+        PasswordPolicyResponseControl control = container.getPasswordPolicyResponseControl();
+        assertEquals( 1, control.getGraceAuthNsRemaining() );
+        assertEquals( 1, control.getPasswordPolicyError().getValue() );
+        
+        ByteBuffer buffer = ByteBuffer.allocate( 0x25 );
+        buffer.put( new byte[]
+               {
+                 0x30, 0x23,
+                  0x04, 0x19,
+                   '1','.', '3', '.', '6', '.', '1', '.', '4',
+                   '.', '1', '.', '4', '2', '.', '2', '.', '2',
+                   '7', '.', '8', '.', '5', '.', '1',
+                   0x04, 0x06,
+                   (byte)0x81, 1, 0x01, //  
+                   0x0A, 0x01, 0x01
+               } );
+        buffer.flip();
+        
+        ByteBuffer encoded = control.encode( ByteBuffer.allocate( control.computeLength() ) );
+        assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes( encoded.array() ) );
+    }
+
+    
     @Test
-    @Ignore( "failing due to a unknown issue related to reading the data from PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG" )
-    public void testDecodeResp() throws Exception
+    public void testDecodeRespWithExpiryWarningOnly() throws Exception
     {
         Asn1Decoder decoder = new PasswordPolicyResponseControlDecoder();
         ByteBuffer bb = ByteBuffer.allocate( 5 );
@@ -46,11 +134,7 @@ public class PasswordPolicyResponseContr
         bb.put( new byte[]
             { 
              0x30, 0x03,
-             // for the below 0x0080 tag the data is coming correctly
-              //(byte)0x0080, 1, 1, //  
-             // FIXME if I give the below tag 0x00A1 the data is coming as empty array
-             // the below tag is PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG
-               ( byte ) 0x00A1, 0x01, 0 // 
+              (byte)0x81, 1, 1 //  
             } );
 
         bb.flip();
@@ -61,7 +145,99 @@ public class PasswordPolicyResponseContr
         decoder.decode( bb, container );
 
         PasswordPolicyResponseControl control = container.getPasswordPolicyResponseControl();
-        //assertEquals( 1, control.getTimeBeforeExpiration() );
         assertEquals( 1, control.getGraceAuthNsRemaining() );
+        
+        ByteBuffer buffer = ByteBuffer.allocate( 0x22 );
+        buffer.put( new byte[]
+               {
+                 0x30, 0x20,
+                  0x04, 0x19,
+                   '1','.', '3', '.', '6', '.', '1', '.', '4',
+                   '.', '1', '.', '4', '2', '.', '2', '.', '2',
+                   '7', '.', '8', '.', '5', '.', '1',
+                   0x04, 0x03,
+                   (byte)0x81, 1, 0x01  
+               } );
+        buffer.flip();
+        
+        ByteBuffer encoded = control.encode( ByteBuffer.allocate( control.computeLength() ) );
+        assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes( encoded.array() ) );
+    }
+
+    
+    @Test
+    public void testDecodeRespWithErrorOnly() throws Exception
+    {
+        Asn1Decoder decoder = new PasswordPolicyResponseControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 5 );
+
+        bb.put( new byte[]
+            { 
+             0x30, 0x03,
+              0x0A, 1, 1 //  
+            } );
+
+        bb.flip();
+
+        PasswordPolicyResponseControlContainer container = new PasswordPolicyResponseControlContainer();
+        container.setPasswordPolicyResponseControl( new PasswordPolicyResponseControl() );
+
+        decoder.decode( bb, container );
+
+        PasswordPolicyResponseControl control = container.getPasswordPolicyResponseControl();
+        assertEquals( 1, control.getPasswordPolicyError().getValue() );
+        
+        ByteBuffer buffer = ByteBuffer.allocate( 0x22 );
+        buffer.put( new byte[]
+               {
+                 0x30, 0x20,
+                  0x04, 0x19,
+                   '1','.', '3', '.', '6', '.', '1', '.', '4',
+                   '.', '1', '.', '4', '2', '.', '2', '.', '2',
+                   '7', '.', '8', '.', '5', '.', '1',
+                   0x04, 0x03,
+                   0x0A, 1, 0x01  
+               } );
+        buffer.flip();
+        
+        ByteBuffer encoded = control.encode( ByteBuffer.allocate( control.computeLength() ) );
+        assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes( encoded.array() ) );
+    }
+
+    
+    @Test
+    public void testDecodeRespWithoutWarningAndError() throws Exception
+    {
+        Asn1Decoder decoder = new PasswordPolicyResponseControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 2 );
+
+        bb.put( new byte[]
+            { 
+             0x30, 0x00
+            } );
+
+        bb.flip();
+
+        PasswordPolicyResponseControlContainer container = new PasswordPolicyResponseControlContainer();
+        container.setPasswordPolicyResponseControl( new PasswordPolicyResponseControl() );
+
+        decoder.decode( bb, container );
+
+        PasswordPolicyResponseControl control = container.getPasswordPolicyResponseControl();
+        assertNotNull( control );
+        
+        ByteBuffer buffer = ByteBuffer.allocate( 0x1D );
+        buffer.put( new byte[]
+               {
+                 0x30, 0x1B,
+                  0x04, 0x19,
+                   '1','.', '3', '.', '6', '.', '1', '.', '4',
+                   '.', '1', '.', '4', '2', '.', '2', '.', '2',
+                   '7', '.', '8', '.', '5', '.', '1'
+               } );
+        buffer.flip();
+        
+        ByteBuffer encoded = control.encode( ByteBuffer.allocate( control.computeLength() ) );
+        assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes( encoded.array() ) );
     }
 }