Author: elecharny
Date: Mon Apr 25 15:31:51 2005
New Revision: 164675
URL: http://svn.apache.org/viewcvs?rev=164675&view=rev
Log:
Added a first draft of a junit test for SPNEGO
Added:
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
Added:
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=164675&view=auto
==============================================================================
---
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
(added)
+++
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/spnego/codec/SpnegoTest.java
Mon Apr 25 15:31:51 2005
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1.spnego.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.codec.BindRequestTest;
+import org.apache.asn1.spnego.pojo.SpnegoPOJO;
+import org.apache.asn1.util.pools.PoolException;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:[email protected]">Apache Directory
Project</a>
+ */
+public class SpnegoTest extends TestCase {
+ /** Logger */
+ protected static Logger log = Logger.getLogger( BindRequestTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a BindRequest with Simple authentication
+ * and no controls
+ */
+ public void testDecodeBindRequestSimpleNoControls()
+ {
+ Asn1Decoder spnegoDecoder = new SpnegoDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x35 );
+ stream.put(
+ new byte[]
+ {
+ (byte)0xa0, 0x24, // SPNEGO --> CHOICE {
+ //
negTokenInit [0] NegTokenInit
+ 0x30, 0x22, // 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)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();
+
+
+ // Free the BindRequest Container. It will be put back in the IPool
+ // after being reset.
+ spnegoContainer.free();
+ }
+
+}