use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method testNodeSet.
/**
* Tests node-set as input. See bug 37708.
* Provided by Pete Hendry.
*/
@org.junit.Test
public void testNodeSet() throws Exception {
final String XML = "<env:Envelope" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:ns0=\"http://xmlsoap.org/Ping\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + "<env:Body wsu:Id=\"body\">" + "<ns0:Ping xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>" + "</env:Envelope>";
final String c14nXML = "<env:Body" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:ns0=\"http://xmlsoap.org/Ping\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " wsu:Id=\"body\">" + "<ns0:Ping xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>";
Document doc = this.db.parse(new InputSource(new StringReader(XML)));
Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
Set<Node> nodeSet = new HashSet<>();
XMLUtils.getSet(doc.getDocumentElement().getFirstChild(), nodeSet, null, false);
XMLSignatureInput input = new XMLSignatureInput(nodeSet);
byte[] bytes = c14n.engineCanonicalize(input, "env ns0 xsi wsu");
assertEquals(c14nXML, new String(bytes));
}
use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method testPropagateDefaultNs1.
/**
* Test default namespace behavior if its in the InclusiveNamespace prefix list.
*
* @throws Exception
*/
@org.junit.Test
public void testPropagateDefaultNs1() throws Exception {
final String XML = "<env:Envelope" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:ns0=\"http://xmlsoap.org/Ping\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + "<env:Body wsu:Id=\"body\">" + "<ns0:Ping xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>" + "</env:Envelope>";
final String c14nXML = "<env:Body" + " xmlns=\"\"" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" + " wsu:Id=\"body\">" + "<ns0:Ping xmlns:ns0=\"http://xmlsoap.org/Ping\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>";
Document doc = this.db.parse(new InputSource(new StringReader(XML)));
Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
byte[] bytes = c14n.engineCanonicalizeSubTree(doc.getDocumentElement().getFirstChild(), "#default", true);
assertEquals(c14nXML, new String(bytes));
}
use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method testPropagateDefaultNs2.
@org.junit.Test
public void testPropagateDefaultNs2() throws Exception {
final String XML = "<env:Envelope" + " xmlns=\"http://example.com\"" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:ns0=\"http://xmlsoap.org/Ping\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + "<env:Body wsu:Id=\"body\">" + "<ns0:Ping xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>" + "</env:Envelope>";
final String c14nXML = "<env:Body" + " xmlns=\"http://example.com\"" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" + " wsu:Id=\"body\">" + "<ns0:Ping xmlns:ns0=\"http://xmlsoap.org/Ping\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>";
Document doc = this.db.parse(new InputSource(new StringReader(XML)));
Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
byte[] bytes = c14n.engineCanonicalizeSubTree(doc.getDocumentElement().getFirstChild(), "#default", true);
assertEquals(c14nXML, new String(bytes));
}
use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments in project santuario-java by apache.
the class Canonicalizer20010315ExclusiveTest method testPropagateDefaultNs3.
@org.junit.Test
public void testPropagateDefaultNs3() throws Exception {
final String XML = "<Envelope" + " xmlns=\"http://example.com\"" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:ns0=\"http://xmlsoap.org/Ping\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + "<env:Body wsu:Id=\"body\">" + "<ns0:Ping xsi:type=\"ns0:ping\">" + "<ns0:text xmlns=\"\" xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>" + "</Envelope>";
final String c14nXML = "<env:Body" + " xmlns=\"http://example.com\"" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" + " wsu:Id=\"body\">" + "<ns0:Ping xmlns:ns0=\"http://xmlsoap.org/Ping\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"ns0:ping\">" + "<ns0:text xmlns=\"\" xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>";
Document doc = this.db.parse(new InputSource(new StringReader(XML)));
Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
byte[] bytes = c14n.engineCanonicalizeSubTree(doc.getDocumentElement().getFirstChild(), "#default", true);
assertEquals(c14nXML, new String(bytes));
}
use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments 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);
}
Aggregations