use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method test24excl.
@org.junit.Test
public void test24excl() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
c.setOutputStream(baos);
canonicalize(c, this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/example2_4.xml"), new QName("http://example.net", "elem2"));
byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml"));
boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
if (!equals) {
System.out.println("Expected:\n" + new String(reference, java.nio.charset.StandardCharsets.UTF_8));
System.out.println("");
System.out.println("Got:\n" + new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8));
}
assertTrue(equals);
}
use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method test222excl.
@org.junit.Test
public void test222excl() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
c.setOutputStream(baos);
canonicalize(c, this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/example2_2_2.xml"), new QName("http://example.net", "elem2"));
byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml"));
boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
if (!equals) {
System.out.println("Expected:\n" + new String(reference, java.nio.charset.StandardCharsets.UTF_8));
System.out.println("");
System.out.println("Got:\n" + new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8));
}
assertTrue(equals);
}
use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method testComplexDocexcl.
@org.junit.Test
public void testComplexDocexcl() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
c.setOutputStream(baos);
canonicalize(c, this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"), new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body", "env"));
byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/plain-soap-c14nized.xml"));
boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
if (!equals) {
System.out.println("Expected:\n" + new String(reference, java.nio.charset.StandardCharsets.UTF_8));
System.out.println("");
System.out.println("Got:\n" + new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8));
}
assertTrue(equals);
}
use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method test24Aexcl.
/**
* Method test24Aexcl - a testcase for SANTUARIO-263
* "Canonicalizer can't handle dynamical created DOM correctly"
* https://issues.apache.org/jira/browse/SANTUARIO-263
*/
@org.junit.Test
public void test24Aexcl() throws Exception {
Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
Element local = doc.createElementNS("foo:bar", "dsig:local");
Element test = doc.createElementNS("http://example.net", "etsi:test");
Element elem2 = doc.createElementNS("http://example.net", "etsi:elem2");
Element stuff = doc.createElementNS("foo:bar", "dsig:stuff");
elem2.appendChild(stuff);
test.appendChild(elem2);
local.appendChild(test);
doc.appendChild(local);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
t.transform(new DOMSource(doc), streamResult);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
List<String> inclusiveNamespaces = new ArrayList<>();
Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
Map<String, Object> transformerProperties = new HashMap<>();
transformerProperties.put(Canonicalizer20010315_Excl.INCLUSIVE_NAMESPACES_PREFIX_LIST, inclusiveNamespaces);
c.setProperties(transformerProperties);
c.setOutputStream(baos);
canonicalize(c, new StringReader(stringWriter.toString()), new QName("http://example.net", "elem2"));
byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml"));
boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
assertTrue(equals);
}
use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method test221excl.
@org.junit.Test
public void test221excl() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
c.setOutputStream(baos);
XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/example2_2_1.xml"));
XMLSecEvent xmlSecEvent = null;
while (xmlSecEventReader.hasNext()) {
xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("http://example.net", "elem2"))) {
break;
}
}
while (xmlSecEventReader.hasNext()) {
c.transform(xmlSecEvent);
if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("http://example.net", "elem2"))) {
break;
}
xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
}
byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml"));
boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
if (!equals) {
System.out.println("Expected:\n" + new String(reference, java.nio.charset.StandardCharsets.UTF_8));
System.out.println("");
System.out.println("Got:\n" + new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8));
}
assertTrue(equals);
}
Aggregations