diff options
Diffstat (limited to 'moaSig/common/src/test/java')
10 files changed, 776 insertions, 722 deletions
diff --git a/moaSig/common/src/test/java/console/SchemaValidationTest.java b/moaSig/common/src/test/java/console/SchemaValidationTest.java new file mode 100644 index 0000000..db3041b --- /dev/null +++ b/moaSig/common/src/test/java/console/SchemaValidationTest.java @@ -0,0 +1,52 @@ +package console; + +import java.io.InputStream; + +import org.w3c.dom.Element; + +import at.gv.egovernment.moaspss.util.DOMUtils; + +public class SchemaValidationTest { + + public static final String SCHEMA_ROOT = "/config/zuseSchema"; + + public static final String XML_NS_URI = "http://www.w3.org/XML/1998/namespace"; + public static final String XML_SCHEMA_LOCATION = SCHEMA_ROOT + "xml.xsd"; + + public static final String XSI_NS_URI = "http://www.w3.org/2001/XMLSchema-instance"; + public static final String XSI_SCHEMA_LOCATION = SCHEMA_ROOT + "XMLSchema-instance.xsd"; + + public static final String eDELIVERY20 = "http://reference.e-government.gv.at/namespace/zustellung/msg/phase2/20181206#"; + public static final String eDELIVERY20_SCHEMA_LOCATION = SCHEMA_ROOT + "zuse_p2.xsd"; + + public static final String eDELIVERY_PERSON_20 = "http://reference.e-government.gv.at/namespace/persondata/phase2/20181206#"; + public static final String eDELIVERY_PERSON_20_SCHEMA_LOCATION = SCHEMA_ROOT + "zuse_mypersondata_en_p2.xsd"; + + private static final String ZUSE_SCHEMAS = + (XML_NS_URI + " " + XML_SCHEMA_LOCATION + " ") + + (XSI_NS_URI + " " + XSI_SCHEMA_LOCATION + " ") + + (eDELIVERY20 + " " + eDELIVERY20_SCHEMA_LOCATION + " ") + + (eDELIVERY_PERSON_20 + " " + eDELIVERY_PERSON_20_SCHEMA_LOCATION); + + /** + * Simple test. + * + * @param args not used yet + * @throws Exception in case of an error + */ + public static void main(String[] args) throws Exception { + + InputStream is = SchemaValidationTest.class.getResourceAsStream("/zuse/msg.xml"); + + + Element result = DOMUtils.parseXmlValidating(is); + +// Document result = DOMUtils.parseDocument(is, +// true, ZUSE_SCHEMAS, null, new MOASPSSEntityResolver(), new MOAErrorHandler()); + + + System.out.print(DOMUtils.serializeNode(result)); + + } + +} diff --git a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/AllTests.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/AllTests.java index 569c24c..f64802d 100644 --- a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/AllTests.java +++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/AllTests.java @@ -24,11 +24,11 @@ package test.at.gv.egovernment.moa; -import test.at.gv.egovernment.moa.util.DOMUtilsTest; +//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 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; diff --git a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/MOATestCase.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/MOATestCase.java index 1754ead..2d2e3ee 100644 --- a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/MOATestCase.java +++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/MOATestCase.java @@ -36,6 +36,7 @@ import org.xml.sax.InputSource; import at.gv.egovernment.moaspss.util.Constants; import at.gv.egovernment.moaspss.util.DOMUtils; +import at.gv.egovernment.moaspss.util.URLEncoder; import junit.framework.TestCase; /** @@ -46,7 +47,7 @@ import junit.framework.TestCase; * @author Patrick Peck * @version $Id$ */ -public class MOATestCase extends TestCase { +public class MOATestCase { protected static final String TESTDATA_ROOT = "data/test/"; @@ -55,13 +56,14 @@ public class MOATestCase extends TestCase { * @param arg0 */ public MOATestCase(String name) { - super(name); + super(); } + /** * Parse an XML file non-validating. */ - public static Document parseXml(String fileName) throws Exception { + protected static Document parseXml(String fileName) throws Exception { return DOMUtils.parseDocument( new FileInputStream(fileName), false, @@ -74,7 +76,7 @@ public class MOATestCase extends TestCase { * * Uses the local schema resources. */ - public static Document parseXmlValidating(String fileName) throws Exception { + protected static Document parseXmlValidating(String fileName) throws Exception { return DOMUtils.parseDocument( new FileInputStream(fileName), true, @@ -85,7 +87,7 @@ public class MOATestCase extends TestCase { /** * Parse an XML from a String. */ - public static Document parseXmlString(String xml) throws Exception { + protected static Document parseXmlString(String xml) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; diff --git a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java index e62d896..5093184 100644 --- a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java +++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/DOMUtilsTest.java @@ -1,160 +1,160 @@ -/* - * 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 at.gv.egovernment.moaspss.util.Constants; -import at.gv.egovernment.moaspss.util.DOMUtils; -import test.at.gv.egovernment.moa.*; - -/** - * @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("")); - } - -} +///* +// * 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 at.gv.egovernment.moaspss.util.Constants; +//import at.gv.egovernment.moaspss.util.DOMUtils; +//import test.at.gv.egovernment.moa.*; +// +///** +// * @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/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/KeyStoreUtilsTest.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/KeyStoreUtilsTest.java index 443452c..5501400 100644 --- a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/KeyStoreUtilsTest.java +++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/KeyStoreUtilsTest.java @@ -1,113 +1,113 @@ -/* - * 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.moaspss.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()); - } - -} +///* +// * 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.moaspss.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/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/SSLUtilsTest.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/SSLUtilsTest.java index 8715380..5b5c910 100644 --- a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/SSLUtilsTest.java +++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/SSLUtilsTest.java @@ -1,182 +1,182 @@ -/* - * 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 com.sun.net.ssl.HostnameVerifier; -//import com.sun.net.ssl.HttpsURLConnection; - -import at.gv.egovernment.moaspss.util.KeyStoreUtils; -import at.gv.egovernment.moaspss.util.SSLUtils; - -/** - * @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; +///* +// * 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 com.sun.net.ssl.HostnameVerifier; +////import com.sun.net.ssl.HttpsURLConnection; +// +//import at.gv.egovernment.moaspss.util.KeyStoreUtils; +//import at.gv.egovernment.moaspss.util.SSLUtils; +// +///** +// * @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); // } - //private class HostnameVerifierHack implements HostnameVerifier { - //public boolean verify(String arg0, String arg1) { - // return 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/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/URLDecoderTest.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/URLDecoderTest.java index 7513b51..8a3f788 100644 --- a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/URLDecoderTest.java +++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/URLDecoderTest.java @@ -1,52 +1,52 @@ -/* - * 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.moaspss.util.FileUtils; -import at.gv.egovernment.moaspss.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); - } -} +///* +// * 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.moaspss.util.FileUtils; +//import at.gv.egovernment.moaspss.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/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/URLEncoderTest.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/URLEncoderTest.java index 78c3c7c..f65b7cf 100644 --- a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/URLEncoderTest.java +++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/URLEncoderTest.java @@ -40,23 +40,23 @@ public class URLEncoderTest extends TestCase { 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 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 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"); diff --git a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/XMLGrammarBuilderTest.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/XMLGrammarBuilderTest.java index b471fe6..69e85b7 100644 --- a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/XMLGrammarBuilderTest.java +++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/XMLGrammarBuilderTest.java @@ -1,122 +1,122 @@ -/* - * 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 at.gv.egovernment.moaspss.util.Constants; -import test.at.gv.egovernment.moa.MOATestCase; - - -/** - * 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(); - } - -} +///* +// * 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 at.gv.egovernment.moaspss.util.Constants; +//import test.at.gv.egovernment.moa.MOATestCase; +// +// +///** +// * 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/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/XPathUtilsTest.java b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/XPathUtilsTest.java index f2b216f..a80417f 100644 --- a/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/XPathUtilsTest.java +++ b/moaSig/common/src/test/java/test/at/gv/egovernment/moa/util/XPathUtilsTest.java @@ -1,74 +1,74 @@ -/* - * 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 at.gv.egovernment.moaspss.util.XPathUtils; -import test.at.gv.egovernment.moa.MOATestCase; - - -/** - * @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()); - } - -} +///* +// * 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 at.gv.egovernment.moaspss.util.XPathUtils; +//import test.at.gv.egovernment.moa.MOATestCase; +// +// +///** +// * @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()); +// } +// +//} |