[jboss-cvs] JBossAS SVN: r76802 - in projects/security/security-negotiation/trunk: jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 7 18:53:43 EDT 2008
Author: darran.lofthouse at jboss.com
Date: 2008-08-07 18:53:43 -0400 (Thu, 07 Aug 2008)
New Revision: 76802
Added:
projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenEncoderTest.java
projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenInitDecoderTest.java
projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenTargEncoderTest.java
Removed:
projects/security/security-negotiation/trunk/X/
Log:
[SECURITY-271] Project refactoring.
Copied: projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenEncoderTest.java (from rev 76801, projects/security/security-negotiation/trunk/X/NegTokenEncoderTest.java)
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenEncoderTest.java (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenEncoderTest.java 2008-08-07 22:53:43 UTC (rev 76802)
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2008 Red Hat Middleware, LLC. or third-party contributors as indicated
+ * by the @author tags or express copyright attribution statements applied by the
+ * authors. All third-party contributions are distributed under license by Red Hat
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy,
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General
+ * Public License, v. 2.1. This program is distributed in the hope that it will be
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details. You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.jboss.security.negotiation.spnego.encoding;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case to test NegTokenEncoder.
+ *
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenEncoderTest extends TestCase
+{
+
+ private static void log(final byte[] name)
+ {
+ String hex = DebugHelper.convertToHex(name);
+ System.out.println(hex);
+ }
+
+ /**
+ * Test the createTypeLength method correctly
+ * creates a lengh of one byte using both extremes
+ * and a value in the middle.
+ */
+ public void testCreateTypeLength_OneBye()
+ {
+ byte[] tl_1 = NegTokenEncoder.createTypeLength((byte) 0x00, 1);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, 0x01}, tl_1));
+ log(tl_1);
+
+ byte[] tl_2 = NegTokenEncoder.createTypeLength((byte) 0x00, 64);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, 0x40}, tl_2));
+ log(tl_2);
+
+ byte[] tl_3 = NegTokenEncoder.createTypeLength((byte) 0x00, 127);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, 0x7F}, tl_3));
+ log(tl_3);
+
+ byte[] tl_4 = NegTokenEncoder.createTypeLength((byte) 0x00, 255);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, (byte) 0x81, (byte) 0xFF}, tl_4));
+ log(tl_4);
+ }
+
+ public void testCreateTypeLength_TwoBytes()
+ {
+ byte[] tl_1 = NegTokenEncoder.createTypeLength((byte) 0x00, 256);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, (byte) 0x82, 0x01, 0x00}, tl_1));
+ log(tl_1);
+
+ byte[] tl_2 = NegTokenEncoder.createTypeLength((byte) 0x00, 32768);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, (byte) 0x82, (byte) 0x80, 0x00}, tl_2));
+ log(tl_2);
+
+ byte[] tl_3 = NegTokenEncoder.createTypeLength((byte) 0x00, 65280);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, (byte) 0x82, (byte) 0xFF, 0x00}, tl_3));
+ log(tl_3);
+
+ byte[] tl_4 = NegTokenEncoder.createTypeLength((byte) 0x00, 65535);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, (byte) 0x82, (byte) 0xFF, (byte) 0xFF}, tl_4));
+ log(tl_4);
+ }
+
+ public void testCreateTypeLength_ThreeBytes()
+ {
+ byte[] tl_1 = NegTokenEncoder.createTypeLength((byte) 0x00, 65536);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, (byte) 0x83, 0x01, 0x00, 0x00}, tl_1));
+ log(tl_1);
+
+ byte[] tl_2 = NegTokenEncoder.createTypeLength((byte) 0x00, 8421375);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, (byte) 0x83, (byte) 0x80, 0x7F, (byte) 0xFF}, tl_2));
+ log(tl_2);
+
+ byte[] tl_3 = NegTokenEncoder.createTypeLength((byte) 0x00, 16777215);
+ assertTrue(Arrays.equals(new byte[]
+ {0x00, (byte) 0x83, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}, tl_3));
+ log(tl_3);
+ }
+}
Copied: projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenInitDecoderTest.java (from rev 76801, projects/security/security-negotiation/trunk/X/NegTokenInitDecoderTest.java)
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenInitDecoderTest.java (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenInitDecoderTest.java 2008-08-07 22:53:43 UTC (rev 76802)
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2008 Red Hat Middleware, LLC. or third-party contributors as indicated
+ * by the @author tags or express copyright attribution statements applied by the
+ * authors. All third-party contributions are distributed under license by Red Hat
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy,
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General
+ * Public License, v. 2.1. This program is distributed in the hope that it will be
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details. You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.jboss.security.negotiation.spnego.encoding;
+
+import java.io.ByteArrayInputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case to test the NegTokenInitDecoder.
+ *
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenInitDecoderTest extends TestCase
+{
+
+ /**
+ * Test that the readLength method can correctly read
+ * and decode the length.
+ *
+ */
+ public void testReadLength() throws Exception
+ {
+ NegTokenInitDecoder decoder = new NegTokenInitDecoder();
+
+ byte[] b1 = new byte[]
+ {0x01};
+ assertEquals(1, NegTokenDecoder.readLength(new ByteArrayInputStream(b1)));
+
+ byte[] b2 = new byte[]
+ {0x40};
+ assertEquals(64, NegTokenDecoder.readLength(new ByteArrayInputStream(b2)));
+
+ byte[] b3 = new byte[]
+ {0x7F};
+ assertEquals(127, NegTokenDecoder.readLength(new ByteArrayInputStream(b3)));
+
+ byte[] b4 = new byte[]
+ {(byte) 0x81, (byte) 0xFF};
+ assertEquals(255, NegTokenDecoder.readLength(new ByteArrayInputStream(b4)));
+
+ byte[] b5 = new byte[]
+ {(byte) 0x82, 0x01, 0x00};
+ assertEquals(256, NegTokenDecoder.readLength(new ByteArrayInputStream(b5)));
+
+ byte[] b6 = new byte[]
+ {(byte) 0x82, (byte) 0x80, 0x00};
+ assertEquals(32768, NegTokenDecoder.readLength(new ByteArrayInputStream(b6)));
+
+ byte[] b7 = new byte[]
+ {(byte) 0x82, (byte) 0xFF, 0x00};
+ assertEquals(65280, NegTokenDecoder.readLength(new ByteArrayInputStream(b7)));
+
+ byte[] b8 = new byte[]
+ {(byte) 0x82, (byte) 0xFF, (byte) 0xFF};
+ assertEquals(65535, NegTokenDecoder.readLength(new ByteArrayInputStream(b8)));
+
+ byte[] b9 = new byte[]
+ {(byte) 0x83, 0x01, 0x00, 0x00};
+ assertEquals(65536, NegTokenDecoder.readLength(new ByteArrayInputStream(b9)));
+
+ byte[] b10 = new byte[]
+ {(byte) 0x83, (byte) 0x80, 0x7F, (byte) 0xFF};
+ assertEquals(8421375, NegTokenDecoder.readLength(new ByteArrayInputStream(b10)));
+
+ byte[] b11 = new byte[]
+ {(byte) 0x83, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
+ assertEquals(16777215, NegTokenDecoder.readLength(new ByteArrayInputStream(b11)));
+
+ }
+}
Copied: projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenTargEncoderTest.java (from rev 76801, projects/security/security-negotiation/trunk/X/NegTokenTargEncoderTest.java)
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenTargEncoderTest.java (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenTargEncoderTest.java 2008-08-07 22:53:43 UTC (rev 76802)
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2008 Red Hat Middleware, LLC. or third-party contributors as indicated
+ * by the @author tags or express copyright attribution statements applied by the
+ * authors. All third-party contributions are distributed under license by Red Hat
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy,
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General
+ * Public License, v. 2.1. This program is distributed in the hope that it will be
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details. You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.jboss.security.negotiation.spnego.encoding;
+
+import java.io.IOException;
+
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.Oid;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for the NegTokenTargEncoder.
+ *
+ * @author <a href="darranlofthouse at hotmail.com">Darran Lofthouse</a>
+ */
+public class NegTokenTargEncoderTest extends TestCase
+{
+
+ /**
+ * Test a NegTokenTarg response can be constructed to request
+ * an alternate supported mechanism.
+ * @throws GSSException
+ * @throws IOException
+ *
+ */
+ public void testSupportedMech() throws GSSException, IOException
+ {
+ NegTokenTarg targ = new NegTokenTarg();
+ targ.setNegResult(NegTokenTarg.ACCEPT_INCOMPLETE);
+ targ.setSupportedMech(new Oid("1.2.840.113554.1.2.2"));
+
+ byte[] response = NegTokenTargEncoder.encode(targ);
+
+ String responseHex = DebugHelper.convertToHex(response);
+ System.out.println(responseHex);
+ }
+}
More information about the jboss-cvs-commits
mailing list