You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by gi...@apache.org on 2012/07/31 09:20:30 UTC
svn commit: r1367437 [3/3] - in /santuario/xml-security-java/trunk/src:
main/java/org/apache/xml/security/stax/config/
main/java/org/apache/xml/security/stax/ext/
main/java/org/apache/xml/security/stax/impl/
main/java/org/apache/xml/security/stax/impl/...
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java Tue Jul 31 07:20:29 2012
@@ -18,52 +18,55 @@
*/
package org.apache.xml.security.test.stax.signature;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-
-import javax.crypto.SecretKey;
-import javax.crypto.spec.SecretKeySpec;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
import org.apache.xml.security.stax.config.Init;
import org.apache.xml.security.stax.ext.InboundXMLSec;
import org.apache.xml.security.stax.ext.XMLSec;
import org.apache.xml.security.stax.ext.XMLSecurityException;
import org.apache.xml.security.stax.ext.XMLSecurityProperties;
+import org.apache.xml.security.stax.impl.resourceResolvers.ResolverHttp;
+import org.apache.xml.security.test.stax.utils.HttpRequestRedirectorProxy;
import org.apache.xml.security.test.stax.utils.StAX2DOM;
import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
+import org.apache.xml.security.utils.resolver.implementations.ResolverDirectHTTP;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.w3c.dom.Document;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+
/**
- * This is a testcase to validate all "phaos-xmldsig-three"
+ * This is a testcase to validate all "phaos-xmldsig-three"
* testcases from Phaos
*/
public class PhaosTest extends org.junit.Assert {
-
+
private XMLInputFactory xmlInputFactory;
private DocumentBuilderFactory documentBuilderFactory;
private TransformerFactory transformerFactory = TransformerFactory.newInstance();
-
+
@Before
public void setUp() throws Exception {
Init.init(PhaosTest.class.getClassLoader().getResource("security-config.xml").toURI());
org.apache.xml.security.Init.init();
-
+
xmlInputFactory = XMLInputFactory.newInstance();
xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
-
+
documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setIgnoringComments(false);
@@ -74,242 +77,278 @@ public class PhaosTest extends org.junit
// See SANTUARIO-319
@Test
- @Ignore
public void test_signature_dsa_detached() throws Exception {
- // Read in plaintext document
- InputStream sourceDocument =
- this.getClass().getClassLoader().getResourceAsStream(
- "com/phaos/phaos-xmldsig-three/signature-dsa-detached.xml");
- DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
- Document document = builder.parse(sourceDocument);
-
- // XMLUtils.outputDOM(document, System.out);
-
- // Convert Document to a Stream Reader
- javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
- xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
- // Verify signature
- XMLSecurityProperties properties = new XMLSecurityProperties();
- InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
- TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
- XMLStreamReader securityStreamReader =
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
- StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
+ Proxy proxy = HttpRequestRedirectorProxy.startHttpEngine();
+
+ try {
+ ResolverHttp.setProxy(proxy);
+
+ ResolverDirectHTTP resolverDirectHTTP = new ResolverDirectHTTP();
+ resolverDirectHTTP.engineSetProperty("http.proxy.host", ((InetSocketAddress) proxy.address()).getAddress().getHostAddress());
+ resolverDirectHTTP.engineSetProperty("http.proxy.port", "" + ((InetSocketAddress) proxy.address()).getPort());
+
+ // Read in plaintext document
+ InputStream sourceDocument =
+ this.getClass().getClassLoader().getResourceAsStream(
+ "com/phaos/phaos-xmldsig-three/signature-dsa-detached.xml");
+ DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
+ Document document = builder.parse(sourceDocument);
+
+ // XMLUtils.outputDOM(document, System.out);
+
+ // Convert Document to a Stream Reader
+ javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ transformer.transform(new DOMSource(document), new StreamResult(baos));
+ final XMLStreamReader xmlStreamReader =
+ xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
+
+ // Verify signature
+ XMLSecurityProperties properties = new XMLSecurityProperties();
+ InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
+ TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
+ XMLStreamReader securityStreamReader =
+ inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+
+ StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
+ } finally {
+ HttpRequestRedirectorProxy.stopHttpEngine();
+ }
}
-
+
// See Santuario-320
@Test
public void test_signature_dsa_enveloped() throws Exception {
// Read in plaintext document
- InputStream sourceDocument =
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"com/phaos/phaos-xmldsig-three/signature-dsa-enveloped.xml");
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(sourceDocument);
-
+
// XMLUtils.outputDOM(document, System.out);
-
+
// Convert Document to a Stream Reader
javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
+ final XMLStreamReader xmlStreamReader =
xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
+
// Verify signature
XMLSecurityProperties properties = new XMLSecurityProperties();
InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
- XMLStreamReader securityStreamReader =
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+ XMLStreamReader securityStreamReader =
+ inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
}
-
+
@Test
public void test_signature_dsa_enveloping() throws Exception {
// Read in plaintext document
- InputStream sourceDocument =
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"com/phaos/phaos-xmldsig-three/signature-dsa-enveloping.xml");
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(sourceDocument);
-
+
// XMLUtils.outputDOM(document, System.out);
-
+
// Convert Document to a Stream Reader
javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
+ final XMLStreamReader xmlStreamReader =
xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
+
// Verify signature
XMLSecurityProperties properties = new XMLSecurityProperties();
InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
- XMLStreamReader securityStreamReader =
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+ XMLStreamReader securityStreamReader =
+ inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
}
// See SANTUARIO-319
@Test
- @Ignore
public void test_signature_hmac_sha1_exclusive_c14n_comments_detached() throws Exception {
- // Read in plaintext document
- InputStream sourceDocument =
- this.getClass().getClassLoader().getResourceAsStream(
- "com/phaos/phaos-xmldsig-three/signature-hmac-sha1-exclusive-c14n-comments-detached.xml");
- DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
- Document document = builder.parse(sourceDocument);
-
- // Set up the key
- byte[] hmacKey = "test".getBytes("ASCII");
- SecretKey key = new SecretKeySpec(hmacKey, "http://www.w3.org/2000/09/xmldsig#hmac-sha1");
-
- // XMLUtils.outputDOM(document, System.out);
-
- // Convert Document to a Stream Reader
- javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
- xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
- // Verify signature
- XMLSecurityProperties properties = new XMLSecurityProperties();
- properties.setSignatureVerificationKey(key);
- InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
- TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
- XMLStreamReader securityStreamReader =
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
- StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
+ Proxy proxy = HttpRequestRedirectorProxy.startHttpEngine();
+
+ try {
+ ResolverHttp.setProxy(proxy);
+
+ ResolverDirectHTTP resolverDirectHTTP = new ResolverDirectHTTP();
+ resolverDirectHTTP.engineSetProperty("http.proxy.host", ((InetSocketAddress) proxy.address()).getAddress().getHostAddress());
+ resolverDirectHTTP.engineSetProperty("http.proxy.port", "" + ((InetSocketAddress) proxy.address()).getPort());
+
+ // Read in plaintext document
+ InputStream sourceDocument =
+ this.getClass().getClassLoader().getResourceAsStream(
+ "com/phaos/phaos-xmldsig-three/signature-hmac-sha1-exclusive-c14n-comments-detached.xml");
+ DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
+ Document document = builder.parse(sourceDocument);
+
+ // Set up the key
+ byte[] hmacKey = "test".getBytes("ASCII");
+ SecretKey key = new SecretKeySpec(hmacKey, "http://www.w3.org/2000/09/xmldsig#hmac-sha1");
+
+ // XMLUtils.outputDOM(document, System.out);
+
+ // Convert Document to a Stream Reader
+ javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ transformer.transform(new DOMSource(document), new StreamResult(baos));
+ final XMLStreamReader xmlStreamReader =
+ xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
+
+ // Verify signature
+ XMLSecurityProperties properties = new XMLSecurityProperties();
+ properties.setSignatureVerificationKey(key);
+ InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
+ TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
+ XMLStreamReader securityStreamReader =
+ inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+
+ StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
+ } finally {
+ HttpRequestRedirectorProxy.stopHttpEngine();
+ }
}
-
+
// See Santuario-320
@Test
public void test_signature_hmac_sha1_exclusive_c14n_enveloped() throws Exception {
// Read in plaintext document
- InputStream sourceDocument =
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"com/phaos/phaos-xmldsig-three/signature-hmac-sha1-exclusive-c14n-enveloped.xml");
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(sourceDocument);
-
+
// Set up the key
byte[] hmacKey = "test".getBytes("ASCII");
SecretKey key = new SecretKeySpec(hmacKey, "http://www.w3.org/2000/09/xmldsig#hmac-sha1");
-
+
// XMLUtils.outputDOM(document, System.out);
-
+
// Convert Document to a Stream Reader
javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
+ final XMLStreamReader xmlStreamReader =
xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
+
// Verify signature
XMLSecurityProperties properties = new XMLSecurityProperties();
properties.setSignatureVerificationKey(key);
InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
- XMLStreamReader securityStreamReader =
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+ XMLStreamReader securityStreamReader =
+ inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
}
-
+
@Test
public void test_signature_rsa_detached_b64_transform() throws Exception {
// Read in plaintext document
- InputStream sourceDocument =
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"com/phaos/phaos-xmldsig-three/signature-rsa-detached-b64-transform.xml");
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(sourceDocument);
-
+
// Set up the key
byte[] hmacKey = "test".getBytes("ASCII");
SecretKey key = new SecretKeySpec(hmacKey, "http://www.w3.org/2000/09/xmldsig#hmac-sha1");
-
+
// XMLUtils.outputDOM(document, System.out);
-
+
// Convert Document to a Stream Reader
javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
+ final XMLStreamReader xmlStreamReader =
xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
+
// Verify signature
XMLSecurityProperties properties = new XMLSecurityProperties();
properties.setSignatureVerificationKey(key);
InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
- XMLStreamReader securityStreamReader =
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+ XMLStreamReader securityStreamReader =
+ inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
}
// See SANTUARIO-319
@Test
- @Ignore
public void test_signature_rsa_detached() throws Exception {
- // Read in plaintext document
- InputStream sourceDocument =
- this.getClass().getClassLoader().getResourceAsStream(
- "com/phaos/phaos-xmldsig-three/signature-rsa-detached.xml");
- DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
- Document document = builder.parse(sourceDocument);
-
- // XMLUtils.outputDOM(document, System.out);
-
- // Convert Document to a Stream Reader
- javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
- xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
- // Verify signature
- XMLSecurityProperties properties = new XMLSecurityProperties();
- InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
- TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
- XMLStreamReader securityStreamReader =
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
- StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
+ Proxy proxy = HttpRequestRedirectorProxy.startHttpEngine();
+
+ try {
+ ResolverHttp.setProxy(proxy);
+
+ ResolverDirectHTTP resolverDirectHTTP = new ResolverDirectHTTP();
+ resolverDirectHTTP.engineSetProperty("http.proxy.host", ((InetSocketAddress) proxy.address()).getAddress().getHostAddress());
+ resolverDirectHTTP.engineSetProperty("http.proxy.port", "" + ((InetSocketAddress) proxy.address()).getPort());
+
+ // Read in plaintext document
+ InputStream sourceDocument =
+ this.getClass().getClassLoader().getResourceAsStream(
+ "com/phaos/phaos-xmldsig-three/signature-rsa-detached.xml");
+ DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
+ Document document = builder.parse(sourceDocument);
+
+ // XMLUtils.outputDOM(document, System.out);
+
+ // Convert Document to a Stream Reader
+ javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ transformer.transform(new DOMSource(document), new StreamResult(baos));
+ final XMLStreamReader xmlStreamReader =
+ xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
+
+ // Verify signature
+ XMLSecurityProperties properties = new XMLSecurityProperties();
+ InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
+ TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
+ XMLStreamReader securityStreamReader =
+ inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+
+ StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
+ } finally {
+ HttpRequestRedirectorProxy.stopHttpEngine();
+ }
}
-
+
// See Santuario-320
@Test
public void test_signature_rsa_enveloped_bad_digest_val() throws Exception {
// Read in plaintext document
- InputStream sourceDocument =
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"com/phaos/phaos-xmldsig-three/signature-rsa-enveloped-bad-digest-val.xml");
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(sourceDocument);
-
+
// XMLUtils.outputDOM(document, System.out);
-
+
// Convert Document to a Stream Reader
javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
+ final XMLStreamReader xmlStreamReader =
xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
+
// Verify signature
XMLSecurityProperties properties = new XMLSecurityProperties();
InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
@@ -323,62 +362,62 @@ public class PhaosTest extends org.junit
Assert.assertEquals("The signature or decryption was invalid", ex.getCause().getMessage());
}
}
-
+
// See Santuario-320
@Test
public void test_signature_rsa_enveloped() throws Exception {
// Read in plaintext document
- InputStream sourceDocument =
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"com/phaos/phaos-xmldsig-three/signature-rsa-enveloped.xml");
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(sourceDocument);
-
+
// XMLUtils.outputDOM(document, System.out);
-
+
// Convert Document to a Stream Reader
javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
+ final XMLStreamReader xmlStreamReader =
xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
+
// Verify signature
XMLSecurityProperties properties = new XMLSecurityProperties();
InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
- XMLStreamReader securityStreamReader =
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+ XMLStreamReader securityStreamReader =
+ inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
}
-
+
@Test
public void test_signature_rsa_enveloping() throws Exception {
// Read in plaintext document
- InputStream sourceDocument =
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"com/phaos/phaos-xmldsig-three/signature-rsa-enveloping.xml");
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(sourceDocument);
-
+
// XMLUtils.outputDOM(document, System.out);
-
+
// Convert Document to a Stream Reader
javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
transformer.transform(new DOMSource(document), new StreamResult(baos));
- final XMLStreamReader xmlStreamReader =
+ final XMLStreamReader xmlStreamReader =
xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()));
-
+
// Verify signature
XMLSecurityProperties properties = new XMLSecurityProperties();
InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
- XMLStreamReader securityStreamReader =
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+ XMLStreamReader securityStreamReader =
+ inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
}
-
+
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationReferenceURIResolverTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationReferenceURIResolverTest.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationReferenceURIResolverTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationReferenceURIResolverTest.java Tue Jul 31 07:20:29 2012
@@ -118,7 +118,10 @@ public class SignatureCreationReferenceU
new SecurePart(new QName("urn:example:po", "PaymentInfo"), SecurePart.Modifier.Element);
properties.addSignaturePart(securePart);
- securePart = new SecurePart("file://" + BASEDIR + "/target/test-classes/org/apache/xml/security/test/stax/signature/SignatureVerificationReferenceURIResolverTest.class", null, XMLSecurityConstants.NS_XMLDSIG_SHA1);
+ securePart = new SecurePart(
+ "file://" + BASEDIR + "/target/test-classes/org/apache/xml/security/test/stax/signature/SignatureVerificationReferenceURIResolverTest.class",
+ null,
+ XMLSecurityConstants.NS_XMLDSIG_SHA1);
properties.addSignaturePart(securePart);
OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
@@ -148,6 +151,10 @@ public class SignatureCreationReferenceU
try {
ResolverHttp.setProxy(proxy);
+ ResolverDirectHTTP resolverDirectHTTP = new ResolverDirectHTTP();
+ resolverDirectHTTP.engineSetProperty("http.proxy.host", ((InetSocketAddress)proxy.address()).getAddress().getHostAddress());
+ resolverDirectHTTP.engineSetProperty("http.proxy.port", "" + ((InetSocketAddress)proxy.address()).getPort());
+
// Set up the Configuration
XMLSecurityProperties properties = new XMLSecurityProperties();
XMLSecurityConstants.Action[] actions =
@@ -187,10 +194,6 @@ public class SignatureCreationReferenceU
Document document =
documentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray()));
- ResolverDirectHTTP resolverDirectHTTP = new ResolverDirectHTTP();
- resolverDirectHTTP.engineSetProperty("http.proxy.host", ((InetSocketAddress)proxy.address()).getAddress().getHostAddress());
- resolverDirectHTTP.engineSetProperty("http.proxy.port", "" + ((InetSocketAddress)proxy.address()).getPort());
-
// Verify using DOM
verifyUsingDOM(document, cert, properties.getSignatureSecureParts(), resolverDirectHTTP);
} finally {
Added: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformBase64DecodeTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformBase64DecodeTest.java?rev=1367437&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformBase64DecodeTest.java (added)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformBase64DecodeTest.java Tue Jul 31 07:20:29 2012
@@ -0,0 +1,333 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.stax.transformer;
+
+import junit.framework.Assert;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.xml.security.stax.ext.Transformer;
+import org.apache.xml.security.stax.ext.XMLSecurityConstants;
+import org.apache.xml.security.stax.ext.XMLSecurityException;
+import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
+import org.apache.xml.security.stax.impl.transformer.TransformBase64Decode;
+import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class TransformBase64DecodeTest extends org.junit.Assert {
+
+ private XMLInputFactory xmlInputFactory;
+
+ @Before
+ public void setUp() throws Exception {
+ this.xmlInputFactory = XMLInputFactory.newInstance();
+ this.xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
+ }
+
+ @Test
+ public void testXMLSecEventToXMLSecEventAPI() throws Exception {
+ TransformBase64Decode transformBase64Decode = new TransformBase64Decode();
+
+ final List<XMLSecEvent> xmlSecEvents = new ArrayList<XMLSecEvent>();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ xmlSecEvents.add(xmlSecEvent);
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(InputStream");
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+ transformBase64Decode.setTransformer(transformer);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")
+ );
+
+ XMLSecEvent xmlSecEvent = null;
+ while (xmlSecEventReader.hasNext()) {
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ }
+ while (xmlSecEventReader.hasNext()) {
+ transformBase64Decode.transform(xmlSecEvent);
+ if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ }
+
+ transformBase64Decode.doFinal();
+
+ Assert.assertEquals(16, xmlSecEvents.size());
+ }
+
+ @Test
+ public void testXMLSecEventToInputStreamAPI() throws Exception {
+ TransformBase64Decode transformBase64Decode = new TransformBase64Decode();
+
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.InputStream;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(XMLSecEvent");
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ try {
+ IOUtils.copy(inputStream, byteArrayOutputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+ transformBase64Decode.setTransformer(transformer);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")
+ );
+
+ XMLSecEvent xmlSecEvent = null;
+ while (xmlSecEventReader.hasNext()) {
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ }
+ while (xmlSecEventReader.hasNext()) {
+ transformBase64Decode.transform(xmlSecEvent);
+ if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ }
+
+ transformBase64Decode.doFinal();
+
+ Assert.assertEquals(153, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testXMLSecEventToOutputStreamStreamAPI() throws Exception {
+ TransformBase64Decode transformBase64Decode = new TransformBase64Decode();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ transformBase64Decode.setOutputStream(byteArrayOutputStream);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")
+ );
+
+ XMLSecEvent xmlSecEvent = null;
+ while (xmlSecEventReader.hasNext()) {
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ }
+ while (xmlSecEventReader.hasNext()) {
+ transformBase64Decode.transform(xmlSecEvent);
+ if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ }
+
+ transformBase64Decode.doFinal();
+
+ Assert.assertEquals(153, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testInputStreamToOutputStreamStreamAPI() throws Exception {
+ TransformBase64Decode transformBase64Decode = new TransformBase64Decode();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ transformBase64Decode.setOutputStream(byteArrayOutputStream);
+
+ transformBase64Decode.transform(this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/xml-stylesheet.b64"));
+
+ Assert.assertEquals(13132, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testInputStreamToXMLSecEventAPI() throws Exception {
+ TransformBase64Decode transformBase64Decode = new TransformBase64Decode();
+ final List<XMLSecEvent> xmlSecEvents = new ArrayList<XMLSecEvent>();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ xmlSecEvents.add(xmlSecEvent);
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(InputStream");
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+
+ transformBase64Decode.setTransformer(transformer);
+
+ transformBase64Decode.transform(this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml"));
+
+ transformBase64Decode.doFinal();
+
+ Assert.assertEquals(44, xmlSecEvents.size());
+ }
+
+ @Test
+ public void testInputStreamToInputStreamAPI() throws Exception {
+ TransformBase64Decode transformBase64Decode = new TransformBase64Decode();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.InputStream;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(XMLSecEvent");
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ try {
+ IOUtils.copy(inputStream, byteArrayOutputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+
+ transformBase64Decode.setTransformer(transformer);
+
+ transformBase64Decode.transform(this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml"));
+
+ transformBase64Decode.doFinal();
+
+ Assert.assertEquals(615, byteArrayOutputStream.size());
+ }
+}
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformBase64DecodeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformBase64DecodeTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformCanonicalizerTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformCanonicalizerTest.java?rev=1367437&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformCanonicalizerTest.java (added)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformCanonicalizerTest.java Tue Jul 31 07:20:29 2012
@@ -0,0 +1,308 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.stax.transformer;
+
+import junit.framework.Assert;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.xml.security.stax.ext.Transformer;
+import org.apache.xml.security.stax.ext.XMLSecurityConstants;
+import org.apache.xml.security.stax.ext.XMLSecurityException;
+import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
+import org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_OmitCommentsTransformer;
+import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class TransformCanonicalizerTest extends org.junit.Assert {
+
+ private XMLInputFactory xmlInputFactory;
+
+ @Before
+ public void setUp() throws Exception {
+ this.xmlInputFactory = XMLInputFactory.newInstance();
+ this.xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
+ }
+
+ @Test
+ public void testXMLSecEventToXMLSecEventAPI() throws Exception {
+ Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
+
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(XMLSecEvent");
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ try {
+ IOUtils.copy(inputStream, byteArrayOutputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+ canonicalizerTransformer.setTransformer(transformer);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")
+ );
+
+ while (xmlSecEventReader.hasNext()) {
+ XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ canonicalizerTransformer.transform(xmlSecEvent);
+ }
+
+ canonicalizerTransformer.doFinal();
+
+ Assert.assertEquals(554, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testXMLSecEventToInputStreamAPI() throws Exception {
+ Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
+
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.InputStream;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(XMLSecEvent");
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ try {
+ IOUtils.copy(inputStream, byteArrayOutputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+ canonicalizerTransformer.setTransformer(transformer);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")
+ );
+
+ while (xmlSecEventReader.hasNext()) {
+ XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ canonicalizerTransformer.transform(xmlSecEvent);
+ }
+
+ canonicalizerTransformer.doFinal();
+
+ Assert.assertEquals(554, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testXMLSecEventToOutputStreamStreamAPI() throws Exception {
+ Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ canonicalizerTransformer.setOutputStream(byteArrayOutputStream);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")
+ );
+
+ while (xmlSecEventReader.hasNext()) {
+ XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ canonicalizerTransformer.transform(xmlSecEvent);
+ }
+
+ canonicalizerTransformer.doFinal();
+ Assert.assertEquals(554, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testInputStreamToOutputStreamStreamAPI() throws Exception {
+ Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ canonicalizerTransformer.setOutputStream(byteArrayOutputStream);
+
+ canonicalizerTransformer.transform(this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
+
+ Assert.assertEquals(554, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testInputStreamToXMLSecEventAPI() throws Exception {
+ Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(XMLSecEvent");
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ try {
+ IOUtils.copy(inputStream, byteArrayOutputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+
+ canonicalizerTransformer.setTransformer(transformer);
+
+ canonicalizerTransformer.transform(this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
+
+ canonicalizerTransformer.doFinal();
+
+ Assert.assertEquals(554, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testInputStreamToInputStreamAPI() throws Exception {
+ Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.InputStream;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(XMLSecEvent");
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ try {
+ IOUtils.copy(inputStream, byteArrayOutputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+
+ canonicalizerTransformer.setTransformer(transformer);
+
+ canonicalizerTransformer.transform(this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
+
+ canonicalizerTransformer.doFinal();
+
+ Assert.assertEquals(554, byteArrayOutputStream.size());
+ }
+}
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformCanonicalizerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformCanonicalizerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformEnvelopedSignatureTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformEnvelopedSignatureTest.java?rev=1367437&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformEnvelopedSignatureTest.java (added)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformEnvelopedSignatureTest.java Tue Jul 31 07:20:29 2012
@@ -0,0 +1,190 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.stax.transformer;
+
+import junit.framework.Assert;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.xml.security.stax.ext.Transformer;
+import org.apache.xml.security.stax.ext.XMLSecurityConstants;
+import org.apache.xml.security.stax.ext.XMLSecurityException;
+import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
+import org.apache.xml.security.stax.impl.transformer.TransformEnvelopedSignature;
+import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class TransformEnvelopedSignatureTest extends org.junit.Assert {
+
+ private XMLInputFactory xmlInputFactory;
+
+ @Before
+ public void setUp() throws Exception {
+ this.xmlInputFactory = XMLInputFactory.newInstance();
+ this.xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
+ }
+
+ @Test
+ public void testXMLSecEventToXMLSecEventAPI() throws Exception {
+ TransformEnvelopedSignature transformEnvelopedSignature = new TransformEnvelopedSignature();
+
+ final List<XMLSecEvent> xmlSecEvents = new ArrayList<XMLSecEvent>();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ xmlSecEvents.add(xmlSecEvent);
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(InputStream");
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+ transformEnvelopedSignature.setTransformer(transformer);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "com/phaos/phaos-xmldsig-three/signature-rsa-enveloped.xml")
+ );
+
+ while (xmlSecEventReader.hasNext()) {
+ XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ transformEnvelopedSignature.transform(xmlSecEvent);
+ }
+
+ transformEnvelopedSignature.doFinal();
+
+ Assert.assertEquals(19, xmlSecEvents.size());
+ }
+
+ @Test
+ public void testXMLSecEventToInputStreamAPI() throws Exception {
+ TransformEnvelopedSignature transformEnvelopedSignature = new TransformEnvelopedSignature();
+
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.InputStream;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(XMLSecEvent");
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ try {
+ IOUtils.copy(inputStream, byteArrayOutputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+ transformEnvelopedSignature.setTransformer(transformer);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "com/phaos/phaos-xmldsig-three/signature-rsa-enveloped.xml")
+ );
+
+ while (xmlSecEventReader.hasNext()) {
+ XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ transformEnvelopedSignature.transform(xmlSecEvent);
+ }
+
+ transformEnvelopedSignature.doFinal();
+
+ Assert.assertEquals(207, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testXMLSecEventToOutputStreamStreamAPI() throws Exception {
+ TransformEnvelopedSignature transformEnvelopedSignature = new TransformEnvelopedSignature();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ transformEnvelopedSignature.setOutputStream(byteArrayOutputStream);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "com/phaos/phaos-xmldsig-three/signature-rsa-enveloped.xml")
+ );
+
+ while (xmlSecEventReader.hasNext()) {
+ XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ transformEnvelopedSignature.transform(xmlSecEvent);
+ }
+
+ transformEnvelopedSignature.doFinal();
+
+ Assert.assertEquals(207, byteArrayOutputStream.size());
+ }
+}
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformEnvelopedSignatureTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformEnvelopedSignatureTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformIdentityTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformIdentityTest.java?rev=1367437&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformIdentityTest.java (added)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformIdentityTest.java Tue Jul 31 07:20:29 2012
@@ -0,0 +1,333 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.stax.transformer;
+
+import junit.framework.Assert;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.xml.security.stax.ext.Transformer;
+import org.apache.xml.security.stax.ext.XMLSecurityConstants;
+import org.apache.xml.security.stax.ext.XMLSecurityException;
+import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
+import org.apache.xml.security.stax.impl.transformer.TransformIdentity;
+import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class TransformIdentityTest extends org.junit.Assert {
+
+ private XMLInputFactory xmlInputFactory;
+
+ @Before
+ public void setUp() throws Exception {
+ this.xmlInputFactory = XMLInputFactory.newInstance();
+ this.xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
+ }
+
+ @Test
+ public void testXMLSecEventToXMLSecEventAPI() throws Exception {
+ TransformIdentity transformIdentity = new TransformIdentity();
+
+ final List<XMLSecEvent> xmlSecEvents = new ArrayList<XMLSecEvent>();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ xmlSecEvents.add(xmlSecEvent);
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(InputStream");
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+ transformIdentity.setTransformer(transformer);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")
+ );
+
+ XMLSecEvent xmlSecEvent = null;
+ while (xmlSecEventReader.hasNext()) {
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ }
+ while (xmlSecEventReader.hasNext()) {
+ transformIdentity.transform(xmlSecEvent);
+ if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ }
+
+ transformIdentity.doFinal();
+
+ Assert.assertEquals(3, xmlSecEvents.size());
+ }
+
+ @Test
+ public void testXMLSecEventToInputStreamAPI() throws Exception {
+ TransformIdentity transformIdentity = new TransformIdentity();
+
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.InputStream;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(XMLSecEvent");
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ try {
+ IOUtils.copy(inputStream, byteArrayOutputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+ transformIdentity.setTransformer(transformer);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")
+ );
+
+ XMLSecEvent xmlSecEvent = null;
+ while (xmlSecEventReader.hasNext()) {
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ }
+ while (xmlSecEventReader.hasNext()) {
+ transformIdentity.transform(xmlSecEvent);
+ if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ }
+
+ transformIdentity.doFinal();
+
+ Assert.assertEquals(255, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testXMLSecEventToOutputStreamStreamAPI() throws Exception {
+ TransformIdentity transformIdentity = new TransformIdentity();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ transformIdentity.setOutputStream(byteArrayOutputStream);
+
+ XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(
+ this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")
+ );
+
+ XMLSecEvent xmlSecEvent = null;
+ while (xmlSecEventReader.hasNext()) {
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ }
+ while (xmlSecEventReader.hasNext()) {
+ transformIdentity.transform(xmlSecEvent);
+ if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
+ break;
+ }
+ xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
+ }
+
+ transformIdentity.doFinal();
+
+ Assert.assertEquals(255, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testInputStreamToOutputStreamStreamAPI() throws Exception {
+ TransformIdentity transformIdentity = new TransformIdentity();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ transformIdentity.setOutputStream(byteArrayOutputStream);
+
+ transformIdentity.transform(this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/xml-stylesheet.b64"));
+
+ Assert.assertEquals(17786, byteArrayOutputStream.size());
+ }
+
+ @Test
+ public void testInputStreamToXMLSecEventAPI() throws Exception {
+ TransformIdentity transformIdentity = new TransformIdentity();
+ final List<XMLSecEvent> xmlSecEvents = new ArrayList<XMLSecEvent>();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.XMLSecEvent;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ xmlSecEvents.add(xmlSecEvent);
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(InputStream");
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+
+ transformIdentity.setTransformer(transformer);
+
+ transformIdentity.transform(this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
+
+ transformIdentity.doFinal();
+
+ Assert.assertEquals(25, xmlSecEvents.size());
+ }
+
+ @Test
+ public void testInputStreamToInputStreamAPI() throws Exception {
+ TransformIdentity transformIdentity = new TransformIdentity();
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ Transformer transformer = new Transformer() {
+ @Override
+ public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setTransformer(Transformer transformer) throws XMLSecurityException {
+ }
+
+ @Override
+ public void setList(List list) throws XMLSecurityException {
+ }
+
+ @Override
+ public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
+ return XMLSecurityConstants.TransformMethod.InputStream;
+ }
+
+ @Override
+ public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
+ Assert.fail("unexpected call to transform(XMLSecEvent");
+ }
+
+ @Override
+ public void transform(InputStream inputStream) throws XMLStreamException {
+ try {
+ IOUtils.copy(inputStream, byteArrayOutputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ }
+ };
+
+ transformIdentity.setTransformer(transformer);
+
+ transformIdentity.transform(this.getClass().getClassLoader().getResourceAsStream(
+ "ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml"));
+
+ transformIdentity.doFinal();
+
+ Assert.assertEquals(831, byteArrayOutputStream.size());
+ }
+}
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformIdentityTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/transformer/TransformIdentityTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/HttpRequestRedirectorProxy.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/HttpRequestRedirectorProxy.java?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/HttpRequestRedirectorProxy.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/HttpRequestRedirectorProxy.java Tue Jul 31 07:20:29 2012
@@ -89,6 +89,8 @@ public class HttpRequestRedirectorProxy
static {
paths.add("ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three");
+ paths.add("com/pothole/xmldsig");
+ paths.add("javax/xml/crypto/dsig");
}
@Override
Added: santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml?rev=1367437&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml (added)
+++ santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml Tue Jul 31 07:20:29 2012
@@ -0,0 +1,11 @@
+PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPFB1cmNoYXNlT3JkZXIgeG1s
+bnM9InVybjpleGFtcGxlOnBvIj4KICA8SXRlbXM+CiAgICA8SXRlbSBDb2RlPSIwMDEtMDAxLTAw
+MSIgUXVhbnRpdHk9IjEiPgogICAgICBzcGFkZQogICAgPC9JdGVtPgogICAgPEl0ZW0gQ29kZT0i
+MDAxLTAwMS0wMDIiIFF1YW50aXR5PSIxIj4KICAgICAgc2hvdmVsCiAgICA8L0l0ZW0+CiAgPC9J
+dGVtcz4KICA8U2hpcHBpbmdBZGRyZXNzPgogICAgRGlnIFBMQywgMSBGaXJzdCBBdmUsIER1Ymxp
+biAxLCBJcmVsYW5kCiAgPC9TaGlwcGluZ0FkZHJlc3M+CiAgPFBheW1lbnRJbmZvPgogICAgPEJp
+bGxpbmdBZGRyZXNzPgogICAgICBEaWcgUExDLCAxIEZpcnN0IEF2ZSwgRHVibGluIDEsIElyZWxh
+bmQKICAgIDwvQmlsbGluZ0FkZHJlc3M+CiAgICA8Q3JlZGl0Q2FyZCBUeXBlPSJBbWV4Ij4KICAg
+ICAgPE5hbWU+Rm9vIEIgQmF6PC9OYW1lPgogICAgICA8TnVtYmVyPjEyMzQgNTY3ODkwIDEyMzQ1
+PC9OdW1iZXI+CiAgICAgIDxFeHBpcmVzIE1vbnRoPSIxIiBZZWFyPSIyMDA1IiAvPgogICAgPC9D
+cmVkaXRDYXJkPgogIDwvUGF5bWVudEluZm8+CjwvUHVyY2hhc2VPcmRlcj4K
Propchange: santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml?rev=1367437&r1=1367436&r2=1367437&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml (original)
+++ santuario/xml-security-java/trunk/src/test/resources/ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml Tue Jul 31 07:20:29 2012
@@ -12,10 +12,8 @@
Dig PLC, 1 First Ave, Dublin 1, Ireland
</ShippingAddress>
<PaymentInfo>
- PEJpbGxpbmdBZGRyZXNzPgogICAgICBEaWcgUExDLCAxIEZpcnN0IEF2ZSwgRHVibGluIDEsIEly
- ZWxhbmQKICAgIDwvQmlsbGluZ0FkZHJlc3M+CiAgICA8Q3JlZGl0Q2FyZCBUeXBlPUFtZXg+CiAg
- ICAgIDxOYW1lPkZvbyBCIEJhejwvTmFtZT4KICAgICAgPE51bWJlcj4xMjM0IDU2Nzg5MCAxMjM0
- NTwvTnVtYmVyPgogICAgICA8RXhwaXJlcyBNb250aD0xIFllYXI9MjAwNSAvPgogICAgPC9DcmVk
- aXRDYXJkPgo=
+ PENyZWRpdENhcmQgVHlwZT0iQW1leCI+CiAgICAgIDxOYW1lPkZvbyBCIEJhejwvTmFtZT4KICAg
+ ICAgPE51bWJlcj4xMjM0IDU2Nzg5MCAxMjM0NTwvTnVtYmVyPgogICAgICA8RXhwaXJlcyBNb250
+ aD0iMSIgWWVhcj0iMjAwNSIgLz4KICAgIDwvQ3JlZGl0Q2FyZD4K
</PaymentInfo>
</PurchaseOrder>