You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2020/01/22 13:06:34 UTC
svn commit: r1873032 [2/2] - in /santuario/xml-security-java/trunk/src:
main/java/org/apache/jcp/xml/dsig/internal/dom/
main/java/org/apache/xml/security/c14n/
main/java/org/apache/xml/security/c14n/implementations/
main/java/org/apache/xml/security/en...
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Canonicalizer20010315Test.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Canonicalizer20010315Test.java?rev=1873032&r1=1873031&r2=1873032&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Canonicalizer20010315Test.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Canonicalizer20010315Test.java Wed Jan 22 13:06:34 2020
@@ -409,10 +409,12 @@ public class Canonicalizer20010315Test {
NodeList nodes = (NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);
Canonicalizer c14n =
Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
- byte[] c14nBytes = c14n.canonicalizeXPathNodeSet(XMLUtils.convertNodelistToSet(nodes));
- InputStream refStream = new FileInputStream(fileRef);
- byte[] refBytes = JavaUtils.getBytesFromStream(refStream);
- assertEquals(new String(refBytes),new String(c14nBytes));
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ c14n.canonicalizeXPathNodeSet(XMLUtils.convertNodelistToSet(nodes), baos);
+ InputStream refStream = new FileInputStream(fileRef);
+ byte[] refBytes = JavaUtils.getBytesFromStream(refStream);
+ assertEquals(new String(refBytes),new String(baos.toByteArray()));
+ }
}
/**
@@ -444,10 +446,10 @@ public class Canonicalizer20010315Test {
}
boolean weCatchedTheRelativeNS = false;
- try {
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
Canonicalizer c14n =
Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
- c14n.canonicalizeSubtree(doc);
+ c14n.canonicalizeSubtree(doc, baos);
} catch (CanonicalizationException cex) {
// if we reach this point - good.
@@ -475,12 +477,14 @@ public class Canonicalizer20010315Test {
byte[] utf16 = convertToUTF16(val.getBytes());
Canonicalizer c14n =
Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
- byte[] c14nBytes = c14n.canonicalize(utf16);
- InputStream refStream = new FileInputStream(prefix + "/in/testTranslationFromUTF16toUTF8.xml");
- byte[] refBytes = JavaUtils.getBytesFromStream(refStream);
- boolean equal = java.security.MessageDigest.isEqual(refBytes, c14nBytes);
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ c14n.canonicalize(utf16, baos);
+ InputStream refStream = new FileInputStream(prefix + "/in/testTranslationFromUTF16toUTF8.xml");
+ byte[] refBytes = JavaUtils.getBytesFromStream(refStream);
+ boolean equal = java.security.MessageDigest.isEqual(refBytes, baos.toByteArray());
- assertTrue(equal, "Parser does not translate to UCS character domain");
+ assertTrue(equal, "Parser does not translate to UCS character domain");
+ }
}
/**
@@ -669,10 +673,13 @@ public class Canonicalizer20010315Test {
NodeList nodes =
(NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);
- byte[] result = c14nizer.canonicalizeXPathNodeSet(XMLUtils.convertNodelistToSet(nodes));
- byte[] defined = definedOutput.getBytes();
- assertEquals(definedOutput, new String(result));
- return java.security.MessageDigest.isEqual(defined, result);
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ c14nizer.canonicalizeXPathNodeSet(XMLUtils.convertNodelistToSet(nodes), baos);
+ byte[] defined = definedOutput.getBytes();
+ byte[] result = baos.toByteArray();
+ assertEquals(definedOutput, new String(result));
+ return java.security.MessageDigest.isEqual(defined, result);
+ }
}
private boolean c14nAndCompare(
@@ -705,18 +712,22 @@ public class Canonicalizer20010315Test {
Canonicalizer c14n = Canonicalizer.getInstance(c14nURI);
byte[] c14nBytes = null;
- if (xpath == null) {
- c14nBytes = c14n.canonicalizeSubtree(doc);
- } else {
- XPathFactory xpf = XPathFactory.newInstance();
- XPath xPath = xpf.newXPath();
- DSNamespaceContext namespaceContext =
- new DSNamespaceContext(namespaces);
- xPath.setNamespaceContext(namespaceContext);
-
- NodeList nl = (NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);
-
- c14nBytes = c14n.canonicalizeXPathNodeSet(XMLUtils.convertNodelistToSet(nl));
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ if (xpath == null) {
+ c14n.canonicalizeSubtree(doc, baos);
+ c14nBytes = baos.toByteArray();
+ } else {
+ XPathFactory xpf = XPathFactory.newInstance();
+ XPath xPath = xpf.newXPath();
+ DSNamespaceContext namespaceContext =
+ new DSNamespaceContext(namespaces);
+ xPath.setNamespaceContext(namespaceContext);
+
+ NodeList nl = (NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);
+
+ c14n.canonicalizeXPathNodeSet(XMLUtils.convertNodelistToSet(nl), baos);
+ c14nBytes = baos.toByteArray();
+ }
}
// org.xml.sax.InputSource refIs = resolver.resolveEntity(null, fileRef);
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/MockCanonicalizationMethod.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/MockCanonicalizationMethod.java?rev=1873032&r1=1873031&r2=1873032&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/MockCanonicalizationMethod.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/MockCanonicalizationMethod.java Wed Jan 22 13:06:34 2020
@@ -36,29 +36,30 @@ public class MockCanonicalizationMethod
_impl = new Canonicalizer11_OmitComments();
}
- public byte[] engineCanonicalizeSubTree(Node rootNode)
+ public void engineCanonicalizeSubTree(Node rootNode, OutputStream writer)
throws CanonicalizationException {
- return _impl.engineCanonicalizeSubTree(rootNode);
+ _impl.engineCanonicalizeSubTree(rootNode, writer);
}
- public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
+ public void engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, OutputStream writer)
throws CanonicalizationException {
- return _impl.engineCanonicalizeSubTree(rootNode, inclusiveNamespaces);
+ _impl.engineCanonicalizeSubTree(rootNode, inclusiveNamespaces, writer);
}
- public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, boolean propagateDefaultNamespace)
+ public void engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces,
+ boolean propagateDefaultNamespace, OutputStream writer)
throws CanonicalizationException {
- return _impl.engineCanonicalizeSubTree(rootNode, inclusiveNamespaces, propagateDefaultNamespace);
+ _impl.engineCanonicalizeSubTree(rootNode, inclusiveNamespaces, propagateDefaultNamespace, writer);
}
- public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet)
+ public void engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, OutputStream writer)
throws CanonicalizationException {
- return _impl.engineCanonicalizeXPathNodeSet(xpathNodeSet);
+ _impl.engineCanonicalizeXPathNodeSet(xpathNodeSet, writer);
}
- public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces)
+ public void engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces, OutputStream writer)
throws CanonicalizationException {
- return _impl.engineCanonicalizeXPathNodeSet(xpathNodeSet, inclusiveNamespaces);
+ _impl.engineCanonicalizeXPathNodeSet(xpathNodeSet, inclusiveNamespaces, writer);
}
public boolean engineGetIncludeComments() {
@@ -69,8 +70,4 @@ public class MockCanonicalizationMethod
return MOCK_CANONICALIZATION_METHOD;
}
- public void setWriter(OutputStream os) {
- _impl.setWriter(os);
- }
-
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Santuario191Test.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Santuario191Test.java?rev=1873032&r1=1873031&r2=1873032&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Santuario191Test.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Santuario191Test.java Wed Jan 22 13:06:34 2020
@@ -73,14 +73,14 @@ public class Santuario191Test {
//
NodeList dataNodes = doc.getElementsByTagName("data");
Canonicalizer11_OmitComments c14ner = new Canonicalizer11_OmitComments();
- byte[] result = c14ner.engineCanonicalizeSubTree(dataNodes.item(0));
+ try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
+ c14ner.engineCanonicalizeSubTree(dataNodes.item(0), output);
- //
- // Test against expected result
- //
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- out.write(result);
- assertEquals(EXPECTED_RESULT, out.toString(StandardCharsets.UTF_8.name()));
+ //
+ // Test against expected result
+ //
+ assertEquals(EXPECTED_RESULT, output.toString(StandardCharsets.UTF_8.name()));
+ }
}
}
\ No newline at end of file
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Santuario273Test.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Santuario273Test.java?rev=1873032&r1=1873031&r2=1873032&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Santuario273Test.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/c14n/implementations/Santuario273Test.java Wed Jan 22 13:06:34 2020
@@ -20,6 +20,7 @@ package org.apache.xml.security.test.dom
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.xml.xpath.XPath;
@@ -93,9 +94,11 @@ public class Santuario273Test {
Node signedInfo =
(Node) xPath.evaluate("//ds:SignedInfo[1]", doc, XPathConstants.NODE);
- byte[] output = c14n.canonicalizeSubtree(signedInfo);
+ try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
+ c14n.canonicalizeSubtree(signedInfo, output);
- assertEquals( new String(output, java.nio.charset.StandardCharsets.UTF_8), expectedResult);
+ assertEquals(new String(output.toByteArray(), java.nio.charset.StandardCharsets.UTF_8), expectedResult);
+ }
}
}
\ No newline at end of file
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/encryption/XMLCipherTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/encryption/XMLCipherTest.java?rev=1873032&r1=1873031&r2=1873032&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/encryption/XMLCipherTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/encryption/XMLCipherTest.java Wed Jan 22 13:06:34 2020
@@ -830,8 +830,7 @@ public class XMLCipherTest {
Canonicalizer canon =
Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- canon.setWriter(baos);
- canon.canonicalizeSubtree(e);
+ canon.canonicalizeSubtree(e, baos);
baos.close();
String before = baos.toString(StandardCharsets.UTF_8.name());
@@ -975,12 +974,10 @@ public class XMLCipherTest {
private String toString (Node n) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Canonicalizer c14n = Canonicalizer.getInstance
- (Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
+ Canonicalizer c14n = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
- byte[] serBytes = c14n.canonicalizeSubtree(n);
- baos.write(serBytes);
- baos.close();
+ c14n.canonicalizeSubtree(n, baos);
+ baos.flush();
return baos.toString(StandardCharsets.UTF_8.name());
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/transforms/EmptyNamespaceTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/transforms/EmptyNamespaceTest.java?rev=1873032&r1=1873031&r2=1873032&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/transforms/EmptyNamespaceTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/transforms/EmptyNamespaceTest.java Wed Jan 22 13:06:34 2020
@@ -102,10 +102,11 @@ public class EmptyNamespaceTest {
}
String inclusiveNamespaces = "SOAP-ENV ec ec1 ns0 ns1 ns11 ns2 ns4 ns9";
- byte[] output =
- transformer.engineCanonicalizeSubTree(document, inclusiveNamespaces);
+ try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
+ transformer.engineCanonicalizeSubTree(document, inclusiveNamespaces, output);
- String result = new String(output, java.nio.charset.StandardCharsets.UTF_8);
- assertEquals(message, result);
+ String result = new String(output.toByteArray(), java.nio.charset.StandardCharsets.UTF_8);
+ assertEquals(message, result);
+ }
}
}
\ No newline at end of file