directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r168448 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
Date Thu, 05 May 2005 22:19:22 GMT
Author: elecharny
Date: Thu May  5 15:19:21 2005
New Revision: 168448

URL: http://svn.apache.org/viewcvs?rev=168448&view=rev
Log:
Added a full SPNEGO NegTokenTarg test.

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=168448&r1=168447&r2=168448&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
Thu May  5 15:19:21 2005
@@ -24,6 +24,7 @@
 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.SpnegoNegTokenTargPOJO;
 import org.apache.asn1.spnego.pojo.SpnegoPOJO;
 import org.apache.asn1.util.pools.PoolException;
 import org.apache.log4j.Logger;
@@ -88,7 +89,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -167,7 +168,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -256,7 +257,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -346,7 +347,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -435,7 +436,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -521,7 +522,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -601,7 +602,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -684,7 +685,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -768,7 +769,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -848,7 +849,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -932,7 +933,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -1033,7 +1034,7 @@
         }
         catch ( PoolException pe )
         {
-            Assert.fail("Cannot allocat a SpnegoContainer : " + pe.getMessage());
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
         }
 
         spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
@@ -1088,6 +1089,104 @@
 
         // 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.
+        spnegoContainer.free();
+    }
+
+    /**
+     * Test the decoding of a full Spnego NegTokenTarg
+     */
+    public void testDecodeSpnegoFullNegTokenTarg()
+    {
+        Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0xE0 );
+        stream.put(
+            new byte[]
+            {
+                (byte)0xA1, (byte)0x81, (byte)0xDD,		 		// SPNEGO --> CHOICE {
+                												//     	negTokenTarg  [1]  NegTokenTarg
+                0x30, (byte)0x81, (byte)0xDA,					// NegTokenTarg ::= SEQUENCE {
+                (byte)0xA0, 0x03,								// 		negResult [0] ENUMERATED { 
+                												//      	accept_completed (0),
+                0x0A, 0x01, 0x01,								// 			accept_incomplete (1),
+                												//			rejected (2) } OPTIONAL,
+                (byte)0xA1, 0x0B, 								// 		supportedMech [1] MechType OPTIONAL, 
+                0x06, 0x09, 0x2a, (byte)0x86, 0x48, (byte)0x82, (byte)0xF7, 0x12, 0x01, 0x02,
0x02, 	// mechType = 1.2.840.48018.1.2.2
+                (byte)0xA2, 0x62,								// 		responseToken [2]  OCTET STRING  OPTIONAL ,
+                0x04, 0x60	 							    	//			responseTokenString (96 bytes)
+            } );
+
+        // Add the responseTokenString
+        for ( int i = 0; i < 0x60; i++ )
+        {
+            stream.put((byte)(i%256));
+        }
+        
+        // Add the mechListMIC
+        // 		mechListMIC [3] OCTET STRING OPTIONAL }
+        stream.put(new byte[]{(byte)0xA3, 0x62, 0x04, 0x60});
+
+        for ( int i = 0; i < 0x60; i++ )
+        {
+            stream.put((byte)(i%256));
+        }
+        
+        stream.flip();
+
+        // Allocate a Spnego Container
+        IAsn1Container spnegoContainer = null;
+
+        try
+        {
+            spnegoContainer = ( IAsn1Container ) spnegoDecoder.allocate(
+                    SpnegoPoolEnum.SPNEGO_CONTAINER_POOL );
+        }
+        catch ( PoolException pe )
+        {
+            Assert.fail("Cannot allocate a SpnegoContainer : " + pe.getMessage());
+        }
+
+        spnegoContainer.setPoolManager( spnegoDecoder.getPoolManager() );
+
+        try
+        {
+            spnegoDecoder.decode( stream, spnegoContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        SpnegoNegTokenTargPOJO spnego = (SpnegoNegTokenTargPOJO)( ( SpnegoContainer ) spnegoContainer
).getSpnego();
+
+        // Checks the result
+        Assert.assertEquals(1, spnego.getNegResult());
+        
+        // Check the supported mech
+        OID supportedMech = spnego.getSupportedMech();
+        Assert.assertEquals("1.2.840.48018.1.2.2", supportedMech.getOID());
+        
+        // Check the responseToken
+        OctetString responseToken = spnego.getResponseToken();
+        byte[] responseTokenBytes = responseToken.getValue();
+        
+        for ( int i = 0; i < 0x60; i++ )
+        {
+            Assert.assertEquals((byte)(i%256), responseTokenBytes[i]);
+        }
+
+        // Check the mechListMIC
+        OctetString mechListMIC = spnego.getMechListMIC();
+        byte[] mechListMICBytes = responseToken.getValue();
+        
+        for ( int i = 0; i < 0x60; i++ )
+        {
+            Assert.assertEquals((byte)(i%256), mechListMICBytes[i]);
+        }
 
         // Free the BindRequest Container. It will be put back in the IPool
         // after being reset.



Mime
View raw message