[java-idp-integration-tests] 01/02: Ignore content and order of attributes in CAS service response
Tom Zeller
tzeller at dragonacea.biz
Wed Jan 26 17:05:51 UTC 2022
This is an automated email from the git hooks/post-receive script.
tzeller pushed a commit to branch main
in repository java-idp-integration-tests.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=b970a9aae651ba1b16d6f571d2f1214f0314b82e
commit b970a9aae651ba1b16d6f571d2f1214f0314b82e
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Wed Jan 26 10:34:45 2022 -0600
Ignore content and order of attributes in CAS service response
https://shibboleth.atlassian.net/browse/IDP-1899
---
.../idp/test/cas/CASIntegrationTest.java | 74 ++++++++++++++++++----
1 file changed, 61 insertions(+), 13 deletions(-)
diff --git a/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java b/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java
index ae33b4f..4b4e4ba 100644
--- a/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java
@@ -46,22 +46,32 @@ public class CASIntegrationTest extends BaseIntegrationTest {
@Nonnull private String idpServiceValidatePageURLPath = "/idp/profile/cas/serviceValidate";
/** Expected CAS service response. */
- @Nonnull final String expectedCASServiceResponse = "<cas:serviceresponse xmlns:cas=\"http://www.yale.edu/tp/cas\">"
- + "<cas:authenticationsuccess><cas:user>jdoe</cas:user></cas:authenticationsuccess></cas:serviceresponse>";
-
+ @Nonnull final String expectedCASServiceResponse =
+ "<cas:serviceresponse xmlns:cas=\"http://www.yale.edu/tp/cas\">"
+ + "<cas:authenticationsuccess>"
+ + "<cas:user>jdoe</cas:user>"
+ + "</cas:authenticationsuccess>"
+ + "</cas:serviceresponse>";
+
/** Expected, but incorrect, CAS service response with attributes for IdP V3. */
@Nonnull final String expectedCASServiceResponseWithAttributesV3 =
- "<cas:serviceresponse xmlns:cas=\"http://www.yale.edu/tp/cas\"><cas:authenticationsuccess>"
- + "<cas:user>jdoe</cas:user><cas:attributes>"
- + "<cas:edupersonscopedaffiliation>member</cas:edupersonscopedaffiliation>"
- + "</cas:attributes></cas:authenticationsuccess></cas:serviceresponse>";
+ "<cas:serviceresponse xmlns:cas=\"http://www.yale.edu/tp/cas\">"
+ + "<cas:authenticationsuccess>"
+ + "<cas:user>jdoe</cas:user>"
+ + "<cas:attributes>"
+ + "<cas:edupersonscopedaffiliation>member</cas:edupersonscopedaffiliation>"
+ + "</cas:attributes>"
+ + "</cas:authenticationsuccess>"
+ + "</cas:serviceresponse>";
/** Expected CAS service response with attributes. */
@Nonnull final String expectedCASServiceResponseWithAttributes =
- "<cas:serviceresponse xmlns:cas=\"http://www.yale.edu/tp/cas\"><cas:authenticationsuccess>"
- + "<cas:user>jdoe</cas:user><cas:attributes>"
- + "<cas:edupersonscopedaffiliation>member at example.org</cas:edupersonscopedaffiliation>"
- + "</cas:attributes></cas:authenticationsuccess></cas:serviceresponse>";
+ "<cas:serviceresponse xmlns:cas=\"http://www.yale.edu/tp/cas\">"
+ + "<cas:authenticationsuccess>"
+ + "<cas:user>jdoe</cas:user>"
+ + "<cas:attributes>ANY_ATTRIBUTES</cas:attributes>"
+ + "</cas:authenticationsuccess>"
+ + "</cas:serviceresponse>";
@BeforeClass
public void setUpURLs() throws Exception {
@@ -98,6 +108,36 @@ public class CASIntegrationTest extends BaseIntegrationTest {
return response;
}
+ /**
+ * Get expected CAS response either with or without attributes.
+ *
+ * @param casServiceResponse
+ * @return the expected CAS response
+ */
+ @Nonnull
+ public String getExpectedCASServiceResponse(@Nonnull final String casServiceResponse) {
+ if (casServiceResponse.contains("<cas:attributes>")) {
+ return expectedCASServiceResponseWithAttributes;
+ } else {
+ return expectedCASServiceResponse;
+ }
+ }
+
+ /**
+ * Remove attributes from response and replace with placeholder.
+ *
+ * Workaround for validating order of attributes.
+ *
+ * @param casServiceResponse
+ * @return the CAS service response with placeholder attributes
+ */
+ @Nonnull
+ public String removeAttributesInCASServiceResponse(@Nonnull final String casServiceResponse) {
+ return casServiceResponse.replaceFirst(
+ "<cas:attributes>.*?</cas:attributes>",
+ "<cas:attributes>ANY_ATTRIBUTES</cas:attributes>");
+ }
+
@Test(dataProvider = "sauceOnDemandBrowserDataProvider")
public void testCASSSO(@Nullable final BrowserData browserData) throws Exception {
@@ -129,7 +169,11 @@ public class CASIntegrationTest extends BaseIntegrationTest {
final String actualCASServiceResponse = getCASServiceResponse(driver.getPageSource());
- Assert.assertEquals(actualCASServiceResponse, expectedCASServiceResponse);
+ final String modifiedCASServiceResponse = removeAttributesInCASServiceResponse(actualCASServiceResponse);
+
+ final String expectedCASServiceResponse = getExpectedCASServiceResponse(actualCASServiceResponse);
+
+ Assert.assertEquals(modifiedCASServiceResponse, expectedCASServiceResponse);
}
@Test(dataProvider = "sauceOnDemandBrowserDataProvider")
@@ -168,7 +212,11 @@ public class CASIntegrationTest extends BaseIntegrationTest {
if (idpVersion.startsWith("3")) {
Assert.assertEquals(actualCASServiceResponse, expectedCASServiceResponseWithAttributesV3);
} else {
- Assert.assertEquals(actualCASServiceResponse, expectedCASServiceResponseWithAttributes);
+ final String modifiedCASServiceResponse = removeAttributesInCASServiceResponse(actualCASServiceResponse);
+
+ final String expectedCASServiceResponse = getExpectedCASServiceResponse(actualCASServiceResponse);
+
+ Assert.assertEquals(modifiedCASServiceResponse, expectedCASServiceResponse);
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list