From fee1dea3e6adfb33aa0490d1a408c76d43372641 Mon Sep 17 00:00:00 2001 From: mhajas Date: Wed, 9 Dec 2015 10:48:53 +0100 Subject: [PATCH] Added SAML example adapter tests to integration-arqullian --- ...WildflyRelativeSAMLExampleAdapterTest.java | 12 ++ .../AbstractSAMLExampleAdapterTest.java | 104 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 testsuite/integration-arquillian/tests/adapters/wildfly-relative/src/test/java/org/keycloak/testsuite/adapter/example/WildflyRelativeSAMLExampleAdapterTest.java create mode 100644 testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/AbstractSAMLExampleAdapterTest.java diff --git a/testsuite/integration-arquillian/tests/adapters/wildfly-relative/src/test/java/org/keycloak/testsuite/adapter/example/WildflyRelativeSAMLExampleAdapterTest.java b/testsuite/integration-arquillian/tests/adapters/wildfly-relative/src/test/java/org/keycloak/testsuite/adapter/example/WildflyRelativeSAMLExampleAdapterTest.java new file mode 100644 index 0000000000..6e0c6df5e2 --- /dev/null +++ b/testsuite/integration-arquillian/tests/adapters/wildfly-relative/src/test/java/org/keycloak/testsuite/adapter/example/WildflyRelativeSAMLExampleAdapterTest.java @@ -0,0 +1,12 @@ +package org.keycloak.testsuite.adapter.example; + +import org.keycloak.testsuite.arquillian.annotation.AdapterLibsLocationProperty; + +/** + * + * @author mhajas + */ +@AdapterLibsLocationProperty("adapter.libs.wildfly") +public class WildflyRelativeSAMLExampleAdapterTest extends AbstractSAMLExampleAdapterTest { + +} \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/AbstractSAMLExampleAdapterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/AbstractSAMLExampleAdapterTest.java new file mode 100644 index 0000000000..1916ffd885 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/AbstractSAMLExampleAdapterTest.java @@ -0,0 +1,104 @@ +package org.keycloak.testsuite.adapter.example; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.graphene.page.Page; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.testsuite.adapter.AbstractExampleAdapterTest; +import org.keycloak.testsuite.adapter.page.SAMLPostEncExample; +import org.keycloak.testsuite.adapter.page.SAMLPostSigExample; +import org.keycloak.testsuite.adapter.page.SAMLRedirectSigExample; +import org.keycloak.testsuite.util.URLAssert; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertTrue; +import static org.keycloak.testsuite.auth.page.AuthRealm.SAMLDEMO; +import static org.keycloak.testsuite.util.IOUtil.loadRealm; + +/** + * @author mhajas + */ +public abstract class AbstractSAMLExampleAdapterTest extends AbstractExampleAdapterTest { + + @Page + private SAMLPostSigExample samlPostSigExamplePage; + + @Page + private SAMLPostEncExample samlPostEncExamplePage; + + @Page + private SAMLRedirectSigExample samlRedirectSigExamplePage; + + @Override + public void addAdapterTestRealms(List testRealms) { + RealmRepresentation samlRealm = loadRealm(new File(EXAMPLES_HOME_DIR + "/saml/testsaml.json")); + testRealms.add(samlRealm); + } + + @Override + public void setDefaultPageUriParameters() { + super.setDefaultPageUriParameters(); + testRealmPage.setAuthRealm(SAMLDEMO); + testRealmSAMLLoginPage.setAuthRealm(SAMLDEMO); + } + + @Deployment(name = SAMLPostSigExample.DEPLOYMENT_NAME) + private static WebArchive samlPostSigExampleDeployment() throws IOException { + return exampleDeployment(SAMLPostSigExample.DEPLOYMENT_NAME); + } + + @Deployment(name = SAMLPostEncExample.DEPLOYMENT_NAME) + private static WebArchive samlPostEncExampleDeployment() throws IOException { + return exampleDeployment(SAMLPostEncExample.DEPLOYMENT_NAME); + } + + @Deployment(name = SAMLRedirectSigExample.DEPLOYMENT_NAME) + private static WebArchive samlRedirectSigExampleDeployment() throws IOException { + return exampleDeployment(SAMLRedirectSigExample.DEPLOYMENT_NAME); + } + + @Test + public void samlPostWithSignatureExampleTest() { + samlPostSigExamplePage.navigateTo(); + testRealmSAMLLoginPage.form().login(bburkeUser); + + assertTrue(driver.getPageSource().contains("Welcome to the Sales Tool, " + bburkeUser.getUsername())); + + samlPostSigExamplePage.logout(); + + samlPostSigExamplePage.navigateTo(); + URLAssert.assertCurrentUrlStartsWith(testRealmSAMLLoginPage); + } + + @Test + public void samlPostWithEncryptionExampleTest() { + samlPostEncExamplePage.navigateTo(); + + testRealmSAMLLoginPage.form().login(bburkeUser); + + assertTrue(driver.getPageSource().contains("Welcome to the Sales Tool, " + bburkeUser.getUsername())); + + samlPostEncExamplePage.logout(); + + samlPostEncExamplePage.navigateTo(); + URLAssert.assertCurrentUrlStartsWith(testRealmSAMLLoginPage); + } + + @Test + public void samlRedirectWithSignatureExampleTest() { + samlRedirectSigExamplePage.navigateTo(); + + testRealmSAMLLoginPage.form().login(bburkeUser); + + assertTrue(driver.getPageSource().contains("Welcome to the Employee Tool,")); + + samlRedirectSigExamplePage.logout(); + + samlRedirectSigExamplePage.navigateTo(); + URLAssert.assertCurrentUrlStartsWith(testRealmSAMLLoginPage); + } +}