directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r165496 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
Date Sun, 01 May 2005 12:28:07 GMT
Author: elecharny
Date: Sun May  1 05:28:06 2005
New Revision: 165496

URL: http://svn.apache.org/viewcvs?rev=165496&view=rev
Log:
Added other tests, especially one that has a length above 127 bytes, to check multi-bytes
length. 

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=165496&r1=165495&r2=165496&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
Sun May  1 05:28:06 2005
@@ -45,10 +45,373 @@
     }
 
     /**
-     * Test the decoding of a BindRequest with Simple authentication
-     * and no controls
+     * Test the decoding of an empty Spnego NegTokenInit.
      */
-    public void testDecodeBindRequestSimpleNoControls()
+    public void testDecodeEmptySpnegoNegTokenInit()
+    {
+        Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x04 );
+        stream.put(
+            new byte[]
+            {
+                (byte)0xa0, 0x02, 		// SPNEGO --> CHOICE {
+                						//     	negTokenInit  [0]  NegTokenInit
+                0x30, 0x00  			// NegTokenInit ::= SEQUENCE {
+                						// } (everything is optional ...)
+            } );
+
+        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
+        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());
+
+        // Check the mech token
+        Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
+
+        // 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 1 mech types.
+     */
+    public void testDecodeSpnegoNegTokenInit1MechType()
+    {
+        Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x13 );
+        stream.put(
+            new byte[]
+            {
+                (byte)0xa0, 0x11, 		// SPNEGO --> CHOICE {
+                						//     	negTokenInit  [0]  NegTokenInit
+                0x30, 0x0F, 			// NegTokenInit ::= SEQUENCE {
+                (byte)0xA0, 0x0D,		// 		[0]  MechTypeList  OPTIONAL
+                0x30, 0x0B, 			// MechTypeList ::= SEQUENCE of MechType
+                        				// MechType ::= OBJECT IDENTIFIER
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02 	// mechType = 1.2.840.48018.1.2.2
+            } );
+
+        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(1, nbOids);
+        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());
+
+        // Check the mech token
+        Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
+
+        // 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 10 mech types.
+     */
+    public void testDecodeSpnegoNegTokenInit10MechTypes()
+    {
+        Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x76 );
+        stream.put(
+            new byte[]
+            {
+                (byte)0xa0, 0x74, 		// SPNEGO --> CHOICE {
+                						//     	negTokenInit  [0]  NegTokenInit
+                0x30, 0x72, 			// NegTokenInit ::= SEQUENCE {
+                (byte)0xA0, 0x70,		// 		[0]  MechTypeList  OPTIONAL
+                0x30, 0x6E, 			// MechTypeList ::= SEQUENCE of MechType
+                        				// MechType ::= OBJECT IDENTIFIER
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02, // mechType = 1.2.840.48018.1.2.2
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02, // mechType = 1.2.840.48018.1.2.2
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02, // mechType = 1.2.840.48018.1.2.2
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02, // mechType = 1.2.840.48018.1.2.2
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02, // mechType = 1.2.840.48018.1.2.2
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02, // mechType = 1.2.840.48018.1.2.2
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02, // mechType = 1.2.840.48018.1.2.2
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02, // mechType = 1.2.840.48018.1.2.2
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02, // mechType = 1.2.840.48018.1.2.2
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12, 0x01, 0x02,
0x02 	// mechType = 1.2.840.48018.1.2.2
+            } );
+
+        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(10, nbOids);
+
+        for ( int i = 0 ; i < nbOids ; i++ )
+        {
+            Assert.assertEquals("1.2.840.48018.1.2.2", oids[i].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());
+
+        // Check the mech token
+        Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
+
+        // 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 100 mech types.
+     */
+    public void testDecodeSpnegoNegTokenInit100MechTypes()
+    {
+        Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x45C );
+        stream.put(
+            new byte[]
+            {
+                (byte)0xa0, (byte)0x82, 0x04, 0x58,	// SPNEGO --> CHOICE {
+                									//     	negTokenInit  [0]  NegTokenInit
+                0x30, (byte)0x82, 0x04, 0x54, 		// NegTokenInit ::= SEQUENCE {
+                (byte)0xA0, (byte)0x82, 0x04, 0x50,	// 		[0]  MechTypeList  OPTIONAL
+                0x30, (byte)0x82, 0x04, 0x4C 		// MechTypeList ::= SEQUENCE of MechType
+            });
+        
+        for (int i = 0 ; i < 100 ; i ++ )
+        {
+            stream.put(new byte[]
+                                { // MechType ::= OBJECT IDENTIFIER
+                    				0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xf7, 0x12,
0x01, 0x02, (byte)i, // mechType = 1.2.840.48018.1.2.2
+                                });
+        }
+                        							
+        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(100, nbOids);
+
+        for ( int i = 0 ; i < nbOids ; i++ )
+        {
+            Assert.assertEquals("1.2.840.48018.1.2." + i, oids[i].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());
+
+        // Check the mech token
+        Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
+
+        // 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.
+     */
+    public void testDecodeSpnegoNegTokenInit2MechTypes1MechToken()
     {
         Asn1Decoder spnegoDecoder = new SpnegoDecoder();
 
@@ -115,12 +478,23 @@
         Assert.assertEquals("1.2.840.48018.1.2.2", oids[0].getOID());
         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());
+
         // 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();
     }
-
 }



Mime
View raw message