directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r168197 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
Date Wed, 04 May 2005 21:19:34 GMT
Author: elecharny
Date: Wed May  4 14:19:34 2005
New Revision: 168197

URL: http://svn.apache.org/viewcvs?rev=168197&view=rev
Log:
- Fixed a little bug in one of the test, where the reqFlags value was incorrect.
- Added two tests, one for the mechListMIC, and a full NegTokenInit decoding.

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=168197&r1=168196&r2=168197&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
Wed May  4 14:19:34 2005
@@ -414,7 +414,7 @@
                 									//     	negTokenInit  [0]  NegTokenInit
                 0x30, 0x06, 						// NegTokenInit ::= SEQUENCE {
                 (byte)0xA1, 0x04, 					// ContextFlags  OPTIONAL,
-                0x03, 0x02, 0x01, (byte)0xF7		// ContextFlags ::= BIT_STRING {
+                0x03, 0x02, 0x01, (byte)0xFE		// ContextFlags ::= BIT_STRING {
 													// delegFlag     (0),
 													// mutualFlag    (1),
 													// replayFlag    (2),
@@ -740,6 +740,164 @@
     }
 
     /**
+     * Test the decoding of a Spnego NegTokenInit with an empty mech list MIC .
+     */
+    public void testDecodeSpnegoNegTokenInitEmptyMechListMIC()
+    {
+        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)0xA3, 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
+        Assert.assertEquals(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
+        
+        // Check the mech list MIC
+        OctetString mechListMIC = ((SpnegoNegTokenInitPOJO)spnego).getMechListMIC();
+
+        Assert.assertEquals(OctetString.EMPTY_STRING, mechListMIC);
+        Assert.assertEquals( "" , mechListMIC.toString() );
+
+        // 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 listMIC.
+     */
+    public void testDecodeSpnegoNegTokenInitMechListMIC()
+    {
+        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)0xA3, 0x06,		// mechListMIC     [3]  OCTET STRING  OPTIONAL ,
+                0x04, 0x04, 'a', 'b', 'c', 'd' 	// mechListMIC = '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(null, ((SpnegoNegTokenInitPOJO)spnego).getMechToken());
+
+        // Check the mech list MIC
+        Assert.assertEquals("[61][62][63][64]", ((SpnegoNegTokenInitPOJO)spnego).getMechListMIC().toString());
+
+
+        // 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.
      */
@@ -818,6 +976,119 @@
 
         // 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 full Spnego NegTokenInit
+     */
+    public void testDecodeSpnegoFullNegTokenInit()
+    {
+        Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x5F2 );
+        stream.put(
+            new byte[]
+            {
+                (byte)0xA0, (byte)0x82, 0x05, (byte)0xEE, 		// SPNEGO --> CHOICE {
+                												//     	negTokenInit  [0]  NegTokenInit
+                0x30, (byte)0x82, 0x05, (byte)0xEA,				// NegTokenInit ::= SEQUENCE {
+                (byte)0xA0, 0x18,								// 		[0]  MechTypeList  OPTIONAL
+                0x30, 0x16, 									// 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)0x86, (byte)0xF7, 0x12, 0x01, 0x02,
0x02, 	// mechType = 1.2.840.113554.1.2.2
+                (byte)0xA1, 0x04, 								// ContextFlags  OPTIONAL,
+                0x03, 0x02, 0x01, (byte)0x6A,					// ContextFlags ::= BIT_STRING {
+																// delegFlag     (0), (false)
+																// mutualFlag    (1), (true)
+																// replayFlag    (2), (true)
+																// sequenceFlag  (3), (false)
+																// anonFlag      (4), (true)
+																// confFlag      (5), (false)
+																// integFlag     (6)  (true)  }
+                (byte)0xA2, (byte)0x82, 0x05, (byte)0xB6,		// mechToken     [2]  OCTET STRING
 OPTIONAL ,
+                0x04, (byte)0x82, 0x05, (byte)0xB2
+            } );
+
+        // Add the mechToekn
+        for ( int i = 0; i < 0x5B2; i++ )
+        {
+            stream.put((byte)(i%256));
+        }
+        
+        // Add the mechListMIC
+        stream.put(new byte[]{(byte)0xA3, 0x0E, 0x04, 0x0C, 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l'});
+        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(2, nbOids);
+        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(true,  ((SpnegoNegTokenInitPOJO)spnego).isConfFlag());
+        Assert.assertEquals(true,  ((SpnegoNegTokenInitPOJO)spnego).isDelegFlag());
+        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isIntegFlag());
+        Assert.assertEquals(true,  ((SpnegoNegTokenInitPOJO)spnego).isMutualFlag());
+        Assert.assertEquals(false, ((SpnegoNegTokenInitPOJO)spnego).isReplayFlag());
+        Assert.assertEquals(true,  ((SpnegoNegTokenInitPOJO)spnego).isSequenceFlag());
+
+        // Check the mech token
+        OctetString mechToken = ((SpnegoNegTokenInitPOJO)spnego).getMechToken();
+        byte[] mechTochenBytes = mechToken.getValue();
+        
+        for ( int i = 0; i < 0x5B2; i++ )
+        {
+            Assert.assertEquals((byte)(i%256), mechTochenBytes[i]);
+        }
+
+        // Check the mechListMIC
+        Assert.assertEquals("[61][62][63][64][65][66][67][68][69][6A][6B][6C]", ((SpnegoNegTokenInitPOJO)spnego).getMechListMIC().toString());
 
         // Free the BindRequest Container. It will be put back in the IPool
         // after being reset.



Mime
View raw message