From 6f036ac43472de483004e796b550889a73d1f31f Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Thu, 28 Jan 2016 09:23:23 -0500 Subject: [PATCH] fix tests --- .../keycloaksaml/SamlAdapterTestStrategy.java | 79 +++++++++++-------- ...ingTest.java => SamlPicketlinkSPTest.java} | 72 ++++++++++------- 2 files changed, 88 insertions(+), 63 deletions(-) rename testsuite/integration/src/test/java/org/keycloak/testsuite/saml/{SamlBindingTest.java => SamlPicketlinkSPTest.java} (90%) diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/keycloaksaml/SamlAdapterTestStrategy.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/keycloaksaml/SamlAdapterTestStrategy.java index 9f07239585..43c8189b3e 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/keycloaksaml/SamlAdapterTestStrategy.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/keycloaksaml/SamlAdapterTestStrategy.java @@ -99,15 +99,27 @@ public class SamlAdapterTestStrategy extends ExternalResource { - protected void checkLoggedOut(String mainUrl) { + protected void checkLoggedOut(String mainUrl, boolean postBinding) { String pageSource = driver.getPageSource(); System.out.println("*** logout pagesource ***"); System.out.println(pageSource); System.out.println("driver url: " + driver.getCurrentUrl()); Assert.assertTrue(pageSource.contains("request-path: /logout.jsp")); driver.navigate().to(mainUrl); + checkAtLoginPage(postBinding); + } + + protected void checkAtLoginPage(boolean postBinding) { + if (postBinding) assertAtLoginPagePostBinding(); + else assertAtLoginPageRedirectBinding(); + } + + protected void assertAtLoginPageRedirectBinding() { Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); } + protected void assertAtLoginPagePostBinding() { + Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/login-actions/authenticate")); + } public void testSavedPostRequest() throws Exception { // test login to customer-portal which does a bearer request to customer-db @@ -116,7 +128,7 @@ public class SamlAdapterTestStrategy extends ExternalResource { Assert.assertTrue(driver.getCurrentUrl().startsWith(APP_SERVER_BASE_URL + "/input-portal")); inputPage.execute("hello"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke@redhat.com", "password"); System.out.println("Current url: " + driver.getCurrentUrl()); Assert.assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/input-portal/secured/post"); @@ -170,13 +182,13 @@ public class SamlAdapterTestStrategy extends ExternalResource { public void testPostSimpleLoginLogout() { driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post/"); System.out.println(driver.getPageSource()); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post/", true); } public void testPostPassiveLoginLogout(boolean forbiddenIfNotauthenticated) { @@ -213,7 +225,7 @@ public class SamlAdapterTestStrategy extends ExternalResource { public void testPostSimpleUnauthorized(CheckAuthError error) { driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("unauthorized", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post/"); System.out.println(driver.getPageSource()); @@ -227,52 +239,52 @@ public class SamlAdapterTestStrategy extends ExternalResource { System.out.println(driver.getPageSource()); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post/", true); } public void testPostSignedLoginLogout() { driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post-sig/"); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-sig/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-sig/", true); } public void testPostSignedLoginLogoutTransientNameID() { driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig-transient/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post-sig-transient/"); System.out.println(driver.getPageSource()); Assert.assertFalse(driver.getPageSource().contains("bburke")); Assert.assertTrue(driver.getPageSource().contains("principal=G-")); driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig-transient?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-sig-transient/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-sig-transient/", true); } public void testPostSignedLoginLogoutPersistentNameID() { driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig-persistent/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post-sig-persistent/"); System.out.println(driver.getPageSource()); Assert.assertFalse(driver.getPageSource().contains("bburke")); Assert.assertTrue(driver.getPageSource().contains("principal=G-")); driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig-persistent?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-sig-persistent/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-sig-persistent/", true); } public void testPostSignedLoginLogoutEmailNameID() { driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig-email/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post-sig-email/"); System.out.println(driver.getPageSource()); Assert.assertTrue(driver.getPageSource().contains("principal=bburke@redhat.com")); driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig-email?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-sig-email/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-sig-email/", true); } @@ -281,7 +293,7 @@ public class SamlAdapterTestStrategy extends ExternalResource { // at the relay state SamlSPFacade.samlResponse = null; driver.navigate().to(APP_SERVER_BASE_URL + "/employee/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); System.out.println(driver.getCurrentUrl()); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/employee/"); @@ -304,7 +316,7 @@ public class SamlAdapterTestStrategy extends ExternalResource { SendUsernameServlet.sentPrincipal = null; SendUsernameServlet.checkRoles = null; driver.navigate().to(APP_SERVER_BASE_URL + "/employee2/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); + assertAtLoginPagePostBinding(); List requiredRoles = new LinkedList<>(); requiredRoles.add("manager"); requiredRoles.add("user"); @@ -322,14 +334,14 @@ public class SamlAdapterTestStrategy extends ExternalResource { Set groupSet = new HashSet<>(); assertEquals("level2@redhat.com", principal.getFriendlyAttribute("email")); driver.navigate().to(APP_SERVER_BASE_URL + "/employee2/?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/employee2/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/employee2/", true); } { SendUsernameServlet.sentPrincipal = null; SendUsernameServlet.checkRoles = null; driver.navigate().to(APP_SERVER_BASE_URL + "/employee2/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); + assertAtLoginPagePostBinding(); List requiredRoles = new LinkedList<>(); requiredRoles.add("manager"); requiredRoles.add("employee"); @@ -345,7 +357,7 @@ public class SamlAdapterTestStrategy extends ExternalResource { assertEquals("617", principal.getAttribute("phone")); Assert.assertNull(principal.getFriendlyAttribute("phone")); driver.navigate().to(APP_SERVER_BASE_URL + "/employee2/?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/employee2/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/employee2/", true); } keycloakRule.update(new KeycloakRule.KeycloakSetup() { @@ -374,7 +386,7 @@ public class SamlAdapterTestStrategy extends ExternalResource { SendUsernameServlet.sentPrincipal = null; SendUsernameServlet.checkRoles = null; driver.navigate().to(APP_SERVER_BASE_URL + "/employee2/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); + assertAtLoginPagePostBinding(); List requiredRoles = new LinkedList<>(); requiredRoles.add("el-jefe"); requiredRoles.add("user"); @@ -394,23 +406,23 @@ public class SamlAdapterTestStrategy extends ExternalResource { public void testRedirectSignedLoginLogout() { driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/employee-sig/"); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/employee-sig/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/employee-sig/", false); } public void testRedirectSignedLoginLogoutFrontNoSSO() { driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig-front/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/employee-sig-front/"); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig-front?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/employee-sig-front/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/employee-sig-front/", false); } @@ -418,7 +430,7 @@ public class SamlAdapterTestStrategy extends ExternalResource { // visit 1st app an logg in System.out.println("visit 1st app "); driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); System.out.println("login to form"); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/employee-sig/"); @@ -439,28 +451,29 @@ public class SamlAdapterTestStrategy extends ExternalResource { // logout of first app System.out.println("GLO"); driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/employee-sig/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/employee-sig/", false); driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig-front/"); String currentUrl = driver.getCurrentUrl(); Assert.assertTrue(currentUrl.startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); + assertAtLoginPagePostBinding(); } public void testPostEncryptedLoginLogout() { driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-enc/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post-enc/"); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-enc?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-enc/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-enc/", true); } public void testPostBadClientSignature() { driver.navigate().to(APP_SERVER_BASE_URL + "/bad-client-sales-post-sig/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + System.out.println(driver.getCurrentUrl()); + Assert.assertTrue(driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml")); assertEquals(driver.getTitle(), "We're sorry..."); } @@ -471,7 +484,7 @@ public class SamlAdapterTestStrategy extends ExternalResource { public void testPostBadRealmSignature() { ErrorServlet.authError = null; driver.navigate().to(APP_SERVER_BASE_URL + "/bad-realm-sales-post-sig/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/bad-realm-sales-post-sig/"); System.out.println(driver.getPageSource()); @@ -484,13 +497,13 @@ public class SamlAdapterTestStrategy extends ExternalResource { public void testMetadataPostSignedLoginLogout() throws Exception { driver.navigate().to(APP_SERVER_BASE_URL + "/sales-metadata/"); - assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-metadata/"); String pageSource = driver.getPageSource(); Assert.assertTrue(pageSource.contains("bburke")); driver.navigate().to(APP_SERVER_BASE_URL + "/sales-metadata?GLO=true"); - checkLoggedOut(APP_SERVER_BASE_URL + "/sales-metadata/"); + checkLoggedOut(APP_SERVER_BASE_URL + "/sales-metadata/", true); } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/saml/SamlBindingTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/saml/SamlPicketlinkSPTest.java similarity index 90% rename from testsuite/integration/src/test/java/org/keycloak/testsuite/saml/SamlBindingTest.java rename to testsuite/integration/src/test/java/org/keycloak/testsuite/saml/SamlPicketlinkSPTest.java index 446c55581c..dfe98686f7 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/saml/SamlBindingTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/saml/SamlPicketlinkSPTest.java @@ -47,13 +47,13 @@ import static org.junit.Assert.assertEquals; * @author Bill Burke * @version $Revision: 1 $ */ -public class SamlBindingTest { +public class SamlPicketlinkSPTest { @ClassRule public static SamlKeycloakRule keycloakRule = new SamlKeycloakRule() { @Override public void initWars() { - ClassLoader classLoader = SamlBindingTest.class.getClassLoader(); + ClassLoader classLoader = SamlPicketlinkSPTest.class.getClassLoader(); initializeSamlSecuredWar("/saml/simple-post", "/sales-post", "post.war", classLoader); initializeSamlSecuredWar("/saml/signed-post", "/sales-post-sig", "post-sig.war", classLoader); @@ -120,15 +120,27 @@ public class SamlBindingTest { @WebResource protected LoginPage loginPage; - protected void checkLoggedOut(String mainUrl) { + protected void checkLoggedOut(String mainUrl, boolean postBinding) { String pageSource = driver.getPageSource(); System.out.println("*** logout pagesouce ***"); System.out.println(pageSource); System.out.println("driver url: " + driver.getCurrentUrl()); Assert.assertTrue(pageSource.contains("request-path: /logout.jsp")); driver.navigate().to(mainUrl); + checkAtLoginPage(postBinding); + } + + protected void checkAtLoginPage(boolean postBinding) { + if (postBinding) assertAtLoginPagePostBinding(); + else assertAtLoginPageRedirectBinding(); + } + + protected void assertAtLoginPageRedirectBinding() { Assert.assertTrue(driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/protocol/saml")); } + protected void assertAtLoginPagePostBinding() { + Assert.assertTrue(driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/login-actions/authenticate")); + } //@Test public void ideTesting() throws Exception { @@ -138,13 +150,13 @@ public class SamlBindingTest { @Test public void testPostSimpleLoginLogout() { driver.navigate().to("http://localhost:8081/sales-post/"); - Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-post/"); System.out.println(driver.getPageSource()); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to("http://localhost:8081/sales-post?GLO=true"); - checkLoggedOut("http://localhost:8081/sales-post/"); + checkLoggedOut("http://localhost:8081/sales-post/", true); } @Test @@ -155,57 +167,57 @@ public class SamlBindingTest { System.out.println(driver.getPageSource()); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to("http://localhost:8081/sales-post?GLO=true"); - checkLoggedOut("http://localhost:8081/sales-post/"); + checkLoggedOut("http://localhost:8081/sales-post/", true); } @Test public void testPostSignedLoginLogout() { driver.navigate().to("http://localhost:8081/sales-post-sig/"); - Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-post-sig/"); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to("http://localhost:8081/sales-post-sig?GLO=true"); - checkLoggedOut("http://localhost:8081/sales-post-sig/"); + checkLoggedOut("http://localhost:8081/sales-post-sig/", true); } @Test public void testPostSignedLoginLogoutTransientNameID() { driver.navigate().to("http://localhost:8081/sales-post-sig-transient/"); - Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-post-sig-transient/"); System.out.println(driver.getPageSource()); Assert.assertFalse(driver.getPageSource().contains("bburke")); Assert.assertTrue(driver.getPageSource().contains("principal=G-")); driver.navigate().to("http://localhost:8081/sales-post-sig-transient?GLO=true"); - checkLoggedOut("http://localhost:8081/sales-post-sig-transient/"); + checkLoggedOut("http://localhost:8081/sales-post-sig-transient/", true); } @Test public void testPostSignedLoginLogoutPersistentNameID() { driver.navigate().to("http://localhost:8081/sales-post-sig-persistent/"); - Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-post-sig-persistent/"); System.out.println(driver.getPageSource()); Assert.assertFalse(driver.getPageSource().contains("bburke")); Assert.assertTrue(driver.getPageSource().contains("principal=G-")); driver.navigate().to("http://localhost:8081/sales-post-sig-persistent?GLO=true"); - checkLoggedOut("http://localhost:8081/sales-post-sig-persistent/"); + checkLoggedOut("http://localhost:8081/sales-post-sig-persistent/", true); } @Test public void testPostSignedLoginLogoutEmailNameID() { driver.navigate().to("http://localhost:8081/sales-post-sig-email/"); - Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-post-sig-email/"); System.out.println(driver.getPageSource()); Assert.assertTrue(driver.getPageSource().contains("principal=bburke@redhat.com")); driver.navigate().to("http://localhost:8081/sales-post-sig-email?GLO=true"); - checkLoggedOut("http://localhost:8081/sales-post-sig-email/"); + checkLoggedOut("http://localhost:8081/sales-post-sig-email/", true); } @@ -215,7 +227,7 @@ public class SamlBindingTest { // at the relay state SamlSPFacade.samlResponse = null; driver.navigate().to("http://localhost:8081/employee/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); System.out.println(driver.getCurrentUrl()); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/employee/"); @@ -234,7 +246,7 @@ public class SamlBindingTest { { SamlSPFacade.samlResponse = null; driver.navigate().to("http://localhost:8081/employee/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); System.out.println(driver.getCurrentUrl()); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/employee/"); @@ -351,24 +363,24 @@ public class SamlBindingTest { @Test public void testRedirectSignedLoginLogout() { driver.navigate().to("http://localhost:8081/employee-sig/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/employee-sig/"); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to("http://localhost:8081/employee-sig?GLO=true"); - checkLoggedOut("http://localhost:8081/employee-sig/"); + checkLoggedOut("http://localhost:8081/employee-sig/", false); } @Test public void testRedirectSignedLoginLogoutFrontNoSSO() { driver.navigate().to("http://localhost:8081/employee-sig-front/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/employee-sig-front/"); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to("http://localhost:8081/employee-sig-front?GLO=true"); - checkLoggedOut("http://localhost:8081/employee-sig-front/"); + checkLoggedOut("http://localhost:8081/employee-sig-front/", false); } @@ -377,7 +389,7 @@ public class SamlBindingTest { // visit 1st app an logg in System.out.println("visit 1st app "); driver.navigate().to("http://localhost:8081/employee-sig/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); System.out.println("login to form"); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/employee-sig/"); @@ -398,23 +410,23 @@ public class SamlBindingTest { // logout of first app System.out.println("GLO"); driver.navigate().to("http://localhost:8081/employee-sig?GLO=true"); - checkLoggedOut("http://localhost:8081/employee-sig/"); + checkLoggedOut("http://localhost:8081/employee-sig/", false); driver.navigate().to("http://localhost:8081/employee-sig-front/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/protocol/saml")); + assertAtLoginPageRedirectBinding(); driver.navigate().to("http://localhost:8081/sales-post-sig/"); - Assert.assertTrue(driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/protocol/saml")); + assertAtLoginPagePostBinding(); } @Test public void testPostEncryptedLoginLogout() { driver.navigate().to("http://localhost:8081/sales-post-enc/"); - Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-post-enc/"); Assert.assertTrue(driver.getPageSource().contains("bburke")); driver.navigate().to("http://localhost:8081/sales-post-enc?GLO=true"); - checkLoggedOut("http://localhost:8081/sales-post-enc/"); + checkLoggedOut("http://localhost:8081/sales-post-enc/", true); } @Test @@ -428,7 +440,7 @@ public class SamlBindingTest { @Test public void testPostBadRealmSignature() { driver.navigate().to("http://localhost:8081/bad-realm-sales-post-sig/"); - Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/bad-realm-sales-post-sig/"); Assert.assertTrue(driver.getPageSource().contains("null")); @@ -445,13 +457,13 @@ public class SamlBindingTest { public void testMetadataPostSignedLoginLogout() throws Exception { driver.navigate().to("http://localhost:8081/sales-metadata/"); - Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml"); + assertAtLoginPagePostBinding(); loginPage.login("bburke", "password"); Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-metadata/"); String pageSource = driver.getPageSource(); Assert.assertTrue(pageSource.contains("bburke")); driver.navigate().to("http://localhost:8081/sales-metadata?GLO=true"); - checkLoggedOut("http://localhost:8081/sales-metadata/"); + checkLoggedOut("http://localhost:8081/sales-metadata/", true); } @@ -462,7 +474,7 @@ public class SamlBindingTest { admin.toRepresentation(); - ClientRepresentation clientRep = admin.convertClientDescription(IOUtils.toString(SamlBindingTest.class.getResourceAsStream("/saml/sp-metadata.xml"))); + ClientRepresentation clientRep = admin.convertClientDescription(IOUtils.toString(SamlPicketlinkSPTest.class.getResourceAsStream("/saml/sp-metadata.xml"))); Response response = admin.clients().create(clientRep); assertEquals(201, response.getStatus());