[java-opensaml] branch master updated: OSJ-226: Refactor SAML encoder tests to be less sensitive to ...
Brent Putman
putmanb at georgetown.edu
Fri Oct 5 12:47:43 EDT 2018
This is an automated email from the git hooks/post-receive script.
putmanb pushed a commit to branch master
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=08d1be7de26204ad8288fa5d084c235a20a52684
The following commit(s) were added to refs/heads/master by this push:
new 08d1be7 OSJ-226: Refactor SAML encoder tests to be less sensitive to ...
08d1be7 is described below
commit 08d1be7de26204ad8288fa5d084c235a20a52684
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Thu Oct 4 20:17:15 2018 -0400
OSJ-226: Refactor SAML encoder tests to be less sensitive to ...
---
opensaml-saml-impl/pom.xml | 5 +
.../binding/encoding/impl/HTTPPostEncoderTest.java | 67 ++++++-
.../encoding/impl/HTTPSOAP11EncoderTest.java | 26 ++-
.../binding/encoding/impl/HTTPPostEncoderTest.java | 122 +++++++++++--
.../impl/HTTPPostSimpleSignEncoderTest.java | 200 ++++++++++++++++++---
.../impl/HTTPRedirectDeflateEncoderTest.java | 138 ++++++++++----
.../encoding/impl/HTTPSOAP11EncoderTest.java | 27 ++-
7 files changed, 502 insertions(+), 83 deletions(-)
diff --git a/opensaml-saml-impl/pom.xml b/opensaml-saml-impl/pom.xml
index 8a983f3..4dc22af 100644
--- a/opensaml-saml-impl/pom.xml
+++ b/opensaml-saml-impl/pom.xml
@@ -152,6 +152,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jsoup</groupId>
+ <artifactId>jsoup</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPPostEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPPostEncoderTest.java
index da9d840..f979522 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPPostEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPPostEncoderTest.java
@@ -17,10 +17,20 @@
package org.opensaml.saml.saml1.binding.encoding.impl;
+import java.io.ByteArrayInputStream;
+import java.util.List;
+
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.joda.time.DateTime;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.DocumentType;
+import org.jsoup.nodes.Element;
+import org.jsoup.nodes.Node;
+import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.core.xml.util.XMLObjectSupport;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.SAMLObjectBuilder;
@@ -29,7 +39,6 @@ import org.opensaml.saml.common.binding.SAMLBindingSupport;
import org.opensaml.saml.common.binding.impl.SAMLOutboundDestinationHandler;
import org.opensaml.saml.common.messaging.context.SAMLEndpointContext;
import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
-import org.opensaml.saml.saml1.binding.encoding.impl.HTTPPostEncoder;
import org.opensaml.saml.saml1.core.Response;
import org.opensaml.saml.saml2.metadata.AssertionConsumerService;
import org.opensaml.saml.saml2.metadata.Endpoint;
@@ -38,7 +47,7 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import net.shibboleth.utilities.java.support.testing.TestSupport;
+import net.shibboleth.utilities.java.support.codec.Base64Support;
/**
* Test class for SAML 1 HTTP Post encoding.
@@ -100,10 +109,56 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals(response.getContentType(), "text/html", "Unexpected content type");
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
- // TODO: this hashes differently for endorsed Xerces and Java 9
- if (TestSupport.isJavaV9OrLater()) {
- return;
+
+ Document webDoc = Jsoup.parse(response.getContentAsString());
+
+ boolean sawDocType = false;
+ List<Node>nods = webDoc.childNodes();
+ for (Node node : nods) {
+ if (node instanceof DocumentType) {
+ sawDocType = true;
+ DocumentType documentType = (DocumentType)node;
+ Assert.assertEquals(documentType.attr("name"), "html");
+ Assert.assertEquals(documentType.attr("publicId"), "");
+ Assert.assertEquals(documentType.attr("systemId"), "");
+ }
}
- Assert.assertEquals(response.getContentAsString().hashCode(), 1601070451);
+ Assert.assertTrue(sawDocType);
+
+ Element head = webDoc.selectFirst("html > head");
+ Assert.assertNotNull(head);
+ Element metaCharSet = head.selectFirst("meta[charset]");
+ Assert.assertNotNull(metaCharSet);
+ Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
+
+ Element body = webDoc.selectFirst("html > body");
+ Assert.assertNotNull(body);
+ Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
+
+ Element form = body.selectFirst("form");
+ Assert.assertNotNull(form);
+ Assert.assertEquals(form.attr("method").toLowerCase(), "post");
+ Assert.assertEquals(form.attr("action"), "http://example.org/response");
+
+ Element relayState = form.selectFirst("input[name=TARGET]");
+ Assert.assertNotNull(relayState);
+ Assert.assertEquals(relayState.val(), "relay");
+
+ Element noscriptMsg = body.selectFirst("noscript > p");
+ Assert.assertNotNull(noscriptMsg);
+ Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
+
+ Element samlResponse = form.selectFirst("input[name=SAMLResponse]");
+ Assert.assertNotNull(samlResponse);
+ Assert.assertNotNull(samlResponse.val());
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
+ XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
+ Assert.assertTrue(xmlObject instanceof Response);
+ assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ }
+
+ Element submit = body.selectFirst("noscript > div > input[type=submit]");
+ Assert.assertNotNull(submit);
+ Assert.assertEquals(submit.val(), "Continue");
}
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPSOAP11EncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPSOAP11EncoderTest.java
index 24316f1..33d323d 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPSOAP11EncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/encoding/impl/HTTPSOAP11EncoderTest.java
@@ -17,8 +17,12 @@
package org.opensaml.saml.saml1.binding.encoding.impl;
+import java.io.ByteArrayInputStream;
+
import org.joda.time.DateTime;
+import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.core.xml.util.XMLObjectSupport;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.SAMLObjectBuilder;
@@ -26,16 +30,14 @@ import org.opensaml.saml.common.SAMLVersion;
import org.opensaml.saml.common.binding.SAMLBindingSupport;
import org.opensaml.saml.common.messaging.context.SAMLEndpointContext;
import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
-import org.opensaml.saml.saml1.binding.encoding.impl.HTTPSOAP11Encoder;
import org.opensaml.saml.saml1.core.Request;
import org.opensaml.saml.saml2.metadata.AssertionConsumerService;
import org.opensaml.saml.saml2.metadata.Endpoint;
+import org.opensaml.soap.soap11.Envelope;
import org.springframework.mock.web.MockHttpServletResponse;
import org.testng.Assert;
import org.testng.annotations.Test;
-import net.shibboleth.utilities.java.support.testing.TestSupport;
-
/**
* Test case for SAML 1.X HTTP SOAP 1.1 binding encoding.
*/
@@ -78,10 +80,20 @@ public class HTTPSOAP11EncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
Assert.assertEquals(response.getHeader("SOAPAction"), "http://www.oasis-open.org/committees/security");
- // TODO: this hashes differently for endorsed Xerces and Java 9
- if (TestSupport.isJavaV9OrLater()) {
- return;
+
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(response.getContentAsByteArray())) {
+ XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
+ Assert.assertNotNull(xmlObject);
+ Assert.assertTrue(xmlObject instanceof Envelope);
+ Envelope envelope = (Envelope) xmlObject;
+ Assert.assertNull(envelope.getHeader());
+ Assert.assertNotNull(envelope.getBody());
+ Assert.assertEquals(envelope.getBody().getUnknownXMLObjects().size(), 1);
+ Request outboundRequest = (Request) envelope.getBody().getUnknownXMLObjects().get(0);
+ outboundRequest.releaseDOM();
+ outboundRequest.releaseChildrenDOM(true);
+ outboundRequest.setParent(null);
+ assertXMLEquals(XMLObjectSupport.marshall(outboundRequest).getOwnerDocument(), request);
}
- Assert.assertEquals(response.getContentAsString().hashCode(), 259113724);
}
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java
index 4def22b..0921ee8 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java
@@ -17,10 +17,20 @@
package org.opensaml.saml.saml2.binding.encoding.impl;
+import java.io.ByteArrayInputStream;
+import java.util.List;
+
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.joda.time.DateTime;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.DocumentType;
+import org.jsoup.nodes.Element;
+import org.jsoup.nodes.Node;
+import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.core.xml.util.XMLObjectSupport;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.SAMLObjectBuilder;
@@ -29,7 +39,6 @@ import org.opensaml.saml.common.binding.SAMLBindingSupport;
import org.opensaml.saml.common.binding.impl.SAMLOutboundDestinationHandler;
import org.opensaml.saml.common.messaging.context.SAMLEndpointContext;
import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
-import org.opensaml.saml.saml2.binding.encoding.impl.HTTPPostEncoder;
import org.opensaml.saml.saml2.core.AuthnRequest;
import org.opensaml.saml.saml2.core.Response;
import org.opensaml.saml.saml2.core.Status;
@@ -41,7 +50,7 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import net.shibboleth.utilities.java.support.testing.TestSupport;
+import net.shibboleth.utilities.java.support.codec.Base64Support;
/**
* Test case for {@link HTTPPostEncoder}.
@@ -119,11 +128,58 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals(response.getContentType(), "text/html", "Unexpected content type");
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
- // TODO: this hashes differently for endorsed Xerces and Java 9
- if (TestSupport.isJavaV9OrLater()) {
- return;
+
+ Document webDoc = Jsoup.parse(response.getContentAsString());
+
+ boolean sawDocType = false;
+ List<Node>nods = webDoc.childNodes();
+ for (Node node : nods) {
+ if (node instanceof DocumentType) {
+ sawDocType = true;
+ DocumentType documentType = (DocumentType)node;
+ Assert.assertEquals(documentType.attr("name"), "html");
+ Assert.assertEquals(documentType.attr("publicId"), "");
+ Assert.assertEquals(documentType.attr("systemId"), "");
+ }
}
- Assert.assertEquals(response.getContentAsString().hashCode(), -1584370770);
+ Assert.assertTrue(sawDocType);
+
+ Element head = webDoc.selectFirst("html > head");
+ Assert.assertNotNull(head);
+ Element metaCharSet = head.selectFirst("meta[charset]");
+ Assert.assertNotNull(metaCharSet);
+ Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
+
+ Element body = webDoc.selectFirst("html > body");
+ Assert.assertNotNull(body);
+ Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
+
+ Element form = body.selectFirst("form");
+ Assert.assertNotNull(form);
+ Assert.assertEquals(form.attr("method").toLowerCase(), "post");
+ Assert.assertEquals(form.attr("action"), "http://example.org/response");
+
+ Element relayState = form.selectFirst("input[name=RelayState]");
+ Assert.assertNotNull(relayState);
+ Assert.assertEquals(relayState.val(), "relay");
+
+ Element noscriptMsg = body.selectFirst("noscript > p");
+ Assert.assertNotNull(noscriptMsg);
+ Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
+
+ Element samlResponse = form.selectFirst("input[name=SAMLResponse]");
+ Assert.assertNotNull(samlResponse);
+ Assert.assertNotNull(samlResponse.val());
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
+ XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
+ Assert.assertTrue(xmlObject instanceof Response);
+ assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ }
+
+ Element submit = body.selectFirst("noscript > div > input[type=submit]");
+ Assert.assertNotNull(submit);
+ Assert.assertEquals(submit.val(), "Continue");
+
}
@Test
@@ -166,11 +222,57 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals(response.getContentType(), "text/html", "Unexpected content type");
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
- // TODO: this hashes differently for endorsed Xerces and Java 9
- if (TestSupport.isJavaV9OrLater()) {
- return;
+
+ Document webDoc = Jsoup.parse(response.getContentAsString());
+
+ boolean sawDocType = false;
+ List<Node>nods = webDoc.childNodes();
+ for (Node node : nods) {
+ if (node instanceof DocumentType) {
+ sawDocType = true;
+ DocumentType documentType = (DocumentType)node;
+ Assert.assertEquals(documentType.attr("name"), "html");
+ Assert.assertEquals(documentType.attr("publicId"), "");
+ Assert.assertEquals(documentType.attr("systemId"), "");
+ }
}
- Assert.assertEquals(response.getContentAsString().hashCode(), 1585035273);
+ Assert.assertTrue(sawDocType);
+
+ Element head = webDoc.selectFirst("html > head");
+ Assert.assertNotNull(head);
+ Element metaCharSet = head.selectFirst("meta[charset]");
+ Assert.assertNotNull(metaCharSet);
+ Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
+
+ Element body = webDoc.selectFirst("html > body");
+ Assert.assertNotNull(body);
+ Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
+
+ Element form = body.selectFirst("form");
+ Assert.assertNotNull(form);
+ Assert.assertEquals(form.attr("method").toLowerCase(), "post");
+ Assert.assertEquals(form.attr("action"), "http://example.org");
+
+ Element relayState = form.selectFirst("input[name=RelayState]");
+ Assert.assertNotNull(relayState);
+ Assert.assertEquals(relayState.val(), "relay");
+
+ Element noscriptMsg = body.selectFirst("noscript > p");
+ Assert.assertNotNull(noscriptMsg);
+ Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
+
+ Element samlResponse = form.selectFirst("input[name=SAMLRequest]");
+ Assert.assertNotNull(samlResponse);
+ Assert.assertNotNull(samlResponse.val());
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
+ XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
+ Assert.assertTrue(xmlObject instanceof AuthnRequest);
+ assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ }
+
+ Element submit = body.selectFirst("noscript > div > input[type=submit]");
+ Assert.assertNotNull(submit);
+ Assert.assertEquals(submit.val(), "Continue");
}
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java
index 3801225..8db3e18 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java
@@ -17,12 +17,21 @@
package org.opensaml.saml.saml2.binding.encoding.impl;
+import java.io.ByteArrayInputStream;
import java.security.KeyPair;
+import java.util.List;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.joda.time.DateTime;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.DocumentType;
+import org.jsoup.nodes.Element;
+import org.jsoup.nodes.Node;
+import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.core.xml.util.XMLObjectSupport;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.SAMLObjectBuilder;
@@ -31,8 +40,6 @@ import org.opensaml.saml.common.binding.SAMLBindingSupport;
import org.opensaml.saml.common.binding.impl.SAMLOutboundDestinationHandler;
import org.opensaml.saml.common.messaging.context.SAMLEndpointContext;
import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
-import org.opensaml.saml.saml2.binding.encoding.impl.HTTPPostEncoder;
-import org.opensaml.saml.saml2.binding.encoding.impl.HTTPPostSimpleSignEncoder;
import org.opensaml.saml.saml2.core.AuthnRequest;
import org.opensaml.saml.saml2.core.Response;
import org.opensaml.saml.saml2.core.Status;
@@ -46,13 +53,14 @@ import org.opensaml.xmlsec.config.impl.DefaultSecurityConfigurationBootstrap;
import org.opensaml.xmlsec.context.SecurityParametersContext;
import org.opensaml.xmlsec.keyinfo.KeyInfoSupport;
import org.opensaml.xmlsec.keyinfo.NamedKeyInfoGeneratorManager;
+import org.opensaml.xmlsec.signature.KeyInfo;
import org.opensaml.xmlsec.signature.support.SignatureConstants;
import org.springframework.mock.web.MockHttpServletResponse;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import net.shibboleth.utilities.java.support.testing.TestSupport;
+import net.shibboleth.utilities.java.support.codec.Base64Support;
/**
* Test case for {@link HTTPPostEncoder}.
@@ -130,11 +138,61 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals(response.getContentType(), "text/html", "Unexpected content type");
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
- // TODO: this hashes differently for endorsed Xerces and Java 9
- if (TestSupport.isJavaV9OrLater()) {
- return;
+
+ Document webDoc = Jsoup.parse(response.getContentAsString());
+
+ boolean sawDocType = false;
+ List<Node>nods = webDoc.childNodes();
+ for (Node node : nods) {
+ if (node instanceof DocumentType) {
+ sawDocType = true;
+ DocumentType documentType = (DocumentType)node;
+ Assert.assertEquals(documentType.attr("name"), "html");
+ Assert.assertEquals(documentType.attr("publicId"), "");
+ Assert.assertEquals(documentType.attr("systemId"), "");
+ }
+ }
+ Assert.assertTrue(sawDocType);
+
+ Element head = webDoc.selectFirst("html > head");
+ Assert.assertNotNull(head);
+ Element metaCharSet = head.selectFirst("meta[charset]");
+ Assert.assertNotNull(metaCharSet);
+ Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
+
+ Element body = webDoc.selectFirst("html > body");
+ Assert.assertNotNull(body);
+ Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
+
+ Element form = body.selectFirst("form");
+ Assert.assertNotNull(form);
+ Assert.assertEquals(form.attr("method").toLowerCase(), "post");
+ Assert.assertEquals(form.attr("action"), "http://example.org/response");
+
+ Element relayState = form.selectFirst("input[name=RelayState]");
+ Assert.assertNotNull(relayState);
+ Assert.assertEquals(relayState.val(), "relay");
+
+ Element noscriptMsg = body.selectFirst("noscript > p");
+ Assert.assertNotNull(noscriptMsg);
+ Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
+
+ Element samlResponse = form.selectFirst("input[name=SAMLResponse]");
+ Assert.assertNotNull(samlResponse);
+ Assert.assertNotNull(samlResponse.val());
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
+ XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
+ Assert.assertTrue(xmlObject instanceof Response);
+ assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
}
- Assert.assertEquals(response.getContentAsString().hashCode(), 300154326);
+
+ Assert.assertNull(form.selectFirst("input[name=SigAlg]"));
+ Assert.assertNull(form.selectFirst("input[name=Signature]"));
+ Assert.assertNull(form.selectFirst("input[name=KeyInfo]"));
+
+ Element submit = body.selectFirst("noscript > div > input[type=submit]");
+ Assert.assertNotNull(submit);
+ Assert.assertEquals(submit.val(), "Continue");
}
@Test
@@ -174,11 +232,61 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals(response.getContentType(), "text/html", "Unexpected content type");
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
- // TODO: this hashes differently for endorsed Xerces and Java 9
- if (TestSupport.isJavaV9OrLater()) {
- return;
+
+ Document webDoc = Jsoup.parse(response.getContentAsString());
+
+ boolean sawDocType = false;
+ List<Node>nods = webDoc.childNodes();
+ for (Node node : nods) {
+ if (node instanceof DocumentType) {
+ sawDocType = true;
+ DocumentType documentType = (DocumentType)node;
+ Assert.assertEquals(documentType.attr("name"), "html");
+ Assert.assertEquals(documentType.attr("publicId"), "");
+ Assert.assertEquals(documentType.attr("systemId"), "");
+ }
}
- Assert.assertEquals(response.getContentAsString().hashCode(), 1094784467);
+ Assert.assertTrue(sawDocType);
+
+ Element head = webDoc.selectFirst("html > head");
+ Assert.assertNotNull(head);
+ Element metaCharSet = head.selectFirst("meta[charset]");
+ Assert.assertNotNull(metaCharSet);
+ Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
+
+ Element body = webDoc.selectFirst("html > body");
+ Assert.assertNotNull(body);
+ Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
+
+ Element form = body.selectFirst("form");
+ Assert.assertNotNull(form);
+ Assert.assertEquals(form.attr("method").toLowerCase(), "post");
+ Assert.assertEquals(form.attr("action"), "http://example.org");
+
+ Element relayState = form.selectFirst("input[name=RelayState]");
+ Assert.assertNotNull(relayState);
+ Assert.assertEquals(relayState.val(), "relay");
+
+ Element noscriptMsg = body.selectFirst("noscript > p");
+ Assert.assertNotNull(noscriptMsg);
+ Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
+
+ Element samlResponse = form.selectFirst("input[name=SAMLRequest]");
+ Assert.assertNotNull(samlResponse);
+ Assert.assertNotNull(samlResponse.val());
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
+ XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
+ Assert.assertTrue(xmlObject instanceof AuthnRequest);
+ assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ }
+
+ Assert.assertNull(form.selectFirst("input[name=SigAlg]"));
+ Assert.assertNull(form.selectFirst("input[name=Signature]"));
+ Assert.assertNull(form.selectFirst("input[name=KeyInfo]"));
+
+ Element submit = body.selectFirst("noscript > div > input[type=submit]");
+ Assert.assertNotNull(submit);
+ Assert.assertEquals(submit.val(), "Continue");
}
@Test
@@ -223,21 +331,71 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
encoder.prepareContext();
encoder.encode();
-
- // Not elegant, but works ok for basic sanity check.
- String form = response.getContentAsString();
- int start;
+ Document webDoc = Jsoup.parse(response.getContentAsString());
+
+ boolean sawDocType = false;
+ List<Node>nods = webDoc.childNodes();
+ for (Node node : nods) {
+ if (node instanceof DocumentType) {
+ sawDocType = true;
+ DocumentType documentType = (DocumentType)node;
+ Assert.assertEquals(documentType.attr("name"), "html");
+ Assert.assertEquals(documentType.attr("publicId"), "");
+ Assert.assertEquals(documentType.attr("systemId"), "");
+ }
+ }
+ Assert.assertTrue(sawDocType);
- start = form.indexOf("name=\"Signature\"");
- Assert.assertTrue(start != -1, "Signature parameter not found in form control data");
+ Element head = webDoc.selectFirst("html > head");
+ Assert.assertNotNull(head);
+ Element metaCharSet = head.selectFirst("meta[charset]");
+ Assert.assertNotNull(metaCharSet);
+ Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
- start = form.indexOf("name=\"SigAlg\"");
- Assert.assertTrue(start != -1, "SigAlg parameter not found in form control data");
+ Element body = webDoc.selectFirst("html > body");
+ Assert.assertNotNull(body);
+ Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
- start = form.indexOf("name=\"KeyInfo\"");
- Assert.assertTrue(start != -1, "KeyInfo parameter not found in form control data");
+ Element form = body.selectFirst("form");
+ Assert.assertNotNull(form);
+ Assert.assertEquals(form.attr("method").toLowerCase(), "post");
+ Assert.assertEquals(form.attr("action"), "http://example.org");
+
+ Element relayState = form.selectFirst("input[name=RelayState]");
+ Assert.assertNotNull(relayState);
+ Assert.assertEquals(relayState.val(), "relay");
+
+ Element noscriptMsg = body.selectFirst("noscript > p");
+ Assert.assertNotNull(noscriptMsg);
+ Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
+
+ Element samlResponse = form.selectFirst("input[name=SAMLRequest]");
+ Assert.assertNotNull(samlResponse);
+ Assert.assertNotNull(samlResponse.val());
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
+ XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
+ Assert.assertTrue(xmlObject instanceof AuthnRequest);
+ assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ }
+
+ Assert.assertNotNull(form.selectFirst("input[name=SigAlg]"));
+ Assert.assertEquals(form.selectFirst("input[name=SigAlg]").val(), SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
+ Assert.assertNotNull(form.selectFirst("input[name=Signature]"));
+ Assert.assertNotNull(form.selectFirst("input[name=Signature]").val());
+ Assert.assertNotNull(form.selectFirst("input[name=KeyInfo]"));
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(form.selectFirst("input[name=KeyInfo]").val()))) {
+ XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
+ Assert.assertTrue(xmlObject instanceof KeyInfo);
+ assertXMLEquals(xmlObject.getDOM().getOwnerDocument(),
+ signingParameters.getKeyInfoGenerator().generate(signingParameters.getSigningCredential()));
+ }
+
+ Element submit = body.selectFirst("noscript > div > input[type=submit]");
+ Assert.assertNotNull(submit);
+ Assert.assertEquals(submit.val(), "Continue");
// Note: to test that actual signature is cryptographically correct, really need a known good test vector.
// Need to verify that we're signing over the right data in the right byte[] encoded form.
}
+
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPRedirectDeflateEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPRedirectDeflateEncoderTest.java
index 9065547..31a9887 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPRedirectDeflateEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPRedirectDeflateEncoderTest.java
@@ -17,11 +17,11 @@
package org.opensaml.saml.saml2.binding.encoding.impl;
-import java.net.URI;
+import java.io.ByteArrayInputStream;
import java.security.KeyPair;
-
-import net.shibboleth.utilities.java.support.net.URISupport;
-import net.shibboleth.utilities.java.support.testing.TestSupport;
+import java.util.Map;
+import java.util.zip.Inflater;
+import java.util.zip.InflaterInputStream;
import org.joda.time.DateTime;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
@@ -33,7 +33,6 @@ import org.opensaml.saml.common.binding.SAMLBindingSupport;
import org.opensaml.saml.common.binding.impl.SAMLOutboundDestinationHandler;
import org.opensaml.saml.common.messaging.context.SAMLEndpointContext;
import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
-import org.opensaml.saml.saml2.binding.encoding.impl.HTTPRedirectDeflateEncoder;
import org.opensaml.saml.saml2.core.Response;
import org.opensaml.saml.saml2.core.Status;
import org.opensaml.saml.saml2.core.StatusCode;
@@ -47,6 +46,11 @@ import org.opensaml.xmlsec.signature.support.SignatureConstants;
import org.springframework.mock.web.MockHttpServletResponse;
import org.testng.Assert;
import org.testng.annotations.Test;
+import org.w3c.dom.Document;
+
+import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.net.URISupport;
+import net.shibboleth.utilities.java.support.net.URLBuilder;
/**
* Unit test for redirect encoding.
@@ -106,11 +110,28 @@ public class HTTPRedirectDeflateEncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
- // TODO: this hashes differently for endorsed Xerces and Java 9
- if (TestSupport.isJavaV9OrLater()) {
- return;
+
+ Assert.assertNotNull(response.getRedirectedUrl());
+ URLBuilder urlBuilder = new URLBuilder(response.getRedirectedUrl());
+ Assert.assertEquals(urlBuilder.getScheme(), "http");
+ Assert.assertEquals(urlBuilder.getHost(), "example.org");
+ Assert.assertEquals(urlBuilder.getPath(), "/response");
+
+ Map<String,String> queryParams = URISupport.buildQueryMap(urlBuilder.getQueryParams());
+ Assert.assertFalse(queryParams.containsKey("Signature"));
+ Assert.assertFalse(queryParams.containsKey("SigAlg"));
+ Assert.assertTrue(queryParams.containsKey("RelayState"));
+ Assert.assertEquals(queryParams.get("RelayState"), "relay");
+ Assert.assertTrue(queryParams.containsKey("SAMLResponse"));
+ try (InflaterInputStream inflater =
+ new InflaterInputStream(
+ new ByteArrayInputStream(
+ Base64Support.decode(queryParams.get("SAMLResponse"))), new Inflater(true))) {
+
+ Document outboundResponse = parserPool.parse(inflater);
+ assertXMLEquals(outboundResponse, samlMessage);
}
- Assert.assertEquals(response.getRedirectedUrl().hashCode(), -178096905);
+
}
/**
@@ -167,10 +188,31 @@ public class HTTPRedirectDeflateEncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
- String queryString = new URI(response.getRedirectedUrl()).getRawQuery();
-
- Assert.assertEquals(URISupport.getRawQueryStringParameter(queryString, "foo"), "foo=bar");
- Assert.assertEquals(URISupport.getRawQueryStringParameter(queryString, "abc"), "abc=123");
+ Assert.assertNotNull(response.getRedirectedUrl());
+ URLBuilder urlBuilder = new URLBuilder(response.getRedirectedUrl());
+ Assert.assertEquals(urlBuilder.getScheme(), "http");
+ Assert.assertEquals(urlBuilder.getHost(), "example.org");
+ Assert.assertEquals(urlBuilder.getPath(), "/response");
+
+ Map<String,String> queryParams = URISupport.buildQueryMap(urlBuilder.getQueryParams());
+ Assert.assertTrue(queryParams.containsKey("foo"));
+ Assert.assertEquals(queryParams.get("foo"), "bar");
+ Assert.assertTrue(queryParams.containsKey("abc"));
+ Assert.assertEquals(queryParams.get("abc"), "123");
+
+ Assert.assertFalse(queryParams.containsKey("Signature"));
+ Assert.assertFalse(queryParams.containsKey("SigAlg"));
+ Assert.assertTrue(queryParams.containsKey("RelayState"));
+ Assert.assertEquals(queryParams.get("RelayState"), "relay");
+ Assert.assertTrue(queryParams.containsKey("SAMLResponse"));
+ try (InflaterInputStream inflater =
+ new InflaterInputStream(
+ new ByteArrayInputStream(
+ Base64Support.decode(queryParams.get("SAMLResponse"))), new Inflater(true))) {
+
+ Document outboundResponse = parserPool.parse(inflater);
+ assertXMLEquals(outboundResponse, samlMessage);
+ }
}
/**
@@ -227,19 +269,35 @@ public class HTTPRedirectDeflateEncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
- String queryString = new URI(response.getRedirectedUrl()).getRawQuery();
-
- Assert.assertEquals(URISupport.getRawQueryStringParameter(queryString, "foo"), "foo=bar");
- Assert.assertEquals(URISupport.getRawQueryStringParameter(queryString, "abc"), "abc=123");
- Assert.assertEquals(URISupport.getRawQueryStringParameter(queryString, "RelayState"), "RelayState=relay");
- Assert.assertNotNull(URISupport.getRawQueryStringParameter(queryString, "SAMLResponse"));
- Assert.assertNotEquals(URISupport.getRawQueryStringParameter(queryString, "SAMLResponse"), "blah");
- Assert.assertFalse(queryString.contains("SAMLResponse=blah"));
-
- Assert.assertNull(URISupport.getRawQueryStringParameter(queryString, "SAMLEncoding"));
- Assert.assertNull(URISupport.getRawQueryStringParameter(queryString, "SAMLRequest"));
- Assert.assertNull(URISupport.getRawQueryStringParameter(queryString, "SigAlg"));
- Assert.assertNull(URISupport.getRawQueryStringParameter(queryString, "Signature"));
+ Assert.assertNotNull(response.getRedirectedUrl());
+ URLBuilder urlBuilder = new URLBuilder(response.getRedirectedUrl());
+ Assert.assertEquals(urlBuilder.getScheme(), "http");
+ Assert.assertEquals(urlBuilder.getHost(), "example.org");
+ Assert.assertEquals(urlBuilder.getPath(), "/response");
+
+ Map<String,String> queryParams = URISupport.buildQueryMap(urlBuilder.getQueryParams());
+ Assert.assertTrue(queryParams.containsKey("foo"));
+ Assert.assertEquals(queryParams.get("foo"), "bar");
+ Assert.assertTrue(queryParams.containsKey("abc"));
+ Assert.assertEquals(queryParams.get("abc"), "123");
+
+ Assert.assertFalse(queryParams.containsKey("SAMLEncoding"));
+ Assert.assertFalse(queryParams.containsKey("SAMLRequest"));
+ Assert.assertFalse(queryParams.containsKey("SigAlg"));
+ Assert.assertFalse(queryParams.containsKey("Signature"));
+ Assert.assertTrue(queryParams.containsKey("RelayState"));
+ Assert.assertEquals(queryParams.get("RelayState"), "relay");
+
+ Assert.assertTrue(queryParams.containsKey("SAMLResponse"));
+ Assert.assertNotEquals(queryParams.get("SAMLResponse"), "blah");
+ try (InflaterInputStream inflater =
+ new InflaterInputStream(
+ new ByteArrayInputStream(
+ Base64Support.decode(queryParams.get("SAMLResponse"))), new Inflater(true))) {
+
+ Document outboundResponse = parserPool.parse(inflater);
+ assertXMLEquals(outboundResponse, samlMessage);
+ }
}
/**
@@ -299,12 +357,28 @@ public class HTTPRedirectDeflateEncoderTest extends XMLObjectBaseTestCase {
encoder.prepareContext();
encoder.encode();
- String queryString = new URI(response.getRedirectedUrl()).getRawQuery();
-
- Assert.assertNotNull(URISupport.getRawQueryStringParameter(queryString, "Signature"),
- "Signature parameter was not found");
- Assert.assertNotNull(URISupport.getRawQueryStringParameter(queryString, "SigAlg"),
- "SigAlg parameter was not found");
+ Assert.assertNotNull(response.getRedirectedUrl());
+ URLBuilder urlBuilder = new URLBuilder(response.getRedirectedUrl());
+ Assert.assertEquals(urlBuilder.getScheme(), "http");
+ Assert.assertEquals(urlBuilder.getHost(), "example.org");
+ Assert.assertEquals(urlBuilder.getPath(), "/response");
+
+ Map<String,String> queryParams = URISupport.buildQueryMap(urlBuilder.getQueryParams());
+ Assert.assertTrue(queryParams.containsKey("Signature"));
+ Assert.assertNotNull(queryParams.get("Signature"));
+ Assert.assertTrue(queryParams.containsKey("SigAlg"));
+ Assert.assertEquals(queryParams.get("SigAlg"), SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1);
+ Assert.assertTrue(queryParams.containsKey("RelayState"));
+ Assert.assertEquals(queryParams.get("RelayState"), "relay");
+ Assert.assertTrue(queryParams.containsKey("SAMLResponse"));
+ try (InflaterInputStream inflater =
+ new InflaterInputStream(
+ new ByteArrayInputStream(
+ Base64Support.decode(queryParams.get("SAMLResponse"))), new Inflater(true))) {
+
+ Document outboundResponse = parserPool.parse(inflater);
+ assertXMLEquals(outboundResponse, samlMessage);
+ }
// Note: to test that actual signature is cryptographically correct, really need a known good test vector.
// Need to verify that we're signing over the right data in the right byte[] encoded form.
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPSOAP11EncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPSOAP11EncoderTest.java
index 6050dea..dea5646 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPSOAP11EncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPSOAP11EncoderTest.java
@@ -17,8 +17,12 @@
package org.opensaml.saml.saml2.binding.encoding.impl;
+import java.io.ByteArrayInputStream;
+
import org.joda.time.DateTime;
+import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.core.xml.util.XMLObjectSupport;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.SAMLObjectBuilder;
@@ -26,18 +30,16 @@ import org.opensaml.saml.common.SAMLVersion;
import org.opensaml.saml.common.binding.SAMLBindingSupport;
import org.opensaml.saml.common.messaging.context.SAMLEndpointContext;
import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
-import org.opensaml.saml.saml2.binding.encoding.impl.HTTPSOAP11Encoder;
import org.opensaml.saml.saml2.core.Response;
import org.opensaml.saml.saml2.core.Status;
import org.opensaml.saml.saml2.core.StatusCode;
import org.opensaml.saml.saml2.metadata.AssertionConsumerService;
import org.opensaml.saml.saml2.metadata.Endpoint;
+import org.opensaml.soap.soap11.Envelope;
import org.springframework.mock.web.MockHttpServletResponse;
import org.testng.Assert;
import org.testng.annotations.Test;
-import net.shibboleth.utilities.java.support.testing.TestSupport;
-
/**
* Test for SAML 2 SOAP 1.1 message encoder.
*/
@@ -95,10 +97,21 @@ public class HTTPSOAP11EncoderTest extends XMLObjectBaseTestCase {
Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
Assert.assertEquals(response.getHeader("SOAPAction"), "http://www.oasis-open.org/committees/security");
- // TODO: this hashes differently for endorsed Xerces and Java 9
- if (TestSupport.isJavaV9OrLater()) {
- return;
+
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(response.getContentAsByteArray())) {
+ XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
+ Assert.assertNotNull(xmlObject);
+ Assert.assertTrue(xmlObject instanceof Envelope);
+ Envelope envelope = (Envelope) xmlObject;
+ Assert.assertNull(envelope.getHeader());
+ Assert.assertNotNull(envelope.getBody());
+ Assert.assertEquals(envelope.getBody().getUnknownXMLObjects().size(), 1);
+ Response outboundResponse = (Response) envelope.getBody().getUnknownXMLObjects().get(0);
+ outboundResponse.releaseDOM();
+ outboundResponse.releaseChildrenDOM(true);
+ outboundResponse.setParent(null);
+ assertXMLEquals(XMLObjectSupport.marshall(outboundResponse).getOwnerDocument(), samlMessage);
}
- Assert.assertEquals(response.getContentAsString().hashCode(), -227316372);
+
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list