From f4bc3a6fb1c1b9b07b74e2254d6acb71985d8c39 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 21 Oct 2016 10:11:50 +0200 Subject: remove unused code --- .../java/test/at/gv/egovernment/moa/AllTests.java | 62 ------- .../test/at/gv/egovernment/moa/MOATestCase.java | 99 ----------- .../at/gv/egovernment/moa/util/DOMUtilsTest.java | 161 ------------------ .../gv/egovernment/moa/util/DateTimeUtilsTest.java | 129 --------------- .../gv/egovernment/moa/util/KeyStoreUtilsTest.java | 114 ------------- .../at/gv/egovernment/moa/util/SSLUtilsTest.java | 181 --------------------- .../at/gv/egovernment/moa/util/URLDecoderTest.java | 53 ------ .../at/gv/egovernment/moa/util/URLEncoderTest.java | 67 -------- .../moa/util/XMLGrammarBuilderTest.java | 123 -------------- .../at/gv/egovernment/moa/util/XPathUtilsTest.java | 75 --------- 10 files changed, 1064 deletions(-) delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/AllTests.java delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/MOATestCase.java delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/util/KeyStoreUtilsTest.java delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/util/SSLUtilsTest.java delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/util/URLDecoderTest.java delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/util/URLEncoderTest.java delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/util/XMLGrammarBuilderTest.java delete mode 100644 common/src/test/java/test/at/gv/egovernment/moa/util/XPathUtilsTest.java (limited to 'common/src/test') diff --git a/common/src/test/java/test/at/gv/egovernment/moa/AllTests.java b/common/src/test/java/test/at/gv/egovernment/moa/AllTests.java deleted file mode 100644 index ba7a0edc4..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/AllTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa; - -import test.at.gv.egovernment.moa.util.DOMUtilsTest; -import test.at.gv.egovernment.moa.util.DateTimeUtilsTest; -import test.at.gv.egovernment.moa.util.KeyStoreUtilsTest; -import test.at.gv.egovernment.moa.util.SSLUtilsTest; -import test.at.gv.egovernment.moa.util.XPathUtilsTest; - -import junit.awtui.TestRunner; -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @author patrick - * @version $Id$ - */ -public class AllTests { - - public static Test suite() { - TestSuite suite = new TestSuite(); - -// suite.addTestSuite(DOMUtilsTest.class); -// suite.addTestSuite(DateTimeUtilsTest.class); -// suite.addTestSuite(XPathUtilsTest.class); -// suite.addTestSuite(KeyStoreUtilsTest.class); -// suite.addTestSuite(SSLUtilsTest.class); - - return suite; - } - - public static void main(String[] args) { - try { - TestRunner.run(AllTests.class); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/common/src/test/java/test/at/gv/egovernment/moa/MOATestCase.java b/common/src/test/java/test/at/gv/egovernment/moa/MOATestCase.java deleted file mode 100644 index 5d1c5371a..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/MOATestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa; - -import java.io.FileInputStream; -import java.io.StringReader; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.w3c.dom.Document; - -import org.xml.sax.InputSource; - -import junit.framework.TestCase; - -import at.gv.egovernment.moa.util.Constants; -import at.gv.egovernment.moa.util.DOMUtils; - -/** - * Base class for MOA test cases. - * - * Provides some utility functions. - * - * @author Patrick Peck - * @version $Id$ - */ -public class MOATestCase extends TestCase { - - protected static final String TESTDATA_ROOT = "data/test/"; - - /** - * Constructor for MOATestCase. - * @param arg0 - */ - public MOATestCase(String name) { - super(name); - } - - /** - * Parse an XML file non-validating. - */ - public static Document parseXml(String fileName) throws Exception { - return DOMUtils.parseDocument( - new FileInputStream(fileName), - false, - null, - null); - } - - /** - * Parse an XML validating with a given file name. - * - * Uses the local schema resources. - */ - public static Document parseXmlValidating(String fileName) throws Exception { - return DOMUtils.parseDocument( - new FileInputStream(fileName), - true, - Constants.ALL_SCHEMA_LOCATIONS, - null); - } - - /** - * Parse an XML from a String. - */ - public static Document parseXmlString(String xml) throws Exception { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder; - - factory.setNamespaceAware(true); - builder = factory.newDocumentBuilder(); - - return builder.parse(new InputSource(new StringReader(xml))); - } - -} diff --git a/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java b/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java deleted file mode 100644 index 1a2b6904d..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa.util; -import java.io.FileInputStream; -import java.util.Map; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import test.at.gv.egovernment.moa.*; - -import at.gv.egovernment.moa.util.Constants; -import at.gv.egovernment.moa.util.DOMUtils; - -/** - * @author Patrick Peck - * @version $Id$ - */ -public class DOMUtilsTest extends MOATestCase { - private static final String TESTDATA_BASE = TESTDATA_ROOT + "xml/"; - private static boolean grammarsInitialized = false; - - /** - * Constructor for DOMUtilsTest. - * @param name - */ - public DOMUtilsTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - if (!grammarsInitialized) { - // preparse XML schema - DOMUtils.addSchemaToPool( - getClass().getResourceAsStream(Constants.XML_SCHEMA_LOCATION), - Constants.XML_NS_URI); - // preparse XMLDsig Filter2 schema - DOMUtils.addSchemaToPool( - getClass().getResourceAsStream(Constants.DSIG_FILTER2_SCHEMA_LOCATION), - Constants.DSIG_FILTER2_NS_URI); - // preparse XMLDsig schema - DOMUtils.addSchemaToPool( - getClass().getResourceAsStream(Constants.DSIG_SCHEMA_LOCATION), - Constants.DSIG_NS_URI); - // preparse MOA schema - DOMUtils.addSchemaToPool( - getClass().getResourceAsStream(Constants.MOA_SCHEMA_LOCATION), - Constants.MOA_NS_URI); - grammarsInitialized = true; - } - } - - private Document parse(String fileName) throws Exception { - return DOMUtils.parseDocument( - new FileInputStream(fileName), - true, - Constants.ALL_SCHEMA_LOCATIONS, - null); - } - - public void testParseCreateXMLSignature() throws Exception { - parse(TESTDATA_BASE + "CreateXMLSignature/TestGeneratorCX2.005.Req.xml"); - parse(TESTDATA_BASE + "CreateXMLSignature/Req000.xml"); - parse(TESTDATA_BASE + "CreateXMLSignature/Req001.xml"); - parse(TESTDATA_BASE + "CreateXMLSignature/Req002.xml"); - parse(TESTDATA_BASE + "CreateXMLSignature/Req004.xml"); - } - - public void testParseVerifyCMSSignature() throws Exception { - parse(TESTDATA_BASE + "VerifyCMSSignature/Req000.xml"); - } - - public void testParseVerifyXMLSignature() throws Exception { - parse(TESTDATA_BASE + "VerifyXMLSignature/Req000.xml"); - parse(TESTDATA_BASE + "VerifyXMLSignature/Req001.xml"); - parse(TESTDATA_BASE + "VerifyXMLSignature/Req002.xml"); - parse(TESTDATA_BASE + "VerifyXMLSignature/TestGeneratorVX.002.Req.xml"); - //parse(TESTDATA_BASE + "VerifyXMLSignature/TestGeneratorVX.006.Req.xml"); - parse(TESTDATA_BASE + "VerifyXMLSignature/VerifySAMLRequest.xml"); - } - - public void testParseInfobox() throws Exception { - parse(TESTDATA_BASE + "Infobox/InfoboxReadResponseMOA4.xml"); - parse(TESTDATA_BASE + "Infobox/InfoboxReadResponse.xml"); - } - - - private Document parsePlain(String fileName) throws Exception { - return DOMUtils.parseDocument( - new FileInputStream(fileName), - false, - null, - null); - } - - public void testValidateCreateXMLSignature() throws Exception { - Document doc; - boolean valid; - - // test a valid request - doc = parsePlain(TESTDATA_BASE + "CreateXMLSignature/Req000.xml"); - valid = - DOMUtils.validateElement( - doc.getDocumentElement(), - Constants.ALL_SCHEMA_LOCATIONS, - null); - assertTrue(valid); - - // test an invalid request - doc = parsePlain(TESTDATA_BASE + "CreateXMLSignature/invalid.xml"); - try { - valid = - DOMUtils.validateElement( - doc.getDocumentElement(), - Constants.ALL_SCHEMA_LOCATIONS, - null); - fail(); - } catch (Exception e) { - } - } - - public void testGetNamespaceDeclarations() throws Exception { - Document doc; - NodeList nl; - Element elem; - Map nsDecls; - - doc = parse(TESTDATA_BASE + "VerifyXMLSignature/Req002.xml"); - nl = doc.getElementsByTagNameNS(Constants.DSIG_NS_URI, "Reference"); - elem = (Element) nl.item(0); - nsDecls = DOMUtils.getNamespaceDeclarations(elem); - - assertEquals(2, nsDecls.size()); - assertEquals(Constants.DSIG_NS_URI, nsDecls.get("dsig")); - assertEquals(Constants.MOA_NS_URI, nsDecls.get("")); - } - -} diff --git a/common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java b/common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java deleted file mode 100644 index e3468b89f..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa.util; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.TimeZone; - -import junit.framework.TestCase; - -import at.gv.egovernment.moa.util.DateTimeUtils; - -/** - * @author Patrick Peck - * @version $Id$ - */ -public class DateTimeUtilsTest extends TestCase { - - /** - * Constructor for DateTimeUtilsTest. - * @param arg0 - */ - public DateTimeUtilsTest(String arg0) { - super(arg0); - } - - public void testParseDateTimeValid() throws Exception { - Date date; - DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); - - String dateStr; - - format.setTimeZone(TimeZone.getTimeZone("GMT")); - date = DateTimeUtils.parseDateTime("+1971-12-12T06:30:15"); - date.setTime(date.getTime() + TimeZone.getDefault().getRawOffset()); - dateStr = format.format(date); - assertEquals("12.12.1971 06:30:15", dateStr); - - date = DateTimeUtils.parseDateTime("2000-01-01T23:59:59.012Z"); - dateStr = format.format(date); - assertEquals("01.01.2000 23:59:59", dateStr); - - date = DateTimeUtils.parseDateTime("2003-05-20T12:17:30-05:00"); - dateStr = format.format(date); - assertEquals("20.05.2003 17:17:30", dateStr); - - - date = DateTimeUtils.parseDateTime("2002-02-02T02:02:02.33+04:30"); - dateStr = format.format(date); - assertEquals("01.02.2002 21:32:02", dateStr); - } - - public void testParseDateTimeInvalid() { - try { - DateTimeUtils.parseDateTime("+1971-12-12T6:30:15"); - fail(); - } catch (ParseException e) { - } - - try { - DateTimeUtils.parseDateTime("2000-01-0123:59:59.999999Z"); - fail(); - } catch (ParseException e) { - } - - try { - DateTimeUtils.parseDateTime("2003-05-20T12:17:3005:00"); - fail(); - } catch (ParseException e) { - } - - try { - DateTimeUtils.parseDateTime(" 2002-02-02T02:02:02.33+04:00"); - fail(); - } catch (ParseException e) { - } - - } - - public void testBuildDateTimeGMTMinus3() { - String should = "2002-01-01T01:01:01-03:00"; - doTestBuildDateTime(2002, 1, 1, 1, 1, 1, "GMT-03:00", should); - } - public void testBuildDateTimeMEZSommerzeit() { - String should = "2002-07-31T23:59:59+02:00"; - doTestBuildDateTime(2002, 7, 31, 23, 59, 59, "GMT+01:00", should); - } - public void testBuildDateTimeGMT() { - String should = "2002-01-01T01:01:01"; - doTestBuildDateTime(2002, 1, 1, 1, 1, 1, "GMT+00:00", should); - } - private void doTestBuildDateTime( - int year, int month, int day, - int hour, int min, int sec, - String timeZone, String dateTimeShould) { - -// Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(timeZone)); -// cal.set(year,month, day, hour, min, sec); -// cal.set(Calendar.MILLISECOND, 0); -// String dateTimeBuilt = DateTimeUtils.buildDateTime(cal, false); -// assertEquals(dateTimeShould, dateTimeBuilt); - } - -} diff --git a/common/src/test/java/test/at/gv/egovernment/moa/util/KeyStoreUtilsTest.java b/common/src/test/java/test/at/gv/egovernment/moa/util/KeyStoreUtilsTest.java deleted file mode 100644 index 2433eca89..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/util/KeyStoreUtilsTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa.util; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import java.security.KeyStore; -import java.security.Security; -import java.security.cert.X509Certificate; -import java.util.Enumeration; - -import at.gv.egovernment.moa.util.KeyStoreUtils; - -import junit.framework.TestCase; - -/** - * @author Paul Ivancsics - * @version $Id$ - */ -public class KeyStoreUtilsTest extends TestCase { - private String tmpDir = "tmp/KeyStoreUtilsTest"; - private String tmpDirURL = "file:" + tmpDir; - - public KeyStoreUtilsTest(String arg0) { - super(arg0); - } - - protected void setUp() throws Exception { - Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); - new File(tmpDir).mkdirs(); - } - protected void tearDown() throws Exception { - new File(tmpDir).delete(); - } - public void testCreateKeyStoreJKS() throws Exception { - String[] certFilenames = new String[] { - "data/test/security/server-certs/baltimore.cer" - }; - KeyStore ks = KeyStoreUtils.createKeyStore("jks", certFilenames); - assertEquals(1, ks.size()); - X509Certificate cert = (X509Certificate)ks.getCertificate("0"); - assertEquals(3424, cert.getSerialNumber().intValue()); - } - public void testCreateKeyStorePKCS12() throws Exception { - String[] certFilenames = new String[] { - "data/test/security/server-certs/baltimore.cer" - }; - KeyStore ks = KeyStoreUtils.createKeyStore("pkcs12", certFilenames); - assertEquals(1, ks.size()); - X509Certificate cert = (X509Certificate)ks.getCertificate("0"); - assertEquals(3424, cert.getSerialNumber().intValue()); - } - public void testCreateKeyStoreFromCertificateDirectory() throws Exception { - // copy certificate files to a temporary directory, - // omitting the "CVS" directory in the source directory - copyCertificates("data/test/security/server-certs", tmpDir); - KeyStore ks = KeyStoreUtils.createKeyStoreFromCertificateDirectory("jks", tmpDirURL); - assertEquals(2, ks.size()); - X509Certificate cert0 = (X509Certificate)ks.getCertificate("0"); - X509Certificate cert1 = (X509Certificate)ks.getCertificate("1"); - assertTrue(3424 == cert0.getSerialNumber().intValue() || 3424 == cert1.getSerialNumber().intValue()); - } - private void copyCertificates(String from, String to) throws IOException { - String[] fromList = new File(from).list(); - for (int i = 0; i < fromList.length; i++) { - File fromFile = new File(from + File.separator + fromList[i]); - if (fromFile.isFile()) { - String toFile = to + "/" + fromList[i]; - FileInputStream in = new FileInputStream(fromFile); - FileOutputStream out = new FileOutputStream(toFile); - for (int ch = in.read(); ch >= 0; ch = in.read()) - out.write(ch); - out.close(); - in.close(); - } - } - - } - public void testLoadKeyStore() throws Exception { - String keyStoreURL = "file:data/test/security/client-certs/sicher-demo(buergerkarte).p12"; - KeyStore ks = KeyStoreUtils.loadKeyStore("pkcs12", keyStoreURL, "buergerkarte"); - assertEquals(1, ks.size()); - Enumeration aliases = ks.aliases(); - String alias = (String)aliases.nextElement(); - X509Certificate cert = (X509Certificate)ks.getCertificate(alias); - assertEquals(new BigInteger("1044289238331").intValue(), cert.getSerialNumber().intValue()); - } - -} diff --git a/common/src/test/java/test/at/gv/egovernment/moa/util/SSLUtilsTest.java b/common/src/test/java/test/at/gv/egovernment/moa/util/SSLUtilsTest.java deleted file mode 100644 index 2b5094fb8..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/util/SSLUtilsTest.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa.util; - -import java.net.URL; -import java.security.KeyStore; -import java.security.Security; - -import javax.net.ssl.SSLException; -import javax.net.ssl.SSLSocketFactory; - -import junit.framework.TestCase; -import at.gv.egovernment.moa.util.KeyStoreUtils; -import at.gv.egovernment.moa.util.SSLUtils; - -import com.sun.net.ssl.HostnameVerifier; -import com.sun.net.ssl.HttpsURLConnection; - -/** - * @author Paul Ivancsics - * @version $Id$ - */ -public class SSLUtilsTest extends TestCase { - - public SSLUtilsTest(String arg0) { - super(arg0); - } - - - protected void setUp() throws Exception { - //System.setProperty("javax.net.debug", "all"); - Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); - System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); - System.setProperty("https.cipherSuites", "SSL_DHE_DSS_WITH_DES_CBC_SHA,SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA,SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA,SSL_RSA_WITH_DES_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_RSA_EXPORT_WITH_RC4_40_MD5"); - } - - public void testGetSSLSocketFactoryBaltimoreOK() throws Exception { - doTestGetSSLSocketFactory( - "GET", - "https://www.baltimore.com/", - false, - "file:data/test/security/cacerts+gt_cybertrust_root", - "changeit", - true); - } - public void testGetSSLSocketFactoryBaltimoreNOK() throws Exception { - doTestGetSSLSocketFactory( - "GET", - "https://www.baltimore.com/", - false, - "file:data/test/security/cacerts", - "changeit", - false); - } - public void testGetSSLSocketFactoryVerisignOK() throws Exception { - doTestGetSSLSocketFactory( - "GET", - "https://www.verisign.com/", - false, - "file:data/test/security/cacerts", - "changeit", - true); - } - public void testGetSSLSocketFactoryVerisignNoTruststoreOK() throws Exception { - doTestGetSSLSocketFactory( - "GET", - "https://www.verisign.com/", - false, - null, - null, - true); - } - public void testGetSSLSocketFactoryLocalhostOK() throws Exception { - String urlString = "https://localhost:8443/moa-id-auth/index.jsp"; - doTestGetSSLSocketFactory( - "GET", - urlString, - true, - "file:data/test/security/server.keystore.tomcat", - "changeit", - true); - } - public void testGetSSLSocketFactoryLocalhostNOK() throws Exception { - String urlString = "https://localhost:8443/moa-id-auth/index.jsp"; - doTestGetSSLSocketFactory( - "GET", - urlString, - true, - null, - null, - false); - } - - public void doTestGetSSLSocketFactory( - String requestMethod, - String urlString, - boolean useHostnameVerifierHack, - String truststoreurl, - String trustpassword, - boolean shouldOk - ) throws Exception { - - doTestGetSSLSocketFactory( - requestMethod, urlString, useHostnameVerifierHack, truststoreurl, trustpassword, null, null, null, shouldOk); - } - public void doTestGetSSLSocketFactory( - String requestMethod, - String urlString, - boolean useHostnameVerifierHack, - String truststoreurl, - String trustpassword, - String keystoretype, - String keystoreurl, - String keypassword, - boolean shouldOk - ) throws Exception { - - KeyStore truststore = null; - if (truststoreurl != null) - truststore = KeyStoreUtils.loadKeyStore("jks", truststoreurl, trustpassword); - SSLSocketFactory sf = SSLUtils.getSSLSocketFactory( - truststore, keystoretype, keystoreurl, keypassword); - System.out.println(requestMethod + " " + urlString); - - URL url = new URL(urlString); - HttpsURLConnection conn = (HttpsURLConnection)url.openConnection(); - conn.setRequestMethod(requestMethod); - conn.setDoInput(true); - conn.setDoOutput(true); - conn.setUseCaches(false); - conn.setAllowUserInteraction(false); - conn.setSSLSocketFactory(sf); - if (useHostnameVerifierHack) - conn.setHostnameVerifier(new HostnameVerifierHack()); - try { - conn.connect(); - assertTrue(shouldOk); - assertEquals(200, conn.getResponseCode()); - conn.disconnect(); - } - catch (SSLException ex) { - assertFalse(shouldOk); - } - } -// private byte[] readTruststore(String filename) throws IOException { -// if (filename == null) -// return null; -// FileInputStream in = new FileInputStream(filename); -// byte[] buffer = new byte[in.available()]; -// in.read(buffer); -// in.close(); -// return buffer; -// } - private class HostnameVerifierHack implements HostnameVerifier { - public boolean verify(String arg0, String arg1) { - return true; - } - } -} diff --git a/common/src/test/java/test/at/gv/egovernment/moa/util/URLDecoderTest.java b/common/src/test/java/test/at/gv/egovernment/moa/util/URLDecoderTest.java deleted file mode 100644 index 2ded896d0..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/util/URLDecoderTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa.util; - -import java.net.URLEncoder; - -import at.gv.egovernment.moa.util.FileUtils; -import at.gv.egovernment.moa.util.URLDecoder; - -import junit.framework.TestCase; - -/* - * @author Paul Ivancsics - * @version $Id$ - */ -public class URLDecoderTest extends TestCase { - - public void test() throws Exception { - String s = "immerZUA0129<>%==$$%&/()@?{()=} \\\""; - String senc = URLEncoder.encode(s); - String sdec = URLDecoder.decode(senc, "ISO-8859-1"); - assertEquals(s, sdec); - } - public void testUTF8() throws Exception { - String s = new String(FileUtils.readFile("data/test/xml/CreateXMLSignature/CreateXMLSignatureResponse.xml")); - String senc = URLEncoder.encode(s); - String sdec = URLDecoder.decode(senc, "UTF-8"); - String sutf8 = FileUtils.readFile("data/test/xml/CreateXMLSignature/CreateXMLSignatureResponse.xml", "UTF-8"); - assertEquals(sutf8, sdec); - } -} diff --git a/common/src/test/java/test/at/gv/egovernment/moa/util/URLEncoderTest.java b/common/src/test/java/test/at/gv/egovernment/moa/util/URLEncoderTest.java deleted file mode 100644 index 5f72c8aad..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/util/URLEncoderTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa.util; - -import at.gv.egovernment.moa.util.FileUtils; -import at.gv.egovernment.moa.util.URLDecoder; -import at.gv.egovernment.moa.util.URLEncoder; -import junit.framework.TestCase; - -/* - * @author Paul Ivancsics - * @version $Id$ - */ -public class URLEncoderTest extends TestCase { - - public void testUnchangedString() throws Exception { - String s = "AZaz0123456789.-*_"; - String senc = URLEncoder.encode(s, "UTF-8"); - assertEquals(s, senc); - } - public void testAumlUTF8() throws Exception { - String s = "รค"; - String senc = URLEncoder.encode(s, "UTF-8"); - assertEquals("%C3%A4", senc); - } - public void testEncodeDecode() throws Exception { - String s = "AZaz09.-*_ <>%=$%&/()@?{}[]\\\""; - String senc = URLEncoder.encode(s, "UTF-8"); - String sdec = URLDecoder.decode(senc, "UTF-8"); - assertEquals(s, sdec); - } - public void testCertInfo() throws Exception { - String s = new String(FileUtils.readFile("data/test/xml/VerifyXMLSignature/CertInfoVerifyXMLSignatureRequest.xml", "UTF-8")); - String senc = URLEncoder.encode(s, "UTF-8"); - String sdec = URLDecoder.decode(senc, "UTF-8"); - assertEquals(s, sdec); - } - /*public void testJDK14() throws Exception { - String s = new String(FileUtils.readFile("data/test/xml/VerifyXMLSignature/CertInfoVerifyXMLSignatureRequest.xml", "UTF-8")); - String senc = URLEncoder.encode(s, "UTF-8"); - String senc14 = java.net.URLEncoder.encode(s, "UTF-8"); - assertEquals(senc, senc14); - }*/ - -} diff --git a/common/src/test/java/test/at/gv/egovernment/moa/util/XMLGrammarBuilderTest.java b/common/src/test/java/test/at/gv/egovernment/moa/util/XMLGrammarBuilderTest.java deleted file mode 100644 index dfe7a5358..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/util/XMLGrammarBuilderTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa.util; -import java.io.FileInputStream; -import java.io.InputStream; - -import org.apache.xerces.parsers.DOMParser; -import org.apache.xerces.parsers.XMLGrammarPreparser; -import org.apache.xerces.util.SymbolTable; -import org.apache.xerces.util.XMLGrammarPoolImpl; -import org.apache.xerces.xni.grammars.Grammar; -import org.apache.xerces.xni.grammars.XMLGrammarDescription; -import org.apache.xerces.xni.parser.XMLInputSource; -import org.xml.sax.InputSource; - -import test.at.gv.egovernment.moa.MOATestCase; - -import at.gv.egovernment.moa.util.Constants; - - -/** - * Experimentation with Xerces grammar caching. - * - * Used the Xerces sample 'XMLGrammarBuilder' as a starting point. - * - * @author Patrick Peck - * @version $Id$ - */ -public class XMLGrammarBuilderTest extends MOATestCase { - - private static final String GRAMMAR_POOL = - org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX - + org.apache.xerces.impl.Constants.XMLGRAMMAR_POOL_PROPERTY; - - protected static final String NAMESPACES_FEATURE_ID = - "http://xml.org/sax/features/namespaces"; - protected static final String VALIDATION_FEATURE_ID = - "http://xml.org/sax/features/validation"; - protected static final String SCHEMA_VALIDATION_FEATURE_ID = - "http://apache.org/xml/features/validation/schema"; - protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID = - "http://apache.org/xml/features/validation/schema-full-checking"; - - private static final int BIG_PRIME = 2039; - private SymbolTable symbolTable; - private XMLGrammarPoolImpl grammarPool; - - /** - * Constructor for XMLGrammarBuilderTest. - * @param name - */ - public XMLGrammarBuilderTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - XMLGrammarPreparser preparser; - - // set up symbol table and grammar pool - symbolTable = new SymbolTable(BIG_PRIME); - grammarPool = new XMLGrammarPoolImpl(); - preparser = new XMLGrammarPreparser(symbolTable); - preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null); - preparser.setProperty(GRAMMAR_POOL, grammarPool); - preparser.setFeature(NAMESPACES_FEATURE_ID, true); - preparser.setFeature(VALIDATION_FEATURE_ID, true); - // now we can still do schema features just in case, - // so long as it's our configuraiton...... - preparser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true); - preparseSchemaResource( - preparser, - Constants.DSIG_SCHEMA_LOCATION, - "/resources/schemas/xmldsig-core-schema.xsd"); - } - - private static Grammar preparseSchemaResource( - XMLGrammarPreparser preparser, - String systemId, - String resource) - throws Exception { - - InputStream is = XMLGrammarBuilderTest.class.getResourceAsStream(resource); - return preparser.preparseGrammar( - XMLGrammarDescription.XML_SCHEMA, - new XMLInputSource(null, systemId, null, is, null)); - } - - public void testParseValidating() throws Exception { - DOMParser parser = new DOMParser(symbolTable, grammarPool); - - parser.setFeature(NAMESPACES_FEATURE_ID, true); - parser.setFeature(VALIDATION_FEATURE_ID, true); - parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true); - - parser.parse( - new InputSource( - new FileInputStream(TESTDATA_ROOT + "xml/dsigTransform/base64.xml"))); - parser.getDocument(); - } - -} diff --git a/common/src/test/java/test/at/gv/egovernment/moa/util/XPathUtilsTest.java b/common/src/test/java/test/at/gv/egovernment/moa/util/XPathUtilsTest.java deleted file mode 100644 index 15e6a62f3..000000000 --- a/common/src/test/java/test/at/gv/egovernment/moa/util/XPathUtilsTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2003 Federal Chancellery Austria - * MOA-ID has been developed in a cooperation between BRZ, the Federal - * Chancellery Austria - ICT staff unit, and Graz University of Technology. - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://www.osor.eu/eupl/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - * - * This product combines work with different licenses. See the "NOTICE" text - * file for details on the various modules and licenses. - * The "NOTICE" text file is part of the distribution. Any derivative works - * that you distribute must include a readable copy of the "NOTICE" text file. - */ - - -package test.at.gv.egovernment.moa.util; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; - -import test.at.gv.egovernment.moa.MOATestCase; - -import at.gv.egovernment.moa.util.XPathUtils; - - -/** - * @author Patrick Peck - * @version $Id$ - */ -public class XPathUtilsTest extends MOATestCase { - - private Document doc1; - - /** - * Constructor for XPathUtilsTest. - * @param name - */ - public XPathUtilsTest(String name) { - super(name); - } - - /** - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - doc1 = - parseXml(TESTDATA_ROOT + "xml/VerifyXMLSignature/Req000.xml"); - } - - public void testSelectNodeList() throws Exception { - NodeList nodes; - - nodes = - XPathUtils.selectNodeList( - doc1.getDocumentElement(), - doc1.getDocumentElement(), - "/VerifyXMLSignatureRequest"); - assertEquals(1, nodes.getLength()); - nodes = - XPathUtils.selectNodeList( - doc1.getDocumentElement(), - "//dsig:Signature"); - assertEquals(1, nodes.getLength()); - } - -} -- cgit v1.2.3