directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r165698 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
Date Mon, 02 May 2005 21:23:09 GMT
Author: elecharny
Date: Mon May  2 14:23:08 2005
New Revision: 165698

URL: http://svn.apache.org/viewcvs?rev=165698&view=rev
Log:
Added a test and factorized some common code in a function.

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java?rev=165698&r1=165697&r2=165698&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
Mon May  2 14:23:08 2005
@@ -23,6 +23,7 @@
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ldap.codec.BindRequestTest;
 import org.apache.asn1.primitives.OID;
+import org.apache.asn1.primitives.OctetString;
 import org.apache.asn1.spnego.pojo.SpnegoNegTokenInitPOJO;
 import org.apache.asn1.spnego.pojo.SpnegoPOJO;
 import org.apache.asn1.util.pools.PoolException;
@@ -43,6 +44,21 @@
     {
         PropertyConfigurator.configure( "conf/log4j.conf" );
     }
+    
+    /**
+     * Check the default value of Req Flags
+     * @param spnego The spnego POJO to test
+     */
+    private void checkDefaultReqFlags(SpnegoPOJO spnego)
+    {
+        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isAnonFlag());
+        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isConfFlag());
+        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isDelegFlag());
+        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isIntegFlag());
+        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isMutualFlag());
+        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isReplayFlag());
+        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isSequenceFlag());
+    }
 
     /**
      * Test the decoding of an empty Spnego NegTokenInit.
@@ -107,13 +123,7 @@
         Assert.assertEquals(0, nbOids);
         
         // Check the reqFlags
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isAnonFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isConfFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isDelegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isIntegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isMutualFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isReplayFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isSequenceFlag());
+        checkDefaultReqFlags(spnego);
 
         // Check the mech token
         Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
@@ -193,13 +203,7 @@
         Assert.assertEquals("1.2.840.48018.1.2.2", oids[0].getOID());
         
         // Check the reqFlags
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isAnonFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isConfFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isDelegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isIntegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isMutualFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isReplayFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isSequenceFlag());
+        checkDefaultReqFlags(spnego);
 
         // Check the mech token
         Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
@@ -292,13 +296,7 @@
         }
         
         // Check the reqFlags
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isAnonFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isConfFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isDelegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isIntegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isMutualFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isReplayFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isSequenceFlag());
+        checkDefaultReqFlags(spnego);
 
         // Check the mech token
         Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
@@ -388,13 +386,7 @@
         }
         
         // Check the reqFlags
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isAnonFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isConfFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isDelegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isIntegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isMutualFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isReplayFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isSequenceFlag());
+        checkDefaultReqFlags(spnego);
 
         // Check the mech token
         Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
@@ -408,6 +400,253 @@
     }
 
     /**
+     * Test the decoding of a Spnego NegTokenInit with an empty mech token .
+     */
+    public void testDecodeSpnegoNegTokenInitEmptyMechToken()
+    {
+        Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x08 );
+        stream.put(
+            new byte[]
+            {
+                (byte)0xa0, 0x06, 	// SPNEGO --> CHOICE {
+                					//     	negTokenInit  [0]  NegTokenInit
+                0x30, 0x04, 		// NegTokenInit ::= SEQUENCE {
+                (byte)0xA2, 0x02,	// mechToken     [2]  OCTET STRING  OPTIONAL ,
+                0x04, 0x00  		// empty mech token 
+            } );
+
+        stream.flip();
+
+        // Allocate a Spnego Container
+        IAsn1Container spnegoContainer = null;
+
+        try
+        {
+            spnegoContainer = ( IAsn1Container ) spnegoDecoder.allocate(
+                    SpnegoPoolEnum.SPNEGO_CONTAINER_POOL );
+        }
+        catch ( PoolException pe )
+        {
+            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+        }
+
+        spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
+
+        try
+        {
+            spnegoDecoder.decode( stream, spnegoContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        SpnegoPOJO spnego = ( ( SpnegoContainer ) spnegoContainer ).getSpnego();
+
+        // Checks the Oids
+        OID oids[] = ((SpnegoNegTokenInitPOJO)spnego).getMechTypeList();
+        int nbOids = 0;
+        
+        for ( int i = 0 ; i < oids.length ; i++ )
+        {
+            if (oids[i] == null)
+            {
+                break;
+            }
+            
+            nbOids ++;
+        }
+        
+        Assert.assertEquals(0, nbOids);
+        
+        // Check the reqFlags
+        checkDefaultReqFlags(spnego);
+
+        // Check the mech token
+        OctetString mechToken = ((SpnegoNegTokenInitPOJO)spnego).getMechToken();
+        
+        Assert.assertEquals(OctetString.EMPTY_STRING, mechToken);
+        Assert.assertEquals( "" , mechToken.toString() );
+
+        // Check the mech list MIC
+        Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechListMIC());
+
+        // Free the BindRequest Container. It will be put back in the IPool
+        // after being reset.
+        spnegoContainer.free();
+    }
+
+    /**
+     * Test the decoding of a Spnego NegTokenInit with a mech token.
+     */
+    public void testDecodeSpnegoNegTokenInitMechToken()
+    {
+        Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x0C );
+        stream.put(
+            new byte[]
+            {
+                (byte)0xa0, 0x0A, 		// SPNEGO --> CHOICE {
+                						//     	negTokenInit  [0]  NegTokenInit
+                0x30, 0x08, 			// NegTokenInit ::= SEQUENCE {
+                (byte)0xA2, 0x06,		// mechToken     [2]  OCTET STRING  OPTIONAL ,
+                0x04, 0x04, 'a', 'b', 'c', 'd' 	// mechToken = 'abcd'
+            } );
+
+        stream.flip();
+
+        // Allocate a Spnego Container
+        IAsn1Container spnegoContainer = null;
+
+        try
+        {
+            spnegoContainer = ( IAsn1Container ) spnegoDecoder.allocate(
+                    SpnegoPoolEnum.SPNEGO_CONTAINER_POOL );
+        }
+        catch ( PoolException pe )
+        {
+            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+        }
+
+        spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
+
+        try
+        {
+            spnegoDecoder.decode( stream, spnegoContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        SpnegoPOJO spnego = ( ( SpnegoContainer ) spnegoContainer ).getSpnego();
+
+        // Checks the Oids
+        OID oids[] = ((SpnegoNegTokenInitPOJO)spnego).getMechTypeList();
+        int nbOids = 0;
+        
+        for ( int i = 0 ; i < oids.length ; i++ )
+        {
+            if (oids[i] == null)
+            {
+                break;
+            }
+            
+            nbOids ++;
+        }
+        
+        Assert.assertEquals(0, nbOids);
+        
+        // Check the reqFlags
+        checkDefaultReqFlags(spnego);
+
+        // Check the mech token
+        Assert.assertEquals("[61][62][63][64]", ((SpnegoNegTokenInitPOJO)spnego).getMechToken().toString());
+
+        // Check the mech list MIC
+        Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechListMIC());
+
+        // Free the BindRequest Container. It will be put back in the IPool
+        // after being reset.
+        spnegoContainer.free();
+    }
+
+    /**
+     * Test the decoding of a Spnego NegTokenInit with a 2048 bytes long mech token .
+     */
+    public void testDecodeSpnegoNegTokenInit2048MechToken()
+    {
+        Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x810 );
+        stream.put(
+            new byte[]
+            {
+                (byte)0xa0, (byte)0x82, (byte)0x08, 0x0C, 	// SPNEGO --> CHOICE {
+                											//     	negTokenInit  [0]  NegTokenInit
+                0x30, (byte)0x82, (byte)0x08, 0x08, 		// NegTokenInit ::= SEQUENCE {
+                (byte)0xA2, (byte)0x82, (byte)0x08, 0x04,	// mechToken     [2]  OCTET STRING
 OPTIONAL ,
+                0x04, (byte)0x82, (byte)0x08, 0x00  		// 2048 octets 
+            } );
+
+        // Stores 2048 bytes in the stream
+        for ( int i = 0 ; i < 2048; i++)
+        {
+            stream.put( (byte)((i % 256) & 0x00FF) );
+        }
+        
+        stream.flip();
+
+        // Allocate a Spnego Container
+        IAsn1Container spnegoContainer = null;
+
+        try
+        {
+            spnegoContainer = ( IAsn1Container ) spnegoDecoder.allocate(
+                    SpnegoPoolEnum.SPNEGO_CONTAINER_POOL );
+        }
+        catch ( PoolException pe )
+        {
+            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+        }
+
+        spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
+
+        try
+        {
+            spnegoDecoder.decode( stream, spnegoContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        SpnegoPOJO spnego = ( ( SpnegoContainer ) spnegoContainer ).getSpnego();
+
+        // Checks the Oids
+        OID oids[] = ((SpnegoNegTokenInitPOJO)spnego).getMechTypeList();
+        int nbOids = 0;
+        
+        for ( int i = 0 ; i < oids.length ; i++ )
+        {
+            if (oids[i] == null)
+            {
+                break;
+            }
+            
+            nbOids ++;
+        }
+        
+        Assert.assertEquals(0, nbOids);
+        
+        // Check the reqFlags
+        checkDefaultReqFlags(spnego);
+
+        // Check the mech token
+        OctetString mechToken = ((SpnegoNegTokenInitPOJO)spnego).getMechToken();
+        
+        Assert.assertEquals(2048, mechToken.getValue().length);
+        
+        for ( int i = 0 ; i < 2048 ; i++ )
+        {
+            Assert.assertEquals( (byte)((i % 256) & 0x00FF) , mechToken.getValue()[i]
);
+        }
+
+        // Check the mech list MIC
+        Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechListMIC());
+
+        // Free the BindRequest Container. It will be put back in the IPool
+        // after being reset.
+        spnegoContainer.free();
+    }
+
+    /**
      * Test the decoding of a Spnego NegTokenInit with 2 mech types and
      * one mech token.
      */
@@ -479,13 +718,7 @@
         Assert.assertEquals("1.2.840.113554.1.2.2", oids[1].getOID());
         
         // Check the reqFlags
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isAnonFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isConfFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isDelegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isIntegFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isMutualFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isReplayFlag());
-        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isSequenceFlag());
+        checkDefaultReqFlags(spnego);
 
         // Check the mech token
         Assert.assertEquals("[61][62][63][64]", ((SpnegoNegTokenInitPOJO)spnego).getMechToken().toString());



Mime
View raw message