directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1040055 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/hostAddress/ main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/ main/java/org/apache/directory/shared/ke...
Date Mon, 29 Nov 2010 10:26:52 GMT
Author: elecharny
Date: Mon Nov 29 10:26:51 2010
New Revision: 1040055

URL: http://svn.apache.org/viewvc?rev=1040055&view=rev
Log:
Reviewed the HostAddress grammar, tests, etc

Modified:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/HostAddressInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/StoreAddrType.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/HostAddressDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressGrammar.java?rev=1040055&r1=1040054&r2=1040055&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressGrammar.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressGrammar.java
Mon Nov 29 10:26:51 2010
@@ -113,9 +113,6 @@ public final class HostAddressGrammar ex
     }
 
 
-    // ~ Methods
-    // ------------------------------------------------------------------------------------
-
     /**
      * Get the instance of this grammar
      * 

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressStatesEnum.java?rev=1040055&r1=1040054&r2=1040055&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressStatesEnum.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/HostAddressStatesEnum.java
Mon Nov 29 10:26:51 2010
@@ -42,11 +42,11 @@ public enum HostAddressStatesEnum implem
     HOST_ADDRESS_ADDR_TYPE_TAG_STATE,       // 2
     HOST_ADDRESS_ADDR_TYPE_STATE,           // 3
     
-    HOST_ADDRESS_ADDRESS_TAG_STATE,          // 4
-    HOST_ADDRESS_ADDRESS_STATE,              // 5
+    HOST_ADDRESS_ADDRESS_TAG_STATE,         // 4
+    HOST_ADDRESS_ADDRESS_STATE,             // 5
     
     // End
-    LAST_HOST_ADDRESS_STATE;                 // 6
+    LAST_HOST_ADDRESS_STATE;                // 6
 
     
     /**

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/HostAddressInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/HostAddressInit.java?rev=1040055&r1=1040054&r2=1040055&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/HostAddressInit.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/HostAddressInit.java
Mon Nov 29 10:26:51 2010
@@ -20,12 +20,11 @@
 package org.apache.directory.shared.kerberos.codec.hostAddress.actions;
 
 
+import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.asn1.ber.Asn1Container;
 import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.i18n.I18n;
-import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
 import org.apache.directory.shared.kerberos.codec.hostAddress.HostAddressContainer;
 import org.apache.directory.shared.kerberos.components.HostAddress;
 import org.slf4j.Logger;
@@ -40,7 +39,7 @@ import org.slf4j.LoggerFactory;
 public class HostAddressInit extends GrammarAction
 {
     /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+    private static final Logger LOG = LoggerFactory.getLogger( HostAddressInit.class );
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
@@ -67,10 +66,10 @@ public class HostAddressInit extends Gra
         // The Length should not be null
         if ( tlv.getLength() == 0 )
         {
-            LOG.error( I18n.err( I18n.ERR_04066 ) );
+            LOG.error( I18n.err( I18n.ERR_744_NULL_PDU_LENGTH ) );
 
             // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+            throw new DecoderException( I18n.err( I18n.ERR_744_NULL_PDU_LENGTH ) );
         }
         
         HostAddress hostAddress = new HostAddress();

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/StoreAddrType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/StoreAddrType.java?rev=1040055&r1=1040054&r2=1040055&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/StoreAddrType.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/hostAddress/actions/StoreAddrType.java
Mon Nov 29 10:26:51 2010
@@ -21,18 +21,10 @@ package org.apache.directory.shared.kerb
 
 
 import org.apache.directory.shared.asn1.ber.Asn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
-import org.apache.directory.shared.asn1.ber.tlv.TLV;
-import org.apache.directory.shared.asn1.ber.tlv.Value;
-import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.asn1.util.IntegerDecoder;
-import org.apache.directory.shared.asn1.util.IntegerDecoderException;
-import org.apache.directory.shared.i18n.I18n;
-import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+import org.apache.directory.shared.asn1.codec.actions.AbstractReadInteger;
 import org.apache.directory.shared.kerberos.codec.hostAddress.HostAddressContainer;
 import org.apache.directory.shared.kerberos.codec.types.HostAddrType;
 import org.apache.directory.shared.kerberos.components.HostAddress;
-import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,66 +34,38 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class StoreAddrType extends GrammarAction
+public class StoreAddrType extends AbstractReadInteger
 {
     /** The logger */
-    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+    private static final Logger LOG = LoggerFactory.getLogger( StoreAddrType.class );
 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
 
-
     /**
      * Instantiates a new HostAddressInit action.
      */
     public StoreAddrType()
     {
-        super( "Creates a HostAddress instance" );
+        super( "Creates a HostAddress instance", 0, Integer.MAX_VALUE );
     }
 
 
     /**
      * {@inheritDoc}
      */
-    public void action( Asn1Container container ) throws DecoderException
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
     {
         HostAddressContainer hostAddressContainer = ( HostAddressContainer ) container;
-
-        TLV tlv = hostAddressContainer.getCurrentTLV();
-
-        // The Length should not be null
-        if ( tlv.getLength() == 0 )
-        {
-            LOG.error( I18n.err( I18n.ERR_04066 ) );
-
-            // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
-        }
+        HostAddress hostAddressData = hostAddressContainer.getHostAddress();
         
-        // Get the address type now
-        Value value = tlv.getValue();
+        HostAddrType hostAddrType = HostAddrType.getTypeByOrdinal( value );
+        hostAddressData.setAddrType( hostAddrType );
         
-        try
+        if ( IS_DEBUG )
         {
-            int addrType = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
-            HostAddrType hostAddrType = HostAddrType.getTypeByOrdinal( addrType );
-
-            HostAddress hostAddressData = hostAddressContainer.getHostAddress();
-            
-            hostAddressData.setAddrType( hostAddrType );
-
-            if ( IS_DEBUG )
-            {
-                LOG.debug( "addr-type : {}", hostAddrType );
-            }
-        }
-        catch ( IntegerDecoderException ide )
-        {
-            LOG.error( I18n.err( I18n.ERR_04070, StringTools.dumpBytes( value.getData() ),
ide
-                .getLocalizedMessage() ) );
-
-            // This will generate a PROTOCOL_ERROR
-            throw new DecoderException( ide.getMessage() );
+            LOG.debug( "addr-type : {}", hostAddrType );
         }
     }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java?rev=1040055&r1=1040054&r2=1040055&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/principalName/actions/StoreNameType.java
Mon Nov 29 10:26:51 2010
@@ -42,7 +42,6 @@ public class StoreNameType extends Abstr
     /** Speedup for logs */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
 
-
     /**
      * Instantiates a new PrincipalNameInit action.
      */
@@ -68,6 +67,5 @@ public class StoreNameType extends Abstr
         {
             LOG.debug( "name-type : {}" + principalNameType );
         }
-
     }
 }

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/HostAddressDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/HostAddressDecoderTest.java?rev=1040055&r1=1040054&r2=1040055&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/HostAddressDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/HostAddressDecoderTest.java
Mon Nov 29 10:26:51 2010
@@ -51,7 +51,7 @@ import org.junit.runner.RunWith;
 public class HostAddressDecoderTest
 {
     /**
-     * Test the decoding of a HostAddress
+     * Test the decoding of a full HostAddress
      */
     @Test
     public void testHostAddress()
@@ -61,7 +61,8 @@ public class HostAddressDecoderTest
         ByteBuffer stream = ByteBuffer.allocate( 0x16 );
         
         stream.put( new byte[]
-            { 0x30, 0x14,
+            { 
+              0x30, 0x14,
                 (byte)0xA0, 0x03,                 // addr-type
                   0x02, 0x01, 0x02,               // IPV4
                 (byte)0xA1, 0x0D,                 // address : 192.168.0.1
@@ -146,7 +147,8 @@ public class HostAddressDecoderTest
         ByteBuffer stream = ByteBuffer.allocate( 0x04 );
         
         stream.put( new byte[]
-            { 0x30, 0x02,
+            { 
+              0x30, 0x02,
                 (byte)0xA0, 0x00                  // addr-type
             } );
 
@@ -172,7 +174,8 @@ public class HostAddressDecoderTest
         ByteBuffer stream = ByteBuffer.allocate( 0x0B );
         
         stream.put( new byte[]
-            { 0x30, 0x04,
+            { 
+              0x30, 0x04,
                 (byte)0xA0, 0x03,                 // addr-type
                   0x02, 0x00                      // 
             } );
@@ -227,7 +230,8 @@ public class HostAddressDecoderTest
         ByteBuffer stream = ByteBuffer.allocate( 0x0E );
         
         stream.put( new byte[]
-                             { 0x30, 0x14,
+        { 
+          0x30, 0x14,
             (byte)0xA0, 0x03,                 // addr-type
               0x02, 0x01, 0x02,               // IPV4
             (byte)0xA1, 0x02,                 // address
@@ -243,4 +247,60 @@ public class HostAddressDecoderTest
         kerberosDecoder.decode( stream, hostAddressContainer );
         fail();
     }
+    
+    
+    /**
+     * Test the decoding of a HostAddress with no add-type
+     */
+    @Test( expected = DecoderException.class )
+    public void testHostAddressMissingAddrType() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x11 );
+        
+        stream.put( new byte[]
+        { 
+            0x30, 0x0F,
+              (byte)0xA1, 0x0D,                 // address : 192.168.0.1
+                0x04, 0x0B, '1', '9', '2', '.', '1', '6', '8', '.', '0', '.', '1'
+        } );
+
+        stream.flip();
+
+        // Allocate a HostAddress Container
+        Asn1Container hostAddressContainer = new HostAddressContainer();
+
+        // Decode the HostAddress PDU
+        kerberosDecoder.decode( stream, hostAddressContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a HostAddress with no adddress
+     */
+    @Test( expected = DecoderException.class )
+    public void testHostAddressMissingAddress() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+        
+        stream.put( new byte[]
+        { 
+            0x30, 0x05,
+              (byte)0xA0, 0x03,                 // addr-type
+                0x02, 0x01, 0x02,               // IPV4
+        } );
+
+        stream.flip();
+
+        // Allocate a HostAddress Container
+        Asn1Container hostAddressContainer = new HostAddressContainer();
+
+        // Decode the HostAddress PDU
+        kerberosDecoder.decode( stream, hostAddressContainer );
+        fail();
+    }
 }



Mime
View raw message