From 7c1eb5582a83a7fc8d0c0bc90ab892ae0e6e8d25 Mon Sep 17 00:00:00 2001 From: mhajas Date: Mon, 20 Mar 2017 10:58:28 +0100 Subject: [PATCH] KEYCLOAK-4141 Added saml tests --- .../page/DifferentCookieNameServlet.java | 39 ++++++++++++ .../AbstractSAMLServletsAdapterTest.java | 21 +++++++ .../WEB-INF/keycloak-saml.xml | 43 ++++++++++++++ .../different-cookie-name/WEB-INF/web.xml | 59 +++++++++++++++++++ .../adapter-test/keycloak-saml/testsaml.json | 15 +++++ 5 files changed, 177 insertions(+) create mode 100644 testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/DifferentCookieNameServlet.java create mode 100755 testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/different-cookie-name/WEB-INF/keycloak-saml.xml create mode 100644 testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/different-cookie-name/WEB-INF/web.xml diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/DifferentCookieNameServlet.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/DifferentCookieNameServlet.java new file mode 100644 index 0000000000..5594b9665f --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/DifferentCookieNameServlet.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed 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 org.keycloak.testsuite.adapter.page; + +import org.jboss.arquillian.container.test.api.OperateOnDeployment; +import org.jboss.arquillian.test.api.ArquillianResource; + +import java.net.URL; + +/** + * @author mhajas + */ +public class DifferentCookieNameServlet extends SAMLServlet { + public static final String DEPLOYMENT_NAME = "different-cookie-name"; + + @ArquillianResource + @OperateOnDeployment(DEPLOYMENT_NAME) + private URL url; + + @Override + public URL getInjectedUrl() { + return url; + } +} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractSAMLServletsAdapterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractSAMLServletsAdapterTest.java index 10d3ab7dab..a199636e57 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractSAMLServletsAdapterTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractSAMLServletsAdapterTest.java @@ -60,6 +60,7 @@ import org.keycloak.testsuite.adapter.AbstractServletsAdapterTest; import org.keycloak.testsuite.adapter.page.BadAssertionSalesPostSig; import org.keycloak.testsuite.adapter.page.BadClientSalesPostSigServlet; import org.keycloak.testsuite.adapter.page.BadRealmSalesPostSigServlet; +import org.keycloak.testsuite.adapter.page.DifferentCookieNameServlet; import org.keycloak.testsuite.adapter.page.Employee2Servlet; import org.keycloak.testsuite.adapter.page.EmployeeServlet; import org.keycloak.testsuite.adapter.page.EmployeeSigFrontServlet; @@ -205,6 +206,9 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd @Page protected EmployeeServlet employeeServletPage; + @Page + protected DifferentCookieNameServlet differentCookieNameServletPage; + @Page private InputPortal inputPortalPage; @@ -303,6 +307,11 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd return samlServletDeployment(SalesPost2Servlet.DEPLOYMENT_NAME, SendUsernameServlet.class); } + @Deployment(name = DifferentCookieNameServlet.DEPLOYMENT_NAME) + protected static WebArchive differentCokieName() { + return samlServletDeployment(DifferentCookieNameServlet.DEPLOYMENT_NAME, "different-cookie-name/WEB-INF/web.xml", SendUsernameServlet.class); + } + @Deployment(name = SalesPostAssertionAndResponseSig.DEPLOYMENT_NAME) protected static WebArchive salesPostAssertionAndResponseSig() { return samlServletDeployment(SalesPostAssertionAndResponseSig.DEPLOYMENT_NAME, SendUsernameServlet.class); @@ -1069,6 +1078,18 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd } } + @Test + // KEYCLOAK-4141 + public void testDifferentCookieName() { + assertSuccessfulLogin(differentCookieNameServletPage, bburkeUser, testRealmSAMLPostLoginPage, "principal=bburke"); + + assertThat(driver.manage().getCookieNamed("DIFFERENT_SESSION_ID"), notNullValue()); + assertThat(driver.manage().getCookieNamed("JSESSIONID"), nullValue()); + + salesPost2ServletPage.logout(); + checkLoggedOut(differentCookieNameServletPage, testRealmSAMLPostLoginPage); + } + private URI getAuthServerSamlEndpoint(String realm) throws IllegalArgumentException, UriBuilderException { return RealmsResource .protocolUrl(UriBuilder.fromUri(getAuthServerRoot())) diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/different-cookie-name/WEB-INF/keycloak-saml.xml b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/different-cookie-name/WEB-INF/keycloak-saml.xml new file mode 100755 index 0000000000..389239a211 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/different-cookie-name/WEB-INF/keycloak-saml.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/different-cookie-name/WEB-INF/web.xml b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/different-cookie-name/WEB-INF/web.xml new file mode 100644 index 0000000000..adb9182233 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/different-cookie-name/WEB-INF/web.xml @@ -0,0 +1,59 @@ + + + + + + %CONTEXT_PATH% + + + javax.ws.rs.core.Application + /* + + + + /error.html + + + + + Application + /* + + + manager + + + + + KEYCLOAK-SAML + demo + + + + manager + + + + + DIFFERENT_SESSION_ID + + + diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/testsaml.json b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/testsaml.json index 6bed985683..87a4fc8d67 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/testsaml.json +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/keycloak-saml/testsaml.json @@ -162,6 +162,21 @@ "saml_idp_initiated_sso_relay_state": "redirectTo=/foo" } }, + { + "clientId": "http://localhost:8081/different-cookie-name/", + "enabled": true, + "fullScopeAllowed": true, + "protocol": "saml", + "baseUrl": "http://localhost:8080/different-cookie-name", + "redirectUris": [ + "http://localhost:8080/different-cookie-name/*" + ], + "attributes": { + "saml.authnstatement": "true", + "saml_assertion_consumer_url_post": "http://localhost:8080/different-cookie-name/saml", + "saml_single_logout_service_url_post": "http://localhost:8080/different-cookie-name/saml" + } + }, { "clientId": "http://localhost:8081/sales-post/", "enabled": true,