From 4e12d1df5daab1f7600fa3a58e6fc535375224ff Mon Sep 17 00:00:00 2001 From: pdanner Date: Mon, 10 Sep 2007 15:16:34 +0000 Subject: moved test classes, cashing of resolved entities git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@1002 d688527b-c9ab-4aba-bd8d-4036d912da1d --- spss/server/history.txt | 8 +- spss/server/pom.xml | 4 +- spss/server/serverlib/pom.xml | 4 +- .../moa/spss/server/invoke/DataObjectFactory.java | 119 +++++-- .../spss/server/invoke/ExternalURIResolver.java | 15 - .../invoke/XMLSignatureVerificationInvoker.java | 6 +- .../moa/spss/server/service/AxisHandler.java | 43 ++- .../server/service/SignatureCreationService.java | 13 +- .../server/transaction/TransactionContext.java | 131 +++++-- .../test/at/gv/egovernment/moa/spss/AllTests.java | 40 --- .../at/gv/egovernment/moa/spss/SPSSTestCase.java | 82 ----- .../egovernment/moa/spss/api/xmlbind/AllTests.java | 24 -- .../CreateXMLSignatureRequestParserTest.java | 71 ---- .../moa/spss/api/xmlbind/TransformParserTest.java | 113 ------ .../VerifyCMSSignatureRequestParserTest.java | 61 ---- .../VerifyXMLSignatureRequestParserTest.java | 81 ----- .../moa/spss/server/config/AllTests.java | 20 -- .../server/config/ConfigurationProviderTest1.java | 377 --------------------- .../server/config/ConfigurationProviderTest2.java | 225 ------------ .../server/config/ConfigurationProviderTest3.java | 166 --------- .../iaik/config/ConfigurationDataImplTest.java | 149 -------- .../server/iaik/config/IaikConfiguratorTest.java | 36 -- .../moa/spss/server/invoke/AllTests.java | 25 -- .../CMSSignatureVerificationInvokerTest.java | 63 ---- .../spss/server/invoke/DataObjectFactoryTest.java | 180 ---------- .../server/invoke/TransformationFactoryTest.java | 201 ----------- .../invoke/XMLSignatureCreationInvokerTest.java | 63 ---- .../XMLSignatureVerificationInvokerTest.java | 61 ---- .../moa/spss/server/tools/CertToolTest.java | 50 --- .../java/at/gv/egovernment/moa/spss/AllTests.java | 40 +++ .../at/gv/egovernment/moa/spss/SPSSTestCase.java | 82 +++++ .../egovernment/moa/spss/api/xmlbind/AllTests.java | 24 ++ .../CreateXMLSignatureRequestParserTest.java | 71 ++++ .../moa/spss/api/xmlbind/TransformParserTest.java | 113 ++++++ .../VerifyCMSSignatureRequestParserTest.java | 61 ++++ .../VerifyXMLSignatureRequestParserTest.java | 81 +++++ .../moa/spss/server/config/AllTests.java | 20 ++ .../server/config/ConfigurationProviderTest1.java | 377 +++++++++++++++++++++ .../server/config/ConfigurationProviderTest2.java | 225 ++++++++++++ .../server/config/ConfigurationProviderTest3.java | 166 +++++++++ .../iaik/config/ConfigurationDataImplTest.java | 149 ++++++++ .../server/iaik/config/IaikConfiguratorTest.java | 36 ++ .../moa/spss/server/invoke/AllTests.java | 25 ++ .../CMSSignatureVerificationInvokerTest.java | 63 ++++ .../spss/server/invoke/DataObjectFactoryTest.java | 180 ++++++++++ .../server/invoke/TransformationFactoryTest.java | 201 +++++++++++ .../invoke/XMLSignatureCreationInvokerTest.java | 63 ++++ .../XMLSignatureVerificationInvokerTest.java | 61 ++++ .../moa/spss/server/tools/CertToolTest.java | 50 +++ spss/server/serverws/pom.xml | 6 +- spss/server/tools/pom.xml | 6 +- 51 files changed, 2348 insertions(+), 2183 deletions(-) delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/AllTests.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/SPSSTestCase.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/AllTests.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/CreateXMLSignatureRequestParserTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/TransformParserTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/VerifyCMSSignatureRequestParserTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/VerifyXMLSignatureRequestParserTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/AllTests.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest1.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest2.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest3.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/iaik/config/ConfigurationDataImplTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/iaik/config/IaikConfiguratorTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/AllTests.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/CMSSignatureVerificationInvokerTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactoryTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/TransformationFactoryTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvokerTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvokerTest.java delete mode 100644 spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/tools/CertToolTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/AllTests.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/SPSSTestCase.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/AllTests.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateXMLSignatureRequestParserTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/TransformParserTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/VerifyCMSSignatureRequestParserTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/VerifyXMLSignatureRequestParserTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/AllTests.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest1.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest2.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest3.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/iaik/config/ConfigurationDataImplTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/iaik/config/IaikConfiguratorTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/AllTests.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/CMSSignatureVerificationInvokerTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactoryTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/TransformationFactoryTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvokerTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvokerTest.java create mode 100644 spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/tools/CertToolTest.java (limited to 'spss/server') diff --git a/spss/server/history.txt b/spss/server/history.txt index d21fef433..3cbb39f06 100644 --- a/spss/server/history.txt +++ b/spss/server/history.txt @@ -1,9 +1,15 @@ +############## +1.4.2 +############## + +- Performance-Verbesserungen bei der Verwendnung von externen Referenzen. + ############## 1.4.1 ############## - Die Projektstruktur wurde eimem Maven Build-Prozess unterlegt. Der Sourcocde - ab dieser Version unter http://egovlabs.gv.at/scm/?group_id=6 verfügbar. + ab dieser Version unter http://egovlabs.gv.at/scm/?group_id=6 verfügbar. ############## 1.4.0 diff --git a/spss/server/pom.xml b/spss/server/pom.xml index aa5db1624..82e8a8c2f 100644 --- a/spss/server/pom.xml +++ b/spss/server/pom.xml @@ -3,14 +3,14 @@ MOA spss - 1.4.1 + 1.4.x 4.0.0 MOA.spss moa-spss pom - 1.4.1 + 1.4.x MOA SP/SS Server diff --git a/spss/server/serverlib/pom.xml b/spss/server/serverlib/pom.xml index 49bc37ceb..c49a234a1 100644 --- a/spss/server/serverlib/pom.xml +++ b/spss/server/serverlib/pom.xml @@ -3,14 +3,14 @@ MOA.spss moa-spss - 1.4.1 + 1.4.x 4.0.0 MOA.spss.server moa-spss-lib jar - 1.4.1 + 1.4.2 MOA SP/SS API diff --git a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java index 1386d5c2d..ad0da28f4 100644 --- a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java +++ b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java @@ -1,5 +1,10 @@ package at.gv.egovernment.moa.spss.server.invoke; +import iaik.ixsil.util.URI; +import iaik.ixsil.util.XPointerReferenceResolver; +import iaik.server.modules.xml.DataObject; +import iaik.server.modules.xml.XMLDataObject; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -7,6 +12,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Vector; import javax.xml.parsers.ParserConfigurationException; @@ -14,25 +20,11 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; - import org.xml.sax.EntityResolver; import org.xml.sax.SAXException; -import iaik.ixsil.util.URI; -import iaik.ixsil.util.XPointerReferenceResolver; -import iaik.server.modules.xml.DataObject; -import iaik.server.modules.xml.XMLDataObject; - import at.gv.egovernment.moa.logging.LogMsg; import at.gv.egovernment.moa.logging.Logger; -import at.gv.egovernment.moa.util.Constants; -import at.gv.egovernment.moa.util.DOMUtils; -import at.gv.egovernment.moa.util.EntityResolverChain; -import at.gv.egovernment.moa.util.MOAEntityResolver; -import at.gv.egovernment.moa.util.MOAErrorHandler; -import at.gv.egovernment.moa.util.StreamEntityResolver; -import at.gv.egovernment.moa.util.StreamUtils; - import at.gv.egovernment.moa.spss.MOAApplicationException; import at.gv.egovernment.moa.spss.MOASystemException; import at.gv.egovernment.moa.spss.api.common.Content; @@ -48,7 +40,16 @@ import at.gv.egovernment.moa.spss.server.iaik.xml.ByteStreamDataObjectImpl; import at.gv.egovernment.moa.spss.server.iaik.xml.DataObjectImpl; import at.gv.egovernment.moa.spss.server.iaik.xml.XMLDataObjectImpl; import at.gv.egovernment.moa.spss.server.iaik.xml.XMLNodeListDataObjectImpl; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; import at.gv.egovernment.moa.spss.util.MessageProvider; +import at.gv.egovernment.moa.util.Constants; +import at.gv.egovernment.moa.util.DOMUtils; +import at.gv.egovernment.moa.util.EntityResolverChain; +import at.gv.egovernment.moa.util.MOAEntityResolver; +import at.gv.egovernment.moa.util.MOAErrorHandler; +import at.gv.egovernment.moa.util.StreamEntityResolver; +import at.gv.egovernment.moa.util.StreamUtils; /** * A class to create DataObjects contained in different @@ -132,12 +133,16 @@ public class DataObjectFactory { } case Content.LOCREF_CONTENT: { - ExternalURIResolver uriResolver = new ExternalURIResolver(); String locRefURI = ((ContentLocRef) content).getLocationReferenceURI(); InputStream is = null; try { - is = uriResolver.resolve(locRefURI); + TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); + is = context.ResolveURI(locRefURI); + if (is == null) { + ExternalURIResolver uriResolver = new ExternalURIResolver(); + is = uriResolver.resolve(locRefURI); + } contentBytes = StreamUtils.readStream(is); } catch (MOAApplicationException e) @@ -299,25 +304,39 @@ public class DataObjectFactory { } case Content.LOCREF_CONTENT: { - ExternalURIResolver uriResolver = new ExternalURIResolver(); - String locRefURI = ((ContentLocRef) content).getLocationReferenceURI(); InputStream contentIS = null; - InputStream uriStream = null; - try - { - uriStream = uriResolver.resolve(locRefURI); - byte[] contentBytes = StreamUtils.readStream(uriStream); - contentIS = new ByteArrayInputStream(contentBytes); - } - catch (Exception e) - { - throw new MOAApplicationException("3202", new Object[]{reference, locRefURI}, e); - } - finally - { - closeInputStream(uriStream); - } - entities.put(reference, contentIS); + String locRefURI = ((ContentLocRef) content).getLocationReferenceURI(); + + + TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); + Vector entity = context.FindResolvedEntity(locRefURI); + if (entity!=null) { + contentIS = (InputStream) entity.get(0); + } else { + + ExternalURIResolver uriResolver = new ExternalURIResolver(); + + InputStream uriStream = null; + byte[] contentBytes; + String contentType = null; + try + { + uriStream = uriResolver.resolve(locRefURI); + contentBytes = StreamUtils.readStream(uriStream); + contentIS = new ByteArrayInputStream(contentBytes); + contentType = uriResolver.getContentType(); + } + catch (Exception e) + { + throw new MOAApplicationException("3202", new Object[]{reference, locRefURI}, e); + } + finally + { + closeInputStream(uriStream); + } + entities.put(locRefURI, contentIS); + context.PutResolvedEntity(locRefURI, contentBytes, contentType); + } break; } case Content.XML_CONTENT : @@ -648,9 +667,23 @@ public class DataObjectFactory { private DataObjectImpl createFromURIImpl(String uri, boolean asXml) throws MOASystemException, MOAApplicationException { + Logger.trace(">>> resolving uri \"" + uri + "\""); + ExternalURIResolver resolver = new ExternalURIResolver(); - InputStream is = resolver.resolve(uri); - String contentType = resolver.getContentType(); + + TransactionContext context = TransactionContextManager.getInstance().getTransactionContext(); + InputStream is = context.ResolveURI(uri); + String contentType = null; + boolean foundURI = false; + if (is == null) { + is = resolver.resolve(uri); + contentType = resolver.getContentType(); + } else { + foundURI = true; + contentType = (String) context.FindResolvedEntity(uri).get(1); + Logger.trace("found \"" + uri + "\" InputStream in preread Supplements!, do not read any more. Content=" + contentType); + } + DataObjectImpl dataObject; // read the content @@ -684,6 +717,7 @@ public class DataObjectFactory { dataObject = new XMLDataObjectImpl(doc.getDocumentElement()); } catch (Exception e) { // this is the last chance: return the data as a byte stream + Logger.trace(">>> reading stream for \"" + uri + "\""); is = resolver.resolve(uri); ByteArrayInputStream bis; try @@ -699,9 +733,11 @@ public class DataObjectFactory { { closeInputStream(is); } + Logger.trace(">>> read stream for \"" + uri + "\""); } } } + else if (asXml) { // if we need XML data, we're in the wrong place here @@ -711,10 +747,13 @@ public class DataObjectFactory { else { // content is binary: make it available as a binary input stream + Logger.trace(">>> getting binary input for \"" + uri + "\""); + byte[] contentBytes; ByteArrayInputStream bis; try { - bis = new ByteArrayInputStream(StreamUtils.readStream(is)); + contentBytes = StreamUtils.readStream(is); + bis = new ByteArrayInputStream(contentBytes); } catch (IOException e) { @@ -724,12 +763,18 @@ public class DataObjectFactory { { closeInputStream(is); } + if (!foundURI) { + context.PutResolvedEntity(uri, contentBytes, contentType); + } dataObject = new ByteStreamDataObjectImpl(bis); + Logger.trace("<<< got binary input for \"" + uri + "\""); } dataObject.setMimeType(contentType); dataObject.setURI(uri); + Logger.trace("<<< resolved uri \"" + uri + "\""); + return dataObject; } diff --git a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/ExternalURIResolver.java b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/ExternalURIResolver.java index 106742067..cbd88f7f3 100644 --- a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/ExternalURIResolver.java +++ b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/ExternalURIResolver.java @@ -61,7 +61,6 @@ public class ExternalURIResolver { //no transaction throw new MOAApplicationException("2282", new Object[] { uri }); } else { - InputStream attachmentIs = context.getAttachmentInputStream(uri); if (attachmentIs != null) { setContentType(context.getAttachmentContentType(uri.getPath())); @@ -70,20 +69,6 @@ public class ExternalURIResolver { //maybe attachments provided but no suiting attachment found throw new MOAApplicationException("2282", new Object[] { uri }); } -/* - try { - InputStream attachmentIs = context.getAttachment(uri).getInputStream(); - if (attachmentIs != null) { - setContentType(context.getAttachmentContentType(uri.getPath())); - return attachmentIs; - } else { - //maybe attachments provided but no suiting attachment found - throw new MOAApplicationException("2282", new Object[] { uri }); - } - } catch (IOException e) { - throw new MOAApplicationException("2208", new Object[] { uri }, e); - } -*/ } } diff --git a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvoker.java b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvoker.java index 4642593eb..3dd7ecf11 100644 --- a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvoker.java +++ b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvoker.java @@ -89,10 +89,8 @@ public class XMLSignatureVerificationInvoker { FILTERED_REF_TYPES = new HashSet(); FILTERED_REF_TYPES.add(DsigManifest.XML_DSIG_MANIFEST_TYPE); FILTERED_REF_TYPES.add(SecurityLayerManifest.SECURITY_LAYER_MANIFEST_TYPE); - FILTERED_REF_TYPES.add( - SecurityLayerManifest.SECURITY_LAYER_MANIFEST_TYPE_OLD); - FILTERED_REF_TYPES.add( - XMLConstants.NAMESPACE_ETSI_STRING + "SignedProperties"); + FILTERED_REF_TYPES.add(SecurityLayerManifest.SECURITY_LAYER_MANIFEST_TYPE_OLD); + FILTERED_REF_TYPES.add(XMLConstants.NAMESPACE_ETSI_STRING + "SignedProperties"); } /** diff --git a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/service/AxisHandler.java b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/service/AxisHandler.java index befbd58dd..f5f77ff50 100644 --- a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/service/AxisHandler.java +++ b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/service/AxisHandler.java @@ -27,6 +27,7 @@ import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.logging.LoggingContext; import at.gv.egovernment.moa.logging.LoggingContextManager; import at.gv.egovernment.moa.spss.MOASystemException; +import at.gv.egovernment.moa.spss.api.common.Content; import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; @@ -94,6 +95,7 @@ public class AxisHandler extends BasicHandler { */ private void handleRequest(MessageContext msgContext) throws AxisFault { try { + Logger.trace("---- Entering Axishandler"); // generate a unique transaction id and build the TransactionContext // for this request HttpServletRequest request = @@ -143,7 +145,9 @@ public class AxisHandler extends BasicHandler { } context.setRequestName(soapAction); + Logger.trace(">>> Get AttachmentCount"); int attachmentCount = soapMessage.getAttachmentsImpl().getAttachmentCount(); + Logger.trace("<<< Finished Get AttachmentCount"); if (attachmentCount>0) { // add SOAP attachments to transaction context @@ -156,12 +160,23 @@ public class AxisHandler extends BasicHandler { //Now get the InputStream (note: we could also get the content with Object content = attachment.getContent();) InputStream is = null; javax.activation.DataHandler datahandler = attachment.getDataHandler(); - org.apache.axis.attachments.ManagedMemoryDataSource mmds = (org.apache.axis.attachments.ManagedMemoryDataSource)datahandler.getDataSource(); - if (mmds!=null){ - is = mmds.getInputStream(); + + int TYPE = 2; + switch (TYPE) { + case 1: + { + org.apache.axis.attachments.ManagedMemoryDataSource mmds = (org.apache.axis.attachments.ManagedMemoryDataSource)datahandler.getDataSource(); + context.addAttachment(id, type, mmds); + break; + } + case 2: + { + is = datahandler.getDataSource().getInputStream(); + context.addAttachment(id, type, is, datahandler.getDataSource().getName()); + break; + } } debug("handler.06", new Object[] {id, type}); - context.addAttachment(id, type, mmds); } } @@ -202,6 +217,7 @@ public class AxisHandler extends BasicHandler { fault.setFaultDetail(new Element[] { e.toErrorResponse()}); throw fault; } + Logger.trace("---- Leaving Axishandler"); } /** @@ -379,4 +395,21 @@ public class AxisHandler extends BasicHandler { Logger.debug(new LogMsg(msg.getMessage(messageId, parameters))); } -} + + +// private byte[] toByteArray(AttachmentPart attachment) throws SOAPException, IOException +// { +// ByteArrayOutputStream outputStream = new ByteArrayOutputStream(attachment.getSize()); +// InputStream inputStream = (InputStream) attachment.getContent(); +// int currentByte = -1; +// while ((currentByte = inputStream.read()) != -1) +// outputStream.write(currentByte); +// +// inputStream.close(); +// outputStream.close(); +// +// return outputStream.toByteArray(); +// +//} + +} \ No newline at end of file diff --git a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/service/SignatureCreationService.java b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/service/SignatureCreationService.java index 2d548ea3a..c173625f8 100644 --- a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/service/SignatureCreationService.java +++ b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/service/SignatureCreationService.java @@ -40,6 +40,7 @@ public class SignatureCreationService { */ public Element[] CreateXMLSignatureRequest(Element[] request) throws AxisFault { + Logger.trace("---- Entering SignatureCreationService"); XMLSignatureCreationInvoker invoker = XMLSignatureCreationInvoker.getInstance(); Element[] response = new Element[1]; @@ -72,17 +73,23 @@ public class SignatureCreationService { reparsedReq = ServiceUtils.reparseRequest(context.getRequest()); // convert to API objects + Logger.trace(">>> preparsing Request"); requestObj = requestParser.parse(reparsedReq); - + Logger.trace("<<< preparsed Request"); + + Logger.trace(">>> creating Signature"); // invoke the core logic - responseObj = - invoker.createXMLSignature(requestObj, Collections.EMPTY_SET); + responseObj = invoker.createXMLSignature(requestObj, Collections.EMPTY_SET); + Logger.trace("<<< created Signature"); + Logger.trace(">>> building Response"); // map back to XML response[0] = responseBuilder.build(responseObj).getDocumentElement(); + Logger.trace("<<< built Response"); // save response in transaction context.setResponse(response[0]); + Logger.trace("---- Leaving SignatureCreationService"); } catch (MOAException e) { AxisFault fault = AxisFault.makeFault(e); diff --git a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContext.java b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContext.java index 774880d26..5c1e35a95 100644 --- a/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContext.java +++ b/spss/server/serverlib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContext.java @@ -2,6 +2,7 @@ package at.gv.egovernment.moa.spss.server.transaction; import iaik.ixsil.util.URI; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -14,6 +15,7 @@ import java.util.Map.Entry; import org.apache.axis.attachments.ManagedMemoryDataSource; import org.w3c.dom.Element; +import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.spss.MOAApplicationException; import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; @@ -37,9 +39,11 @@ public class TransactionContext { private Element response; /** The map pointing to SOAP attachments needed by the request. */ private HashMap attachments = null; + /** The map containing cashed entities used in DataObjectFactory. */ + private HashMap resolvedEntities = null; /** The configuration to use throughout the request. */ private ConfigurationProvider configuration = null; - + /** * Create a TransactionContext object. * @@ -169,6 +173,23 @@ public class TransactionContext { this.attachments.put(referenceId, entry); } + /** + * Adds an attachment to the transactions list of SOAP attachments. + * + * @param referenceId Identification value for the SOAP attachment. + * @param contentType MIME type of the SOAP attachment. + * @param is Handle to the InputStream of the SOAP attachment. + * @param filename Filename of the temporary file the InputStream belongs to + */ + public void addAttachment(String referenceId, String contentType, InputStream is, String filename) { + if (this.attachments == null) this.attachments = new HashMap(); + Vector entry = new Vector(3); + entry.add(contentType); + entry.add(is); + entry.add(filename); + this.attachments.put(referenceId, entry); + } + /** * Returns the ManagedMemoryDataSource to a specific SOAP attachment identified by referenceId. * @@ -182,10 +203,14 @@ public class TransactionContext { if (entry==null) { return null; } - //return (InputStream) ( ((ManagedMemoryDataSource)entry.get(1)).getInputStream()); - return (ManagedMemoryDataSource) entry.get(1); + Object object = entry.get(1); + if (object instanceof ManagedMemoryDataSource) { + return (ManagedMemoryDataSource) object; + } else { + return null; + } } - + /** * Returns the InputStream to a specific SOAP attachment identified by uri. * @@ -202,12 +227,17 @@ public class TransactionContext { } InputStream attachmentIs = null; - try { - attachmentIs = (InputStream) ( ((ManagedMemoryDataSource)entry.get(1)).getInputStream()); - } catch (IOException e) { - throw new MOAApplicationException("2208", new Object[] { uri }, e); + Object object = entry.get(1); + + if (object instanceof ManagedMemoryDataSource) { + try { + attachmentIs = (InputStream) ( ((ManagedMemoryDataSource)object).getInputStream()); + } catch (IOException e) { + throw new MOAApplicationException("2208", new Object[] { uri }, e); + } + } else { + attachmentIs = (InputStream) object; } - return attachmentIs; //If we would return the whole mmds: return (ManagedMemoryDataSource) entry.get(1); } @@ -236,17 +266,32 @@ public void cleanAttachmentCache() { while (iterator.hasNext()) { Entry hmEntry = (Entry) iterator.next(); Vector entry = (Vector)hmEntry.getValue(); - ManagedMemoryDataSource mmds = (ManagedMemoryDataSource)entry.get(1); - try { - if (mmds!=null) { - InputStream is = mmds.getInputStream(); - if (is!=null) is.close(); - File f = mmds.getDiskCacheFile(); - if (f!=null) f.delete(); - mmds.delete(); - } - } catch (IOException e) { - // ok to do nothing here + Object object = entry.get(1); + if (object instanceof ManagedMemoryDataSource) { + ManagedMemoryDataSource mmds = (ManagedMemoryDataSource)object; + try { + if (mmds!=null) { + InputStream is = mmds.getInputStream(); + if (is!=null) is.close(); + File f = mmds.getDiskCacheFile(); + if (f!=null) f.delete(); + mmds.delete(); + } + } catch (IOException e) { + // ok to do nothing here + } + } else if (object instanceof InputStream) { + InputStream is = (InputStream)object; + try { + if (is!=null) is.close(); + String tempFile = (String) entry.get(2); + if (tempFile!=null){ + File f = new File(tempFile); + f.delete(); + } + } catch (IOException e) { + // ok to do nothing here + } } } } @@ -261,4 +306,50 @@ public void cleanAttachmentCache() { return configuration; } + /** + * Search an uri content in cashed map. + * + * @param uri The value to look for. + * @return If found the cached entity, null otherwise. + */ + public Vector FindResolvedEntity(String uri) { + if (resolvedEntities==null) return null; + return (Vector) resolvedEntities.get(uri); + } + + /** + * Get a new InputStream of a cached entity. + * + * @param uri The value to look for. + * @return A new InputStream of the cached entity. + */ + public InputStream ResolveURI(String uri) { + InputStream is = null; + Vector entity = FindResolvedEntity(uri); + if (entity!=null) { + byte[] contentBytes = (byte[]) entity.get(0); + if (contentBytes!=null) { + is = new ByteArrayInputStream(contentBytes); + } + } + return is; + } + + /** + * Put a read entity (supplement, detached content, data object) on + * transactions entity cash, to prevent repeated reading on slower channels. + * + * @param uri A transaction-wide unique URI used as key of the entity cash + * table. + * @param contentBytes The cached content belonging to the uri. + * @param contentType If known, the MIME-type of the cashed content. + */ + public void PutResolvedEntity(String uri, byte[] contentBytes, String contentType) { + Logger.trace(" storing uri content of uri \"" + uri + "\" for future references"); + if (resolvedEntities==null) resolvedEntities = new HashMap(); + Vector entity = new Vector(); + entity.add(contentBytes); + entity.add(contentType); + resolvedEntities.put(uri, entity); + } } diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/AllTests.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/AllTests.java deleted file mode 100644 index c670b5e55..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/AllTests.java +++ /dev/null @@ -1,40 +0,0 @@ -package test.at.gv.egovernment.moa.spss; - -import test.at.gv.egovernment.moa.spss.server.iaik.config.ConfigurationDataImplTest; -import test.at.gv.egovernment.moa.spss.server.iaik.config.IaikConfiguratorTest; -import test.at.gv.egovernment.moa.spss.server.tools.CertToolTest; - -import junit.awtui.TestRunner; -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Test suite for all unit tests. - * - * @author Patrick Peck - * @version $Id$ - */ -public class AllTests { - - public static Test suite() { - TestSuite suite = new TestSuite(); - - suite.addTestSuite(test.at.gv.egovernment.moa.spss.server.config.AllTests.class); - suite.addTestSuite(ConfigurationDataImplTest.class); - suite.addTestSuite(IaikConfiguratorTest.class); - suite.addTest( - test.at.gv.egovernment.moa.spss.server.invoke.AllTests.suite()); - suite.addTest(test.at.gv.egovernment.moa.spss.api.xmlbind.AllTests.suite()); - suite.addTestSuite(CertToolTest.class); - - return suite; - } - - public static void main(String[] args) { - try { - TestRunner.run(AllTests.class); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/SPSSTestCase.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/SPSSTestCase.java deleted file mode 100644 index a585e30a0..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/SPSSTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -package test.at.gv.egovernment.moa.spss; - -import java.security.Security; - -import test.at.gv.egovernment.moa.MOATestCase; - -import at.gv.egovernment.moa.logging.Logger; -import at.gv.egovernment.moa.logging.LoggingContext; -import at.gv.egovernment.moa.logging.LoggingContextManager; -import at.gv.egovernment.moa.util.MessageProvider; - -import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; -import at.gv.egovernment.moa.spss.server.iaik.config.IaikConfigurator; -import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; -import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; - -/** - * Base class for MOA test cases. - * - * Provides some utility functions. - * - * @author Patrick Peck - * @version $Id$ - */ -public class SPSSTestCase extends MOATestCase { - - protected static final String TESTDATA_ROOT = "data/test/"; - - /** - * Constructor for MOATestCase. - * @param arg0 - */ - public SPSSTestCase(String name) { - super(name); - } - - /** - * Set up a transaction context with a test configuration. - */ - protected void setUpTransactionContext() throws Exception { - System.setProperty( - ConfigurationProvider.CONFIG_PROPERTY_NAME, - "data/test/conf/moa-spss/MOA-SPSSConfiguration.xml"); - ConfigurationProvider config = ConfigurationProvider.getInstance(); - TransactionContext context = new TransactionContext("test", null, config); - TransactionContextManager.getInstance().setTransactionContext(context); - } - - protected void setUpLoggingContext() throws Exception { - LoggingContext context = new LoggingContext("test"); - LoggingContextManager.getInstance().setLoggingContext(context); - } - - /** - * Configure the IAIK modules with the current configuration. - * - * A TransactionContext must have been set up before. - */ - protected void setUpIaikConfiguration() throws Exception { - TransactionContext context = - TransactionContextManager.getInstance().getTransactionContext(); - ClassLoader cl = getClass().getClassLoader(); - MessageProvider msg = MessageProvider.getInstance(); - - try { - cl.loadClass("javax.security.cert.Certificate"); // from jcert.jar - } catch (ClassNotFoundException e) { - Logger.warn(msg.getMessage("init.03", null), e); - } - - new IaikConfigurator().configure(context.getConfiguration()); - } - - protected void setUpSSL() 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"); - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/AllTests.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/AllTests.java deleted file mode 100644 index 28f79729e..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/AllTests.java +++ /dev/null @@ -1,24 +0,0 @@ -package test.at.gv.egovernment.moa.spss.api.xmlbind; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Runs all tests in this package. - * - * @author Patrick Peck - * @version $Id$ - */ -public class AllTests { - public static Test suite() { - TestSuite suite = new TestSuite(); - - suite.addTestSuite(CreateXMLSignatureRequestParserTest.class); - suite.addTestSuite(TransformParserTest.class); - suite.addTestSuite(VerifyCMSSignatureRequestParserTest.class); - suite.addTestSuite(VerifyXMLSignatureRequestParserTest.class); - - return suite; - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/CreateXMLSignatureRequestParserTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/CreateXMLSignatureRequestParserTest.java deleted file mode 100644 index 7ce705b01..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/CreateXMLSignatureRequestParserTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package test.at.gv.egovernment.moa.spss.api.xmlbind; - -import org.w3c.dom.Element; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import at.gv.egovernment.moa.spss.api.xmlbind.CreateXMLSignatureRequestParser; -import at.gv.egovernment.moa.spss.api.xmlsign.CreateSignatureEnvironmentProfileExplicit; -import at.gv.egovernment.moa.spss.api.xmlsign.CreateTransformsInfoProfileExplicit; -import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureRequest; -import at.gv.egovernment.moa.spss.api.xmlsign.DataObjectInfo; -import at.gv.egovernment.moa.spss.api.xmlsign.SingleSignatureInfo; - -/** - * Test the CreateXMLSignatureRequestParser. - * - * @author Patrick Peck - * @version $Id$ - */ -public class CreateXMLSignatureRequestParserTest extends SPSSTestCase { - private static final String TESTDATA_BASE = - TESTDATA_ROOT + "xml/CreateXMLSignature/"; - - private CreateXMLSignatureRequestParser requestParser; - - public CreateXMLSignatureRequestParserTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - requestParser = new CreateXMLSignatureRequestParser(); - } - - public void testParse() throws Exception { - Element requestElem = - parseXml(TESTDATA_BASE + "TestGeneratorCX2.001.Req.xml") - .getDocumentElement(); - CreateXMLSignatureRequest request = requestParser.parse(requestElem); - SingleSignatureInfo sigInfo; - DataObjectInfo dataObjInfo; - CreateTransformsInfoProfileExplicit transProfile; - CreateSignatureEnvironmentProfileExplicit envProfile; - - assertNotNull(request); - assertEquals("PKCS12RSAKey1", request.getKeyIdentifier()); - assertEquals(1, request.getSingleSignatureInfos().size()); - - sigInfo = (SingleSignatureInfo) request.getSingleSignatureInfos().get(0); - assertEquals(1, sigInfo.getDataObjectInfos().size()); - assertFalse(sigInfo.isSecurityLayerConform()); - - dataObjInfo = (DataObjectInfo) sigInfo.getDataObjectInfos().get(0); - assertNotNull(dataObjInfo.getDataObject()); - - transProfile = - (CreateTransformsInfoProfileExplicit) dataObjInfo - .getCreateTransformsInfoProfile(); - assertNotNull( - transProfile.getCreateTransformsInfo().getFinalDataMetaInfo()); - - envProfile = - (CreateSignatureEnvironmentProfileExplicit) sigInfo - .getCreateSignatureInfo() - .getCreateSignatureEnvironmentProfile(); - assertEquals( - "//data:Document", - envProfile.getCreateSignatureLocation().getXPathExpression()); - assertEquals(0, envProfile.getCreateSignatureLocation().getIndex()); - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/TransformParserTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/TransformParserTest.java deleted file mode 100644 index f580f86bc..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/TransformParserTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package test.at.gv.egovernment.moa.spss.api.xmlbind; - -import java.util.List; - -import org.w3c.dom.Element; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import at.gv.egovernment.moa.spss.api.common.CanonicalizationTransform; -import at.gv.egovernment.moa.spss.api.common.EnvelopedSignatureTransform; -import at.gv.egovernment.moa.spss.api.common.ExclusiveCanonicalizationTransform; -import at.gv.egovernment.moa.spss.api.common.XPathFilter2Transform; -import at.gv.egovernment.moa.spss.api.common.XPathTransform; -import at.gv.egovernment.moa.spss.api.common.XSLTTransform; -import at.gv.egovernment.moa.spss.api.xmlbind.TransformParser; - -/** - * Test the TransformParser. - * - * @author Patrick Peck - * @version $Id$ - */ -public class TransformParserTest extends SPSSTestCase { - private static String TESTDATA_BASE = TESTDATA_ROOT + "xml/dsigTransform/"; - - private TransformParser transformParser; - - public TransformParserTest(String name) { - super(name); - } - - protected void setUp() { - transformParser = new TransformParser(); - } - - public void testParseTransforms() throws Exception { - Element transformsElem = - parseXml(TESTDATA_BASE + "transforms.xml").getDocumentElement(); - List transforms = transformParser.parseTransforms(transformsElem); - - assertNotNull(transforms); - assertEquals(3, transforms.size()); - - } - - public void testParseCanonicalizationTransform() throws Exception { - Element transformElem = - parseXml(TESTDATA_BASE + "canonicalization.xml").getDocumentElement(); - CanonicalizationTransform transform = - (CanonicalizationTransform) transformParser.parseTransform(transformElem); - - assertNotNull(transform); - assertEquals( - CanonicalizationTransform.CANONICAL_XML, - transform.getAlgorithmURI()); - } - - public void testParseExclCanonicalizationTransform() throws Exception { - Element transformElem = - parseXml(TESTDATA_BASE + "exclusiveCanonicalization.xml") - .getDocumentElement(); - ExclusiveCanonicalizationTransform transform = - (ExclusiveCanonicalizationTransform) transformParser.parseTransform( - transformElem); - - assertNotNull(transform); - assertEquals( - ExclusiveCanonicalizationTransform.EXCLUSIVE_CANONICAL_XML, - transform.getAlgorithmURI()); - assertEquals(3, transform.getInclusiveNamespacePrefixes().size()); - } - - public void testParseEnvelopedTransform() throws Exception { - Element transformElem = - parseXml(TESTDATA_BASE + "enveloped.xml").getDocumentElement(); - EnvelopedSignatureTransform transform = - (EnvelopedSignatureTransform) transformParser.parseTransform( - transformElem); - - assertNotNull(transform); - } - - public void testParseXPathTransform() throws Exception { - Element transformElem = - parseXml(TESTDATA_BASE + "xpath.xml").getDocumentElement(); - XPathTransform transform = - (XPathTransform) transformParser.parseTransform(transformElem); - - assertNotNull(transform); - assertEquals("//ToBeSigned/Data", transform.getXPathExpression()); - assertEquals(1, transform.getNamespaceDeclarations().size()); - } - - public void testParseXPathFilter2Transform() throws Exception { - Element transformElem = - parseXml(TESTDATA_BASE + "xpath2.xml").getDocumentElement(); - XPathFilter2Transform transform = - (XPathFilter2Transform) transformParser.parseTransform(transformElem); - - assertNotNull(transform); - assertEquals(3, transform.getFilters().size()); - } - - public void testParseXSLTTransform() throws Exception { - Element transformElem = - parseXml(TESTDATA_BASE + "xslt.xml").getDocumentElement(); - XSLTTransform transform = - (XSLTTransform) transformParser.parseTransform(transformElem); - - assertNotNull(transform); - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/VerifyCMSSignatureRequestParserTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/VerifyCMSSignatureRequestParserTest.java deleted file mode 100644 index 4be7667eb..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/VerifyCMSSignatureRequestParserTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package test.at.gv.egovernment.moa.spss.api.xmlbind; - -import org.w3c.dom.Element; - -import at.gv.egovernment.moa.util.DateTimeUtils; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import at.gv.egovernment.moa.spss.api.cmsverify.CMSContentExcplicit; -import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureRequest; -import at.gv.egovernment.moa.spss.api.common.MetaInfo; -import at.gv.egovernment.moa.spss.api.xmlbind.VerifyCMSSignatureRequestParser; - -/** - * Test the VerifyCMSSignatureRequestParserTest. - * - * @author Patrick Peck - * @version $Id$ - */ -public class VerifyCMSSignatureRequestParserTest extends SPSSTestCase { - private static String TESTDATA_BASE = - TESTDATA_ROOT + "xml/VerifyCMSSignature/"; - - private VerifyCMSSignatureRequestParser requestParser; - - public VerifyCMSSignatureRequestParserTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - requestParser = new VerifyCMSSignatureRequestParser(); - } - - public void testParse() throws Exception { - Element requestElem = - parseXml(TESTDATA_BASE + "TestGeneratorVC0.001.Req.xml") - .getDocumentElement(); - VerifyCMSSignatureRequest request = requestParser.parse(requestElem); - MetaInfo metaInfo; - CMSContentExcplicit content; - - assertNotNull(request); - assertEquals(1, request.getSignatories()[0]); - assertEquals( - DateTimeUtils.parseDateTime("2003-04-04T09:30:47-05:00"), - request.getDateTime()); - assertNotNull(request.getCMSSignature()); - assertNotNull(request.getDataObject()); - assertEquals("TrustProfile1", request.getTrustProfileId()); - - metaInfo = request.getDataObject().getMetaInfo(); - assertNotNull(metaInfo); - assertEquals("text/plain", metaInfo.getMimeType()); - assertEquals("http://10.16.46.109/TestDatenGenerator/resources/testDaten.txt", metaInfo.getDescription()); - - content = (CMSContentExcplicit) request.getDataObject().getContent(); - assertNotNull(content.getBinaryContent()); - - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/VerifyXMLSignatureRequestParserTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/VerifyXMLSignatureRequestParserTest.java deleted file mode 100644 index 3b8e8b00e..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/api/xmlbind/VerifyXMLSignatureRequestParserTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package test.at.gv.egovernment.moa.spss.api.xmlbind; - -import org.w3c.dom.Element; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import at.gv.egovernment.moa.util.DateTimeUtils; - -import at.gv.egovernment.moa.spss.api.xmlbind.VerifyXMLSignatureRequestParser; -import at.gv.egovernment.moa.spss.api.xmlverify.ReferenceInfo; -import at.gv.egovernment.moa.spss.api.xmlverify.SignatureManifestCheckParams; -import at.gv.egovernment.moa.spss.api.xmlverify.VerifySignatureInfo; -import at.gv.egovernment.moa.spss.api.xmlverify.VerifySignatureLocation; -import at.gv.egovernment.moa.spss.api.xmlverify.VerifyTransformsInfoProfileExplicit; -import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureRequest; - -/** - * Test the VerifyXMLSignatureRequestParserTest. - * - * @author Patrick Peck - * @version $Id$ - */ -public class VerifyXMLSignatureRequestParserTest extends SPSSTestCase { - private static String TESTDATA_BASE = - TESTDATA_ROOT + "xml/VerifyXMLSignature/"; - - private VerifyXMLSignatureRequestParser parser; - - public VerifyXMLSignatureRequestParserTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - parser = new VerifyXMLSignatureRequestParser(); - } - - public void testParse() throws Exception { - Element requestElem = - parseXml(TESTDATA_BASE + "TestGeneratorVX.201.Req.xml") - .getDocumentElement(); - VerifyXMLSignatureRequest request = parser.parse(requestElem); - VerifySignatureInfo verifySignatureInfo; - VerifySignatureLocation verifyLocation; - SignatureManifestCheckParams checkParams; - ReferenceInfo refInfo; - VerifyTransformsInfoProfileExplicit transformsProfile; - - assertNotNull(request); - assertEquals( - DateTimeUtils.parseDateTime("2003-04-01T12:53:57+01:00"), - request.getDateTime()); - assertFalse(request.getReturnHashInputData()); - assertEquals("TrustProfile1", request.getTrustProfileId()); - - verifySignatureInfo = request.getSignatureInfo(); - assertNotNull(verifySignatureInfo); - assertNotNull(verifySignatureInfo.getVerifySignatureEnvironment()); - - verifyLocation = verifySignatureInfo.getVerifySignatureLocation(); - assertNotNull(verifyLocation); - assertEquals("//dsig:Signature", verifyLocation.getXPathExpression()); - assertEquals(3, verifyLocation.getNamespaceDeclarations().size()); - - checkParams = request.getSignatureManifestCheckParams(); - assertNotNull(checkParams); - assertEquals(true, checkParams.getReturnReferenceInputData()); - assertEquals(1, checkParams.getReferenceInfos().size()); - - refInfo = (ReferenceInfo) checkParams.getReferenceInfos().get(0); - assertEquals(1, refInfo.getVerifyTransformsInfoProfiles().size()); - - transformsProfile = - (VerifyTransformsInfoProfileExplicit) refInfo - .getVerifyTransformsInfoProfiles() - .get(0); - assertEquals(1, transformsProfile.getTransforms().size()); - assertEquals(1, transformsProfile.getTransformParameters().size()); - - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/AllTests.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/AllTests.java deleted file mode 100644 index 131f38c19..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/AllTests.java +++ /dev/null @@ -1,20 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.config; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @author Gregor Karlinger - * @version $Id$ - */ -public class AllTests -{ - public static Test suite() - { - TestSuite suite = new TestSuite(); - suite.addTestSuite(ConfigurationProviderTest1.class); - suite.addTestSuite(ConfigurationProviderTest2.class); - suite.addTestSuite(ConfigurationProviderTest3.class); - return suite; - } -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest1.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest1.java deleted file mode 100644 index 474a387ad..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest1.java +++ /dev/null @@ -1,377 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.config; - -import iaik.asn1.structures.Name; -import iaik.pki.pathvalidation.ChainingModes; -import iaik.utils.RFC2253NameParser; -import iaik.utils.RFC2253NameParserException; -import iaik.x509.X509Certificate; - -import java.math.BigInteger; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import junit.framework.TestCase; - -import org.w3c.dom.Element; - -import at.gv.egovernment.moa.spss.MOAException; -import at.gv.egovernment.moa.spss.server.config.CRLDistributionPoint; -import at.gv.egovernment.moa.spss.server.config.ConfigurationException; -import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; -import at.gv.egovernment.moa.spss.server.config.HardwareCryptoModule; -import at.gv.egovernment.moa.spss.server.config.HardwareKeyModule; -import at.gv.egovernment.moa.spss.server.config.KeyGroup; -import at.gv.egovernment.moa.spss.server.config.KeyGroupEntry; -import at.gv.egovernment.moa.spss.server.config.OCSPDistributionPoint; -import at.gv.egovernment.moa.spss.server.config.SoftwareKeyModule; -import at.gv.egovernment.moa.spss.server.config.TrustProfile; -import at.gv.egovernment.moa.util.Constants; - -/** - * @author Gregor Karlinger - * @version $Id$ - */ -public class ConfigurationProviderTest1 extends TestCase -{ - private static final String CONFIG_BASE_ = - "e:/cio/projekte/basismodule/wartung/projekt/spss.server/res/test/resources/config/"; - - static at.gv.egovernment.moa.spss.server.config.ConfigurationProvider provider_; - - static - { - System.setProperty( - "log4j.configuration", - "file:/" + CONFIG_BASE_ + "log4j.properties"); - System.setProperty( - at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.CONFIG_PROPERTY_NAME, - CONFIG_BASE_ + "moa.spss.complete-config.xml"); - try - { - ConfigurationProvider.reload(); - provider_ = at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.getInstance(); - } - catch (ConfigurationException e) - { - throw new RuntimeException("Fehler beim Setup des Tests: " + e.getMessage()); - } - } - - /** - * Constructor for ConfigurationProvider. - * @param arg0 - */ - public ConfigurationProviderTest1() throws MOAException - { - super("ConfigurationProvider"); - } - - public void testGetWarnings() - { - assertEquals(0, provider_.getWarnings().size()); - } - - public void testGetDigestMethodAlgorithmName() - { - assertEquals( - Constants.SHA1_URI, - provider_.getDigestMethodAlgorithmName()); - } - - public void testGetCanonicalizationAlgorithmName() - { - assertEquals( - Constants.C14N_WITH_COMMENTS_URI, - provider_.getCanonicalizationAlgorithmName()); - } - - public void testGetHardwareCryptoModules() - { - List hwcms = provider_.getHardwareCryptoModules(); - assertEquals(2, hwcms.size()); - - HardwareCryptoModule hwc1 = (HardwareCryptoModule) hwcms.get(0); - assertEquals("HWC1_Name", hwc1.getName()); - assertEquals("HWC1_SlotId", hwc1.getSlotID()); - assertEquals("HWC1_UserPIN", hwc1.getUserPIN()); - - HardwareCryptoModule hwc2 = (HardwareCryptoModule) hwcms.get(1); - assertEquals("HWC2_Name", hwc2.getName()); - assertNull(hwc2.getSlotID()); - assertEquals("HWC2_UserPIN", hwc2.getUserPIN()); - } - - public void testGetHardwareKeyModules() - { - List hwkms = provider_.getHardwareKeyModules(); - assertEquals(2, hwkms.size()); - - HardwareKeyModule hwk1 = (HardwareKeyModule) hwkms.get(0); - assertEquals("HWK1_Id", hwk1.getId()); - assertEquals("HWK1_Name", hwk1.getName()); - assertEquals("HWK1_SlotId", hwk1.getSlotID()); - assertEquals("HWK1_UserPIN", hwk1.getUserPIN()); - - HardwareKeyModule hwk2 = (HardwareKeyModule) hwkms.get(1); - assertEquals("HWK2_Id", hwk2.getId()); - assertEquals("HWK2_Name", hwk2.getName()); - assertNull(hwk2.getSlotID()); - assertEquals("HWK2_UserPIN", hwk2.getUserPIN()); - } - - public void testGetSoftwareKeyModules() - { - List swkms = provider_.getSoftwareKeyModules(); - assertEquals(2, swkms.size()); - - SoftwareKeyModule swk1 = (SoftwareKeyModule) swkms.get(0); - assertEquals("SWK1_Id", swk1.getId()); - assertEquals(CONFIG_BASE_ + "swk/SWK1_FileName.txt", swk1.getFileName().replace('\\', '/')); - assertEquals("SWK1_Password", swk1.getPassWord()); - - SoftwareKeyModule swk2 = (SoftwareKeyModule) swkms.get(1); - assertEquals("SWK2_Id", swk2.getId()); - assertEquals(CONFIG_BASE_ + "swk/SWK2_FileName.txt", swk2.getFileName().replace('\\', '/')); - assertNull(swk2.getPassWord()); - } - - public void testGetKeyGroups() - { - Map keyGroups = provider_.getKeyGroups(); - assertEquals(2, keyGroups.size()); - - KeyGroup kg1 = (KeyGroup) keyGroups.get("KG1_Id"); - assertNotNull(kg1); - assertEquals("KG1_Id", kg1.getId()); - - Set kg1Entries = kg1.getKeyGroupEntries(); - assertEquals(2, kg1Entries.size()); - - Iterator kg1EntriesIt = kg1Entries.iterator(); - while(kg1EntriesIt.hasNext()) - { - KeyGroupEntry currentEntry = (KeyGroupEntry)kg1EntriesIt.next(); - if ("HWK1_Id".equals(currentEntry.getModuleID())) - { - assertEquals("CN=HWK1_Issuer", currentEntry.getIssuerDN()); - assertEquals(0, currentEntry.getSerialNumber().intValue()); - } - else if ("HWK2_Id".equals(currentEntry.getModuleID())) - { - assertEquals("CN=HWK2_Issuer", currentEntry.getIssuerDN()); - assertEquals(1, currentEntry.getSerialNumber().intValue()); - } - else fail("Invalid module identifer found."); - } - - KeyGroup kg2 = (KeyGroup) keyGroups.get("KG2_Id"); - assertNotNull(kg2); - assertEquals("KG2_Id", kg2.getId()); - - Set kg2Entries = kg2.getKeyGroupEntries(); - assertEquals(2, kg2Entries.size()); - - Iterator kg2EntriesIt = kg1Entries.iterator(); - while(kg1EntriesIt.hasNext()) - { - KeyGroupEntry currentEntry = (KeyGroupEntry)kg2EntriesIt.next(); - if ("SWK1_Id".equals(currentEntry.getModuleID())) - { - assertEquals("CN=CN=SWK1_Issuer", currentEntry.getIssuerDN()); - assertEquals(2, currentEntry.getSerialNumber().intValue()); - } - else if ("SWK2_Id".equals(currentEntry.getModuleID())) - { - assertEquals("CN=SWK2_Issuer", currentEntry.getIssuerDN()); - assertEquals(3, currentEntry.getSerialNumber().intValue()); - } - else fail("Invalid module identifer found."); - } - } - - public void testGetKeyGroupEntries() throws RFC2253NameParserException - { - RFC2253NameParser parser = new RFC2253NameParser("CN=Customer1_Issuer"); - Name name = parser.parse(); - Set kgEntries = provider_.getKeyGroupEntries(name, BigInteger.valueOf(4), "KG1_Id"); - assertEquals(2, kgEntries.size()); - - Iterator kgEntriesIt = kgEntries.iterator(); - while (kgEntriesIt.hasNext()) - { - KeyGroupEntry currentEntry = (KeyGroupEntry) kgEntriesIt.next(); - if (!"HWK1_Id".equals(currentEntry.getModuleID()) && !"HWK2_Id".equals(currentEntry.getModuleID())) - { - fail("Invalid module identifier found."); - } - } - } - - public void testGetChainingMode() throws RFC2253NameParserException - { - X509Certificate cert = new X509Certificate(); - RFC2253NameParser parser = new RFC2253NameParser("CN=Unknown"); - Name name = parser.parse(); - cert.setIssuerDN(name); - cert.setSerialNumber(BigInteger.valueOf(0)); - assertEquals(ChainingModes.PKIX_MODE, provider_.getChainingMode(cert)); // Default chaining mode - - parser = new RFC2253NameParser("CN=TA1_Issuer"); - name = parser.parse(); - cert.setIssuerDN(name); - cert.setSerialNumber(BigInteger.valueOf(5)); - assertEquals(ChainingModes.CHAIN_MODE, provider_.getChainingMode(cert)); - } - - public void testGetDistributionPoints() throws RFC2253NameParserException - { - X509Certificate cert = new X509Certificate(); - RFC2253NameParser parser = new RFC2253NameParser("CN=DP1_Issuer"); - Name name = parser.parse(); - cert.setIssuerDN(name); - - Set dps = provider_.getDistributionPoints(cert); - assertEquals(2, dps.size()); - - Iterator dpIt = dps.iterator(); - while (dpIt.hasNext()) - { - CRLDistributionPoint currentDP = (CRLDistributionPoint)dpIt.next(); - if ("http://crl.myca.org".equals(currentDP.getUri())) - { - int reasonCodes = - iaik.asn1.structures.DistributionPoint.unused | - iaik.asn1.structures.DistributionPoint.keyCompromise | - iaik.asn1.structures.DistributionPoint.cACompromise | - iaik.asn1.structures.DistributionPoint.affiliationChanged | - iaik.asn1.structures.DistributionPoint.superseded | - iaik.asn1.structures.DistributionPoint.cessationOfOperation | - iaik.asn1.structures.DistributionPoint.certificateHold | - iaik.asn1.structures.DistributionPoint.privilegeWithdrawn | - iaik.asn1.structures.DistributionPoint.aACompromise; - assertEquals(reasonCodes, currentDP.getReasonCodes()); - } - else if ("http://crl.myotherca.org".equals(currentDP.getUri())) - { - int reasonCodes = - iaik.asn1.structures.DistributionPoint.aACompromise | - iaik.asn1.structures.DistributionPoint.affiliationChanged; - assertEquals(reasonCodes, currentDP.getReasonCodes()); - } - else fail("Invalid CRL DP URI found: " + currentDP.getUri()); - } - - parser = new RFC2253NameParser("CN=DP2_Issuer"); - name = parser.parse(); - cert.setIssuerDN(name); - - dps = provider_.getDistributionPoints(cert); - assertEquals(1, dps.size()); - - OCSPDistributionPoint dpo = (OCSPDistributionPoint) dps.toArray()[0]; - assertEquals("http://crl.yetanotherca.org", dpo.getUri()); - } - - public void testGetCRLArchiveDuration() - { - assertEquals(730, provider_.getCRLArchiveDuration()); - } - - public void testGetEnableRevocationArchiving() - { - assertFalse(provider_.getEnableRevocationArchiving()); - } - - public void testGetCertStoreLocation() - { - assertEquals( - CONFIG_BASE_ + "certstore_test", - provider_.getCertStoreLocation().replace('\\', '/')); - } - - public void testGetCreateTransformsInfoProfile() - { - Element ctip1 = provider_.getCreateTransformsInfoProfile("CTIP_1"); - assertEquals("CreateTransformsInfoProfile", ctip1.getLocalName()); - - Element ctip2 = provider_.getCreateTransformsInfoProfile("CTIP_2"); - assertEquals("CreateTransformsInfoProfile", ctip2.getLocalName()); - } - - public void testGetCreateSignatureEnvironmentProfile() - { - Element csep = provider_.getCreateSignatureEnvironmentProfile("CSEP_1"); - assertEquals("CreateSignatureEnvironmentProfile", csep.getLocalName()); - } - - public void testGetVerifyTransformsInfoProfile() - { - Element vtip = provider_.getVerifyTransformsInfoProfile("VTIP_1"); - assertEquals("VerifyTransformsInfoProfile", vtip.getLocalName()); - } - - public void testGetSupplementProfile() - { - Element sp = provider_.getSupplementProfile("SP_1"); - assertEquals("SupplementProfile", sp.getLocalName()); - } - - public void testGetTrustProfile() - { - TrustProfile tp1 = provider_.getTrustProfile("TP1_Id"); - assertEquals( - "file:/" + CONFIG_BASE_ + "trustprofiles/tp1/anchors", - tp1.getUri()); - assertEquals( - "file:/" + CONFIG_BASE_ + "trustprofiles/tp1/signercerts", - tp1.getSignerCertsUri()); - - TrustProfile tp2 = provider_.getTrustProfile("TP2_Id"); - assertEquals( - "file:" + CONFIG_BASE_ + "trustprofiles/tp2/anchors", - tp2.getUri()); - assertEquals( - "file:" + CONFIG_BASE_ + "trustprofiles/tp2/signercerts", - tp2.getSignerCertsUri()); - } - - public void testGetRevocationArchiveJDBCURL() - { - assertEquals("jdbc://dummy", provider_.getRevocationArchiveJDBCURL()); - } - - public void testGetRevocationArchiveJDBCDriverClass() - { - assertEquals("fully.qualified.classname", provider_.getRevocationArchiveJDBCDriverClass()); - } - - public void testGetEnableRevocationChecking() - { - assertFalse(provider_.getEnableRevocationChecking()); - } - - public void testGetMaxRevocationAge() - { - assertEquals(10000, provider_.getMaxRevocationAge()); - } - - public void testGetServiceOrder() - { - String[] serviceOrder = provider_.getServiceOrder(); - assertEquals(2, serviceOrder.length); - assertEquals("crl", serviceOrder[0]); - assertEquals("ocsp", serviceOrder[1]); - } - - public void testGetAutoAddCertificates() - { - assertFalse(provider_.getAutoAddCertificates()); - } - - public void testGetUseAuthorityInfoAccess() - { - assertFalse(provider_.getUseAuthorityInfoAccess()); - } -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest2.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest2.java deleted file mode 100644 index adf02809b..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest2.java +++ /dev/null @@ -1,225 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.config; - -import iaik.asn1.structures.Name; -import iaik.pki.pathvalidation.ChainingModes; -import iaik.utils.RFC2253NameParser; -import iaik.utils.RFC2253NameParserException; -import iaik.x509.X509Certificate; - -import java.math.BigInteger; -import java.util.List; -import java.util.Set; - -import junit.framework.TestCase; - -import org.w3c.dom.Element; - -import at.gv.egovernment.moa.spss.MOAException; -import at.gv.egovernment.moa.spss.server.config.ConfigurationException; -import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; -import at.gv.egovernment.moa.spss.server.config.TrustProfile; -import at.gv.egovernment.moa.util.Constants; - -/** - * @author Gregor Karlinger - * @version $Id$ - */ -public class ConfigurationProviderTest2 extends TestCase -{ - private static final String CONFIG_BASE_ = - "e:/cio/projekte/basismodule/wartung/projekt/spss.server/res/test/resources/config/"; - - static at.gv.egovernment.moa.spss.server.config.ConfigurationProvider provider_; - - static - { - System.setProperty( - "log4j.configuration", - "file:/" + CONFIG_BASE_ + "log4j.properties"); - System.setProperty( - at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.CONFIG_PROPERTY_NAME, - CONFIG_BASE_ + "moa.ss.noopts-config.xml"); - try - { - ConfigurationProvider.reload(); - provider_ = at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.getInstance(); - } - catch (ConfigurationException e) - { - throw new RuntimeException("Fehler beim Setup des Tests: " + e.getMessage()); - } - } - - - /** - * Constructor for ConfigurationProvider. - * @param arg0 - */ - public ConfigurationProviderTest2() throws MOAException - { - super("ConfigurationProvider"); - } - - public void testGetWarnings() - { - // 3 Warnings should be collected: C14N not found, DigestMethod not found, ArchiveDuration not found - assertEquals(3, provider_.getWarnings().size()); - } - - public void testGetDigestMethodAlgorithmName() - { - // Element is missing in config file, check if default value is returned - assertEquals( - Constants.SHA1_URI, - provider_.getDigestMethodAlgorithmName()); - } - - public void testGetCanonicalizationAlgorithmName() - { - // Element is missing in config file, check if default value is returned - assertEquals( - Constants.C14N_URI, - provider_.getCanonicalizationAlgorithmName()); - } - - public void testGetHardwareCryptoModules() - { - // No hardware crypto modules in config file, check for empty list - List hwcms = provider_.getHardwareCryptoModules(); - assertEquals(0, hwcms.size()); - } - - public void testGetHardwareKeyModules() - { - List hwkms = provider_.getHardwareKeyModules(); - assertEquals(1, hwkms.size()); - } - - public void testGetSoftwareKeyModules() - { - // No software key modules in config file, check for empty list - List swkms = provider_.getSoftwareKeyModules(); - assertEquals(0, swkms.size()); - } - - public void testGetChainingMode() throws RFC2253NameParserException - { - // Default Chaining Mode not set in configuration, check for default value - X509Certificate cert = new X509Certificate(); - RFC2253NameParser parser = new RFC2253NameParser("CN=Unknown"); - Name name = parser.parse(); - cert.setIssuerDN(name); - cert.setSerialNumber(BigInteger.valueOf(0)); - assertEquals(ChainingModes.PKIX_MODE, provider_.getChainingMode(cert)); - } - - public void testGetDistributionPoints() throws RFC2253NameParserException - { - // Element is missing in config file, check if emty list is returned - X509Certificate cert = new X509Certificate(); - RFC2253NameParser parser = new RFC2253NameParser("CN=DP1_Issuer"); - Name name = parser.parse(); - cert.setIssuerDN(name); - - Set dps = provider_.getDistributionPoints(cert); - assertEquals(0, dps.size()); - } - - public void testGetCRLArchiveDuration() - { - // Element is missing in config file, check if default value is returned - assertEquals(0, provider_.getCRLArchiveDuration()); - } - - public void testGetEnableRevocationArchiving() - { - // Element is missing in config file, check if default value is returned - assertFalse(provider_.getEnableRevocationArchiving()); - } - - public void testGetCertStoreLocation() - { - // Element is missing in config file, check if default value is returned - assertEquals( - CONFIG_BASE_ + "certstore", - provider_.getCertStoreLocation().replace('\\', '/')); - } - - public void testGetCreateTransformsInfoProfile() - { - // No profile in config file, check for null - Element ctip1 = provider_.getCreateTransformsInfoProfile("CTIP_1"); - assertNull(ctip1); - } - - public void testGetCreateSignatureEnvironmentProfile() - { - // No profile in config file, check for null - Element csep = provider_.getCreateSignatureEnvironmentProfile("CSEP_1"); - assertNull(csep); - } - - public void testGetVerifyTransformsInfoProfile() - { - // No profile in config file, check for null - Element vtip = provider_.getVerifyTransformsInfoProfile("VTIP_1"); - assertNull(vtip); - } - - public void testGetSupplementProfile() - { - // No profile in config file, check for null - Element sp = provider_.getSupplementProfile("SP_1"); - assertNull(sp); - } - - public void testGetTrustProfile() - { - // No trust profiles config file, check for null - TrustProfile tp1 = provider_.getTrustProfile("TP1_Id"); - assertNull(tp1); - } - - public void testGetRevocationArchiveJDBCURL() - { - // Element is missing in config file, check for null - assertNull(provider_.getRevocationArchiveJDBCURL()); - } - - public void testGetRevocationArchiveJDBCDriverClass() - { - // Element is missing in config file, check for null - assertNull(provider_.getRevocationArchiveJDBCDriverClass()); - } - - public void testGetEnableRevocationChecking() - { - // Element is missing in config file, check for default value - assertFalse(provider_.getEnableRevocationChecking()); - } - - public void testGetMaxRevocationAge() - { - // Element is missing in config file, check for default value - assertEquals(0, provider_.getMaxRevocationAge()); - } - - public void testGetServiceOrder() - { - // Element is missing in config file, check for empty array - String[] serviceOrder = provider_.getServiceOrder(); - assertEquals(0, serviceOrder.length); - } - - public void testGetAutoAddCertificates() - { - // Element is missing in config file, check for default value - assertFalse(provider_.getAutoAddCertificates()); - } - - public void testGetUseAuthorityInfoAccess() - { - // Element is missing in config file, check for default value - assertFalse(provider_.getUseAuthorityInfoAccess()); - } -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest3.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest3.java deleted file mode 100644 index 7da2165cb..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest3.java +++ /dev/null @@ -1,166 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.config; - -import iaik.asn1.structures.Name; -import iaik.utils.RFC2253NameParser; -import iaik.utils.RFC2253NameParserException; -import iaik.x509.X509Certificate; - -import java.util.List; -import java.util.Set; - -import junit.framework.TestCase; - -import org.w3c.dom.Element; - -import at.gv.egovernment.moa.spss.MOAException; -import at.gv.egovernment.moa.spss.server.config.ConfigurationException; -import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; -import at.gv.egovernment.moa.util.Constants; - -/** - * @author Gregor Karlinger - * @version $Id$ - */ -public class ConfigurationProviderTest3 extends TestCase -{ - private static final String CONFIG_BASE_ = - "e:/cio/projekte/basismodule/wartung/projekt/spss.server/res/test/resources/config/"; - - static at.gv.egovernment.moa.spss.server.config.ConfigurationProvider provider_; - - static - { - System.setProperty( - "log4j.configuration", - "file:/" + CONFIG_BASE_ + "log4j.properties"); - System.setProperty( - at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.CONFIG_PROPERTY_NAME, - CONFIG_BASE_ + "moa.sp.noopts-config.xml"); - try - { - ConfigurationProvider.reload(); - provider_ = at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.getInstance(); - } - catch (ConfigurationException e) - { - throw new RuntimeException("Fehler beim Setup des Tests: " + e.getMessage()); - } - } - - /** - * Constructor for ConfigurationProvider. - * @param arg0 - */ - public ConfigurationProviderTest3() throws MOAException - { - super("ConfigurationProvider"); - } - - public void testGetWarnings() - { - // 3 Warnings should be collected: C14N not found, DigestMethod not found, ArchiveDuration not found - assertEquals(3, provider_.getWarnings().size()); - } - - public void testGetDigestMethodAlgorithmName() - { - // Element is missing in config file, check if default value is returned - assertEquals( - Constants.SHA1_URI, - provider_.getDigestMethodAlgorithmName()); - } - - public void testGetCanonicalizationAlgorithmName() - { - // Element is missing in config file, check if default value is returned - assertEquals( - Constants.C14N_URI, - provider_.getCanonicalizationAlgorithmName()); - } - - public void testGetHardwareCryptoModules() - { - // No hardware crypto modules in config file, check for empty list - List hwcms = provider_.getHardwareCryptoModules(); - assertEquals(0, hwcms.size()); - } - - public void testGetHardwareKeyModules() - { - // No hardware key modules in config file, check for empty list - List hwkms = provider_.getHardwareKeyModules(); - assertEquals(0, hwkms.size()); - } - - public void testGetSoftwareKeyModules() - { - // No software key modules in config file, check for empty list - List swkms = provider_.getSoftwareKeyModules(); - assertEquals(0, swkms.size()); - } - - public void testGetDistributionPoints() throws RFC2253NameParserException - { - // No distribution points in config file, check for emtpy set - X509Certificate cert = new X509Certificate(); - RFC2253NameParser parser = new RFC2253NameParser("CN=DP1_Issuer"); - Name name = parser.parse(); - cert.setIssuerDN(name); - - Set dps = provider_.getDistributionPoints(cert); - assertEquals(0, dps.size()); - } - - public void testGetCRLArchiveDuration() - { - // No archive duration in config file, check for default value - assertEquals(0, provider_.getCRLArchiveDuration()); - } - - public void testGetCreateTransformsInfoProfile() - { - // No profile in config file, check for null - Element ctip1 = provider_.getCreateTransformsInfoProfile("CTIP_1"); - assertNull(ctip1); - } - - public void testGetCreateSignatureEnvironmentProfile() - { - // No profile in config file, check for null - Element csep = provider_.getCreateSignatureEnvironmentProfile("CSEP_1"); - assertNull(csep); - } - - public void testGetVerifyTransformsInfoProfile() - { - // No profile in config file, check for null - Element vtip = provider_.getVerifyTransformsInfoProfile("VTIP_1"); - assertNull(vtip); - } - - public void testGetSupplementProfile() - { - // No profile in config file, check for null - Element sp = provider_.getSupplementProfile("SP_1"); - assertNull(sp); - } - - public void testGetRevocationArchiveJDBCURL() - { - // No archive in config file, check for null - assertNull(provider_.getRevocationArchiveJDBCURL()); - } - - public void testGetRevocationArchiveJDBCDriverClass() - { - // No archive in config file, check for null - assertNull(provider_.getRevocationArchiveJDBCDriverClass()); - } - - public void testGetServiceOrder() - { - // Element is missing in config file, check for empty array - String[] serviceOrder = provider_.getServiceOrder(); - assertEquals(0, serviceOrder.length); - } -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/iaik/config/ConfigurationDataImplTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/iaik/config/ConfigurationDataImplTest.java deleted file mode 100644 index be1090e4a..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/iaik/config/ConfigurationDataImplTest.java +++ /dev/null @@ -1,149 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.iaik.config; - -import java.io.FileInputStream; -import java.security.KeyStore; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import iaik.asn1.structures.DistributionPoint; -import iaik.pki.PKIConfiguration; -import iaik.pki.pathvalidation.ChainingModes; -import iaik.pki.pathvalidation.ValidationConfiguration; -import iaik.pki.revocation.CRLDistributionPoint; -import iaik.pki.revocation.RevocationConfiguration; -import iaik.pki.store.certstore.CertStoreConfiguration; -import iaik.pki.store.certstore.CertStoreTypes; -import iaik.pki.store.revocation.archive.ArchiveConfiguration; -import iaik.pki.store.revocation.archive.db.DataBaseArchiveParameter; -import iaik.server.ConfigurationData; -import iaik.server.modules.keys.HardwareKeyModuleConfiguration; -import iaik.server.modules.keys.SoftwareKeyModuleConfiguration; - -import at.gv.egovernment.moa.spss.server.iaik.config.ConfigurationDataImpl; -import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; -import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; - -/** - * Tests the ConfigurationDataImpl. - * - * @author Patrick Peck - * @version $Id$ - */ -public class ConfigurationDataImplTest extends SPSSTestCase { - - private ConfigurationData config; - private X509Certificate iaikCert; - - public ConfigurationDataImplTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - TransactionContext context; - - setUpTransactionContext(); - context = TransactionContextManager.getInstance().getTransactionContext(); - - config = new ConfigurationDataImpl(context.getConfiguration()); - - KeyStore ks = KeyStore.getInstance("JKS", "SUN"); - ks.load( - new FileInputStream(TESTDATA_ROOT + "security/server.keystore"), - "changeit".toCharArray()); - - CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - Collection certs = - certFactory.generateCertificates( - new FileInputStream( - TESTDATA_ROOT - + "conf/moa-spss/trustprofiles/TrustProfile1/IAIKRoot.cer")); - iaikCert = (X509Certificate) certs.toArray()[0]; - - } - - public void testGetPKIConfiguration() { - PKIConfiguration pkiConfig = config.getPKIConfiguration(); - ArchiveConfiguration archiveConfig = pkiConfig.getArchiveConfiguration(); - CertStoreConfiguration certStoreConfig = - pkiConfig.getCertStoreConfiguration(); - RevocationConfiguration revocationConfig = - pkiConfig.getRevocationConfiguration(); - ValidationConfiguration validationConfig = - pkiConfig.getValidationConfiguration(); - DataBaseArchiveParameter archiveParam; - Set distributionPoints; - Iterator iter; - boolean found; - - // test archive parameters - archiveParam = - (DataBaseArchiveParameter) archiveConfig.getArchiveParameters(); - assertEquals( - archiveParam.getJDBCUrl(), - "jdbc:postgresql://10.16.46.108/moa?user=moa&password=moatest"); - - // test cert store configuration - assertEquals(1, certStoreConfig.getParameters().length); - assertEquals( - CertStoreTypes.DIRECTORY, - certStoreConfig.getParameters()[0].getType()); - - // test revocation configuration - distributionPoints = - revocationConfig.getAlternativeDistributionPoints(iaikCert, null, new Date()); - assertEquals(3, distributionPoints.size()); - found = false; - for (iter = distributionPoints.iterator(); iter.hasNext();) { - CRLDistributionPoint dp = (CRLDistributionPoint) iter.next(); - if (dp.getUri().equals("http://www.iaik.at/testCA/iaik_test_sig.crl")) { - found = - dp.getReasonCodes() - == (DistributionPoint.keyCompromise - | DistributionPoint.affiliationChanged); - } - } - assertTrue(found); - - // test validation configuration - assertEquals( - ChainingModes.PKIX_MODE, - validationConfig.getChainingMode(iaikCert)); - } - - /* - public void testGetCryptoModuleConfigurations() { - List cryptoConfigs = config.getCryptoModuleConfigurations(); - HardwareCryptoModuleConfiguration moduleConfig; - - assertEquals(2, cryptoConfigs.size()); - moduleConfig = (HardwareCryptoModuleConfiguration) cryptoConfigs.get(0); - assertEquals("Module1", moduleConfig.getModuleName()); - assertEquals("Slot1", moduleConfig.getSlotID()); - assertEquals("PIN1", new String(moduleConfig.getUserPIN())); - } - */ - - public void testGetKeyModuleConfigurations() { - List keyConfigs = config.getKeyModuleConfigurations(); - HardwareKeyModuleConfiguration hwKey; - SoftwareKeyModuleConfiguration swKey; - - assertEquals(7, keyConfigs.size()); - hwKey = (HardwareKeyModuleConfiguration) keyConfigs.get(0); - assertEquals("cryptoki.dll", hwKey.getModuleName()); - assertEquals("0", hwKey.getSlotID()); - assertEquals("0000", new String(hwKey.getUserPIN())); - swKey = (SoftwareKeyModuleConfiguration) keyConfigs.get(1); - assertEquals( - "buergerkarte", - new String(swKey.getKeyStoreAuthenticationData())); - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/iaik/config/IaikConfiguratorTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/iaik/config/IaikConfiguratorTest.java deleted file mode 100644 index 3b403dc19..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/iaik/config/IaikConfiguratorTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.iaik.config; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import at.gv.egovernment.moa.spss.server.iaik.config.IaikConfigurator; -import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; -import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; - -/** - * Tests the IaikConfigurator. - * - * @author Patrick Peck - * @version $Id$ - */ -public class IaikConfiguratorTest extends SPSSTestCase { - - public IaikConfiguratorTest(String name) { - super(name); - } - - /** - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUpTransactionContext(); - } - - public void testConfigure() throws Exception { - IaikConfigurator configurator = new IaikConfigurator(); - TransactionContext context = - TransactionContextManager.getInstance().getTransactionContext(); - - configurator.configure(context.getConfiguration()); - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/AllTests.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/AllTests.java deleted file mode 100644 index 65fa2bf72..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/AllTests.java +++ /dev/null @@ -1,25 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.invoke; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Runs all tests in this package. - * - * @author Patrick Peck - * @version $Id$ - */ -public class AllTests { - public static Test suite() { - TestSuite suite = new TestSuite(); - - suite.addTestSuite(DataObjectFactoryTest.class); - suite.addTestSuite(TransformationFactoryTest.class); - suite.addTestSuite(XMLSignatureCreationInvokerTest.class); - suite.addTestSuite(CMSSignatureVerificationInvokerTest.class); - suite.addTestSuite(XMLSignatureVerificationInvokerTest.class); - - return suite; - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/CMSSignatureVerificationInvokerTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/CMSSignatureVerificationInvokerTest.java deleted file mode 100644 index 3024730f4..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/CMSSignatureVerificationInvokerTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.invoke; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import at.gv.egovernment.moa.util.DOMUtils; - -import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureRequest; -import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureResponse; -import at.gv.egovernment.moa.spss.api.xmlbind.VerifyCMSSignatureRequestParser; -import at.gv.egovernment.moa.spss.api.xmlbind.VerifyCMSSignatureResponseBuilder; -import at.gv.egovernment.moa.spss.server.invoke.CMSSignatureVerificationInvoker; - -/** - * Mainly a smoke test for debugging the CMSSignatureVerificationInvoker. - * - * @author Patrick Peck - * @version $Id$ - */ -public class CMSSignatureVerificationInvokerTest extends SPSSTestCase { - private static final String TESTDATA_BASE = - TESTDATA_ROOT + "xml/VerifyCMSSignature/"; - - /** - * Constructor for CMSSignatureVerificationInvokerTest. - * @param name - */ - public CMSSignatureVerificationInvokerTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - setUpTransactionContext(); - setUpLoggingContext(); - setUpIaikConfiguration(); - } - - public void testVerifyCMSSignature() throws Exception { - try { - CMSSignatureVerificationInvoker invoker = - CMSSignatureVerificationInvoker.getInstance(); - VerifyCMSSignatureRequestParser requestParser = - new VerifyCMSSignatureRequestParser(); - Document doc = - SPSSTestCase.parseXmlValidating( - TESTDATA_BASE + "TestGeneratorVC0.001.Req.xml"); - VerifyCMSSignatureRequest request = - requestParser.parse(doc.getDocumentElement()); - VerifyCMSSignatureResponse response = invoker.verifyCMSSignature(request); - VerifyCMSSignatureResponseBuilder responseBuilder = - new VerifyCMSSignatureResponseBuilder(); - Element result = responseBuilder.build(response).getDocumentElement(); - - System.out.println(DOMUtils.serializeNode(result)); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactoryTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactoryTest.java deleted file mode 100644 index 7de2add33..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactoryTest.java +++ /dev/null @@ -1,180 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.invoke; - -import java.io.InputStream; -import java.security.Security; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import iaik.server.modules.xml.BinaryDataObject; -import iaik.server.modules.xml.DataObject; -import iaik.server.modules.xml.XMLDataObject; - -import at.gv.egovernment.moa.util.Base64Utils; - -import at.gv.egovernment.moa.spss.MOAException; -import at.gv.egovernment.moa.spss.api.SPSSFactory; -import at.gv.egovernment.moa.spss.api.common.Content; -import at.gv.egovernment.moa.spss.server.iaik.xml.ByteArrayDataObjectImpl; -import at.gv.egovernment.moa.spss.server.iaik.xml.ByteStreamDataObjectImpl; -import at.gv.egovernment.moa.spss.server.iaik.xml.XMLDataObjectImpl; -import at.gv.egovernment.moa.spss.server.iaik.xml.XMLNodeListDataObjectImpl; -import at.gv.egovernment.moa.spss.server.invoke.DataObjectFactory; - -/** - * Test cases for the DataObjectFactory class. - * - * @author Patrick Peck - * @version $Id$ - */ -public class DataObjectFactoryTest extends SPSSTestCase { - - private static final String HTTP_BINARY_CONTENT_URL = "http://www.google.com"; - private static final String HTTP_XML_CONTENT_URL = - "http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"; - private static final String HTTPS_BINARY_CONTENT_URL = - "https://businessnet.ba-ca.com"; - private static final String HTTPS_UNTRUSTED_URL = - "https://heribert.anecon.com"; - private static final String HTTP_UNKNOWN_HOST_URL = "http://uurjmjmruuw.com"; - private static final String MALFORMED_URL = "//hsld///ddd"; - private static final String FILE_BINARY_CONTENT_URL = "file:/C:/boot.ini"; - private static final String XML_CONTENT = - "" - + " " - + " " - + ""; - private static final String BASE64_CONTENT = "U3Zlbg=="; - - private SPSSFactory spssFactory = SPSSFactory.getInstance(); - private DataObjectFactory factory; - - /** - * Constructor for DataObjectFactoryTest. - * @param name - */ - public DataObjectFactoryTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - factory = DataObjectFactory.getInstance(); - - // set up SSL - 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( - "javax.net.ssl.keyStore", - "data/test/security/client.keystore"); - System.setProperty("javax.net.ssl.keyStorePassword", "changeit"); - System.setProperty( - "javax.net.ssl.trustStore", - "data/test/security/client.keystore"); - System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); - */ - } - - public void testCreateFromURIWithBinaryHttp() throws Exception { - DataObject dataObject = - factory.createFromURI(HTTP_BINARY_CONTENT_URL, false); - - assertNotNull(dataObject); - assertTrue(dataObject instanceof ByteStreamDataObjectImpl); - assertNotNull(((BinaryDataObject) dataObject).getInputStream()); - } - - public void testCreateFromURIWithXmlHttp() throws Exception { - DataObject dataObject = factory.createFromURI(HTTP_XML_CONTENT_URL, false); - Element element; - - assertNotNull(dataObject); - assertTrue(dataObject instanceof XMLDataObjectImpl); - element = ((XMLDataObject) dataObject).getElement(); - assertNotNull(element); - assertEquals("schema", element.getTagName()); - } - - public void testCreateFromURIWithMalformedURI() throws Exception { - try { - factory.createFromURI(MALFORMED_URL, false); - fail(); - } catch (MOAException e) { - } - } - - public void testCreateFromURIWithNonExistingHttpURL() throws Exception { - try { - factory.createFromURI(HTTP_UNKNOWN_HOST_URL, false); - fail(); - } catch (MOAException e) { - } - } - - public void testCreateFromURIWithHttps() throws Exception { - DataObject dataObject = - factory.createFromURI(HTTPS_BINARY_CONTENT_URL, false); - assertNotNull(dataObject); - assertTrue(dataObject instanceof BinaryDataObject); - } - - public void testCreateFromURIWithUntrustedHttps() throws Exception { - try { - factory.createFromURI(HTTPS_UNTRUSTED_URL, false); - fail(); - } catch (MOAException e) { - - } - } - - public void testCreateFromURIWithFile() throws Exception { - try { - factory.createFromURI(FILE_BINARY_CONTENT_URL, false); - fail(); - } catch (MOAException e) { - } - } - - public void testCreateFromContentOptionalRefTypeWithXmlContent() - throws Exception { - Document doc = parseXmlString(XML_CONTENT); - Content content = - spssFactory.createContent( - doc.getDocumentElement().getChildNodes(), - "http://data"); - DataObject dataObject = - factory.createFromContentOptionalRefType( - content, - null, - null, - true, - false, - true, - false); - - assertTrue(dataObject instanceof XMLNodeListDataObjectImpl); - } - - public void testCreateFromContentOptionalRefTypeWithBase64Content() - throws Exception { - InputStream is = Base64Utils.decodeToStream(BASE64_CONTENT, true); - Content content = spssFactory.createContent(is, "http://data"); - DataObject dataObject = - factory.createFromContentOptionalRefType( - content, - null, - null, - false, - false, - true, - false); - - assertNotNull(dataObject); - assertTrue(dataObject instanceof ByteArrayDataObjectImpl); - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/TransformationFactoryTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/TransformationFactoryTest.java deleted file mode 100644 index 13a80cbf1..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/TransformationFactoryTest.java +++ /dev/null @@ -1,201 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.invoke; - -import java.util.List; -import java.util.Map; - -import org.w3c.dom.Document; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import iaik.ixsil.init.IXSILInit; -import iaik.ixsil.util.URI; -import iaik.server.modules.xml.Base64Transformation; -import iaik.server.modules.xml.Canonicalization; -import iaik.server.modules.xml.EnvelopedSignatureTransformation; -import iaik.server.modules.xml.Transformation; -import iaik.server.modules.xml.XPath2Transformation; -import iaik.server.modules.xml.XPathTransformation; -import iaik.server.modules.xml.XSLTTransformation; - -import at.gv.egovernment.moa.util.Constants; - -import at.gv.egovernment.moa.spss.MOAApplicationException; -import at.gv.egovernment.moa.spss.api.common.Transform; -import at.gv.egovernment.moa.spss.api.xmlbind.TransformParser; -import at.gv.egovernment.moa.spss.server.invoke.TransformationFactory; - -/** - * Test cases for the TransformationFactory class. - * - * @author Patrick Peck - * @version $Id$ - */ -public class TransformationFactoryTest extends SPSSTestCase { - - private static final String TESTDATA_BASE = - TESTDATA_ROOT + "xml/dsigTransform/"; - private TransformationFactory factory = TransformationFactory.getInstance(); - private TransformParser transformParser = new TransformParser(); - - /** - * Constructor for TransformationFactoryTest. - * @param name - */ - public TransformationFactoryTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - IXSILInit.init(new URI("init/properties/init.properties")); - //IXSILInit.init(new URI("file:data/deploy/ixsil/init/properties/init.properties")); - - } - - public void testCreateCanonicalization() throws Exception { - Document transform = parseXml(TESTDATA_BASE + "canonicalization.xml"); - Transform tr = - transformParser.parseTransform(transform.getDocumentElement()); - Transformation t = factory.createTransformation(tr); - - assertTrue(t instanceof Canonicalization); - assertEquals( - "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", - t.getAlgorithmURI()); - } - - public void testCreateCanonicalizationWithComments() throws Exception { - Document transform = - parseXml(TESTDATA_BASE + "canonicalizationWithComments.xml"); - Transform tr = - transformParser.parseTransform(transform.getDocumentElement()); - Transformation t = factory.createTransformation(tr); - - assertTrue(t instanceof Canonicalization); - assertEquals( - "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", - t.getAlgorithmURI()); - } - - public void testCreateBase64Decode() throws Exception { - Document transform = parseXml(TESTDATA_BASE + "base64.xml"); - Transform tr = - transformParser.parseTransform(transform.getDocumentElement()); - Transformation t = factory.createTransformation(tr); - assertTrue(t instanceof Base64Transformation); - } - - public void testCreateEnvelopedSignature() throws Exception { - Document transform = parseXml(TESTDATA_BASE + "enveloped.xml"); - Transform tr = - transformParser.parseTransform(transform.getDocumentElement()); - Transformation t = factory.createTransformation(tr); - assertTrue(t instanceof EnvelopedSignatureTransformation); - } - - public void testXPathTransformation() throws Exception { - Document transform = parseXml(TESTDATA_BASE + "xpath.xml"); - Transform tr = - transformParser.parseTransform(transform.getDocumentElement()); - Transformation t = factory.createTransformation(tr); - Map nsDecls; - - assertTrue(t instanceof XPathTransformation); - nsDecls = ((XPathTransformation) t).getNamespaceDeclarations(); - assertEquals(1, nsDecls.size()); - assertEquals(Constants.DSIG_NS_URI, nsDecls.get("dsig")); - } - - public void testCreateXPath2Transformation() throws Exception { - Document transform = parseXml(TESTDATA_BASE + "xpath2.xml"); - Transform tr = - transformParser.parseTransform(transform.getDocumentElement()); - Transformation t = factory.createTransformation(tr); - assertTrue(t instanceof XPath2Transformation); - } - - public void testCreateXSLTTransformation() throws Exception { - Document transform = parseXml(TESTDATA_BASE + "xslt.xml"); - Transform tr = - transformParser.parseTransform(transform.getDocumentElement()); - XSLTTransformation t = - (XSLTTransformation) factory.createTransformation(tr); - assertNotNull(t.getStylesheetElement()); - } - - public void testCreateWithIllegalAlgorithm() throws Exception { - try { - Document transform = parseXml(TESTDATA_BASE + "illegalAlgorithm.xml"); - Transform tr = - transformParser.parseTransform(transform.getDocumentElement()); - factory.createTransformation(tr); - fail(); - } catch (MOAApplicationException e) { - } - } - - public void testEqualsXslt() throws Exception { - Document xslt = parseXml(TESTDATA_BASE + "xslt.xml"); - Transform tr = transformParser.parseTransform(xslt.getDocumentElement()); - Transformation trXslt = factory.createTransformation(tr); - - Document xsltEqu = parseXml(TESTDATA_BASE + "xsltEqual.xml"); - tr = transformParser.parseTransform(xsltEqu.getDocumentElement()); - Transformation trXsltEqu = factory.createTransformation(tr); - - Document xsltDiff = parseXml(TESTDATA_BASE + "xsltDifferent.xml"); - tr = transformParser.parseTransform(xsltDiff.getDocumentElement()); - Transformation trXsltDiff = factory.createTransformation(tr); - - Document canonicalization = - parseXml(TESTDATA_BASE + "canonicalization.xml"); - - assertTrue(trXslt.equals(trXsltEqu)); - assertFalse(trXslt.equals(trXsltDiff)); - assertFalse(trXsltEqu.equals(trXsltDiff)); - assertEquals(trXslt.hashCode(), trXsltEqu.hashCode()); - assertFalse(trXslt.hashCode() == trXsltDiff.hashCode()); - assertFalse(trXsltEqu.hashCode() == trXsltDiff.hashCode()); - assertFalse(trXslt.equals(canonicalization)); - } - - public void testEqualsXPath() throws Exception { - Document xpath = parseXml(TESTDATA_BASE + "xpath.xml"); - Transform tr = transformParser.parseTransform(xpath.getDocumentElement()); - Transformation trXpath = factory.createTransformation(tr); - Transformation trXpathEqu = factory.createTransformation(tr); - - Document xpathDiff = parseXml(TESTDATA_BASE + "xpathDifferent.xml"); - tr = transformParser.parseTransform(xpathDiff.getDocumentElement()); - Transformation trXpathDiff = factory.createTransformation(tr); - - assertTrue(trXpath.equals(trXpathEqu)); - assertEquals(trXpath.hashCode(), trXpathEqu.hashCode()); - assertFalse(trXpath.equals(trXpathDiff)); - assertFalse(trXpath.hashCode() == trXpathDiff.hashCode()); - } - - public void testEqualsXPath2() throws Exception { - Document xpath2 = parseXml(TESTDATA_BASE + "xpath2.xml"); - Transform tr = transformParser.parseTransform(xpath2.getDocumentElement()); - Transformation trXpath2 = factory.createTransformation(tr); - Transformation trXpath2Equ = factory.createTransformation(tr); - - Document xpath2Diff = parseXml(TESTDATA_BASE + "xpath2Different.xml"); - tr = transformParser.parseTransform(xpath2Diff.getDocumentElement()); - Transformation trXpath2Diff = factory.createTransformation(tr); - - assertTrue(trXpath2.equals(trXpath2Equ)); - assertEquals(trXpath2.hashCode(), trXpath2Equ.hashCode()); - assertFalse(trXpath2.equals(trXpath2Diff)); - assertFalse(trXpath2.hashCode() == trXpath2Diff.hashCode()); - } - - public void testCreateTransformationList() throws Exception { - Document transforms = parseXml(TESTDATA_BASE + "transforms.xml"); - List trs = transformParser.parseTransforms(transforms.getDocumentElement()); - List transformationList = factory.createTransformationList(trs); - - assertEquals(3, transformationList.size()); - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvokerTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvokerTest.java deleted file mode 100644 index 28cd3805a..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvokerTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.invoke; - -import java.util.Collections; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import at.gv.egovernment.moa.util.DOMUtils; - -import at.gv.egovernment.moa.spss.api.xmlbind.CreateXMLSignatureRequestParser; -import at.gv.egovernment.moa.spss.api.xmlbind.CreateXMLSignatureResponseBuilder; -import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureRequest; -import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureResponse; -import at.gv.egovernment.moa.spss.server.invoke.XMLSignatureCreationInvoker; - -/** - * Mainly a smoke test for debugging the XMLSignatureCreationInvoker. - * - * @author Patrick Peck - * @version $Id$ - */ -public class XMLSignatureCreationInvokerTest extends SPSSTestCase { - private static final String TESTDATA_BASE = - TESTDATA_ROOT + "xml/CreateXMLSignature/"; - - public XMLSignatureCreationInvokerTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - setUpTransactionContext(); - setUpLoggingContext(); - setUpIaikConfiguration(); - setUpSSL(); - } - - public void testCreateXMLSignature() throws Exception { - try { - XMLSignatureCreationInvoker invoker = - XMLSignatureCreationInvoker.getInstance(); - CreateXMLSignatureRequestParser requestParser = - new CreateXMLSignatureRequestParser(); - Document doc = - SPSSTestCase.parseXmlValidating( - TESTDATA_BASE + "TestGeneratorCX2.004.Req.xml"); - CreateXMLSignatureRequest request = - requestParser.parse(doc.getDocumentElement()); - CreateXMLSignatureResponse response = - invoker.createXMLSignature(request, Collections.EMPTY_SET); - CreateXMLSignatureResponseBuilder responseBuilder = - new CreateXMLSignatureResponseBuilder(); - Element result = responseBuilder.build(response).getDocumentElement(); - - System.out.println(DOMUtils.serializeNode(result)); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - } - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvokerTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvokerTest.java deleted file mode 100644 index 56e3d541b..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvokerTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.invoke; - -import org.w3c.dom.Document; - -import test.at.gv.egovernment.moa.spss.SPSSTestCase; - -import at.gv.egovernment.moa.util.DOMUtils; - -import at.gv.egovernment.moa.spss.api.xmlbind.VerifyXMLSignatureRequestParser; -import at.gv.egovernment.moa.spss.api.xmlbind.VerifyXMLSignatureResponseBuilder; -import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureRequest; -import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureResponse; -import at.gv.egovernment.moa.spss.server.invoke.XMLSignatureVerificationInvoker; - -/** - * Mainly a smoke test for debugging the XMLSignatureVerificationInvoker. - * - * @author Patrick Peck - * @version $Id$ - */ -public class XMLSignatureVerificationInvokerTest extends SPSSTestCase { - private static final String TESTDATA_BASE = - TESTDATA_ROOT + "xml/VerifyXMLSignature/"; - - public XMLSignatureVerificationInvokerTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - setUpTransactionContext(); - setUpLoggingContext(); - setUpIaikConfiguration(); - } - - public void testVerifyXMLSignature() throws Exception { - try { - XMLSignatureVerificationInvoker invoker = - XMLSignatureVerificationInvoker.getInstance(); - VerifyXMLSignatureRequestParser requestParser = - new VerifyXMLSignatureRequestParser(); - VerifyXMLSignatureResponseBuilder responseBuilder = - new VerifyXMLSignatureResponseBuilder(); - Document doc = - SPSSTestCase.parseXmlValidating( - TESTDATA_BASE + "TestGeneratorVX.201.Req.xml"); - - VerifyXMLSignatureRequest request = - requestParser.parse(doc.getDocumentElement()); - VerifyXMLSignatureResponse response; - - response = invoker.verifyXMLSignature(request); - System.out.println( - DOMUtils.serializeNode(responseBuilder.build(response))); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - } - - -} diff --git a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/tools/CertToolTest.java b/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/tools/CertToolTest.java deleted file mode 100644 index b46c20086..000000000 --- a/spss/server/serverlib/src/test/at/gv/egovernment/moa/spss/server/tools/CertToolTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package test.at.gv.egovernment.moa.spss.server.tools; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; - -import at.gv.egovernment.moa.spss.server.tools.CertTool; - -import test.at.gv.egovernment.moa.MOATestCase; - -/** - * Tests for the CertTool. - * - * @author Patrick Peck - * @version $Id$ - */ -public class CertToolTest extends MOATestCase { - - private static final String EXPECTED_RESULT = - "SubjectDN (RFC2253):" - + " CN=Patrick Peck,OU=MOA Team,O=BRZ,L=Vienna,ST=Vienna,C=AT\r\n" - + "IssuerDN (RFC2253) :" - + " CN=Patrick Peck,OU=MOA Team,O=BRZ,L=Vienna,ST=Vienna,C=AT\r\n" - + "Serial Number :" - + " 1047548672\r\n"; - private CertTool certTool; - - /** - * Constructor for CertToolTest. - * @param name - */ - public CertToolTest(String name) { - super(name); - } - - protected void setUp() { - certTool = new CertTool(); - } - - public void testPrintCertInfo() { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - PrintStream ps = new PrintStream(bos); - String result; - - certTool.printCertInfo(TESTDATA_ROOT + "security/server.cer", ps); - result = new String(bos.toByteArray()); - System.out.println(result); - assertEquals(EXPECTED_RESULT, result); - } - -} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/AllTests.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/AllTests.java new file mode 100644 index 000000000..c670b5e55 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/AllTests.java @@ -0,0 +1,40 @@ +package test.at.gv.egovernment.moa.spss; + +import test.at.gv.egovernment.moa.spss.server.iaik.config.ConfigurationDataImplTest; +import test.at.gv.egovernment.moa.spss.server.iaik.config.IaikConfiguratorTest; +import test.at.gv.egovernment.moa.spss.server.tools.CertToolTest; + +import junit.awtui.TestRunner; +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite for all unit tests. + * + * @author Patrick Peck + * @version $Id$ + */ +public class AllTests { + + public static Test suite() { + TestSuite suite = new TestSuite(); + + suite.addTestSuite(test.at.gv.egovernment.moa.spss.server.config.AllTests.class); + suite.addTestSuite(ConfigurationDataImplTest.class); + suite.addTestSuite(IaikConfiguratorTest.class); + suite.addTest( + test.at.gv.egovernment.moa.spss.server.invoke.AllTests.suite()); + suite.addTest(test.at.gv.egovernment.moa.spss.api.xmlbind.AllTests.suite()); + suite.addTestSuite(CertToolTest.class); + + return suite; + } + + public static void main(String[] args) { + try { + TestRunner.run(AllTests.class); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/SPSSTestCase.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/SPSSTestCase.java new file mode 100644 index 000000000..a585e30a0 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/SPSSTestCase.java @@ -0,0 +1,82 @@ +package test.at.gv.egovernment.moa.spss; + +import java.security.Security; + +import test.at.gv.egovernment.moa.MOATestCase; + +import at.gv.egovernment.moa.logging.Logger; +import at.gv.egovernment.moa.logging.LoggingContext; +import at.gv.egovernment.moa.logging.LoggingContextManager; +import at.gv.egovernment.moa.util.MessageProvider; + +import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; +import at.gv.egovernment.moa.spss.server.iaik.config.IaikConfigurator; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; + +/** + * Base class for MOA test cases. + * + * Provides some utility functions. + * + * @author Patrick Peck + * @version $Id$ + */ +public class SPSSTestCase extends MOATestCase { + + protected static final String TESTDATA_ROOT = "data/test/"; + + /** + * Constructor for MOATestCase. + * @param arg0 + */ + public SPSSTestCase(String name) { + super(name); + } + + /** + * Set up a transaction context with a test configuration. + */ + protected void setUpTransactionContext() throws Exception { + System.setProperty( + ConfigurationProvider.CONFIG_PROPERTY_NAME, + "data/test/conf/moa-spss/MOA-SPSSConfiguration.xml"); + ConfigurationProvider config = ConfigurationProvider.getInstance(); + TransactionContext context = new TransactionContext("test", null, config); + TransactionContextManager.getInstance().setTransactionContext(context); + } + + protected void setUpLoggingContext() throws Exception { + LoggingContext context = new LoggingContext("test"); + LoggingContextManager.getInstance().setLoggingContext(context); + } + + /** + * Configure the IAIK modules with the current configuration. + * + * A TransactionContext must have been set up before. + */ + protected void setUpIaikConfiguration() throws Exception { + TransactionContext context = + TransactionContextManager.getInstance().getTransactionContext(); + ClassLoader cl = getClass().getClassLoader(); + MessageProvider msg = MessageProvider.getInstance(); + + try { + cl.loadClass("javax.security.cert.Certificate"); // from jcert.jar + } catch (ClassNotFoundException e) { + Logger.warn(msg.getMessage("init.03", null), e); + } + + new IaikConfigurator().configure(context.getConfiguration()); + } + + protected void setUpSSL() 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"); + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/AllTests.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/AllTests.java new file mode 100644 index 000000000..28f79729e --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/AllTests.java @@ -0,0 +1,24 @@ +package test.at.gv.egovernment.moa.spss.api.xmlbind; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Runs all tests in this package. + * + * @author Patrick Peck + * @version $Id$ + */ +public class AllTests { + public static Test suite() { + TestSuite suite = new TestSuite(); + + suite.addTestSuite(CreateXMLSignatureRequestParserTest.class); + suite.addTestSuite(TransformParserTest.class); + suite.addTestSuite(VerifyCMSSignatureRequestParserTest.class); + suite.addTestSuite(VerifyXMLSignatureRequestParserTest.class); + + return suite; + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateXMLSignatureRequestParserTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateXMLSignatureRequestParserTest.java new file mode 100644 index 000000000..7ce705b01 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateXMLSignatureRequestParserTest.java @@ -0,0 +1,71 @@ +package test.at.gv.egovernment.moa.spss.api.xmlbind; + +import org.w3c.dom.Element; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import at.gv.egovernment.moa.spss.api.xmlbind.CreateXMLSignatureRequestParser; +import at.gv.egovernment.moa.spss.api.xmlsign.CreateSignatureEnvironmentProfileExplicit; +import at.gv.egovernment.moa.spss.api.xmlsign.CreateTransformsInfoProfileExplicit; +import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureRequest; +import at.gv.egovernment.moa.spss.api.xmlsign.DataObjectInfo; +import at.gv.egovernment.moa.spss.api.xmlsign.SingleSignatureInfo; + +/** + * Test the CreateXMLSignatureRequestParser. + * + * @author Patrick Peck + * @version $Id$ + */ +public class CreateXMLSignatureRequestParserTest extends SPSSTestCase { + private static final String TESTDATA_BASE = + TESTDATA_ROOT + "xml/CreateXMLSignature/"; + + private CreateXMLSignatureRequestParser requestParser; + + public CreateXMLSignatureRequestParserTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + requestParser = new CreateXMLSignatureRequestParser(); + } + + public void testParse() throws Exception { + Element requestElem = + parseXml(TESTDATA_BASE + "TestGeneratorCX2.001.Req.xml") + .getDocumentElement(); + CreateXMLSignatureRequest request = requestParser.parse(requestElem); + SingleSignatureInfo sigInfo; + DataObjectInfo dataObjInfo; + CreateTransformsInfoProfileExplicit transProfile; + CreateSignatureEnvironmentProfileExplicit envProfile; + + assertNotNull(request); + assertEquals("PKCS12RSAKey1", request.getKeyIdentifier()); + assertEquals(1, request.getSingleSignatureInfos().size()); + + sigInfo = (SingleSignatureInfo) request.getSingleSignatureInfos().get(0); + assertEquals(1, sigInfo.getDataObjectInfos().size()); + assertFalse(sigInfo.isSecurityLayerConform()); + + dataObjInfo = (DataObjectInfo) sigInfo.getDataObjectInfos().get(0); + assertNotNull(dataObjInfo.getDataObject()); + + transProfile = + (CreateTransformsInfoProfileExplicit) dataObjInfo + .getCreateTransformsInfoProfile(); + assertNotNull( + transProfile.getCreateTransformsInfo().getFinalDataMetaInfo()); + + envProfile = + (CreateSignatureEnvironmentProfileExplicit) sigInfo + .getCreateSignatureInfo() + .getCreateSignatureEnvironmentProfile(); + assertEquals( + "//data:Document", + envProfile.getCreateSignatureLocation().getXPathExpression()); + assertEquals(0, envProfile.getCreateSignatureLocation().getIndex()); + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/TransformParserTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/TransformParserTest.java new file mode 100644 index 000000000..f580f86bc --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/TransformParserTest.java @@ -0,0 +1,113 @@ +package test.at.gv.egovernment.moa.spss.api.xmlbind; + +import java.util.List; + +import org.w3c.dom.Element; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import at.gv.egovernment.moa.spss.api.common.CanonicalizationTransform; +import at.gv.egovernment.moa.spss.api.common.EnvelopedSignatureTransform; +import at.gv.egovernment.moa.spss.api.common.ExclusiveCanonicalizationTransform; +import at.gv.egovernment.moa.spss.api.common.XPathFilter2Transform; +import at.gv.egovernment.moa.spss.api.common.XPathTransform; +import at.gv.egovernment.moa.spss.api.common.XSLTTransform; +import at.gv.egovernment.moa.spss.api.xmlbind.TransformParser; + +/** + * Test the TransformParser. + * + * @author Patrick Peck + * @version $Id$ + */ +public class TransformParserTest extends SPSSTestCase { + private static String TESTDATA_BASE = TESTDATA_ROOT + "xml/dsigTransform/"; + + private TransformParser transformParser; + + public TransformParserTest(String name) { + super(name); + } + + protected void setUp() { + transformParser = new TransformParser(); + } + + public void testParseTransforms() throws Exception { + Element transformsElem = + parseXml(TESTDATA_BASE + "transforms.xml").getDocumentElement(); + List transforms = transformParser.parseTransforms(transformsElem); + + assertNotNull(transforms); + assertEquals(3, transforms.size()); + + } + + public void testParseCanonicalizationTransform() throws Exception { + Element transformElem = + parseXml(TESTDATA_BASE + "canonicalization.xml").getDocumentElement(); + CanonicalizationTransform transform = + (CanonicalizationTransform) transformParser.parseTransform(transformElem); + + assertNotNull(transform); + assertEquals( + CanonicalizationTransform.CANONICAL_XML, + transform.getAlgorithmURI()); + } + + public void testParseExclCanonicalizationTransform() throws Exception { + Element transformElem = + parseXml(TESTDATA_BASE + "exclusiveCanonicalization.xml") + .getDocumentElement(); + ExclusiveCanonicalizationTransform transform = + (ExclusiveCanonicalizationTransform) transformParser.parseTransform( + transformElem); + + assertNotNull(transform); + assertEquals( + ExclusiveCanonicalizationTransform.EXCLUSIVE_CANONICAL_XML, + transform.getAlgorithmURI()); + assertEquals(3, transform.getInclusiveNamespacePrefixes().size()); + } + + public void testParseEnvelopedTransform() throws Exception { + Element transformElem = + parseXml(TESTDATA_BASE + "enveloped.xml").getDocumentElement(); + EnvelopedSignatureTransform transform = + (EnvelopedSignatureTransform) transformParser.parseTransform( + transformElem); + + assertNotNull(transform); + } + + public void testParseXPathTransform() throws Exception { + Element transformElem = + parseXml(TESTDATA_BASE + "xpath.xml").getDocumentElement(); + XPathTransform transform = + (XPathTransform) transformParser.parseTransform(transformElem); + + assertNotNull(transform); + assertEquals("//ToBeSigned/Data", transform.getXPathExpression()); + assertEquals(1, transform.getNamespaceDeclarations().size()); + } + + public void testParseXPathFilter2Transform() throws Exception { + Element transformElem = + parseXml(TESTDATA_BASE + "xpath2.xml").getDocumentElement(); + XPathFilter2Transform transform = + (XPathFilter2Transform) transformParser.parseTransform(transformElem); + + assertNotNull(transform); + assertEquals(3, transform.getFilters().size()); + } + + public void testParseXSLTTransform() throws Exception { + Element transformElem = + parseXml(TESTDATA_BASE + "xslt.xml").getDocumentElement(); + XSLTTransform transform = + (XSLTTransform) transformParser.parseTransform(transformElem); + + assertNotNull(transform); + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/VerifyCMSSignatureRequestParserTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/VerifyCMSSignatureRequestParserTest.java new file mode 100644 index 000000000..4be7667eb --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/VerifyCMSSignatureRequestParserTest.java @@ -0,0 +1,61 @@ +package test.at.gv.egovernment.moa.spss.api.xmlbind; + +import org.w3c.dom.Element; + +import at.gv.egovernment.moa.util.DateTimeUtils; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import at.gv.egovernment.moa.spss.api.cmsverify.CMSContentExcplicit; +import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureRequest; +import at.gv.egovernment.moa.spss.api.common.MetaInfo; +import at.gv.egovernment.moa.spss.api.xmlbind.VerifyCMSSignatureRequestParser; + +/** + * Test the VerifyCMSSignatureRequestParserTest. + * + * @author Patrick Peck + * @version $Id$ + */ +public class VerifyCMSSignatureRequestParserTest extends SPSSTestCase { + private static String TESTDATA_BASE = + TESTDATA_ROOT + "xml/VerifyCMSSignature/"; + + private VerifyCMSSignatureRequestParser requestParser; + + public VerifyCMSSignatureRequestParserTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + requestParser = new VerifyCMSSignatureRequestParser(); + } + + public void testParse() throws Exception { + Element requestElem = + parseXml(TESTDATA_BASE + "TestGeneratorVC0.001.Req.xml") + .getDocumentElement(); + VerifyCMSSignatureRequest request = requestParser.parse(requestElem); + MetaInfo metaInfo; + CMSContentExcplicit content; + + assertNotNull(request); + assertEquals(1, request.getSignatories()[0]); + assertEquals( + DateTimeUtils.parseDateTime("2003-04-04T09:30:47-05:00"), + request.getDateTime()); + assertNotNull(request.getCMSSignature()); + assertNotNull(request.getDataObject()); + assertEquals("TrustProfile1", request.getTrustProfileId()); + + metaInfo = request.getDataObject().getMetaInfo(); + assertNotNull(metaInfo); + assertEquals("text/plain", metaInfo.getMimeType()); + assertEquals("http://10.16.46.109/TestDatenGenerator/resources/testDaten.txt", metaInfo.getDescription()); + + content = (CMSContentExcplicit) request.getDataObject().getContent(); + assertNotNull(content.getBinaryContent()); + + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/VerifyXMLSignatureRequestParserTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/VerifyXMLSignatureRequestParserTest.java new file mode 100644 index 000000000..3b8e8b00e --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/api/xmlbind/VerifyXMLSignatureRequestParserTest.java @@ -0,0 +1,81 @@ +package test.at.gv.egovernment.moa.spss.api.xmlbind; + +import org.w3c.dom.Element; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import at.gv.egovernment.moa.util.DateTimeUtils; + +import at.gv.egovernment.moa.spss.api.xmlbind.VerifyXMLSignatureRequestParser; +import at.gv.egovernment.moa.spss.api.xmlverify.ReferenceInfo; +import at.gv.egovernment.moa.spss.api.xmlverify.SignatureManifestCheckParams; +import at.gv.egovernment.moa.spss.api.xmlverify.VerifySignatureInfo; +import at.gv.egovernment.moa.spss.api.xmlverify.VerifySignatureLocation; +import at.gv.egovernment.moa.spss.api.xmlverify.VerifyTransformsInfoProfileExplicit; +import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureRequest; + +/** + * Test the VerifyXMLSignatureRequestParserTest. + * + * @author Patrick Peck + * @version $Id$ + */ +public class VerifyXMLSignatureRequestParserTest extends SPSSTestCase { + private static String TESTDATA_BASE = + TESTDATA_ROOT + "xml/VerifyXMLSignature/"; + + private VerifyXMLSignatureRequestParser parser; + + public VerifyXMLSignatureRequestParserTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + parser = new VerifyXMLSignatureRequestParser(); + } + + public void testParse() throws Exception { + Element requestElem = + parseXml(TESTDATA_BASE + "TestGeneratorVX.201.Req.xml") + .getDocumentElement(); + VerifyXMLSignatureRequest request = parser.parse(requestElem); + VerifySignatureInfo verifySignatureInfo; + VerifySignatureLocation verifyLocation; + SignatureManifestCheckParams checkParams; + ReferenceInfo refInfo; + VerifyTransformsInfoProfileExplicit transformsProfile; + + assertNotNull(request); + assertEquals( + DateTimeUtils.parseDateTime("2003-04-01T12:53:57+01:00"), + request.getDateTime()); + assertFalse(request.getReturnHashInputData()); + assertEquals("TrustProfile1", request.getTrustProfileId()); + + verifySignatureInfo = request.getSignatureInfo(); + assertNotNull(verifySignatureInfo); + assertNotNull(verifySignatureInfo.getVerifySignatureEnvironment()); + + verifyLocation = verifySignatureInfo.getVerifySignatureLocation(); + assertNotNull(verifyLocation); + assertEquals("//dsig:Signature", verifyLocation.getXPathExpression()); + assertEquals(3, verifyLocation.getNamespaceDeclarations().size()); + + checkParams = request.getSignatureManifestCheckParams(); + assertNotNull(checkParams); + assertEquals(true, checkParams.getReturnReferenceInputData()); + assertEquals(1, checkParams.getReferenceInfos().size()); + + refInfo = (ReferenceInfo) checkParams.getReferenceInfos().get(0); + assertEquals(1, refInfo.getVerifyTransformsInfoProfiles().size()); + + transformsProfile = + (VerifyTransformsInfoProfileExplicit) refInfo + .getVerifyTransformsInfoProfiles() + .get(0); + assertEquals(1, transformsProfile.getTransforms().size()); + assertEquals(1, transformsProfile.getTransformParameters().size()); + + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/AllTests.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/AllTests.java new file mode 100644 index 000000000..131f38c19 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/AllTests.java @@ -0,0 +1,20 @@ +package test.at.gv.egovernment.moa.spss.server.config; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * @author Gregor Karlinger + * @version $Id$ + */ +public class AllTests +{ + public static Test suite() + { + TestSuite suite = new TestSuite(); + suite.addTestSuite(ConfigurationProviderTest1.class); + suite.addTestSuite(ConfigurationProviderTest2.class); + suite.addTestSuite(ConfigurationProviderTest3.class); + return suite; + } +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest1.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest1.java new file mode 100644 index 000000000..474a387ad --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest1.java @@ -0,0 +1,377 @@ +package test.at.gv.egovernment.moa.spss.server.config; + +import iaik.asn1.structures.Name; +import iaik.pki.pathvalidation.ChainingModes; +import iaik.utils.RFC2253NameParser; +import iaik.utils.RFC2253NameParserException; +import iaik.x509.X509Certificate; + +import java.math.BigInteger; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import junit.framework.TestCase; + +import org.w3c.dom.Element; + +import at.gv.egovernment.moa.spss.MOAException; +import at.gv.egovernment.moa.spss.server.config.CRLDistributionPoint; +import at.gv.egovernment.moa.spss.server.config.ConfigurationException; +import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; +import at.gv.egovernment.moa.spss.server.config.HardwareCryptoModule; +import at.gv.egovernment.moa.spss.server.config.HardwareKeyModule; +import at.gv.egovernment.moa.spss.server.config.KeyGroup; +import at.gv.egovernment.moa.spss.server.config.KeyGroupEntry; +import at.gv.egovernment.moa.spss.server.config.OCSPDistributionPoint; +import at.gv.egovernment.moa.spss.server.config.SoftwareKeyModule; +import at.gv.egovernment.moa.spss.server.config.TrustProfile; +import at.gv.egovernment.moa.util.Constants; + +/** + * @author Gregor Karlinger + * @version $Id$ + */ +public class ConfigurationProviderTest1 extends TestCase +{ + private static final String CONFIG_BASE_ = + "e:/cio/projekte/basismodule/wartung/projekt/spss.server/res/test/resources/config/"; + + static at.gv.egovernment.moa.spss.server.config.ConfigurationProvider provider_; + + static + { + System.setProperty( + "log4j.configuration", + "file:/" + CONFIG_BASE_ + "log4j.properties"); + System.setProperty( + at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.CONFIG_PROPERTY_NAME, + CONFIG_BASE_ + "moa.spss.complete-config.xml"); + try + { + ConfigurationProvider.reload(); + provider_ = at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.getInstance(); + } + catch (ConfigurationException e) + { + throw new RuntimeException("Fehler beim Setup des Tests: " + e.getMessage()); + } + } + + /** + * Constructor for ConfigurationProvider. + * @param arg0 + */ + public ConfigurationProviderTest1() throws MOAException + { + super("ConfigurationProvider"); + } + + public void testGetWarnings() + { + assertEquals(0, provider_.getWarnings().size()); + } + + public void testGetDigestMethodAlgorithmName() + { + assertEquals( + Constants.SHA1_URI, + provider_.getDigestMethodAlgorithmName()); + } + + public void testGetCanonicalizationAlgorithmName() + { + assertEquals( + Constants.C14N_WITH_COMMENTS_URI, + provider_.getCanonicalizationAlgorithmName()); + } + + public void testGetHardwareCryptoModules() + { + List hwcms = provider_.getHardwareCryptoModules(); + assertEquals(2, hwcms.size()); + + HardwareCryptoModule hwc1 = (HardwareCryptoModule) hwcms.get(0); + assertEquals("HWC1_Name", hwc1.getName()); + assertEquals("HWC1_SlotId", hwc1.getSlotID()); + assertEquals("HWC1_UserPIN", hwc1.getUserPIN()); + + HardwareCryptoModule hwc2 = (HardwareCryptoModule) hwcms.get(1); + assertEquals("HWC2_Name", hwc2.getName()); + assertNull(hwc2.getSlotID()); + assertEquals("HWC2_UserPIN", hwc2.getUserPIN()); + } + + public void testGetHardwareKeyModules() + { + List hwkms = provider_.getHardwareKeyModules(); + assertEquals(2, hwkms.size()); + + HardwareKeyModule hwk1 = (HardwareKeyModule) hwkms.get(0); + assertEquals("HWK1_Id", hwk1.getId()); + assertEquals("HWK1_Name", hwk1.getName()); + assertEquals("HWK1_SlotId", hwk1.getSlotID()); + assertEquals("HWK1_UserPIN", hwk1.getUserPIN()); + + HardwareKeyModule hwk2 = (HardwareKeyModule) hwkms.get(1); + assertEquals("HWK2_Id", hwk2.getId()); + assertEquals("HWK2_Name", hwk2.getName()); + assertNull(hwk2.getSlotID()); + assertEquals("HWK2_UserPIN", hwk2.getUserPIN()); + } + + public void testGetSoftwareKeyModules() + { + List swkms = provider_.getSoftwareKeyModules(); + assertEquals(2, swkms.size()); + + SoftwareKeyModule swk1 = (SoftwareKeyModule) swkms.get(0); + assertEquals("SWK1_Id", swk1.getId()); + assertEquals(CONFIG_BASE_ + "swk/SWK1_FileName.txt", swk1.getFileName().replace('\\', '/')); + assertEquals("SWK1_Password", swk1.getPassWord()); + + SoftwareKeyModule swk2 = (SoftwareKeyModule) swkms.get(1); + assertEquals("SWK2_Id", swk2.getId()); + assertEquals(CONFIG_BASE_ + "swk/SWK2_FileName.txt", swk2.getFileName().replace('\\', '/')); + assertNull(swk2.getPassWord()); + } + + public void testGetKeyGroups() + { + Map keyGroups = provider_.getKeyGroups(); + assertEquals(2, keyGroups.size()); + + KeyGroup kg1 = (KeyGroup) keyGroups.get("KG1_Id"); + assertNotNull(kg1); + assertEquals("KG1_Id", kg1.getId()); + + Set kg1Entries = kg1.getKeyGroupEntries(); + assertEquals(2, kg1Entries.size()); + + Iterator kg1EntriesIt = kg1Entries.iterator(); + while(kg1EntriesIt.hasNext()) + { + KeyGroupEntry currentEntry = (KeyGroupEntry)kg1EntriesIt.next(); + if ("HWK1_Id".equals(currentEntry.getModuleID())) + { + assertEquals("CN=HWK1_Issuer", currentEntry.getIssuerDN()); + assertEquals(0, currentEntry.getSerialNumber().intValue()); + } + else if ("HWK2_Id".equals(currentEntry.getModuleID())) + { + assertEquals("CN=HWK2_Issuer", currentEntry.getIssuerDN()); + assertEquals(1, currentEntry.getSerialNumber().intValue()); + } + else fail("Invalid module identifer found."); + } + + KeyGroup kg2 = (KeyGroup) keyGroups.get("KG2_Id"); + assertNotNull(kg2); + assertEquals("KG2_Id", kg2.getId()); + + Set kg2Entries = kg2.getKeyGroupEntries(); + assertEquals(2, kg2Entries.size()); + + Iterator kg2EntriesIt = kg1Entries.iterator(); + while(kg1EntriesIt.hasNext()) + { + KeyGroupEntry currentEntry = (KeyGroupEntry)kg2EntriesIt.next(); + if ("SWK1_Id".equals(currentEntry.getModuleID())) + { + assertEquals("CN=CN=SWK1_Issuer", currentEntry.getIssuerDN()); + assertEquals(2, currentEntry.getSerialNumber().intValue()); + } + else if ("SWK2_Id".equals(currentEntry.getModuleID())) + { + assertEquals("CN=SWK2_Issuer", currentEntry.getIssuerDN()); + assertEquals(3, currentEntry.getSerialNumber().intValue()); + } + else fail("Invalid module identifer found."); + } + } + + public void testGetKeyGroupEntries() throws RFC2253NameParserException + { + RFC2253NameParser parser = new RFC2253NameParser("CN=Customer1_Issuer"); + Name name = parser.parse(); + Set kgEntries = provider_.getKeyGroupEntries(name, BigInteger.valueOf(4), "KG1_Id"); + assertEquals(2, kgEntries.size()); + + Iterator kgEntriesIt = kgEntries.iterator(); + while (kgEntriesIt.hasNext()) + { + KeyGroupEntry currentEntry = (KeyGroupEntry) kgEntriesIt.next(); + if (!"HWK1_Id".equals(currentEntry.getModuleID()) && !"HWK2_Id".equals(currentEntry.getModuleID())) + { + fail("Invalid module identifier found."); + } + } + } + + public void testGetChainingMode() throws RFC2253NameParserException + { + X509Certificate cert = new X509Certificate(); + RFC2253NameParser parser = new RFC2253NameParser("CN=Unknown"); + Name name = parser.parse(); + cert.setIssuerDN(name); + cert.setSerialNumber(BigInteger.valueOf(0)); + assertEquals(ChainingModes.PKIX_MODE, provider_.getChainingMode(cert)); // Default chaining mode + + parser = new RFC2253NameParser("CN=TA1_Issuer"); + name = parser.parse(); + cert.setIssuerDN(name); + cert.setSerialNumber(BigInteger.valueOf(5)); + assertEquals(ChainingModes.CHAIN_MODE, provider_.getChainingMode(cert)); + } + + public void testGetDistributionPoints() throws RFC2253NameParserException + { + X509Certificate cert = new X509Certificate(); + RFC2253NameParser parser = new RFC2253NameParser("CN=DP1_Issuer"); + Name name = parser.parse(); + cert.setIssuerDN(name); + + Set dps = provider_.getDistributionPoints(cert); + assertEquals(2, dps.size()); + + Iterator dpIt = dps.iterator(); + while (dpIt.hasNext()) + { + CRLDistributionPoint currentDP = (CRLDistributionPoint)dpIt.next(); + if ("http://crl.myca.org".equals(currentDP.getUri())) + { + int reasonCodes = + iaik.asn1.structures.DistributionPoint.unused | + iaik.asn1.structures.DistributionPoint.keyCompromise | + iaik.asn1.structures.DistributionPoint.cACompromise | + iaik.asn1.structures.DistributionPoint.affiliationChanged | + iaik.asn1.structures.DistributionPoint.superseded | + iaik.asn1.structures.DistributionPoint.cessationOfOperation | + iaik.asn1.structures.DistributionPoint.certificateHold | + iaik.asn1.structures.DistributionPoint.privilegeWithdrawn | + iaik.asn1.structures.DistributionPoint.aACompromise; + assertEquals(reasonCodes, currentDP.getReasonCodes()); + } + else if ("http://crl.myotherca.org".equals(currentDP.getUri())) + { + int reasonCodes = + iaik.asn1.structures.DistributionPoint.aACompromise | + iaik.asn1.structures.DistributionPoint.affiliationChanged; + assertEquals(reasonCodes, currentDP.getReasonCodes()); + } + else fail("Invalid CRL DP URI found: " + currentDP.getUri()); + } + + parser = new RFC2253NameParser("CN=DP2_Issuer"); + name = parser.parse(); + cert.setIssuerDN(name); + + dps = provider_.getDistributionPoints(cert); + assertEquals(1, dps.size()); + + OCSPDistributionPoint dpo = (OCSPDistributionPoint) dps.toArray()[0]; + assertEquals("http://crl.yetanotherca.org", dpo.getUri()); + } + + public void testGetCRLArchiveDuration() + { + assertEquals(730, provider_.getCRLArchiveDuration()); + } + + public void testGetEnableRevocationArchiving() + { + assertFalse(provider_.getEnableRevocationArchiving()); + } + + public void testGetCertStoreLocation() + { + assertEquals( + CONFIG_BASE_ + "certstore_test", + provider_.getCertStoreLocation().replace('\\', '/')); + } + + public void testGetCreateTransformsInfoProfile() + { + Element ctip1 = provider_.getCreateTransformsInfoProfile("CTIP_1"); + assertEquals("CreateTransformsInfoProfile", ctip1.getLocalName()); + + Element ctip2 = provider_.getCreateTransformsInfoProfile("CTIP_2"); + assertEquals("CreateTransformsInfoProfile", ctip2.getLocalName()); + } + + public void testGetCreateSignatureEnvironmentProfile() + { + Element csep = provider_.getCreateSignatureEnvironmentProfile("CSEP_1"); + assertEquals("CreateSignatureEnvironmentProfile", csep.getLocalName()); + } + + public void testGetVerifyTransformsInfoProfile() + { + Element vtip = provider_.getVerifyTransformsInfoProfile("VTIP_1"); + assertEquals("VerifyTransformsInfoProfile", vtip.getLocalName()); + } + + public void testGetSupplementProfile() + { + Element sp = provider_.getSupplementProfile("SP_1"); + assertEquals("SupplementProfile", sp.getLocalName()); + } + + public void testGetTrustProfile() + { + TrustProfile tp1 = provider_.getTrustProfile("TP1_Id"); + assertEquals( + "file:/" + CONFIG_BASE_ + "trustprofiles/tp1/anchors", + tp1.getUri()); + assertEquals( + "file:/" + CONFIG_BASE_ + "trustprofiles/tp1/signercerts", + tp1.getSignerCertsUri()); + + TrustProfile tp2 = provider_.getTrustProfile("TP2_Id"); + assertEquals( + "file:" + CONFIG_BASE_ + "trustprofiles/tp2/anchors", + tp2.getUri()); + assertEquals( + "file:" + CONFIG_BASE_ + "trustprofiles/tp2/signercerts", + tp2.getSignerCertsUri()); + } + + public void testGetRevocationArchiveJDBCURL() + { + assertEquals("jdbc://dummy", provider_.getRevocationArchiveJDBCURL()); + } + + public void testGetRevocationArchiveJDBCDriverClass() + { + assertEquals("fully.qualified.classname", provider_.getRevocationArchiveJDBCDriverClass()); + } + + public void testGetEnableRevocationChecking() + { + assertFalse(provider_.getEnableRevocationChecking()); + } + + public void testGetMaxRevocationAge() + { + assertEquals(10000, provider_.getMaxRevocationAge()); + } + + public void testGetServiceOrder() + { + String[] serviceOrder = provider_.getServiceOrder(); + assertEquals(2, serviceOrder.length); + assertEquals("crl", serviceOrder[0]); + assertEquals("ocsp", serviceOrder[1]); + } + + public void testGetAutoAddCertificates() + { + assertFalse(provider_.getAutoAddCertificates()); + } + + public void testGetUseAuthorityInfoAccess() + { + assertFalse(provider_.getUseAuthorityInfoAccess()); + } +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest2.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest2.java new file mode 100644 index 000000000..adf02809b --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest2.java @@ -0,0 +1,225 @@ +package test.at.gv.egovernment.moa.spss.server.config; + +import iaik.asn1.structures.Name; +import iaik.pki.pathvalidation.ChainingModes; +import iaik.utils.RFC2253NameParser; +import iaik.utils.RFC2253NameParserException; +import iaik.x509.X509Certificate; + +import java.math.BigInteger; +import java.util.List; +import java.util.Set; + +import junit.framework.TestCase; + +import org.w3c.dom.Element; + +import at.gv.egovernment.moa.spss.MOAException; +import at.gv.egovernment.moa.spss.server.config.ConfigurationException; +import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; +import at.gv.egovernment.moa.spss.server.config.TrustProfile; +import at.gv.egovernment.moa.util.Constants; + +/** + * @author Gregor Karlinger + * @version $Id$ + */ +public class ConfigurationProviderTest2 extends TestCase +{ + private static final String CONFIG_BASE_ = + "e:/cio/projekte/basismodule/wartung/projekt/spss.server/res/test/resources/config/"; + + static at.gv.egovernment.moa.spss.server.config.ConfigurationProvider provider_; + + static + { + System.setProperty( + "log4j.configuration", + "file:/" + CONFIG_BASE_ + "log4j.properties"); + System.setProperty( + at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.CONFIG_PROPERTY_NAME, + CONFIG_BASE_ + "moa.ss.noopts-config.xml"); + try + { + ConfigurationProvider.reload(); + provider_ = at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.getInstance(); + } + catch (ConfigurationException e) + { + throw new RuntimeException("Fehler beim Setup des Tests: " + e.getMessage()); + } + } + + + /** + * Constructor for ConfigurationProvider. + * @param arg0 + */ + public ConfigurationProviderTest2() throws MOAException + { + super("ConfigurationProvider"); + } + + public void testGetWarnings() + { + // 3 Warnings should be collected: C14N not found, DigestMethod not found, ArchiveDuration not found + assertEquals(3, provider_.getWarnings().size()); + } + + public void testGetDigestMethodAlgorithmName() + { + // Element is missing in config file, check if default value is returned + assertEquals( + Constants.SHA1_URI, + provider_.getDigestMethodAlgorithmName()); + } + + public void testGetCanonicalizationAlgorithmName() + { + // Element is missing in config file, check if default value is returned + assertEquals( + Constants.C14N_URI, + provider_.getCanonicalizationAlgorithmName()); + } + + public void testGetHardwareCryptoModules() + { + // No hardware crypto modules in config file, check for empty list + List hwcms = provider_.getHardwareCryptoModules(); + assertEquals(0, hwcms.size()); + } + + public void testGetHardwareKeyModules() + { + List hwkms = provider_.getHardwareKeyModules(); + assertEquals(1, hwkms.size()); + } + + public void testGetSoftwareKeyModules() + { + // No software key modules in config file, check for empty list + List swkms = provider_.getSoftwareKeyModules(); + assertEquals(0, swkms.size()); + } + + public void testGetChainingMode() throws RFC2253NameParserException + { + // Default Chaining Mode not set in configuration, check for default value + X509Certificate cert = new X509Certificate(); + RFC2253NameParser parser = new RFC2253NameParser("CN=Unknown"); + Name name = parser.parse(); + cert.setIssuerDN(name); + cert.setSerialNumber(BigInteger.valueOf(0)); + assertEquals(ChainingModes.PKIX_MODE, provider_.getChainingMode(cert)); + } + + public void testGetDistributionPoints() throws RFC2253NameParserException + { + // Element is missing in config file, check if emty list is returned + X509Certificate cert = new X509Certificate(); + RFC2253NameParser parser = new RFC2253NameParser("CN=DP1_Issuer"); + Name name = parser.parse(); + cert.setIssuerDN(name); + + Set dps = provider_.getDistributionPoints(cert); + assertEquals(0, dps.size()); + } + + public void testGetCRLArchiveDuration() + { + // Element is missing in config file, check if default value is returned + assertEquals(0, provider_.getCRLArchiveDuration()); + } + + public void testGetEnableRevocationArchiving() + { + // Element is missing in config file, check if default value is returned + assertFalse(provider_.getEnableRevocationArchiving()); + } + + public void testGetCertStoreLocation() + { + // Element is missing in config file, check if default value is returned + assertEquals( + CONFIG_BASE_ + "certstore", + provider_.getCertStoreLocation().replace('\\', '/')); + } + + public void testGetCreateTransformsInfoProfile() + { + // No profile in config file, check for null + Element ctip1 = provider_.getCreateTransformsInfoProfile("CTIP_1"); + assertNull(ctip1); + } + + public void testGetCreateSignatureEnvironmentProfile() + { + // No profile in config file, check for null + Element csep = provider_.getCreateSignatureEnvironmentProfile("CSEP_1"); + assertNull(csep); + } + + public void testGetVerifyTransformsInfoProfile() + { + // No profile in config file, check for null + Element vtip = provider_.getVerifyTransformsInfoProfile("VTIP_1"); + assertNull(vtip); + } + + public void testGetSupplementProfile() + { + // No profile in config file, check for null + Element sp = provider_.getSupplementProfile("SP_1"); + assertNull(sp); + } + + public void testGetTrustProfile() + { + // No trust profiles config file, check for null + TrustProfile tp1 = provider_.getTrustProfile("TP1_Id"); + assertNull(tp1); + } + + public void testGetRevocationArchiveJDBCURL() + { + // Element is missing in config file, check for null + assertNull(provider_.getRevocationArchiveJDBCURL()); + } + + public void testGetRevocationArchiveJDBCDriverClass() + { + // Element is missing in config file, check for null + assertNull(provider_.getRevocationArchiveJDBCDriverClass()); + } + + public void testGetEnableRevocationChecking() + { + // Element is missing in config file, check for default value + assertFalse(provider_.getEnableRevocationChecking()); + } + + public void testGetMaxRevocationAge() + { + // Element is missing in config file, check for default value + assertEquals(0, provider_.getMaxRevocationAge()); + } + + public void testGetServiceOrder() + { + // Element is missing in config file, check for empty array + String[] serviceOrder = provider_.getServiceOrder(); + assertEquals(0, serviceOrder.length); + } + + public void testGetAutoAddCertificates() + { + // Element is missing in config file, check for default value + assertFalse(provider_.getAutoAddCertificates()); + } + + public void testGetUseAuthorityInfoAccess() + { + // Element is missing in config file, check for default value + assertFalse(provider_.getUseAuthorityInfoAccess()); + } +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest3.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest3.java new file mode 100644 index 000000000..7da2165cb --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/config/ConfigurationProviderTest3.java @@ -0,0 +1,166 @@ +package test.at.gv.egovernment.moa.spss.server.config; + +import iaik.asn1.structures.Name; +import iaik.utils.RFC2253NameParser; +import iaik.utils.RFC2253NameParserException; +import iaik.x509.X509Certificate; + +import java.util.List; +import java.util.Set; + +import junit.framework.TestCase; + +import org.w3c.dom.Element; + +import at.gv.egovernment.moa.spss.MOAException; +import at.gv.egovernment.moa.spss.server.config.ConfigurationException; +import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; +import at.gv.egovernment.moa.util.Constants; + +/** + * @author Gregor Karlinger + * @version $Id$ + */ +public class ConfigurationProviderTest3 extends TestCase +{ + private static final String CONFIG_BASE_ = + "e:/cio/projekte/basismodule/wartung/projekt/spss.server/res/test/resources/config/"; + + static at.gv.egovernment.moa.spss.server.config.ConfigurationProvider provider_; + + static + { + System.setProperty( + "log4j.configuration", + "file:/" + CONFIG_BASE_ + "log4j.properties"); + System.setProperty( + at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.CONFIG_PROPERTY_NAME, + CONFIG_BASE_ + "moa.sp.noopts-config.xml"); + try + { + ConfigurationProvider.reload(); + provider_ = at.gv.egovernment.moa.spss.server.config.ConfigurationProvider.getInstance(); + } + catch (ConfigurationException e) + { + throw new RuntimeException("Fehler beim Setup des Tests: " + e.getMessage()); + } + } + + /** + * Constructor for ConfigurationProvider. + * @param arg0 + */ + public ConfigurationProviderTest3() throws MOAException + { + super("ConfigurationProvider"); + } + + public void testGetWarnings() + { + // 3 Warnings should be collected: C14N not found, DigestMethod not found, ArchiveDuration not found + assertEquals(3, provider_.getWarnings().size()); + } + + public void testGetDigestMethodAlgorithmName() + { + // Element is missing in config file, check if default value is returned + assertEquals( + Constants.SHA1_URI, + provider_.getDigestMethodAlgorithmName()); + } + + public void testGetCanonicalizationAlgorithmName() + { + // Element is missing in config file, check if default value is returned + assertEquals( + Constants.C14N_URI, + provider_.getCanonicalizationAlgorithmName()); + } + + public void testGetHardwareCryptoModules() + { + // No hardware crypto modules in config file, check for empty list + List hwcms = provider_.getHardwareCryptoModules(); + assertEquals(0, hwcms.size()); + } + + public void testGetHardwareKeyModules() + { + // No hardware key modules in config file, check for empty list + List hwkms = provider_.getHardwareKeyModules(); + assertEquals(0, hwkms.size()); + } + + public void testGetSoftwareKeyModules() + { + // No software key modules in config file, check for empty list + List swkms = provider_.getSoftwareKeyModules(); + assertEquals(0, swkms.size()); + } + + public void testGetDistributionPoints() throws RFC2253NameParserException + { + // No distribution points in config file, check for emtpy set + X509Certificate cert = new X509Certificate(); + RFC2253NameParser parser = new RFC2253NameParser("CN=DP1_Issuer"); + Name name = parser.parse(); + cert.setIssuerDN(name); + + Set dps = provider_.getDistributionPoints(cert); + assertEquals(0, dps.size()); + } + + public void testGetCRLArchiveDuration() + { + // No archive duration in config file, check for default value + assertEquals(0, provider_.getCRLArchiveDuration()); + } + + public void testGetCreateTransformsInfoProfile() + { + // No profile in config file, check for null + Element ctip1 = provider_.getCreateTransformsInfoProfile("CTIP_1"); + assertNull(ctip1); + } + + public void testGetCreateSignatureEnvironmentProfile() + { + // No profile in config file, check for null + Element csep = provider_.getCreateSignatureEnvironmentProfile("CSEP_1"); + assertNull(csep); + } + + public void testGetVerifyTransformsInfoProfile() + { + // No profile in config file, check for null + Element vtip = provider_.getVerifyTransformsInfoProfile("VTIP_1"); + assertNull(vtip); + } + + public void testGetSupplementProfile() + { + // No profile in config file, check for null + Element sp = provider_.getSupplementProfile("SP_1"); + assertNull(sp); + } + + public void testGetRevocationArchiveJDBCURL() + { + // No archive in config file, check for null + assertNull(provider_.getRevocationArchiveJDBCURL()); + } + + public void testGetRevocationArchiveJDBCDriverClass() + { + // No archive in config file, check for null + assertNull(provider_.getRevocationArchiveJDBCDriverClass()); + } + + public void testGetServiceOrder() + { + // Element is missing in config file, check for empty array + String[] serviceOrder = provider_.getServiceOrder(); + assertEquals(0, serviceOrder.length); + } +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/iaik/config/ConfigurationDataImplTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/iaik/config/ConfigurationDataImplTest.java new file mode 100644 index 000000000..be1090e4a --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/iaik/config/ConfigurationDataImplTest.java @@ -0,0 +1,149 @@ +package test.at.gv.egovernment.moa.spss.server.iaik.config; + +import java.io.FileInputStream; +import java.security.KeyStore; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import iaik.asn1.structures.DistributionPoint; +import iaik.pki.PKIConfiguration; +import iaik.pki.pathvalidation.ChainingModes; +import iaik.pki.pathvalidation.ValidationConfiguration; +import iaik.pki.revocation.CRLDistributionPoint; +import iaik.pki.revocation.RevocationConfiguration; +import iaik.pki.store.certstore.CertStoreConfiguration; +import iaik.pki.store.certstore.CertStoreTypes; +import iaik.pki.store.revocation.archive.ArchiveConfiguration; +import iaik.pki.store.revocation.archive.db.DataBaseArchiveParameter; +import iaik.server.ConfigurationData; +import iaik.server.modules.keys.HardwareKeyModuleConfiguration; +import iaik.server.modules.keys.SoftwareKeyModuleConfiguration; + +import at.gv.egovernment.moa.spss.server.iaik.config.ConfigurationDataImpl; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; + +/** + * Tests the ConfigurationDataImpl. + * + * @author Patrick Peck + * @version $Id$ + */ +public class ConfigurationDataImplTest extends SPSSTestCase { + + private ConfigurationData config; + private X509Certificate iaikCert; + + public ConfigurationDataImplTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + TransactionContext context; + + setUpTransactionContext(); + context = TransactionContextManager.getInstance().getTransactionContext(); + + config = new ConfigurationDataImpl(context.getConfiguration()); + + KeyStore ks = KeyStore.getInstance("JKS", "SUN"); + ks.load( + new FileInputStream(TESTDATA_ROOT + "security/server.keystore"), + "changeit".toCharArray()); + + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + Collection certs = + certFactory.generateCertificates( + new FileInputStream( + TESTDATA_ROOT + + "conf/moa-spss/trustprofiles/TrustProfile1/IAIKRoot.cer")); + iaikCert = (X509Certificate) certs.toArray()[0]; + + } + + public void testGetPKIConfiguration() { + PKIConfiguration pkiConfig = config.getPKIConfiguration(); + ArchiveConfiguration archiveConfig = pkiConfig.getArchiveConfiguration(); + CertStoreConfiguration certStoreConfig = + pkiConfig.getCertStoreConfiguration(); + RevocationConfiguration revocationConfig = + pkiConfig.getRevocationConfiguration(); + ValidationConfiguration validationConfig = + pkiConfig.getValidationConfiguration(); + DataBaseArchiveParameter archiveParam; + Set distributionPoints; + Iterator iter; + boolean found; + + // test archive parameters + archiveParam = + (DataBaseArchiveParameter) archiveConfig.getArchiveParameters(); + assertEquals( + archiveParam.getJDBCUrl(), + "jdbc:postgresql://10.16.46.108/moa?user=moa&password=moatest"); + + // test cert store configuration + assertEquals(1, certStoreConfig.getParameters().length); + assertEquals( + CertStoreTypes.DIRECTORY, + certStoreConfig.getParameters()[0].getType()); + + // test revocation configuration + distributionPoints = + revocationConfig.getAlternativeDistributionPoints(iaikCert, null, new Date()); + assertEquals(3, distributionPoints.size()); + found = false; + for (iter = distributionPoints.iterator(); iter.hasNext();) { + CRLDistributionPoint dp = (CRLDistributionPoint) iter.next(); + if (dp.getUri().equals("http://www.iaik.at/testCA/iaik_test_sig.crl")) { + found = + dp.getReasonCodes() + == (DistributionPoint.keyCompromise + | DistributionPoint.affiliationChanged); + } + } + assertTrue(found); + + // test validation configuration + assertEquals( + ChainingModes.PKIX_MODE, + validationConfig.getChainingMode(iaikCert)); + } + + /* + public void testGetCryptoModuleConfigurations() { + List cryptoConfigs = config.getCryptoModuleConfigurations(); + HardwareCryptoModuleConfiguration moduleConfig; + + assertEquals(2, cryptoConfigs.size()); + moduleConfig = (HardwareCryptoModuleConfiguration) cryptoConfigs.get(0); + assertEquals("Module1", moduleConfig.getModuleName()); + assertEquals("Slot1", moduleConfig.getSlotID()); + assertEquals("PIN1", new String(moduleConfig.getUserPIN())); + } + */ + + public void testGetKeyModuleConfigurations() { + List keyConfigs = config.getKeyModuleConfigurations(); + HardwareKeyModuleConfiguration hwKey; + SoftwareKeyModuleConfiguration swKey; + + assertEquals(7, keyConfigs.size()); + hwKey = (HardwareKeyModuleConfiguration) keyConfigs.get(0); + assertEquals("cryptoki.dll", hwKey.getModuleName()); + assertEquals("0", hwKey.getSlotID()); + assertEquals("0000", new String(hwKey.getUserPIN())); + swKey = (SoftwareKeyModuleConfiguration) keyConfigs.get(1); + assertEquals( + "buergerkarte", + new String(swKey.getKeyStoreAuthenticationData())); + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/iaik/config/IaikConfiguratorTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/iaik/config/IaikConfiguratorTest.java new file mode 100644 index 000000000..3b403dc19 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/iaik/config/IaikConfiguratorTest.java @@ -0,0 +1,36 @@ +package test.at.gv.egovernment.moa.spss.server.iaik.config; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import at.gv.egovernment.moa.spss.server.iaik.config.IaikConfigurator; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContext; +import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager; + +/** + * Tests the IaikConfigurator. + * + * @author Patrick Peck + * @version $Id$ + */ +public class IaikConfiguratorTest extends SPSSTestCase { + + public IaikConfiguratorTest(String name) { + super(name); + } + + /** + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUpTransactionContext(); + } + + public void testConfigure() throws Exception { + IaikConfigurator configurator = new IaikConfigurator(); + TransactionContext context = + TransactionContextManager.getInstance().getTransactionContext(); + + configurator.configure(context.getConfiguration()); + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/AllTests.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/AllTests.java new file mode 100644 index 000000000..65fa2bf72 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/AllTests.java @@ -0,0 +1,25 @@ +package test.at.gv.egovernment.moa.spss.server.invoke; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Runs all tests in this package. + * + * @author Patrick Peck + * @version $Id$ + */ +public class AllTests { + public static Test suite() { + TestSuite suite = new TestSuite(); + + suite.addTestSuite(DataObjectFactoryTest.class); + suite.addTestSuite(TransformationFactoryTest.class); + suite.addTestSuite(XMLSignatureCreationInvokerTest.class); + suite.addTestSuite(CMSSignatureVerificationInvokerTest.class); + suite.addTestSuite(XMLSignatureVerificationInvokerTest.class); + + return suite; + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/CMSSignatureVerificationInvokerTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/CMSSignatureVerificationInvokerTest.java new file mode 100644 index 000000000..3024730f4 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/CMSSignatureVerificationInvokerTest.java @@ -0,0 +1,63 @@ +package test.at.gv.egovernment.moa.spss.server.invoke; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import at.gv.egovernment.moa.util.DOMUtils; + +import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureRequest; +import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureResponse; +import at.gv.egovernment.moa.spss.api.xmlbind.VerifyCMSSignatureRequestParser; +import at.gv.egovernment.moa.spss.api.xmlbind.VerifyCMSSignatureResponseBuilder; +import at.gv.egovernment.moa.spss.server.invoke.CMSSignatureVerificationInvoker; + +/** + * Mainly a smoke test for debugging the CMSSignatureVerificationInvoker. + * + * @author Patrick Peck + * @version $Id$ + */ +public class CMSSignatureVerificationInvokerTest extends SPSSTestCase { + private static final String TESTDATA_BASE = + TESTDATA_ROOT + "xml/VerifyCMSSignature/"; + + /** + * Constructor for CMSSignatureVerificationInvokerTest. + * @param name + */ + public CMSSignatureVerificationInvokerTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + setUpTransactionContext(); + setUpLoggingContext(); + setUpIaikConfiguration(); + } + + public void testVerifyCMSSignature() throws Exception { + try { + CMSSignatureVerificationInvoker invoker = + CMSSignatureVerificationInvoker.getInstance(); + VerifyCMSSignatureRequestParser requestParser = + new VerifyCMSSignatureRequestParser(); + Document doc = + SPSSTestCase.parseXmlValidating( + TESTDATA_BASE + "TestGeneratorVC0.001.Req.xml"); + VerifyCMSSignatureRequest request = + requestParser.parse(doc.getDocumentElement()); + VerifyCMSSignatureResponse response = invoker.verifyCMSSignature(request); + VerifyCMSSignatureResponseBuilder responseBuilder = + new VerifyCMSSignatureResponseBuilder(); + Element result = responseBuilder.build(response).getDocumentElement(); + + System.out.println(DOMUtils.serializeNode(result)); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactoryTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactoryTest.java new file mode 100644 index 000000000..7de2add33 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactoryTest.java @@ -0,0 +1,180 @@ +package test.at.gv.egovernment.moa.spss.server.invoke; + +import java.io.InputStream; +import java.security.Security; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import iaik.server.modules.xml.BinaryDataObject; +import iaik.server.modules.xml.DataObject; +import iaik.server.modules.xml.XMLDataObject; + +import at.gv.egovernment.moa.util.Base64Utils; + +import at.gv.egovernment.moa.spss.MOAException; +import at.gv.egovernment.moa.spss.api.SPSSFactory; +import at.gv.egovernment.moa.spss.api.common.Content; +import at.gv.egovernment.moa.spss.server.iaik.xml.ByteArrayDataObjectImpl; +import at.gv.egovernment.moa.spss.server.iaik.xml.ByteStreamDataObjectImpl; +import at.gv.egovernment.moa.spss.server.iaik.xml.XMLDataObjectImpl; +import at.gv.egovernment.moa.spss.server.iaik.xml.XMLNodeListDataObjectImpl; +import at.gv.egovernment.moa.spss.server.invoke.DataObjectFactory; + +/** + * Test cases for the DataObjectFactory class. + * + * @author Patrick Peck + * @version $Id$ + */ +public class DataObjectFactoryTest extends SPSSTestCase { + + private static final String HTTP_BINARY_CONTENT_URL = "http://www.google.com"; + private static final String HTTP_XML_CONTENT_URL = + "http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"; + private static final String HTTPS_BINARY_CONTENT_URL = + "https://businessnet.ba-ca.com"; + private static final String HTTPS_UNTRUSTED_URL = + "https://heribert.anecon.com"; + private static final String HTTP_UNKNOWN_HOST_URL = "http://uurjmjmruuw.com"; + private static final String MALFORMED_URL = "//hsld///ddd"; + private static final String FILE_BINARY_CONTENT_URL = "file:/C:/boot.ini"; + private static final String XML_CONTENT = + "" + + " " + + " " + + ""; + private static final String BASE64_CONTENT = "U3Zlbg=="; + + private SPSSFactory spssFactory = SPSSFactory.getInstance(); + private DataObjectFactory factory; + + /** + * Constructor for DataObjectFactoryTest. + * @param name + */ + public DataObjectFactoryTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + factory = DataObjectFactory.getInstance(); + + // set up SSL + 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( + "javax.net.ssl.keyStore", + "data/test/security/client.keystore"); + System.setProperty("javax.net.ssl.keyStorePassword", "changeit"); + System.setProperty( + "javax.net.ssl.trustStore", + "data/test/security/client.keystore"); + System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); + */ + } + + public void testCreateFromURIWithBinaryHttp() throws Exception { + DataObject dataObject = + factory.createFromURI(HTTP_BINARY_CONTENT_URL, false); + + assertNotNull(dataObject); + assertTrue(dataObject instanceof ByteStreamDataObjectImpl); + assertNotNull(((BinaryDataObject) dataObject).getInputStream()); + } + + public void testCreateFromURIWithXmlHttp() throws Exception { + DataObject dataObject = factory.createFromURI(HTTP_XML_CONTENT_URL, false); + Element element; + + assertNotNull(dataObject); + assertTrue(dataObject instanceof XMLDataObjectImpl); + element = ((XMLDataObject) dataObject).getElement(); + assertNotNull(element); + assertEquals("schema", element.getTagName()); + } + + public void testCreateFromURIWithMalformedURI() throws Exception { + try { + factory.createFromURI(MALFORMED_URL, false); + fail(); + } catch (MOAException e) { + } + } + + public void testCreateFromURIWithNonExistingHttpURL() throws Exception { + try { + factory.createFromURI(HTTP_UNKNOWN_HOST_URL, false); + fail(); + } catch (MOAException e) { + } + } + + public void testCreateFromURIWithHttps() throws Exception { + DataObject dataObject = + factory.createFromURI(HTTPS_BINARY_CONTENT_URL, false); + assertNotNull(dataObject); + assertTrue(dataObject instanceof BinaryDataObject); + } + + public void testCreateFromURIWithUntrustedHttps() throws Exception { + try { + factory.createFromURI(HTTPS_UNTRUSTED_URL, false); + fail(); + } catch (MOAException e) { + + } + } + + public void testCreateFromURIWithFile() throws Exception { + try { + factory.createFromURI(FILE_BINARY_CONTENT_URL, false); + fail(); + } catch (MOAException e) { + } + } + + public void testCreateFromContentOptionalRefTypeWithXmlContent() + throws Exception { + Document doc = parseXmlString(XML_CONTENT); + Content content = + spssFactory.createContent( + doc.getDocumentElement().getChildNodes(), + "http://data"); + DataObject dataObject = + factory.createFromContentOptionalRefType( + content, + null, + null, + true, + false, + true, + false); + + assertTrue(dataObject instanceof XMLNodeListDataObjectImpl); + } + + public void testCreateFromContentOptionalRefTypeWithBase64Content() + throws Exception { + InputStream is = Base64Utils.decodeToStream(BASE64_CONTENT, true); + Content content = spssFactory.createContent(is, "http://data"); + DataObject dataObject = + factory.createFromContentOptionalRefType( + content, + null, + null, + false, + false, + true, + false); + + assertNotNull(dataObject); + assertTrue(dataObject instanceof ByteArrayDataObjectImpl); + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/TransformationFactoryTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/TransformationFactoryTest.java new file mode 100644 index 000000000..13a80cbf1 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/TransformationFactoryTest.java @@ -0,0 +1,201 @@ +package test.at.gv.egovernment.moa.spss.server.invoke; + +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import iaik.ixsil.init.IXSILInit; +import iaik.ixsil.util.URI; +import iaik.server.modules.xml.Base64Transformation; +import iaik.server.modules.xml.Canonicalization; +import iaik.server.modules.xml.EnvelopedSignatureTransformation; +import iaik.server.modules.xml.Transformation; +import iaik.server.modules.xml.XPath2Transformation; +import iaik.server.modules.xml.XPathTransformation; +import iaik.server.modules.xml.XSLTTransformation; + +import at.gv.egovernment.moa.util.Constants; + +import at.gv.egovernment.moa.spss.MOAApplicationException; +import at.gv.egovernment.moa.spss.api.common.Transform; +import at.gv.egovernment.moa.spss.api.xmlbind.TransformParser; +import at.gv.egovernment.moa.spss.server.invoke.TransformationFactory; + +/** + * Test cases for the TransformationFactory class. + * + * @author Patrick Peck + * @version $Id$ + */ +public class TransformationFactoryTest extends SPSSTestCase { + + private static final String TESTDATA_BASE = + TESTDATA_ROOT + "xml/dsigTransform/"; + private TransformationFactory factory = TransformationFactory.getInstance(); + private TransformParser transformParser = new TransformParser(); + + /** + * Constructor for TransformationFactoryTest. + * @param name + */ + public TransformationFactoryTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + IXSILInit.init(new URI("init/properties/init.properties")); + //IXSILInit.init(new URI("file:data/deploy/ixsil/init/properties/init.properties")); + + } + + public void testCreateCanonicalization() throws Exception { + Document transform = parseXml(TESTDATA_BASE + "canonicalization.xml"); + Transform tr = + transformParser.parseTransform(transform.getDocumentElement()); + Transformation t = factory.createTransformation(tr); + + assertTrue(t instanceof Canonicalization); + assertEquals( + "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", + t.getAlgorithmURI()); + } + + public void testCreateCanonicalizationWithComments() throws Exception { + Document transform = + parseXml(TESTDATA_BASE + "canonicalizationWithComments.xml"); + Transform tr = + transformParser.parseTransform(transform.getDocumentElement()); + Transformation t = factory.createTransformation(tr); + + assertTrue(t instanceof Canonicalization); + assertEquals( + "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", + t.getAlgorithmURI()); + } + + public void testCreateBase64Decode() throws Exception { + Document transform = parseXml(TESTDATA_BASE + "base64.xml"); + Transform tr = + transformParser.parseTransform(transform.getDocumentElement()); + Transformation t = factory.createTransformation(tr); + assertTrue(t instanceof Base64Transformation); + } + + public void testCreateEnvelopedSignature() throws Exception { + Document transform = parseXml(TESTDATA_BASE + "enveloped.xml"); + Transform tr = + transformParser.parseTransform(transform.getDocumentElement()); + Transformation t = factory.createTransformation(tr); + assertTrue(t instanceof EnvelopedSignatureTransformation); + } + + public void testXPathTransformation() throws Exception { + Document transform = parseXml(TESTDATA_BASE + "xpath.xml"); + Transform tr = + transformParser.parseTransform(transform.getDocumentElement()); + Transformation t = factory.createTransformation(tr); + Map nsDecls; + + assertTrue(t instanceof XPathTransformation); + nsDecls = ((XPathTransformation) t).getNamespaceDeclarations(); + assertEquals(1, nsDecls.size()); + assertEquals(Constants.DSIG_NS_URI, nsDecls.get("dsig")); + } + + public void testCreateXPath2Transformation() throws Exception { + Document transform = parseXml(TESTDATA_BASE + "xpath2.xml"); + Transform tr = + transformParser.parseTransform(transform.getDocumentElement()); + Transformation t = factory.createTransformation(tr); + assertTrue(t instanceof XPath2Transformation); + } + + public void testCreateXSLTTransformation() throws Exception { + Document transform = parseXml(TESTDATA_BASE + "xslt.xml"); + Transform tr = + transformParser.parseTransform(transform.getDocumentElement()); + XSLTTransformation t = + (XSLTTransformation) factory.createTransformation(tr); + assertNotNull(t.getStylesheetElement()); + } + + public void testCreateWithIllegalAlgorithm() throws Exception { + try { + Document transform = parseXml(TESTDATA_BASE + "illegalAlgorithm.xml"); + Transform tr = + transformParser.parseTransform(transform.getDocumentElement()); + factory.createTransformation(tr); + fail(); + } catch (MOAApplicationException e) { + } + } + + public void testEqualsXslt() throws Exception { + Document xslt = parseXml(TESTDATA_BASE + "xslt.xml"); + Transform tr = transformParser.parseTransform(xslt.getDocumentElement()); + Transformation trXslt = factory.createTransformation(tr); + + Document xsltEqu = parseXml(TESTDATA_BASE + "xsltEqual.xml"); + tr = transformParser.parseTransform(xsltEqu.getDocumentElement()); + Transformation trXsltEqu = factory.createTransformation(tr); + + Document xsltDiff = parseXml(TESTDATA_BASE + "xsltDifferent.xml"); + tr = transformParser.parseTransform(xsltDiff.getDocumentElement()); + Transformation trXsltDiff = factory.createTransformation(tr); + + Document canonicalization = + parseXml(TESTDATA_BASE + "canonicalization.xml"); + + assertTrue(trXslt.equals(trXsltEqu)); + assertFalse(trXslt.equals(trXsltDiff)); + assertFalse(trXsltEqu.equals(trXsltDiff)); + assertEquals(trXslt.hashCode(), trXsltEqu.hashCode()); + assertFalse(trXslt.hashCode() == trXsltDiff.hashCode()); + assertFalse(trXsltEqu.hashCode() == trXsltDiff.hashCode()); + assertFalse(trXslt.equals(canonicalization)); + } + + public void testEqualsXPath() throws Exception { + Document xpath = parseXml(TESTDATA_BASE + "xpath.xml"); + Transform tr = transformParser.parseTransform(xpath.getDocumentElement()); + Transformation trXpath = factory.createTransformation(tr); + Transformation trXpathEqu = factory.createTransformation(tr); + + Document xpathDiff = parseXml(TESTDATA_BASE + "xpathDifferent.xml"); + tr = transformParser.parseTransform(xpathDiff.getDocumentElement()); + Transformation trXpathDiff = factory.createTransformation(tr); + + assertTrue(trXpath.equals(trXpathEqu)); + assertEquals(trXpath.hashCode(), trXpathEqu.hashCode()); + assertFalse(trXpath.equals(trXpathDiff)); + assertFalse(trXpath.hashCode() == trXpathDiff.hashCode()); + } + + public void testEqualsXPath2() throws Exception { + Document xpath2 = parseXml(TESTDATA_BASE + "xpath2.xml"); + Transform tr = transformParser.parseTransform(xpath2.getDocumentElement()); + Transformation trXpath2 = factory.createTransformation(tr); + Transformation trXpath2Equ = factory.createTransformation(tr); + + Document xpath2Diff = parseXml(TESTDATA_BASE + "xpath2Different.xml"); + tr = transformParser.parseTransform(xpath2Diff.getDocumentElement()); + Transformation trXpath2Diff = factory.createTransformation(tr); + + assertTrue(trXpath2.equals(trXpath2Equ)); + assertEquals(trXpath2.hashCode(), trXpath2Equ.hashCode()); + assertFalse(trXpath2.equals(trXpath2Diff)); + assertFalse(trXpath2.hashCode() == trXpath2Diff.hashCode()); + } + + public void testCreateTransformationList() throws Exception { + Document transforms = parseXml(TESTDATA_BASE + "transforms.xml"); + List trs = transformParser.parseTransforms(transforms.getDocumentElement()); + List transformationList = factory.createTransformationList(trs); + + assertEquals(3, transformationList.size()); + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvokerTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvokerTest.java new file mode 100644 index 000000000..28cd3805a --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureCreationInvokerTest.java @@ -0,0 +1,63 @@ +package test.at.gv.egovernment.moa.spss.server.invoke; + +import java.util.Collections; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import at.gv.egovernment.moa.util.DOMUtils; + +import at.gv.egovernment.moa.spss.api.xmlbind.CreateXMLSignatureRequestParser; +import at.gv.egovernment.moa.spss.api.xmlbind.CreateXMLSignatureResponseBuilder; +import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureRequest; +import at.gv.egovernment.moa.spss.api.xmlsign.CreateXMLSignatureResponse; +import at.gv.egovernment.moa.spss.server.invoke.XMLSignatureCreationInvoker; + +/** + * Mainly a smoke test for debugging the XMLSignatureCreationInvoker. + * + * @author Patrick Peck + * @version $Id$ + */ +public class XMLSignatureCreationInvokerTest extends SPSSTestCase { + private static final String TESTDATA_BASE = + TESTDATA_ROOT + "xml/CreateXMLSignature/"; + + public XMLSignatureCreationInvokerTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + setUpTransactionContext(); + setUpLoggingContext(); + setUpIaikConfiguration(); + setUpSSL(); + } + + public void testCreateXMLSignature() throws Exception { + try { + XMLSignatureCreationInvoker invoker = + XMLSignatureCreationInvoker.getInstance(); + CreateXMLSignatureRequestParser requestParser = + new CreateXMLSignatureRequestParser(); + Document doc = + SPSSTestCase.parseXmlValidating( + TESTDATA_BASE + "TestGeneratorCX2.004.Req.xml"); + CreateXMLSignatureRequest request = + requestParser.parse(doc.getDocumentElement()); + CreateXMLSignatureResponse response = + invoker.createXMLSignature(request, Collections.EMPTY_SET); + CreateXMLSignatureResponseBuilder responseBuilder = + new CreateXMLSignatureResponseBuilder(); + Element result = responseBuilder.build(response).getDocumentElement(); + + System.out.println(DOMUtils.serializeNode(result)); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvokerTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvokerTest.java new file mode 100644 index 000000000..56e3d541b --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/invoke/XMLSignatureVerificationInvokerTest.java @@ -0,0 +1,61 @@ +package test.at.gv.egovernment.moa.spss.server.invoke; + +import org.w3c.dom.Document; + +import test.at.gv.egovernment.moa.spss.SPSSTestCase; + +import at.gv.egovernment.moa.util.DOMUtils; + +import at.gv.egovernment.moa.spss.api.xmlbind.VerifyXMLSignatureRequestParser; +import at.gv.egovernment.moa.spss.api.xmlbind.VerifyXMLSignatureResponseBuilder; +import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureRequest; +import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureResponse; +import at.gv.egovernment.moa.spss.server.invoke.XMLSignatureVerificationInvoker; + +/** + * Mainly a smoke test for debugging the XMLSignatureVerificationInvoker. + * + * @author Patrick Peck + * @version $Id$ + */ +public class XMLSignatureVerificationInvokerTest extends SPSSTestCase { + private static final String TESTDATA_BASE = + TESTDATA_ROOT + "xml/VerifyXMLSignature/"; + + public XMLSignatureVerificationInvokerTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + setUpTransactionContext(); + setUpLoggingContext(); + setUpIaikConfiguration(); + } + + public void testVerifyXMLSignature() throws Exception { + try { + XMLSignatureVerificationInvoker invoker = + XMLSignatureVerificationInvoker.getInstance(); + VerifyXMLSignatureRequestParser requestParser = + new VerifyXMLSignatureRequestParser(); + VerifyXMLSignatureResponseBuilder responseBuilder = + new VerifyXMLSignatureResponseBuilder(); + Document doc = + SPSSTestCase.parseXmlValidating( + TESTDATA_BASE + "TestGeneratorVX.201.Req.xml"); + + VerifyXMLSignatureRequest request = + requestParser.parse(doc.getDocumentElement()); + VerifyXMLSignatureResponse response; + + response = invoker.verifyXMLSignature(request); + System.out.println( + DOMUtils.serializeNode(responseBuilder.build(response))); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + +} diff --git a/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/tools/CertToolTest.java b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/tools/CertToolTest.java new file mode 100644 index 000000000..b46c20086 --- /dev/null +++ b/spss/server/serverlib/src/test/java/at/gv/egovernment/moa/spss/server/tools/CertToolTest.java @@ -0,0 +1,50 @@ +package test.at.gv.egovernment.moa.spss.server.tools; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import at.gv.egovernment.moa.spss.server.tools.CertTool; + +import test.at.gv.egovernment.moa.MOATestCase; + +/** + * Tests for the CertTool. + * + * @author Patrick Peck + * @version $Id$ + */ +public class CertToolTest extends MOATestCase { + + private static final String EXPECTED_RESULT = + "SubjectDN (RFC2253):" + + " CN=Patrick Peck,OU=MOA Team,O=BRZ,L=Vienna,ST=Vienna,C=AT\r\n" + + "IssuerDN (RFC2253) :" + + " CN=Patrick Peck,OU=MOA Team,O=BRZ,L=Vienna,ST=Vienna,C=AT\r\n" + + "Serial Number :" + + " 1047548672\r\n"; + private CertTool certTool; + + /** + * Constructor for CertToolTest. + * @param name + */ + public CertToolTest(String name) { + super(name); + } + + protected void setUp() { + certTool = new CertTool(); + } + + public void testPrintCertInfo() { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(bos); + String result; + + certTool.printCertInfo(TESTDATA_ROOT + "security/server.cer", ps); + result = new String(bos.toByteArray()); + System.out.println(result); + assertEquals(EXPECTED_RESULT, result); + } + +} diff --git a/spss/server/serverws/pom.xml b/spss/server/serverws/pom.xml index de0f511c2..88b3345d6 100644 --- a/spss/server/serverws/pom.xml +++ b/spss/server/serverws/pom.xml @@ -3,14 +3,14 @@ MOA.spss moa-spss - 1.4.1 + 1.4.x 4.0.0 MOA.spss.server moa-spss-ws war - 1.4.1 + 1.4.2 MOA SP/SS WebService @@ -57,7 +57,7 @@ MOA.spss.server moa-spss-lib - ${project.version} + ${pom.version} MOA diff --git a/spss/server/tools/pom.xml b/spss/server/tools/pom.xml index 3bfb747f8..3a3cde79c 100644 --- a/spss/server/tools/pom.xml +++ b/spss/server/tools/pom.xml @@ -3,14 +3,14 @@ MOA.spss moa-spss - 1.4.1 + 1.4.x 4.0.0 MOA.spss.server moa-spss-tools jar - 1.4.1 + 1.4.2 MOA SP/SS Tools @@ -21,7 +21,7 @@ MOA.spss.server moa-spss-lib - ${project.version} + ${pom.version} iaik.prod -- cgit v1.2.3