directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1037261 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java
Date Sat, 20 Nov 2010 16:46:29 GMT
Author: kayyagari
Date: Sat Nov 20 16:46:28 2010
New Revision: 1037261

URL: http://svn.apache.org/viewvc?rev=1037261&view=rev
Log:
o added more tests
o fixed the actions of optional transitions to s-address

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java?rev=1037261&r1=1037260&r2=1037261&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/krbSafeBody/KrbSafeBodyGrammar.java
Sat Nov 20 16:46:28 2010
@@ -194,7 +194,7 @@ public final class KrbSafeBodyGrammar ex
         // s-address       [4]
         super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG]
= new GrammarTransition(
             KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USER_DATA_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SENDER_ADDRESS_TAG_STATE,
KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG,
-            new CheckNotNullLength() );
+            new StoreSenderAddress() );
 
         // --------------------------------------------------------------------------------------------
         // Transition from usec value to s-address tag
@@ -203,7 +203,7 @@ public final class KrbSafeBodyGrammar ex
         // s-address       [4]
         super.transitions[KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_STATE.ordinal()][KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG]
= new GrammarTransition(
             KrbSafeBodyStatesEnum.KRB_SAFE_BODY_USEC_STATE, KrbSafeBodyStatesEnum.KRB_SAFE_BODY_SENDER_ADDRESS_TAG_STATE,
KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG,
-            new CheckNotNullLength() );
+            new StoreSenderAddress() );
     }
 
 

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java?rev=1037261&r1=1037260&r2=1037261&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KrbSafeBodyDecoderTest.java
Sat Nov 20 16:46:28 2010
@@ -23,6 +23,7 @@ package org.apache.directory.shared.kerb
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 import java.net.InetAddress;
 import java.nio.ByteBuffer;
@@ -38,7 +39,7 @@ import org.apache.directory.shared.ldap.
 import org.junit.Test;
 
 /**
- * TODO KrbSafeBodyDecoderTest.
+ * Test cases for KrbSafeBody codec.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -121,4 +122,378 @@ public class KrbSafeBodyDecoderTest
             fail();
         }
     }
+    
+    
+    @Test
+    public void testDecodeKrbSafeBodyWithoutTimestamp() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x34;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x32,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+                     // NO timestamp
+              (byte)0xA2, 0x03,       // usec
+                     0x02, 0x01, 0x01,
+              (byte)0xA3, 0x03,       // seq-number
+                     0x02, 0x01, 0x01,
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+              (byte)0xA5, 0xF,        // r-adress
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        KrbSafeBodyContainer container = new KrbSafeBodyContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            fail();
+        }
+        
+        KrbSafeBody body = container.getKrbSafeBody();
+        
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, body.getUserData() ) );
+        assertNull( body.getTimestamp() );
+        assertEquals( 1, body.getUsec() );
+        assertEquals( 1, body.getSeqNumber() );
+        assertEquals( ad, body.getSenderAddress() );
+        assertEquals( ad, body.getRecipientAddress() );
+
+        int computedLen = body.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            body.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
+    
+    @Test
+    public void testDecodeKrbSafeBodyWithoutTimestampAndUsec() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x2F;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x2D,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+                     // NO timestamp and usec
+              (byte)0xA3, 0x03,       // seq-number
+                     0x02, 0x01, 0x01,
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+              (byte)0xA5, 0xF,        // r-adress
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        KrbSafeBodyContainer container = new KrbSafeBodyContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            fail();
+        }
+        
+        KrbSafeBody body = container.getKrbSafeBody();
+        
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, body.getUserData() ) );
+        assertNull( body.getTimestamp() );
+        assertEquals( 0, body.getUsec() );
+        assertEquals( 1, body.getSeqNumber() );
+        assertEquals( ad, body.getSenderAddress() );
+        assertEquals( ad, body.getRecipientAddress() );
+
+        int computedLen = body.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            body.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
+    
+    @Test
+    public void testDecodeKrbSafeBodyWithoutTimestampUsecAndSeqNumber() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x2A;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x28,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+                     // NO timestamp, usec and seq-number
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+              (byte)0xA5, 0xF,        // r-adress
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        KrbSafeBodyContainer container = new KrbSafeBodyContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            e.printStackTrace();
+            fail();
+        }
+        
+        KrbSafeBody body = container.getKrbSafeBody();
+        
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, body.getUserData() ) );
+        assertNull( body.getTimestamp() );
+        assertEquals( 0, body.getUsec() );
+        assertEquals( 0, body.getSeqNumber() );
+        assertEquals( ad, body.getSenderAddress() );
+        assertEquals( ad, body.getRecipientAddress() );
+
+        int computedLen = body.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            body.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
+    
+    @Test
+    public void testDecodeKrbSafeBodyWithoutSequenceNumber() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x42;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x40,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+              (byte)0xA1, 0x11,       // timestamp
+                     0x18, 0xF, '2', '0', '1', '0', '1', '1', '1', '9', '0', '8', '0', '0',
'4', '3', 'Z',
+              (byte)0xA2, 0x03,       // usec
+                     0x02, 0x01, 0x01,
+                     // NO seq-number
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+              (byte)0xA5, 0xF,        // r-adress
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        KrbSafeBodyContainer container = new KrbSafeBodyContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            fail();
+        }
+        
+        KrbSafeBody body = container.getKrbSafeBody();
+        
+        String time = "20101119080043Z";
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, body.getUserData() ) );
+        assertEquals( time, body.getTimestamp().getDate() );
+        assertEquals( 1, body.getUsec() );
+        assertEquals( 0, body.getSeqNumber() );
+        assertEquals( ad, body.getSenderAddress() );
+        assertEquals( ad, body.getRecipientAddress() );
+
+        int computedLen = body.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            body.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
+    
+    @Test
+    public void testDecodeKrbSafeBodyWithoutOptionalValues() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x19;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x30, 0x17,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+                     // NO timestamp, usec and seq-number
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+                    // NO r-address
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        KrbSafeBodyContainer container = new KrbSafeBodyContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            e.printStackTrace();
+            fail();
+        }
+        
+        KrbSafeBody body = container.getKrbSafeBody();
+        
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, body.getUserData() ) );
+        assertNull( body.getTimestamp() );
+        assertEquals( 0, body.getUsec() );
+        assertEquals( 0, body.getSeqNumber() );
+        assertEquals( ad, body.getSenderAddress() );
+        assertNull( body.getRecipientAddress() );
+
+        int computedLen = body.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            body.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
 }



Mime
View raw message