directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1040816 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/ test/java/org/apache/directory/shared/kerberos/codec/
Date Tue, 30 Nov 2010 22:48:32 GMT
Author: elecharny
Date: Tue Nov 30 22:48:32 2010
New Revision: 1040816

URL: http://svn.apache.org/viewvc?rev=1040816&view=rev
Log:
Added some tests for the KerberosMessage

Added:
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java?rev=1040816&r1=1040815&r2=1040816&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageContainer.java
Tue Nov 30 22:48:32 2010
@@ -23,7 +23,6 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.kerberos.components.PrincipalName;
 import org.apache.directory.shared.kerberos.messages.KerberosMessage;
 import org.apache.directory.shared.kerberos.messages.Ticket;
-import org.apache.directory.shared.ldap.codec.LdapStatesEnum;
 
 
 /**
@@ -48,9 +47,9 @@ public class KerberosMessageContainer ex
     public KerberosMessageContainer()
     {
         super();
-        this.stateStack = new int[10];
+        this.stateStack = new int[1];
         this.grammar = KerberosMessageGrammar.getInstance();
-        setTransition( LdapStatesEnum.START_STATE );
+        setTransition( KerberosMessageStatesEnum.START_STATE );
     }
 
 

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java?rev=1040816&r1=1040815&r2=1040816&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/KerberosMessageGrammar.java
Tue Nov 30 22:48:32 2010
@@ -74,7 +74,7 @@ public final class KerberosMessageGramma
             KerberosMessageContainer kerberosMessageContainer = ( KerberosMessageContainer
) container;
 
             ByteBuffer stream = kerberosMessageContainer.getStream();
-            stream.flip();
+            stream.rewind();
             
             TLV tlv = kerberosMessageContainer.getCurrentTLV();
 
@@ -295,30 +295,39 @@ public final class KerberosMessageGramma
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.AS_REQ_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.AS_REQ_STATE,
KerberosConstants.AS_REQ_TAG,
             new DecodeKerberosMessage() );
+        
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.AS_REP_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.AS_REP_TAG_STATE,
KerberosConstants.AS_REP_TAG,
             new DecodeKerberosMessage() );
+        
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.TGS_REQ_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.TGS_REQ_TAG_STATE,
KerberosConstants.TGS_REQ_TAG,
             new DecodeKerberosMessage() );
+        
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.TGS_REP_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.TGS_REP_TAG_STATE,
KerberosConstants.TGS_REP_TAG,
             new DecodeKerberosMessage() );
+        
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.AP_REQ_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.AP_REQ_TAG_STATE,
KerberosConstants.AP_REQ_TAG,
             new DecodeKerberosMessage() );
+        
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.AP_REP_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.AP_REP_TAG_STATE,
KerberosConstants.AP_REP_TAG,
             new DecodeKerberosMessage() );
+        
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.KRB_SAFE_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.KRB_SAFE_STATE,
KerberosConstants.KRB_SAFE_TAG,
             new DecodeKerberosMessage() );
+        
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.KRB_PRIV_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.KRB_PRIV_STATE,
KerberosConstants.KRB_PRIV_TAG,
             new DecodeKerberosMessage() );
+        
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.KRB_CRED_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.KRB_CRED_STATE,
KerberosConstants.KRB_CRED_TAG,
             new DecodeKerberosMessage() );
+        
         super.transitions[KerberosMessageStatesEnum.START_STATE.ordinal()][KerberosConstants.KRB_ERROR_TAG]
= new GrammarTransition(
             KerberosMessageStatesEnum.START_STATE, KerberosMessageStatesEnum.KRB_ERROR_STATE,
KerberosConstants.KRB_ERROR_TAG,
             new DecodeKerberosMessage() );

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java?rev=1040816&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/KerberosMessageDecoderTest.java
Tue Nov 30 22:48:32 2010
@@ -0,0 +1,289 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.codec.tgsReq.TgsReqContainer;
+import org.apache.directory.shared.kerberos.messages.ApRep;
+import org.apache.directory.shared.kerberos.messages.TgsReq;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the decoder for some KerberosMessage
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class KerberosMessageDecoderTest
+{
+    /**
+     * Test the decoding of a AP-REP message and a TGS-REQ message
+     */
+    @Test
+    public void testDecodeApRep() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x21 );
+        
+        stream.put( new byte[]
+        {
+            0x6F, 0x1F,
+              0x30, 0x1D,
+                (byte)0xA0, 0x03,                 // pvno
+                  0x02, 0x01, 0x05,
+                (byte)0xA1, 0x03,                 // msg-type
+                  0x02, 0x01, 0x0F,
+                (byte)0xA2, 0x11,                 // enc-part
+                  0x30, 0x0F, 
+                    (byte)0xA0, 0x03, 
+                      0x02, 0x01, 0x11, 
+                    (byte)0xA2, 0x08, 
+                      0x04, 0x06, 
+                        'a', 'b', 'c', 'd', 'e', 'f', 
+        });
+
+        stream.flip();
+
+        // Allocate a KerberosMessage Container
+        KerberosMessageContainer kerberosMessageContainer = new KerberosMessageContainer();
+        kerberosMessageContainer.setStream( stream );
+        
+        // Decode the ApRep PDU
+        try
+        {
+            kerberosDecoder.decode( stream, kerberosMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        ApRep apRep = (ApRep)kerberosMessageContainer.getMessage();
+        
+        // Check the encoding
+        int length = apRep.computeLength();
+
+        // Check the length
+        assertEquals( 0x21, length );
+        
+        // Check the encoding
+        ByteBuffer encodedPdu = ByteBuffer.allocate( length );
+        
+        try
+        {
+            encodedPdu = apRep.encode( encodedPdu );
+            
+            // Check the length
+            assertEquals( 0x21, encodedPdu.limit() );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+        
+        // Now try to decode a TGS-REQ
+        stream = ByteBuffer.allocate( 0x193 );
+
+        stream.put( new byte[]
+             {
+               0x6C, (byte)0x82, 0x01, (byte)0x8F,
+                 0x30, (byte)0x82, 0x01, (byte)0x8B,
+                   (byte)0xA1, 0x03,
+                     0x02, 0x01, 0x05,
+                   (byte)0xA2, 0x03,
+                     0x02, 0x01, 0x0C,
+                   (byte)0xA3, 0x20,
+                     0x30, 0x1E,
+                       0x30, 0x0D,
+                         (byte)0xA1,0x03,
+                           0x02, 0x01, 01,
+                         (byte)0xA2, 0x06,
+                           0x04, 0x04, 'a', 'b', 'c', 'd',
+                       0x30, 0x0D,
+                         (byte)0xA1,0x03,
+                           0x02, 0x01, 01,
+                         (byte)0xA2, 0x06,
+                           0x04, 0x04, 'e', 'f', 'g', 'h',
+                   (byte)0xA4, (byte)0x82, 0x01, 0x5B,
+                     0x30, (byte)0x82, 0x01, 0x57, 
+                       (byte)0xA0, 0x07,
+                         0x03, 0x05, 
+                           0x00, 0x01, 0x04, 0x00, 0x32, 
+                       (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 TgsReq Container
+        TgsReqContainer tgsReqContainer = new TgsReqContainer();
+        tgsReqContainer.setStream( stream );
+        
+        // Decode the TgsReq PDU
+        try
+        {
+            kerberosDecoder.decode( stream, tgsReqContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        TgsReq tgsReq = tgsReqContainer.getTgsReq();
+        
+        assertTrue( tgsReq instanceof TgsReq );
+        
+        // Check the encoding
+        length = tgsReq.computeLength();
+
+        // Check the length
+        assertEquals( 0x193, length );
+        
+        // Check the encoding
+        encodedPdu = ByteBuffer.allocate( length );
+        
+        try
+        {
+            encodedPdu = tgsReq.encode( encodedPdu );
+    
+            // Check the length
+            assertEquals( 0x193, encodedPdu.limit() );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+}



Mime
View raw message