From jboss-remoting-commits at lists.jboss.org Sun Mar 2 01:22:45 2008 Content-Type: multipart/mixed; boundary="===============1780995799125454424==" MIME-Version: 1.0 From: jboss-remoting-commits at lists.jboss.org To: jboss-remoting-commits at lists.jboss.org Subject: [jboss-remoting-commits] JBoss Remoting SVN: r3560 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/marshall/encrypt. Date: Sun, 02 Mar 2008 01:22:43 -0500 Message-ID: --===============1780995799125454424== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2008-03-02 01:22:43 -0500 (Sun, 02 Mar 2008) New Revision: 3560 Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/marshall/encryp= t/EncryptionStandaloneTest.java Log: JBREM-898: Renamed so it won't run in test suite. Copied: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/marshall/e= ncrypt/EncryptionStandaloneTest.java (from rev 3546, remoting2/branches/2.x= /src/tests/org/jboss/test/remoting/marshall/encrypt/EncryptionStandaloneTes= tCase.java) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/marshall/encry= pt/EncryptionStandaloneTest.java (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/marshall/encry= pt/EncryptionStandaloneTest.java 2008-03-02 06:22:43 UTC (rev 3560) @@ -0,0 +1,183 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY 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 along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.test.remoting.marshall.encrypt; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.jboss.remoting.marshal.MarshalFactory; +import org.jboss.remoting.marshal.Marshaller; +import org.jboss.remoting.marshal.UnMarshaller; +import org.jboss.remoting.marshal.encryption.EncryptingMarshaller; +import org.jboss.remoting.marshal.encryption.EncryptingUnMarshaller; +import org.jboss.remoting.marshal.http.HTTPMarshaller; +import org.jboss.remoting.marshal.http.HTTPUnMarshaller; +import org.jboss.remoting.marshal.serializable.SerializableMarshaller; +import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller; + +import junit.framework.TestCase; + +//$Id$ + +/** + * Tests Remoting Encryption facilities + * @author Anil Saldhana + * @since Aug 16, 2006 = + * @version $Revision$ + */ +public class EncryptionStandaloneTest extends TestCase +{ + private Marshaller marshaller; + private UnMarshaller unmarshaller; + = + private String[] standard =3D new String[] + {null, "AES", "DES", "Blowfish", "DESede"}; + = + private String[] padded =3D new String[] + {"AES/CBC/PKCS5Padding", "AES/PCBC/PKCS5Padding","AES/PCBC/PKCS5Pa= dding", + "AES/CFB/PKCS5Padding", "AES/OFB/PKCS5Padding", + "DES/CBC/PKCS5Padding", "DES/PCBC/PKCS5Padding","DES/PCBC/PKCS5Pa= dding", + "DES/CFB/PKCS5Padding", "DES/OFB/PKCS5Padding", + "DESede/CBC/PKCS5Padding", "DESede/PCBC/PKCS5Padding","DESede/PCB= C/PKCS5Padding", + "DESede/CFB/PKCS5Padding", "DESede/OFB/PKCS5Padding"}; + = + private String[] unpadded =3D new String[] + {"AES/CBC/NoPadding", "AES/PCBC/NoPadding","AES/PCBC/NoPadding", + "AES/CFB/NoPadding", "AES/OFB/NoPadding", + "DES/CBC/NoPadding", "DES/PCBC/NoPadding","DES/PCBC/NoPadding", + "DES/CFB/NoPadding", "DES/OFB/NoPadding", + "DESede/CBC/NoPadding", "DESede/PCBC/NoPadding","DESede/PCBC/NoPa= dding", + "DESede/CFB/NoPadding", "DESede/OFB/NoPadding"}; = + + = + public void testSerializable() throws IOException, ClassNotFoundExcepti= on + { = + for(int i =3D 0 ; i < standard.length; i++) + runAlgoTest(standard[i]); + for(int i =3D 0 ; i < padded.length; i++) + runAlgoTest(padded[i]); + for(int i =3D 0 ; i < unpadded.length; i++) + runAlgoTest(unpadded[i]); = + } + + + public void testWrappedSerializable() throws IOException, ClassNotFound= Exception + { = + for(int i =3D 0 ; i < standard.length; i++) + runWrappedSerializableTest(standard[i]); + for(int i =3D 0 ; i < padded.length; i++) + runWrappedSerializableTest(padded[i]); + for(int i =3D 0 ; i < unpadded.length; i++) + runWrappedSerializableTest(unpadded[i]); = + } + + /** + * Commented out usecases not supported + * @throws IOException + * @throws ClassNotFoundException + */ + public void testHTTP() throws IOException, ClassNotFoundException + { = + for(int i =3D 0 ; i < standard.length; i++) + runHttpTest(standard[i]); + for(int i =3D 0 ; i < padded.length; i++) + runHttpTest(padded[i]); + //NoPadding is not correctly supported by HttpUnMarshaller + /*for(int i =3D 0 ; i < unpadded.length; i++) + runHttpTest(unpadded[i]); */ = + } + = + + protected void runOneTest() throws IOException, ClassNotFoundException + { + String testData =3D "This is some test data"; + Object param =3D new String(testData); + + ByteArrayOutputStream output =3D new ByteArrayOutputStream(); + marshaller.write(param, output); + byte[] byteArray =3D new byte[output.size()]; + byteArray =3D output.toByteArray(); + ByteArrayInputStream input =3D new ByteArrayInputStream(byteArray); + Object result =3D unmarshaller.read(input, null); + + System.out.println("Result: " + result); + assertEquals(testData, result); + } + = + private void runAlgoTest(String algo) = + throws IOException, ClassNotFoundException + { + EncryptingMarshaller em =3D new EncryptingMarshaller(); + EncryptingUnMarshaller um =3D new EncryptingUnMarshaller(); + if(algo !=3D null) + { + em.setCipherAlgorithm(algo); + um.setCipherAlgorithm(algo); + } + MarshalFactory.addMarshaller(EncryptingMarshaller.DATATYPE,em, um); = + + marshaller =3D MarshalFactory.getMarshaller(EncryptingMarshaller.DAT= ATYPE); + unmarshaller =3D MarshalFactory.getUnMarshaller(EncryptingMarshaller= .DATATYPE); + runOneTest(); = + } + = + private void runHttpTest(String algo) = + throws IOException, ClassNotFoundException + { + String datatype =3D "encryptedHTTP"; = + Marshaller m =3D MarshalFactory.getMarshaller(HTTPMarshaller.DATATYP= E); + UnMarshaller u =3D MarshalFactory.getUnMarshaller(HTTPUnMarshaller.D= ATATYPE); + EncryptingMarshaller em =3D new EncryptingMarshaller(m); + EncryptingUnMarshaller um =3D new EncryptingUnMarshaller(u); + if(algo !=3D null) + { + em.setCipherAlgorithm(algo); + um.setCipherAlgorithm(algo); + } + MarshalFactory.addMarshaller(datatype,em, um); = + marshaller =3D MarshalFactory.getMarshaller(datatype); + unmarshaller =3D MarshalFactory.getUnMarshaller(datatype); + runOneTest(); + } = + = + private void runWrappedSerializableTest(String algo) = + throws IOException, ClassNotFoundException + { = + String datatype =3D "encryptedSerializable"; + String sd =3D SerializableMarshaller.DATATYPE; + String sud =3D SerializableUnMarshaller.DATATYPE; + EncryptingMarshaller em =3D = + new EncryptingMarshaller(MarshalFactory.getMarshaller(sd)); + EncryptingUnMarshaller um =3D = + new EncryptingUnMarshaller(MarshalFactory.getUnMarshaller(sud)); + if(algo !=3D null) + { + em.setCipherAlgorithm(algo); + um.setCipherAlgorithm(algo); + } + MarshalFactory.addMarshaller(datatype,em, um); = + = + marshaller =3D MarshalFactory.getMarshaller(datatype); + unmarshaller =3D MarshalFactory.getUnMarshaller(datatype); + } = +} --===============1780995799125454424==--