[java-idp-integration-tests] 03/03: Add CAS test.
Tom Zeller
tzeller at dragonacea.biz
Wed Nov 11 20:57:49 EST 2015
This is an automated email from the git hooks/post-receive script.
tzeller pushed a commit to branch master
in repository java-idp-integration-tests.
commit b1c2942a7bc588c6679b23c901dcf337cae1e3dc
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Wed Nov 11 19:55:15 2015 -0600
Add CAS test.
---
.../shibboleth/idp/test/BaseIntegrationTest.java | 43 ++++++++
.../idp/test/cas/CASIntegrationTest.java | 116 +++++++++++++++++++++
2 files changed, 159 insertions(+)
diff --git a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
index 5d1d5ab..fa4276d 100644
--- a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
@@ -853,6 +853,35 @@ public abstract class BaseIntegrationTest
}
/**
+ * Enable CAS protocol for the default relying party.
+ *
+ * @throws IOException
+ */
+ public void enableCASProtocol() throws IOException {
+ final Path pathToRelyingPartyXML = Paths.get("conf", "relying-party.xml");
+
+ final String regex = "<ref bean=\"Liberty.SSOS\" />";
+ final String replacement = regex + "\n" + "<ref bean=\"CAS.LoginConfiguration\" />\n"
+ + "<ref bean=\"CAS.ProxyConfiguration\" />\n" + "<ref bean=\"CAS.ValidateConfiguration\" />";
+ replaceIdPHomeFile(pathToRelyingPartyXML, regex, replacement);
+ }
+
+ /**
+ * Add localhost to CAS service definition.
+ *
+ * @throws IOException
+ */
+ public void enableLocalhostCASServiceDefinition() throws IOException {
+ final Path pathToCASProtocolXML = Paths.get("conf", "cas-protocol.xml");
+
+ final String regex = "</list>";
+ final String replacement = "<bean class=\"net.shibboleth.idp.cas.service.ServiceDefinition\"\n"
+ + "c:regex=\"https?://localhost(:\\\\d+)?/.*\"\n" + "p:group=\"test-services\"\n"
+ + "p:authorizedToProxy=\"false\" />\n" + "</list>";
+ replaceIdPHomeFile(pathToCASProtocolXML, regex, replacement);
+ }
+
+ /**
* Log unencrypted SAML.
*/
public void logUnencryptedSAML() {
@@ -1253,6 +1282,20 @@ public abstract class BaseIntegrationTest
}
/**
+ * Wait for the page whose URL starts with the given prefix.
+ *
+ * @param prefix the URL prefix
+ */
+ public void waitForPageWithURL(@Nonnull final String prefix) {
+ Assert.assertNotNull(prefix);
+ (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
+ public Boolean apply(WebDriver d) {
+ return d.getCurrentUrl().startsWith(prefix);
+ }
+ });
+ }
+
+ /**
* Select web element with id {@link #REMEMBER_CONSENT_ID}.
*/
public void releaseAllAttributes() {
diff --git a/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java b/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java
new file mode 100644
index 0000000..ffef4c1
--- /dev/null
+++ b/src/test/java/net/shibboleth/idp/test/cas/CASIntegrationTest.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.test.cas;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.openqa.selenium.By;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.test.BaseIntegrationTest;
+import net.shibboleth.idp.test.BrowserData;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/**
+ * Simple CAS integration test.
+ */
+public class CASIntegrationTest extends BaseIntegrationTest {
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(CASIntegrationTest.class);
+
+ /** URL of testbed SP service. */
+ @Nonnull private String spServicePageURLPath = "/sp/CAS/Service";
+
+ /** URL of IdP to validate ticket. */
+ @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>";
+
+ @BeforeClass
+ public void setUpURLs() throws Exception {
+
+ startFlowURLPath = "/sp/CAS/InitSSO";
+
+ loginPageURLPath = "/idp/profile/cas/login;";
+ }
+
+ /**
+ * Get the CAS service response from the page source.
+ *
+ * This method is likely fragile across browsers, it is known to work with Firefox and HtmlUnit.
+ *
+ * @param pageSource
+ * @return the CAS service response.
+ */
+ @Nullable
+ public String getCASServiceResponse(@Nullable final String pageSource) {
+ if (StringSupport.trimOrNull(pageSource) == null) {
+ return null;
+ }
+
+ // Trim anything before "<cas:serviceresponse"
+ String response = pageSource.substring(pageSource.indexOf("<cas:serviceresponse"));
+
+ // Trim anything after and including "</body>"
+ response = response.substring(0, response.indexOf("</body>"));
+
+ // Trim newlines and whitespace between elements
+ response = response.replaceAll("\n", "").replaceAll("\\s+<", "<").replaceAll(">\\s+", ">");
+
+ return response;
+ }
+
+ @Test(dataProvider = "sauceOnDemandBrowserDataProvider")
+ public void testCASSSO(@Nullable final BrowserData browserData) throws Exception {
+
+ startSeleniumClient(browserData);
+
+ enableLogout();
+
+ enableCASProtocol();
+
+ enableLocalhostCASServiceDefinition();
+
+ startJettyServer();
+
+ startFlow();
+
+ waitForLoginPage();
+
+ login();
+
+ waitForPageWithURL(getBaseURL() + spServicePageURLPath);
+
+ driver.findElement(By.id("cas-service-validate")).click();
+
+ waitForPageWithURL(getBaseURL() + idpServiceValidatePageURLPath);
+
+ final String actualCASServiceResponse = getCASServiceResponse(driver.getPageSource());
+
+ Assert.assertEquals(actualCASServiceResponse, expectedCASServiceResponse);
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list