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 2010/11/17 19:02:39 UTC

svn commit: r1036149 - /directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java

Author: elecharny
Date: Wed Nov 17 18:02:38 2010
New Revision: 1036149

URL: http://svn.apache.org/viewvc?rev=1036149&view=rev
Log:
Fixed tests for KdcReq

Modified:
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java?rev=1036149&r1=1036148&r2=1036149&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KdcReqDecoderTest.java Wed Nov 17 18:02:38 2010
@@ -21,7 +21,6 @@ package org.apache.directory.shared.kerb
 
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
@@ -33,17 +32,14 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.kerberos.codec.kdcReq.KdcReqContainer;
-import org.apache.directory.shared.kerberos.codec.kdcReqBody.KdcReqBodyContainer;
 import org.apache.directory.shared.kerberos.components.KdcReq;
-import org.apache.directory.shared.kerberos.components.KdcReqBody;
 import org.apache.directory.shared.kerberos.messages.AsReq;
-import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 
 /**
- * Test the decoder for a KdcReq
+ * Test the decoder for a KDC-REQ
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -51,10 +47,10 @@ import org.junit.runner.RunWith;
 public class KdcReqDecoderTest
 {
     /**
-     * Test the decoding of a KdcReqBody message
+     * Test the decoding of a KDC-REQ message
      */
     @Test
-    public void testDecodeFullKdcReqBody() throws Exception
+    public void testDecodeFullKdcReq() throws Exception
     {
         Asn1Decoder kerberosDecoder = new Asn1Decoder();
 
@@ -189,7 +185,6 @@ public class KdcReqDecoderTest
                                   'a', 'b', 'c', 'd', 'e', 'f'
         });
 
-        String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a KdcReq Container
@@ -233,10 +228,10 @@ public class KdcReqDecoderTest
     
     
     /**
-     * Test the decoding of a KDC-REQ-BODY with nothing in it
+     * Test the decoding of a KDC-REQ with nothing in it
      */
     @Test( expected = DecoderException.class)
-    public void testKdcReqBodyEmpty() throws DecoderException
+    public void testKdcReqEmpty() throws DecoderException
     {
         Asn1Decoder kerberosDecoder = new Asn1Decoder();
 
@@ -247,20 +242,20 @@ public class KdcReqDecoderTest
 
         stream.flip();
 
-        // Allocate a KDC-REQ-BODY Container
-        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+        // Allocate a KDC-REQ Container
+        Asn1Container kdcReqContainer = new KdcReqContainer();
 
-        // Decode the KDC-REQ-BODY PDU
-        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        // Decode the KDC-REQ PDU
+        kerberosDecoder.decode( stream, kdcReqContainer );
         fail();
     }
     
     
     /**
-     * Test the decoding of a KDC-REQ-BODY with empty options tag
+     * Test the decoding of a KDC-REQ with empty Pvno tag
      */
     @Test( expected = DecoderException.class)
-    public void testKdcReqBodyEmptyOptionTag() throws DecoderException
+    public void testKdcReqEmptyPvnoTag() throws DecoderException
     {
         Asn1Decoder kerberosDecoder = new Asn1Decoder();
 
@@ -269,25 +264,25 @@ public class KdcReqDecoderTest
         stream.put( new byte[]
             { 
                 0x30, 0x02,
-                  (byte)0xA0, 0x00
+                  (byte)0xA1, 0x00
             } );
 
         stream.flip();
 
-        // Allocate a KDC-REQ-BODY Container
-        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+        // Allocate a KDC-REQ Container
+        Asn1Container kdcReqContainer = new KdcReqContainer();
 
-        // Decode the KDC-REQ-BODY PDU
-        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        // Decode the KDC-REQ PDU
+        kerberosDecoder.decode( stream, kdcReqContainer );
         fail();
     }
     
     
     /**
-     * Test the decoding of a KDC-REQ-BODY with empty options value
+     * Test the decoding of a KDC-REQ with empty Pvno value
      */
     @Test( expected = DecoderException.class)
-    public void testKdcReqBodyEmptyOptionValue() throws DecoderException
+    public void testKdcReqEmptyPvnoValue() throws DecoderException
     {
         Asn1Decoder kerberosDecoder = new Asn1Decoder();
 
@@ -296,221 +291,17 @@ public class KdcReqDecoderTest
         stream.put( new byte[]
             { 
                 0x30, 0x04,
-                  (byte)0xA0, 0x02,
+                  (byte)0xA1, 0x02,
                     0x02, 0x00
             } );
 
         stream.flip();
 
-        // Allocate a KDC-REQ-BODY Container
-        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
+        // Allocate a KDC-REQ Container
+        Asn1Container kdcReqContainer = new KdcReqContainer();
 
-        // Decode the KDC-REQ-BODY PDU
-        kerberosDecoder.decode( stream, kdcReqBodyContainer );
+        // Decode the KDC-REQ PDU
+        kerberosDecoder.decode( stream, kdcReqContainer );
         fail();
     }
-    
-    
-    /**
-     * Test the decoding of a KDC-REQ-BODY with no options
-     */
-    @Test( expected = DecoderException.class)
-    public void testKdcReqBodyNoOptions() throws DecoderException
-    {
-        Asn1Decoder kerberosDecoder = new Asn1Decoder();
-
-        ByteBuffer stream = ByteBuffer.allocate( 0x152 );
-        
-        stream.put( new byte[]
-             {
-                 0x30, (byte)0x82, 0x01, 0x4E, 
-                   (byte)0xA1, 0x13, 
-                     0x30, 0x11, 
-                       (byte)0xA0, 0x03, 
-                         0x02, 0x01, 0x0A, 
-                       (byte)0xA1, 0x0A, 
-                         0x30, 0x08, 
-                           0x1B, 0x06, 
-                             'c', 'l', 'i', 'e', 'n', 't', 
-                   (byte)0xA2, 0x0D, 
-                     0x1B, 0x0B, 
-                       'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
-                   (byte)0xA3, 0x13, 
-                     0x30, 0x11, 
-                       (byte)0xA0, 0x03, 
-                         0x02, 0x01, 0x0A, 
-                       (byte)0xA1, 0x0A, 
-                         0x30, 0x08, 
-                           0x1B, 0x06, 
-                             's', 'e', 'r', 'v', 'e', 'r', 
-                   (byte)0xA4, 0x11, 
-                     0x18, 0x0F, 
-                       '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z', 
-                   (byte)0xA5, 0x11, 
-                     0x18, 0x0F, 
-                       '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z', 
-                   (byte)0xA6, 0x11, 
-                     0x18, 0x0F, 
-                       '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z', 
-                   (byte)0xA7, 0x04, 
-                     0x02, 0x02, 
-                       0x30, 0x39, 
-                   (byte)0xA8, 0x0B, 
-                     0x30, 0x09, 
-                       0x02, 0x01, 0x06, 
-                       0x02, 0x01, 0x11, 
-                       0x02, 0x01, 0x12, 
-                   (byte)0xA9, 0x2E, 
-                     0x30, 0x2C, 
-                       0x30, 0x14, 
-                         (byte)0xA0, 0x03, 
-                           0x02, 0x01, 0x02, 
-                         (byte)0xA1, 0x0D, 
-                           0x04, 0x0B, 
-                             '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '1', 
-                       0x30, 0x14, 
-                         (byte)0xA0, 0x03, 
-                           0x02, 0x01, 0x02, 
-                         (byte)0xA1, 0x0D, 
-                           0x04, 0x0B, 
-                             '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '2', 
-                   (byte)0xAA, 0x11, 
-                     0x30, 0x0F, 
-                       (byte)0xA0, 0x03, 
-                         0x02, 0x01, 0x11, 
-                       (byte)0xA2, 0x08, 
-                         0x04, 0x06, 
-                           'a', 'b', 'c', 'd', 'e', 'f', 
-                   (byte)0xAB, (byte)0x81, (byte)0x83, 
-                     0x30, (byte)0x81, (byte)0x80, 
-                       0x61, 0x3E, 
-                         0x30, 0x3C, 
-                           (byte)0xA0, 0x03, 
-                             0x02, 0x01, 0x05, 
-                           (byte)0xA1, 0x0D, 
-                             0x1B, 0x0B, 
-                               'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
-                           (byte)0xA2, 0x13, 
-                             0x30, 0x11, 
-                               (byte)0xA0, 0x03, 
-                                 0x02, 0x01, 0x01, 
-                               (byte)0xA1, 0x0A, 
-                                 0x30, 0x08, 
-                                   0x1B, 0x06, 
-                                     'c', 'l', 'i', 'e', 'n', 't', 
-                           (byte)0xA3, 0x11, 
-                             0x30, 0x0F, 
-                               (byte)0xA0, 0x03, 
-                                 0x02, 0x01, 0x11, 
-                               (byte)0xA2, 0x08, 
-                                 0x04, 0x06, 
-                                   'a', 'b', 'c', 'd', 'e', 'f', 
-                       0x61, 0x3E, 
-                         0x30, 0x3C, 
-                           (byte)0xA0, 0x03, 
-                             0x02, 0x01, 0x05, 
-                           (byte)0xA1, 0x0D, 
-                             0x1B, 0x0B, 
-                               'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
-                           (byte)0xA2, 0x13, 
-                             0x30, 0x11, 
-                               (byte)0xA0, 0x03, 
-                                 0x02, 0x01, 0x01, 
-                               (byte)0xA1, 0x0A, 
-                                 0x30, 0x08, 
-                                   0x1B, 0x06, 
-                                     's', 'e', 'r', 'v', 'e', 'r', 
-                           (byte)0xA3, 0x11, 
-                             0x30, 0x0F, 
-                               (byte)0xA0, 0x03, 
-                                 0x02, 0x01, 0x11, 
-                               (byte)0xA2, 0x08, 
-                                 0x04, 0x06, 
-                                   'a', 'b', 'c', 'd', 'e', 'f'
-             });
-
-        stream.flip();
-
-        // Allocate a KDC-REQ-BODY Container
-        Asn1Container kdcReqBodyContainer = new KdcReqBodyContainer();
-
-        // Decode the KDC-REQ-BODY PDU
-        kerberosDecoder.decode( stream, kdcReqBodyContainer );
-        fail();
-    }
-
-
-    /**
-     * Test the decoding of a KdcReqBody message with no optional value
-     * ( we only have options, realm, till, nonce and etype )
-     */
-    @Test
-    public void testDecodeKdcReqBodyNoOptionalValue() throws Exception
-    {
-        Asn1Decoder kerberosDecoder = new Asn1Decoder();
-
-        ByteBuffer stream = ByteBuffer.allocate( 0x40 );
-        
-        stream.put( new byte[]
-        {
-            0x30, (byte)0x3E, 
-              (byte)0xA0, 0x07,
-                0x03, 0x05, 
-                  0x00, 0x01, 0x04, 0x00, 0x32, 
-              (byte)0xA2, 0x0D, 
-                0x1B, 0x0B, 
-                  'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M', 
-              (byte)0xA5, 0x11, 
-                0x18, 0x0F, 
-                  '2', '0', '1', '0', '1', '1', '1', '0', '1', '5', '4', '5', '2', '5', 'Z', 
-              (byte)0xA7, 0x04, 
-                0x02, 0x02, 
-                  0x30, 0x39, 
-              (byte)0xA8, 0x0B, 
-                0x30, 0x09, 
-                  0x02, 0x01, 0x06, 
-                  0x02, 0x01, 0x11, 
-                  0x02, 0x01, 0x12
-        });
-
-        String decodedPdu = StringTools.dumpBytes( stream.array() );
-        stream.flip();
-
-        // Allocate a KdcReqBody Container
-        KdcReqBodyContainer kdcReqBodyContainer = new KdcReqBodyContainer();
-        kdcReqBodyContainer.setStream( stream );
-        
-        // Decode the KdcReqBody PDU
-        try
-        {
-            kerberosDecoder.decode( stream, kdcReqBodyContainer );
-        }
-        catch ( DecoderException de )
-        {
-            fail( de.getMessage() );
-        }
-
-        KdcReqBody body = kdcReqBodyContainer.getKdcReqBody();
-        
-        assertNotNull( body );
-        
-        // Check the encoding
-        ByteBuffer bb = ByteBuffer.allocate( body.computeLength() );
-
-        try
-        {
-            bb = body.encode( bb );
-    
-            // Check the length
-            assertEquals( 0x40, bb.limit() );
-
-            String encodedPdu = StringTools.dumpBytes( bb.array() );
-            
-            assertEquals( decodedPdu, encodedPdu );
-        }
-        catch ( EncoderException ee )
-        {
-            fail();
-        }
-    }
 }