Search in sources :

Example 1 with Canonicalizer20010315Excl

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method test222excl.

/**
 * Method test222excl
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XMLSecurityException
 * @throws XMLSignatureException
 */
@org.junit.Test
public void test222excl() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException {
    Document doc = this.db.parse(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_2.xml"));
    Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
    Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
    byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml"));
    byte[] result = c.engineCanonicalizeSubTree(root);
    boolean equals = java.security.MessageDigest.isEqual(reference, result);
    assertTrue(equals);
}
Also used : Canonicalizer20010315Excl(org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl) Canonicalizer20010315ExclWithComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document)

Example 2 with Canonicalizer20010315Excl

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl 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);
    Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
    Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
    byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml"));
    byte[] result = c.engineCanonicalizeSubTree(root);
    boolean equals = java.security.MessageDigest.isEqual(reference, result);
    assertTrue(equals);
}
Also used : Canonicalizer20010315Excl(org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl) Canonicalizer20010315ExclWithComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document)

Example 3 with Canonicalizer20010315Excl

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method test24excl.

/**
 * Method test24excl - 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 test24excl() throws Exception {
    Document doc = this.db.parse(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_4.xml"));
    Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
    Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
    byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml"));
    byte[] result = c.engineCanonicalizeSubTree(root);
    boolean equals = java.security.MessageDigest.isEqual(reference, result);
    assertTrue(equals);
}
Also used : Canonicalizer20010315Excl(org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl) Canonicalizer20010315ExclWithComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document)

Example 4 with Canonicalizer20010315Excl

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl in project santuario-java by apache.

the class EmptyNamespaceTest method doDOMTest.

@org.junit.Test
public void doDOMTest() throws Exception {
    org.apache.xml.security.Init.init();
    org.apache.xml.security.stax.config.Init.init(null, EmptyNamespaceTest.class);
    Canonicalizer20010315Excl transformer = new Canonicalizer20010315ExclOmitComments();
    final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilderFactory.setValidating(false);
    final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = null;
    try (InputStream is = new ByteArrayInputStream(message.getBytes(java.nio.charset.StandardCharsets.UTF_8))) {
        document = documentBuilder.parse(is);
    }
    String inclusiveNamespaces = "SOAP-ENV ec ec1 ns0 ns1 ns11 ns2 ns4 ns9";
    byte[] output = transformer.engineCanonicalizeSubTree(document, inclusiveNamespaces);
    String result = new String(output, java.nio.charset.StandardCharsets.UTF_8);
    Assert.assertEquals(message, result);
}
Also used : Canonicalizer20010315Excl(org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Canonicalizer20010315ExclOmitComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments) Document(org.w3c.dom.Document)

Example 5 with Canonicalizer20010315Excl

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method test223excl.

/**
 * Method test223excl
 *
 * Provided by Gabriel McGoldrick - see e-mail of 21/11/03
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XMLSecurityException
 * @throws XMLSignatureException
 * @throws XPathExpressionException
 */
@org.junit.Test
public void test223excl() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException, XPathExpressionException {
    Document doc = this.db.parse(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_3.xml"));
    XPathFactory xpf = XPathFactory.newInstance();
    XPath xpath = xpf.newXPath();
    xpath.setNamespaceContext(new DSNamespaceContext());
    String expression = "(//. | //@* | //namespace::*)[ancestor-or-self::p]";
    NodeList nodes = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET);
    Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
    byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_3_c14nized_exclusive.xml"));
    byte[] result = c.engineCanonicalizeXPathNodeSet(nodes);
    assertEquals(new String(reference), new String(result));
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) Canonicalizer20010315Excl(org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl) Canonicalizer20010315ExclWithComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments) DSNamespaceContext(org.apache.xml.security.test.dom.DSNamespaceContext) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Aggregations

Canonicalizer20010315Excl (org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl)6 Document (org.w3c.dom.Document)6 Canonicalizer20010315ExclWithComments (org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclWithComments)5 Node (org.w3c.dom.Node)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 XPath (javax.xml.xpath.XPath)1 XPathFactory (javax.xml.xpath.XPathFactory)1 Canonicalizer20010315ExclOmitComments (org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments)1 DSNamespaceContext (org.apache.xml.security.test.dom.DSNamespaceContext)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1