directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1039194 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java
Date Thu, 25 Nov 2010 21:39:06 GMT
Author: kayyagari
Date: Thu Nov 25 21:39:06 2010
New Revision: 1039194

URL: http://svn.apache.org/viewvc?rev=1039194&view=rev
Log:
o added optional transitions
o added another test case

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java?rev=1039194&r1=1039193&r2=1039194&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbCredPart/EncKrbCredPartGrammar.java
Thu Nov 25 21:39:06 2010
@@ -120,6 +120,47 @@ public final class EncKrbCredPartGrammar
         super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG]
= new GrammarTransition(
             EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG,
             new StoreRecipientAddress());
+        
+        // ---------------------------------- OPTIONAL transitions -----------------------------------------------
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_TIMESTAMP_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_TIMESTAMP_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_USEC_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_USEC_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG,
+            new StoreSenderAddress());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TICKET_INFO_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG,
+            new StoreRecipientAddress());
+
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_USEC_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_USEC_TAG,
+            new CheckNotNullLength());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG,
+            new StoreSenderAddress());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_NONCE_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG,
+            new StoreRecipientAddress());
+
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_SENDER_ADDRESS_TAG,
+            new StoreSenderAddress());
+        
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_TIMESTAMP_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG,
+            new StoreRecipientAddress());
+
+        super.transitions[EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_STATE.ordinal()][KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG]
= new GrammarTransition(
+            EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_USEC_STATE, EncKrbCredPartStatesEnum.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG_STATE,
KerberosConstants.ENC_KRB_CRED_PART_RECIPIENT_ADDRESS_TAG,
+            new StoreRecipientAddress());
     }
 
 

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java?rev=1039194&r1=1039193&r2=1039194&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbCredPartDecoderTest.java
Thu Nov 25 21:39:06 2010
@@ -119,7 +119,7 @@ public class EncKrbCredPartDecoderTest
     public void testEncKrbCredPart() throws Exception
     {
         int size = optionalFieldValueList.size();
-        for ( int i = 0; i < 1; i++ ) // FIXME i < 1 should be changed to i < size
after adding optional transitions
+        for ( int i = 0; i < size; i++ )
         {
             EncKrbCredPart expected = new EncKrbCredPart();
             expected.setTicketInfo( ticketInfo );
@@ -166,6 +166,52 @@ public class EncKrbCredPartDecoderTest
         }
     }
     
+    
+    @Test
+    public void testKrbCredInfoWithEachOptElement() throws Exception
+    {
+        // algorithm:
+        // start from the first mandatory element and add ONLY one OPTIONAL element and then
test decoding
+
+        int size = optionalFieldValueList.size();
+        for ( int i = size - 1; i >= 0; i-- )
+        {
+            EncKrbCredPart expected = new EncKrbCredPart();
+            expected.setTicketInfo( ticketInfo );
+            Map<String, Field> encKrbCredPartFieldNameMap = getFieldMap( expected );
+
+            List<FieldValueHolder> presentFieldList = new ArrayList<FieldValueHolder>();
+
+            FieldValueHolder fieldValHolder = optionalFieldValueList.get( i );
+            presentFieldList.add( fieldValHolder );
+
+            Field f = encKrbCredPartFieldNameMap.get( fieldValHolder.fieldName.toLowerCase()
);
+            f.set( expected, fieldValHolder.value );
+
+            ByteBuffer stream = ByteBuffer.allocate( expected.computeLength() );
+            expected.encode( stream );
+            stream.flip();
+
+            Asn1Decoder decoder = new Asn1Decoder();
+            EncKrbCredPartContainer container = new EncKrbCredPartContainer();
+            container.setStream( stream );
+
+            try
+            {
+                decoder.decode( stream, container );
+            }
+            catch ( DecoderException e )
+            {
+                // NOTE: keep this sysout for easy debugging (no need to setup a logger)
+                System.out.println( "failed sequence:\n" + expected );
+                throw e;
+            }
+
+            EncKrbCredPart actual = container.getEncKrbCredPart();
+            assertValues( presentFieldList, actual );
+        }
+    }
+
     /**
      * compare the values that are inserted into the EncKrbCredPart objects before encoding
to
      * those that are obtained from decoded EncKrbCredPart



Mime
View raw message