From 29015dbabfeda65dbb889ffc95c2379b89c11fe2 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Thu, 26 Sep 2013 14:09:02 +0100 Subject: [PATCH] Removed Arquillian from testsuite --- pom.xml | 20 +- testsuite/pom.xml | 205 ++++++++++++------ .../keycloak/testsuite/AbstractDroneTest.java | 75 ------- .../org/keycloak/testsuite/AccountTest.java | 88 -------- .../testsuite/ApplicationServlet.java | 17 ++ .../org/keycloak/testsuite/Constants.java | 4 +- .../org/keycloak/testsuite/Deployments.java | 32 --- .../org/keycloak/testsuite/OAuthClient.java | 152 +++++++++++++ .../RequiredActionResetPasswordTest.java | 80 ------- .../RequiredActionUpdateProfileTest.java | 70 ------ .../testsuite/SystemPropertiesSetter.java | 55 ----- .../keycloak/testsuite/TestApplication.java | 94 -------- .../java/org/keycloak/testsuite/TotpTest.java | 115 ---------- .../RequiredActionEmailVerificationTest.java | 104 +++++---- .../RequiredActionMultipleActionsTest.java | 79 +++---- .../RequiredActionResetPasswordTest.java | 94 ++++++++ .../RequiredActionTotpSetupTest.java | 99 +++++---- .../RequiredActionUpdateProfileTest.java | 85 ++++++++ .../keycloak/testsuite/forms/AccountTest.java | 146 +++++++++++++ .../testsuite/{ => forms}/LoginTest.java | 59 ++--- .../testsuite/forms/LoginTotpTest.java | 119 ++++++++++ .../testsuite/{ => forms}/RegisterTest.java | 84 ++++--- .../{ => forms}/ResetPasswordTest.java | 67 +++--- ...wordPage.java => AccountPasswordPage.java} | 8 +- .../{TotpPage.java => AccountTotpPage.java} | 8 +- ...age.java => AccountUpdateProfilePage.java} | 8 +- .../org/keycloak/testsuite/pages/AppPage.java | 38 ---- .../testsuite/pages/LoginConfigTotpPage.java | 11 +- .../keycloak/testsuite/pages/LoginPage.java | 17 +- .../pages/LoginPasswordResetPage.java | 11 +- .../pages/LoginPasswordUpdatePage.java | 11 +- .../testsuite/pages/LoginTotpPage.java | 24 +- .../pages/LoginUpdateProfilePage.java | 14 +- .../org/keycloak/testsuite/pages/Page.java | 26 +++ .../testsuite/pages/RegisterPage.java | 13 +- .../testsuite/rule/GreenMailRule.java | 23 ++ .../keycloak/testsuite/rule/KeycloakRule.java | 179 +++++++++++++++ .../org/keycloak/testsuite/rule/Page.java | 12 - .../rule/{Driver.java => WebResource.java} | 3 +- .../org/keycloak/testsuite/rule/WebRule.java | 41 ++-- .../resources/{ => META-INF}/persistence.xml | 13 +- .../src/test/resources/app-jboss-web.xml | 5 - .../test/resources/app-resteasy-oauth.json | 11 - testsuite/src/test/resources/app-web.xml | 27 --- testsuite/src/test/resources/arquillian.xml | 9 - .../resources/jboss-deployment-structure.xml | 12 - .../src/test/resources/testrealm-email.json | 76 ------- .../src/test/resources/testrealm-totp.json | 75 ------- testsuite/src/test/resources/testrealm.json | 72 +----- testsuite/src/test/resources/user.jsp | 14 -- .../web-properties-email-verfication.xml | 26 --- testsuite/src/test/resources/web.xml | 49 ----- 52 files changed, 1362 insertions(+), 1417 deletions(-) delete mode 100644 testsuite/src/test/java/org/keycloak/testsuite/AbstractDroneTest.java delete mode 100644 testsuite/src/test/java/org/keycloak/testsuite/AccountTest.java create mode 100644 testsuite/src/test/java/org/keycloak/testsuite/ApplicationServlet.java delete mode 100644 testsuite/src/test/java/org/keycloak/testsuite/Deployments.java create mode 100644 testsuite/src/test/java/org/keycloak/testsuite/OAuthClient.java delete mode 100644 testsuite/src/test/java/org/keycloak/testsuite/RequiredActionResetPasswordTest.java delete mode 100644 testsuite/src/test/java/org/keycloak/testsuite/RequiredActionUpdateProfileTest.java delete mode 100644 testsuite/src/test/java/org/keycloak/testsuite/SystemPropertiesSetter.java delete mode 100755 testsuite/src/test/java/org/keycloak/testsuite/TestApplication.java delete mode 100644 testsuite/src/test/java/org/keycloak/testsuite/TotpTest.java rename testsuite/src/test/java/org/keycloak/testsuite/{ => actions}/RequiredActionEmailVerificationTest.java (55%) rename testsuite/src/test/java/org/keycloak/testsuite/{ => actions}/RequiredActionMultipleActionsTest.java (56%) create mode 100644 testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionResetPasswordTest.java rename testsuite/src/test/java/org/keycloak/testsuite/{ => actions}/RequiredActionTotpSetupTest.java (52%) create mode 100644 testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionUpdateProfileTest.java create mode 100644 testsuite/src/test/java/org/keycloak/testsuite/forms/AccountTest.java rename testsuite/src/test/java/org/keycloak/testsuite/{ => forms}/LoginTest.java (59%) create mode 100644 testsuite/src/test/java/org/keycloak/testsuite/forms/LoginTotpTest.java rename testsuite/src/test/java/org/keycloak/testsuite/{ => forms}/RegisterTest.java (55%) rename testsuite/src/test/java/org/keycloak/testsuite/{ => forms}/ResetPasswordTest.java (59%) rename testsuite/src/test/java/org/keycloak/testsuite/pages/{ChangePasswordPage.java => AccountPasswordPage.java} (87%) rename testsuite/src/test/java/org/keycloak/testsuite/pages/{TotpPage.java => AccountTotpPage.java} (86%) rename testsuite/src/test/java/org/keycloak/testsuite/pages/{UpdateProfilePage.java => AccountUpdateProfilePage.java} (90%) delete mode 100644 testsuite/src/test/java/org/keycloak/testsuite/pages/AppPage.java create mode 100644 testsuite/src/test/java/org/keycloak/testsuite/pages/Page.java create mode 100644 testsuite/src/test/java/org/keycloak/testsuite/rule/KeycloakRule.java delete mode 100644 testsuite/src/test/java/org/keycloak/testsuite/rule/Page.java rename testsuite/src/test/java/org/keycloak/testsuite/rule/{Driver.java => WebResource.java} (89%) rename testsuite/src/test/resources/{ => META-INF}/persistence.xml (81%) delete mode 100755 testsuite/src/test/resources/app-jboss-web.xml delete mode 100755 testsuite/src/test/resources/app-resteasy-oauth.json delete mode 100755 testsuite/src/test/resources/app-web.xml delete mode 100644 testsuite/src/test/resources/arquillian.xml delete mode 100755 testsuite/src/test/resources/jboss-deployment-structure.xml delete mode 100755 testsuite/src/test/resources/testrealm-email.json delete mode 100755 testsuite/src/test/resources/testrealm-totp.json delete mode 100755 testsuite/src/test/resources/user.jsp delete mode 100755 testsuite/src/test/resources/web-properties-email-verfication.xml delete mode 100755 testsuite/src/test/resources/web.xml diff --git a/pom.xml b/pom.xml index 8966893542..e8447932a1 100755 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,7 @@ forms admin-ui-styles examples + testsuite @@ -234,21 +235,18 @@ greenmail 1.3.1b - - - - org.jboss.arquillian - arquillian-bom - 1.1.1.Final - pom - import - - + + org.seleniumhq.selenium selenium-java - 2.26.0 + 2.35.0 + + org.seleniumhq.selenium + selenium-chrome-driver + 2.35.0 + diff --git a/testsuite/pom.xml b/testsuite/pom.xml index 973b7a32d1..cd9c0b52b2 100755 --- a/testsuite/pom.xml +++ b/testsuite/pom.xml @@ -23,11 +23,11 @@ - - org.jboss.resteasy - jose-jwt - provided - + + org.bouncycastle + bcprov-jdk16 + provided + org.keycloak keycloak-core @@ -63,76 +63,143 @@ keycloak-forms ${project.version} + + + org.jboss.logging + jboss-logging + provided + + + org.picketlink + picketlink-idm-api + provided + + + org.picketlink + picketlink-common + provided + + + org.picketlink + picketlink-idm-impl + provided + + + org.picketlink + picketlink-idm-simple-schema + provided + + + org.picketlink + picketlink-config + provided + + + org.jboss.resteasy + resteasy-jaxrs + provided + + + log4j + log4j + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-simple + + + + + org.jboss.resteasy + jaxrs-api + provided + + + org.jboss.resteasy + resteasy-client + provided + + + org.jboss.resteasy + resteasy-crypto + provided + + + org.jboss.resteasy + jose-jwt + provided + + + org.jboss.resteasy + resteasy-undertow + test + + + io.undertow + undertow-servlet + test + + + io.undertow + undertow-core + test + + + org.codehaus.jackson + jackson-core-asl + provided + + + org.codehaus.jackson + jackson-mapper-asl + provided + + + org.jboss.spec.javax.servlet + jboss-servlet-api_3.0_spec + provided + + + org.codehaus.jackson + jackson-xc + provided + + + junit + junit + test + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + provided + + + com.h2database + h2 + 1.3.161 + test + + + org.hibernate + hibernate-entitymanager + 3.6.6.Final + test + - org.picketlink - picketlink-idm-api - - - org.picketlink - picketlink-idm-impl - - - org.picketlink - picketlink-idm-simple-schema - - - org.picketlink - picketlink-config - - - org.jboss.resteasy - resteasy-jaxrs - provided - - - log4j - log4j - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-simple - - - - - org.jboss.resteasy - jaxrs-api - provided - - - com.h2database - h2 - 1.3.161 - - - - junit - junit - - - org.jboss.arquillian.junit - arquillian-junit-container - test - + com.icegreen + greenmail + test + org.seleniumhq.selenium selenium-java test - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven - test - - - com.icegreen - greenmail - test - diff --git a/testsuite/src/test/java/org/keycloak/testsuite/AbstractDroneTest.java b/testsuite/src/test/java/org/keycloak/testsuite/AbstractDroneTest.java deleted file mode 100644 index e261ab05ba..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/AbstractDroneTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2012, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.keycloak.testsuite; - -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.After; -import org.junit.Rule; -import org.keycloak.testsuite.pages.AppPage; -import org.keycloak.testsuite.pages.LoginPage; -import org.keycloak.testsuite.pages.RegisterPage; -import org.keycloak.testsuite.rule.Driver; -import org.keycloak.testsuite.rule.Page; -import org.keycloak.testsuite.rule.WebRule; -import org.openqa.selenium.WebDriver; - -/** - * @author Stian Thorgersen - */ -public abstract class AbstractDroneTest { - - @Deployment(name = "app", testable = false, order = 2) - public static WebArchive appDeployment() { - return Deployments.appDeployment(); - } - - @Deployment(name = "auth-server", testable = false, order = 1) - public static WebArchive deployment() { - return Deployments.deployment(); - } - - @Rule - public WebRule webRule = new WebRule(this); - - @Page - protected AppPage appPage; - - @Driver - protected WebDriver driver; - - @Page - protected LoginPage loginPage; - - @Page - protected RegisterPage registerPage; - - @After - public void after() { - appPage.open(); - if (appPage.isCurrent()) { - appPage.logout(); - } - driver.manage().deleteAllCookies(); - } - -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/AccountTest.java b/testsuite/src/test/java/org/keycloak/testsuite/AccountTest.java deleted file mode 100644 index 8301e515ae..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/AccountTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2012, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.keycloak.testsuite; - -import org.jboss.arquillian.junit.Arquillian; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.keycloak.testsuite.pages.ChangePasswordPage; -import org.keycloak.testsuite.pages.UpdateProfilePage; -import org.keycloak.testsuite.rule.Page; - -/** - * @author Stian Thorgersen - */ -@RunWith(Arquillian.class) -public class AccountTest extends AbstractDroneTest { - - @Page - protected ChangePasswordPage changePasswordPage; - - @Page - protected UpdateProfilePage profilePage; - - @Test - public void changePassword() { - appPage.open(); - loginPage.register(); - registerPage.register("name", "email", "changePassword", "password", "password"); - - changePasswordPage.open(); - changePasswordPage.changePassword("password", "new-password", "new-password"); - - appPage.open(); - Assert.assertTrue(appPage.isCurrent()); - appPage.logout(); - - Assert.assertTrue(loginPage.isCurrent()); - - loginPage.login("changePassword", "password"); - - Assert.assertEquals("Invalid username or password", loginPage.getError()); - - loginPage.login("changePassword", "new-password"); - - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("changePassword", appPage.getUser()); - } - - @Test - public void changeProfile() { - appPage.open(); - loginPage.register(); - registerPage.register("first last", "old@email.com", "changeProfile", "password", "password"); - - profilePage.open(); - - Assert.assertEquals("first", profilePage.getFirstName()); - Assert.assertEquals("last", profilePage.getLastName()); - Assert.assertEquals("old@email.com", profilePage.getEmail()); - - profilePage.updateProfile("New first", "New last", "new@email.com"); - - Assert.assertEquals("New first", profilePage.getFirstName()); - Assert.assertEquals("New last", profilePage.getLastName()); - Assert.assertEquals("new@email.com", profilePage.getEmail()); - } - -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/ApplicationServlet.java b/testsuite/src/test/java/org/keycloak/testsuite/ApplicationServlet.java new file mode 100644 index 0000000000..300d089354 --- /dev/null +++ b/testsuite/src/test/java/org/keycloak/testsuite/ApplicationServlet.java @@ -0,0 +1,17 @@ +package org.keycloak.testsuite; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ApplicationServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.getWriter().print("Hello world!"); + } + +} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/Constants.java b/testsuite/src/test/java/org/keycloak/testsuite/Constants.java index 389945d2c4..8313995d03 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/Constants.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/Constants.java @@ -2,8 +2,6 @@ package org.keycloak.testsuite; public class Constants { - public static String APP_ROOT = "http://localhost:8080/app"; - - public static String AUTH_SERVER_ROOT = "http://localhost:8080/auth-server"; + public static String AUTH_SERVER_ROOT = "http://localhost:8081/auth-server"; } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/Deployments.java b/testsuite/src/test/java/org/keycloak/testsuite/Deployments.java deleted file mode 100644 index c536210132..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/Deployments.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.keycloak.testsuite; - -import java.io.File; - -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.jboss.shrinkwrap.resolver.api.maven.Maven; - -public class Deployments { - public static WebArchive appDeployment() { - File[] libs = Maven.resolver().loadPomFromFile("pom.xml") - .resolve("org.keycloak:keycloak-core", "org.keycloak:keycloak-as7-adapter").withoutTransitivity().asFile(); - - WebArchive archive = ShrinkWrap.create(WebArchive.class, "app.war").addClasses(TestApplication.class) - .addAsLibraries(libs).addAsWebInfResource("jboss-deployment-structure.xml") - .addAsWebInfResource("app-web.xml", "web.xml").addAsWebInfResource("app-jboss-web.xml", "jboss-web.xml") - .addAsWebInfResource("app-resteasy-oauth.json", "resteasy-oauth.json").addAsWebResource("user.jsp"); - return archive; - } - - public static WebArchive deployment() { - File[] libs = Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withTransitivity() - .asFile(); - - WebArchive archive = ShrinkWrap.create(WebArchive.class, "auth-server.war").addClasses(TestApplication.class) - .addAsLibraries(libs).addAsWebInfResource("jboss-deployment-structure.xml").addAsWebInfResource("web.xml") - .addAsResource("persistence.xml", "META-INF/persistence.xml") - .addAsResource("testrealm.json", "META-INF/testrealm.json"); - - return archive; - } -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/OAuthClient.java b/testsuite/src/test/java/org/keycloak/testsuite/OAuthClient.java new file mode 100644 index 0000000000..34ad2b8226 --- /dev/null +++ b/testsuite/src/test/java/org/keycloak/testsuite/OAuthClient.java @@ -0,0 +1,152 @@ +package org.keycloak.testsuite; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.UriBuilder; + +import org.apache.http.NameValuePair; +import org.apache.http.client.utils.URLEncodedUtils; +import org.openqa.selenium.WebDriver; + +public class OAuthClient { + + private WebDriver driver; + + private String baseUrl = "http://localhost:8081/auth-server/rest"; + + private String realm = "test"; + + private String responseType = "code"; + + private String clientId = "test-app"; + + private String redirectUri = "http://localhost:8081/app/auth"; + + private String scope; + + private String state; + + public OAuthClient(WebDriver driver) { + this.driver = driver; + } + + // public void login(String username, String password) throws UnsupportedEncodingException { + // HttpClient client = new DefaultHttpClient(); + // HttpPost post = new HttpPost(getLoginFormUrl()); + // + // List parameters = new LinkedList(); + // parameters.add(new BasicNameValuePair("username", username)); + // parameters.add(new BasicNameValuePair("password", password)); + // + // UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parameters, Charset.forName("UTF-8")); + // post.setEntity(formEntity); + // } + + public boolean isAuthorizationResponse() { + return getCurrentRequest().equals(redirectUri) && getCurrentQuery().containsKey("code"); + } + + public String getState() { + return state; + } + + public String getClientId() { + return clientId; + } + + public String getResponseType() { + return responseType; + } + + public String getCurrentRequest() { + return driver.getCurrentUrl().substring(0, driver.getCurrentUrl().indexOf('?')); + } + + public URI getCurrentUri() { + try { + return new URI(driver.getCurrentUrl()); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + + public Map getCurrentQuery() { + Map m = new HashMap(); + List pairs = URLEncodedUtils.parse(getCurrentUri(), "UTF-8"); + for (NameValuePair p : pairs) { + m.put(p.getName(), p.getValue()); + } + return m; + } + + public void openLoginForm() { + driver.navigate().to(getLoginFormUrl()); + } + + public void openLogout() { + UriBuilder b = UriBuilder.fromUri(baseUrl + "/realms/" + realm + "/tokens/logout"); + if (redirectUri != null) { + b.queryParam("redirect_uri", redirectUri); + } + driver.navigate().to(b.build().toString()); + } + + public String getRedirectUri() { + return redirectUri; + } + + public String getScope() { + return scope; + } + + public String getLoginFormUrl() { + UriBuilder b = UriBuilder.fromUri(baseUrl + "/realms/" + realm + "/tokens/login"); + b.queryParam("response_type", responseType); + b.queryParam("client_id", clientId); + if (redirectUri != null) { + b.queryParam("redirect_uri", redirectUri); + } + if (scope != null) { + b.queryParam("scope", scope); + } + if (state != null) { + b.queryParam("state", state); + } + return b.build().toString(); + } + + public OAuthClient realm(String realm) { + this.realm = realm; + return this; + } + + public OAuthClient clientId(String clientId) { + this.clientId = clientId; + return this; + } + + public OAuthClient redirectUri(String redirectUri) { + this.redirectUri = redirectUri; + return this; + } + + public OAuthClient responseType(String responseType) { + this.responseType = responseType; + return this; + } + + public OAuthClient scope(String scope) { + this.scope = scope; + return this; + } + + public OAuthClient state(String state) { + this.state = state; + return this; + } + +} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionResetPasswordTest.java b/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionResetPasswordTest.java deleted file mode 100644 index c9ea42b9ac..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionResetPasswordTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2012, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.keycloak.testsuite; - -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.keycloak.testsuite.pages.LoginPasswordUpdatePage; -import org.keycloak.testsuite.rule.GreenMailRule; -import org.keycloak.testsuite.rule.Page; - -/** - * @author Stian Thorgersen - */ -@RunWith(Arquillian.class) -public class RequiredActionResetPasswordTest extends AbstractDroneTest { - - @Deployment(name = "properties", testable = false, order = 1) - public static WebArchive propertiesDeployment() { - return ShrinkWrap.create(WebArchive.class, "properties.war").addClass(SystemPropertiesSetter.class) - .addAsWebInfResource("web-properties-email-verfication.xml", "web.xml"); - } - - @Rule - public GreenMailRule greenMail = new GreenMailRule(); - - @Page - protected LoginPasswordUpdatePage changePasswordPage; - - @Test - public void tempPassword() { - appPage.open(); - - Assert.assertTrue(loginPage.isCurrent()); - - loginPage.login("reset@pass.com", "temp-password"); - - Assert.assertTrue(changePasswordPage.isCurrent()); - - changePasswordPage.changePassword("new-password", "new-password"); - - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("reset@pass.com", appPage.getUser()); - - appPage.logout(); - appPage.open(); - - Assert.assertTrue(loginPage.isCurrent()); - - loginPage.login("reset@pass.com", "new-password"); - - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("reset@pass.com", appPage.getUser()); - } - -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionUpdateProfileTest.java b/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionUpdateProfileTest.java deleted file mode 100644 index 6520152b29..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionUpdateProfileTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2012, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.keycloak.testsuite; - -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.keycloak.testsuite.pages.LoginUpdateProfilePage; -import org.keycloak.testsuite.rule.GreenMailRule; -import org.keycloak.testsuite.rule.Page; - -/** - * @author Stian Thorgersen - */ -@RunWith(Arquillian.class) -public class RequiredActionUpdateProfileTest extends AbstractDroneTest { - - @Deployment(name = "properties", testable = false, order = 1) - public static WebArchive propertiesDeployment() { - return ShrinkWrap.create(WebArchive.class, "properties.war").addClass(SystemPropertiesSetter.class) - .addAsWebInfResource("web-properties-email-verfication.xml", "web.xml"); - } - - @Rule - public GreenMailRule greenMail = new GreenMailRule(); - - @Page - protected LoginUpdateProfilePage updateProfilePage; - - @Test - public void updateProfile() { - appPage.open(); - - Assert.assertTrue(loginPage.isCurrent()); - - loginPage.login("updateprof@pass.com", "password"); - - Assert.assertTrue(updateProfilePage.isCurrent()); - - updateProfilePage.update("New first", "New last", "new@email.com"); - - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("updateprof@pass.com", appPage.getUser()); - } - -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/SystemPropertiesSetter.java b/testsuite/src/test/java/org/keycloak/testsuite/SystemPropertiesSetter.java deleted file mode 100644 index d9e68c9266..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/SystemPropertiesSetter.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.keycloak.testsuite; - -import java.io.IOException; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -public class SystemPropertiesSetter implements Servlet { - - @Override - public void destroy() { - for (Entry e : original.entrySet()) { - System.setProperty(e.getKey(), e.getValue()); - System.out.println("RESET " + e.getKey() + "=" + e.getValue()); - } - } - - @Override - public ServletConfig getServletConfig() { - return null; - } - - @Override - public String getServletInfo() { - return null; - } - - private Map original = new HashMap(); - - @Override - public void init(ServletConfig arg0) throws ServletException { - Enumeration n = arg0.getInitParameterNames(); - while (n.hasMoreElements()) { - String k = n.nextElement(); - String v = arg0.getInitParameter(k); - - original.put(k, v); - - System.setProperty(k, v); - System.out.println("SET " + k + "=" + v); - } - } - - @Override - public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException { - } - -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/TestApplication.java b/testsuite/src/test/java/org/keycloak/testsuite/TestApplication.java deleted file mode 100755 index 6b8b1218ae..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/TestApplication.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2012, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.keycloak.testsuite; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -import javax.servlet.ServletContext; -import javax.ws.rs.core.Context; - -import org.jboss.resteasy.jwt.JsonSerialization; -import org.keycloak.representations.idm.CredentialRepresentation; -import org.keycloak.representations.idm.RealmRepresentation; -import org.keycloak.services.managers.RealmManager; -import org.keycloak.services.models.KeycloakSession; -import org.keycloak.services.models.RealmModel; -import org.keycloak.services.resources.KeycloakApplication; -import org.keycloak.services.resources.SaasService; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class TestApplication extends KeycloakApplication { - - public TestApplication(@Context ServletContext servletContext) { - super(servletContext); - KeycloakSession session = factory.createSession(); - session.getTransaction().begin(); - RealmManager realmManager = new RealmManager(session); - if (realmManager.defaultRealm() == null) { - install(realmManager); - } - session.getTransaction().commit(); - } - - public void install(RealmManager manager) { - RealmModel defaultRealm = manager.createRealm(RealmModel.DEFAULT_REALM, RealmModel.DEFAULT_REALM); - defaultRealm.setName(RealmModel.DEFAULT_REALM); - defaultRealm.setEnabled(true); - defaultRealm.setTokenLifespan(300); - defaultRealm.setAccessCodeLifespan(60); - defaultRealm.setSslNotRequired(true); - defaultRealm.setCookieLoginAllowed(true); - defaultRealm.setRegistrationAllowed(true); - manager.generateRealmKeys(defaultRealm); - defaultRealm.addRequiredCredential(CredentialRepresentation.PASSWORD); - defaultRealm.addRole(SaasService.REALM_CREATOR_ROLE); - defaultRealm.addDefaultRole(SaasService.REALM_CREATOR_ROLE); - - RealmRepresentation rep = loadJson("META-INF/testrealm.json"); - RealmModel realm = manager.createRealm("demo", rep.getRealm()); - manager.importRealm(rep, realm); - - } - - public static RealmRepresentation loadJson(String path) { - InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - int c; - try { - while ((c = is.read()) != -1) { - os.write(c); - } - byte[] bytes = os.toByteArray(); - // System.out.println(new String(bytes)); - - return JsonSerialization.fromBytes(RealmRepresentation.class, bytes); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/TotpTest.java b/testsuite/src/test/java/org/keycloak/testsuite/TotpTest.java deleted file mode 100644 index 91e2d70b1f..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/TotpTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2012, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.keycloak.testsuite; - -import java.net.MalformedURLException; - -import org.jboss.arquillian.junit.Arquillian; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.keycloak.testsuite.pages.LoginTotpPage; -import org.keycloak.testsuite.pages.TotpPage; -import org.keycloak.testsuite.rule.Page; -import org.picketlink.idm.credential.util.TimeBasedOTP; - -/** - * @author Stian Thorgersen - */ -@RunWith(Arquillian.class) -public class TotpTest extends AbstractDroneTest { - - @Page - private LoginTotpPage loginTotpPage; - - private TimeBasedOTP totp; - - @Page - protected TotpPage totpPage; - - @Before - public void before() throws MalformedURLException { - totp = new TimeBasedOTP(); - } - - @Test - public void loginWithTotpFailure() { - appPage.open(); - loginPage.register(); - registerPage.register("name", "email", "loginWithTotpFailure", "password", "password"); - totpPage.open(); - - String totpSecret = totpPage.getTotpSecret(); - totpPage.configure(totp.generate(totpSecret)); - - appPage.open(); - appPage.logout(); - - loginPage.login("loginWithTotpSuccess", "password"); - - Assert.assertFalse(appPage.isCurrent()); - - loginTotpPage.login("123456"); - - Assert.assertTrue(loginTotpPage.isCurrent()); - Assert.assertEquals("Invalid username or password", loginTotpPage.getError()); - } - - @Test - public void loginWithTotpSuccess() { - appPage.open(); - loginPage.register(); - registerPage.register("name", "email", "loginWithTotpSuccess", "password", "password"); - totpPage.open(); - - String totpSecret = totpPage.getTotpSecret(); - totpPage.configure(totp.generate(totpSecret)); - - appPage.open(); - appPage.logout(); - - loginPage.login("loginWithTotpSuccess", "password"); - - Assert.assertFalse(appPage.isCurrent()); - - loginTotpPage.login(totp.generate(totpSecret)); - - Assert.assertTrue(appPage.isCurrent()); - } - - @Test - public void setupTotp() { - appPage.open(); - loginPage.register(); - registerPage.register("name", "email", "setupTotp", "password", "password"); - - totpPage.open(); - - Assert.assertTrue(totpPage.isCurrent()); - - totpPage.configure(totp.generate(totpPage.getTotpSecret())); - - Assert.assertTrue(driver.getPageSource().contains("Google Authenticator enabled")); - } - -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionEmailVerificationTest.java b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionEmailVerificationTest.java similarity index 55% rename from testsuite/src/test/java/org/keycloak/testsuite/RequiredActionEmailVerificationTest.java rename to testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionEmailVerificationTest.java index 738e681995..374b93487c 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionEmailVerificationTest.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionEmailVerificationTest.java @@ -19,7 +19,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.keycloak.testsuite; +package org.keycloak.testsuite.actions; import java.io.IOException; import java.util.regex.Matcher; @@ -28,77 +28,86 @@ import java.util.regex.Pattern; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.After; import org.junit.Assert; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.keycloak.testsuite.pages.AppPage; +import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.models.RealmModel; +import org.keycloak.services.models.UserModel; +import org.keycloak.services.models.UserModel.RequiredAction; +import org.keycloak.testsuite.OAuthClient; import org.keycloak.testsuite.pages.LoginPage; import org.keycloak.testsuite.pages.RegisterPage; -import org.keycloak.testsuite.rule.Driver; import org.keycloak.testsuite.rule.GreenMailRule; -import org.keycloak.testsuite.rule.Page; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup; +import org.keycloak.testsuite.rule.WebResource; import org.keycloak.testsuite.rule.WebRule; import org.openqa.selenium.WebDriver; /** * @author Stian Thorgersen */ -@RunWith(Arquillian.class) public class RequiredActionEmailVerificationTest { - @Deployment(name = "app", testable = false, order = 3) - public static WebArchive appDeployment() { - return Deployments.appDeployment(); - } + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakSetup() { - @Deployment(name = "auth-server", testable = false, order = 2) - public static WebArchive deployment() { - return Deployments.deployment().addAsResource("testrealm-email.json", "META-INF/testrealm.json"); - } + @Override + public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) { + appRealm.setVerifyEmail(true); - @Deployment(name = "properties", testable = false, order = 1) - public static WebArchive propertiesDeployment() { - return ShrinkWrap.create(WebArchive.class, "properties.war").addClass(SystemPropertiesSetter.class) - .addAsWebInfResource("web-properties-email-verfication.xml", "web.xml"); - } + UserModel user = appRealm.getUser("test-user@localhost"); + user.addRequiredAction(RequiredAction.VERIFY_EMAIL); + } + + }); @Rule public WebRule webRule = new WebRule(this); - @Page - protected AppPage appPage; - - @Driver - protected WebDriver driver; - - @Page - protected LoginPage loginPage; - - @Page - protected RegisterPage registerPage; - @Rule public GreenMailRule greenMail = new GreenMailRule(); - @After - public void after() { - appPage.open(); - if (appPage.isCurrent()) { - appPage.logout(); - } + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + @WebResource + protected LoginPage loginPage; + + @WebResource + protected RegisterPage registerPage; + + @Test + public void verifyEmailExisting() throws IOException, MessagingException { + loginPage.open(); + loginPage.login("test-user@localhost", "password"); + + Assert.assertTrue(driver.getPageSource().contains("Verify email")); + + MimeMessage message = greenMail.getReceivedMessages()[0]; + + String body = (String) message.getContent(); + + Pattern p = Pattern.compile("(?s).*(http://[^\\s]*).*"); + Matcher m = p.matcher(body); + m.matches(); + + String verificationUrl = m.group(1); + + driver.navigate().to(verificationUrl.trim()); + + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); } @Test - public void verifyEmail() throws IOException, MessagingException { - appPage.open(); - - loginPage.register(); + public void verifyEmailRegister() throws IOException, MessagingException { + loginPage.open(); + loginPage.clickRegister(); registerPage.register("name", "email", "verifyEmail", "password", "password"); Assert.assertTrue(driver.getPageSource().contains("Verify email")); @@ -115,8 +124,7 @@ public class RequiredActionEmailVerificationTest { driver.navigate().to(verificationUrl.trim()); - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("verifyEmail", appPage.getUser()); + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionMultipleActionsTest.java b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionMultipleActionsTest.java similarity index 56% rename from testsuite/src/test/java/org/keycloak/testsuite/RequiredActionMultipleActionsTest.java rename to testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionMultipleActionsTest.java index 147e29b763..b64f911332 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionMultipleActionsTest.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionMultipleActionsTest.java @@ -19,76 +19,81 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.keycloak.testsuite; +package org.keycloak.testsuite.actions; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.After; import org.junit.Assert; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; +import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.models.RealmModel; +import org.keycloak.services.models.UserModel; +import org.keycloak.services.models.UserModel.RequiredAction; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.pages.LoginPage; import org.keycloak.testsuite.pages.LoginPasswordUpdatePage; import org.keycloak.testsuite.pages.LoginUpdateProfilePage; -import org.keycloak.testsuite.rule.GreenMailRule; -import org.keycloak.testsuite.rule.Page; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup; +import org.keycloak.testsuite.rule.WebResource; +import org.keycloak.testsuite.rule.WebRule; +import org.openqa.selenium.WebDriver; /** * @author Stian Thorgersen */ -@RunWith(Arquillian.class) -public class RequiredActionMultipleActionsTest extends AbstractDroneTest { +public class RequiredActionMultipleActionsTest { - @Deployment(name = "properties", testable = false, order = 1) - public static WebArchive propertiesDeployment() { - return ShrinkWrap.create(WebArchive.class, "properties.war").addClass(SystemPropertiesSetter.class) - .addAsWebInfResource("web-properties-email-verfication.xml", "web.xml"); - } + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakSetup() { + + @Override + public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) { + UserModel user = appRealm.getUser("test-user@localhost"); + user.addRequiredAction(RequiredAction.UPDATE_PROFILE); + user.addRequiredAction(RequiredAction.UPDATE_PASSWORD); + } + + }); @Rule - public GreenMailRule greenMail = new GreenMailRule(); + public WebRule webRule = new WebRule(this); - @Page + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + @WebResource + protected LoginPage loginPage; + + @WebResource protected LoginPasswordUpdatePage changePasswordPage; - @Page + @WebResource protected LoginUpdateProfilePage updateProfilePage; - @After - public void after() { - appPage.open(); - if (appPage.isCurrent()) { - appPage.logout(); - } - } - @Test public void updateProfileAndPassword() { - appPage.open(); - - Assert.assertTrue(loginPage.isCurrent()); - - loginPage.login("multiple@actions.com", "temp-password"); + loginPage.open(); + loginPage.login("test-user@localhost", "password"); if (changePasswordPage.isCurrent()) { updatePassword(); - Assert.assertTrue(updateProfilePage.isCurrent()); + updateProfilePage.assertCurrent(); updateProfile(); } else if (updateProfilePage.isCurrent()) { updateProfile(); - Assert.assertTrue(changePasswordPage.isCurrent()); + changePasswordPage.assertCurrent(); updatePassword(); } else { Assert.fail("Expected to update password and profile before login"); } - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("multiple@actions.com", appPage.getUser()); - + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); } public void updatePassword() { diff --git a/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionResetPasswordTest.java b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionResetPasswordTest.java new file mode 100644 index 0000000000..44f4c98843 --- /dev/null +++ b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionResetPasswordTest.java @@ -0,0 +1,94 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.keycloak.testsuite.actions; + +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.models.RealmModel; +import org.keycloak.services.models.UserModel; +import org.keycloak.services.models.UserModel.RequiredAction; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.pages.LoginPage; +import org.keycloak.testsuite.pages.LoginPasswordUpdatePage; +import org.keycloak.testsuite.rule.GreenMailRule; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup; +import org.keycloak.testsuite.rule.WebResource; +import org.keycloak.testsuite.rule.WebRule; +import org.openqa.selenium.WebDriver; + +/** + * @author Stian Thorgersen + */ +public class RequiredActionResetPasswordTest { + + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakSetup() { + + @Override + public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) { + appRealm.setResetPasswordAllowed(true); + + UserModel user = appRealm.getUser("test-user@localhost"); + user.addRequiredAction(RequiredAction.UPDATE_PASSWORD); + } + + }); + + @Rule + public WebRule webRule = new WebRule(this); + + @Rule + public GreenMailRule greenMail = new GreenMailRule(); + + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + @WebResource + protected LoginPage loginPage; + + @WebResource + protected LoginPasswordUpdatePage changePasswordPage; + + @Test + public void tempPassword() { + loginPage.open(); + loginPage.login("test-user@localhost", "password"); + + changePasswordPage.assertCurrent(); + changePasswordPage.changePassword("new-password", "new-password"); + + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); + + oauth.openLogout(); + + loginPage.open(); + loginPage.login("test-user@localhost", "new-password"); + } + +} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionTotpSetupTest.java b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionTotpSetupTest.java similarity index 52% rename from testsuite/src/test/java/org/keycloak/testsuite/RequiredActionTotpSetupTest.java rename to testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionTotpSetupTest.java index 88f86b1e63..5a95d6435d 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/RequiredActionTotpSetupTest.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionTotpSetupTest.java @@ -19,25 +19,24 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.keycloak.testsuite; +package org.keycloak.testsuite.actions; -import java.net.MalformedURLException; - -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; -import org.keycloak.testsuite.pages.AppPage; +import org.keycloak.representations.idm.CredentialRepresentation; +import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.models.RealmModel; +import org.keycloak.services.models.UserModel; +import org.keycloak.services.models.UserModel.RequiredAction; +import org.keycloak.testsuite.OAuthClient; import org.keycloak.testsuite.pages.LoginConfigTotpPage; import org.keycloak.testsuite.pages.LoginPage; import org.keycloak.testsuite.pages.RegisterPage; -import org.keycloak.testsuite.rule.Driver; -import org.keycloak.testsuite.rule.Page; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup; +import org.keycloak.testsuite.rule.WebResource; import org.keycloak.testsuite.rule.WebRule; import org.openqa.selenium.WebDriver; import org.picketlink.idm.credential.util.TimeBasedOTP; @@ -45,65 +44,65 @@ import org.picketlink.idm.credential.util.TimeBasedOTP; /** * @author Stian Thorgersen */ -@RunWith(Arquillian.class) public class RequiredActionTotpSetupTest { - @Deployment(name = "app", testable = false, order = 2) - public static WebArchive appDeployment() { - return Deployments.appDeployment(); - } + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakSetup() { - @Deployment(name = "auth-server", testable = false, order = 1) - public static WebArchive deployment() { - return Deployments.deployment().addAsResource("testrealm-totp.json", "META-INF/testrealm.json"); - } + @Override + public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) { + appRealm.addRequiredCredential(CredentialRepresentation.TOTP); + appRealm.setResetPasswordAllowed(true); + + UserModel user = appRealm.getUser("test-user@localhost"); + user.addRequiredAction(RequiredAction.CONFIGURE_TOTP); + } + + }); @Rule public WebRule webRule = new WebRule(this); - @Page - protected AppPage appPage; - - @Driver + @WebResource protected WebDriver driver; - @Page - protected LoginConfigTotpPage totpPage; + @WebResource + protected OAuthClient oauth; - @Page + @WebResource protected LoginPage loginPage; - @Page + @WebResource + protected LoginConfigTotpPage totpPage; + + @WebResource protected RegisterPage registerPage; - protected TimeBasedOTP totp; - - @Before - public void before() throws MalformedURLException { - totp = new TimeBasedOTP(); - } - - @After - public void after() { - appPage.open(); - if (appPage.isCurrent()) { - appPage.logout(); - } - } + protected TimeBasedOTP totp = new TimeBasedOTP(); @Test - public void setupTotp() { - appPage.open(); - - loginPage.register(); + public void setupTotpRegister() { + loginPage.open(); + loginPage.clickRegister(); registerPage.register("name", "email", "setupTotp", "password", "password"); - Assert.assertTrue(totpPage.isCurrent()); + totpPage.assertCurrent(); totpPage.configure(totp.generate(totpPage.getTotpSecret())); - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("setupTotp", appPage.getUser()); + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); + } + + @Test + public void setupTotpExisting() { + loginPage.open(); + loginPage.login("test-user@localhost", "password"); + + totpPage.assertCurrent(); + + totpPage.configure(totp.generate(totpPage.getTotpSecret())); + + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionUpdateProfileTest.java b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionUpdateProfileTest.java new file mode 100644 index 0000000000..b6890bbd98 --- /dev/null +++ b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionUpdateProfileTest.java @@ -0,0 +1,85 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.keycloak.testsuite.actions; + +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.models.RealmModel; +import org.keycloak.services.models.UserModel; +import org.keycloak.services.models.UserModel.RequiredAction; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.pages.LoginPage; +import org.keycloak.testsuite.pages.LoginUpdateProfilePage; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup; +import org.keycloak.testsuite.rule.WebResource; +import org.keycloak.testsuite.rule.WebRule; +import org.openqa.selenium.WebDriver; + +/** + * @author Stian Thorgersen + */ +public class RequiredActionUpdateProfileTest { + + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakSetup() { + + @Override + public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) { + UserModel user = appRealm.getUser("test-user@localhost"); + user.addRequiredAction(RequiredAction.UPDATE_PROFILE); + } + + }); + + @Rule + public WebRule webRule = new WebRule(this); + + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + @WebResource + protected LoginPage loginPage; + + @WebResource + protected LoginUpdateProfilePage updateProfilePage; + + @Test + public void updateProfile() { + loginPage.open(); + + loginPage.login("test-user@localhost", "password"); + + updateProfilePage.assertCurrent(); + + updateProfilePage.update("New first", "New last", "new@email.com"); + + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); + } + +} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/forms/AccountTest.java b/testsuite/src/test/java/org/keycloak/testsuite/forms/AccountTest.java new file mode 100644 index 0000000000..d00d9268b6 --- /dev/null +++ b/testsuite/src/test/java/org/keycloak/testsuite/forms/AccountTest.java @@ -0,0 +1,146 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.keycloak.testsuite.forms; + +import org.junit.After; +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.keycloak.representations.idm.CredentialRepresentation; +import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.models.RealmModel; +import org.keycloak.services.models.UserCredentialModel; +import org.keycloak.services.models.UserModel; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.pages.AccountPasswordPage; +import org.keycloak.testsuite.pages.AccountTotpPage; +import org.keycloak.testsuite.pages.AccountUpdateProfilePage; +import org.keycloak.testsuite.pages.LoginPage; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup; +import org.keycloak.testsuite.rule.WebResource; +import org.keycloak.testsuite.rule.WebRule; +import org.openqa.selenium.WebDriver; +import org.picketlink.idm.credential.util.TimeBasedOTP; + +/** + * @author Stian Thorgersen + */ +public class AccountTest { + + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(); + + @Rule + public WebRule webRule = new WebRule(this); + + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + @WebResource + protected LoginPage loginPage; + + @WebResource + protected AccountPasswordPage changePasswordPage; + + @WebResource + protected AccountUpdateProfilePage profilePage; + + @WebResource + protected AccountTotpPage totpPage; + + private TimeBasedOTP totp = new TimeBasedOTP(); + + @After + public void after() { + keycloakRule.configure(new KeycloakSetup() { + @Override + public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) { + UserModel user = appRealm.getUser("test-user@localhost"); + + UserCredentialModel cred = new UserCredentialModel(); + cred.setType(CredentialRepresentation.PASSWORD); + cred.setValue("password"); + + appRealm.updateCredential(user, cred); + } + }); + } + + @Test + public void changePassword() { + loginPage.open(); + loginPage.login("test-user@localhost", "password"); + + changePasswordPage.open(); + changePasswordPage.changePassword("password", "new-password", "new-password"); + + oauth.openLogout(); + + loginPage.open(); + loginPage.login("test-user@localhost", "password"); + + Assert.assertEquals("Invalid username or password", loginPage.getError()); + + loginPage.open(); + loginPage.login("test-user@localhost", "new-password"); + + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); + } + + @Test + public void changeProfile() { + loginPage.open(); + loginPage.login("test-user@localhost", "password"); + + profilePage.open(); + + Assert.assertEquals("", profilePage.getFirstName()); + Assert.assertEquals("", profilePage.getLastName()); + Assert.assertEquals("test-user@localhost", profilePage.getEmail()); + + profilePage.updateProfile("New first", "New last", "new@email.com"); + + Assert.assertEquals("New first", profilePage.getFirstName()); + Assert.assertEquals("New last", profilePage.getLastName()); + Assert.assertEquals("new@email.com", profilePage.getEmail()); + } + + @Test + public void setupTotp() { + loginPage.open(); + loginPage.login("test-user@localhost", "password"); + + totpPage.open(); + + Assert.assertTrue(totpPage.isCurrent()); + + totpPage.configure(totp.generate(totpPage.getTotpSecret())); + + Assert.assertTrue(driver.getPageSource().contains("Google Authenticator enabled")); + } + +} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/LoginTest.java b/testsuite/src/test/java/org/keycloak/testsuite/forms/LoginTest.java similarity index 59% rename from testsuite/src/test/java/org/keycloak/testsuite/LoginTest.java rename to testsuite/src/test/java/org/keycloak/testsuite/forms/LoginTest.java index ecd65fe225..d2a91e345f 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/LoginTest.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/forms/LoginTest.java @@ -19,56 +19,65 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.keycloak.testsuite; +package org.keycloak.testsuite.forms; -import org.jboss.arquillian.junit.Arquillian; import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.pages.LoginPage; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.WebResource; +import org.keycloak.testsuite.rule.WebRule; +import org.openqa.selenium.WebDriver; /** * @author Stian Thorgersen */ -@RunWith(Arquillian.class) -public class LoginTest extends AbstractDroneTest { +public class LoginTest { + + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(); + + @Rule + public WebRule webRule = new WebRule(this); + + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + @WebResource + protected LoginPage loginPage; @Test public void loginInvalidPassword() { - appPage.open(); + loginPage.open(); + loginPage.login("test-user@localhost", "invalid"); - Assert.assertTrue(loginPage.isCurrent()); - loginPage.login("bburke@redhat.com", "invalid"); + loginPage.assertCurrent(); Assert.assertEquals("Invalid username or password", loginPage.getError()); } @Test public void loginInvalidUsername() { - appPage.open(); - - Assert.assertTrue(loginPage.isCurrent()); + loginPage.open(); loginPage.login("invalid", "password"); + loginPage.assertCurrent(); + Assert.assertEquals("Invalid username or password", loginPage.getError()); } @Test public void loginSuccess() { - appPage.open(); - - loginPage.login("bburke@redhat.com", "password"); + loginPage.open(); + loginPage.login("test-user@localhost", "password"); - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("bburke@redhat.com", appPage.getUser()); - } - - @Test - public void logout() { - loginSuccess(); - appPage.logout(); - - appPage.open(); - Assert.assertTrue(loginPage.isCurrent()); + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/forms/LoginTotpTest.java b/testsuite/src/test/java/org/keycloak/testsuite/forms/LoginTotpTest.java new file mode 100644 index 0000000000..e38e958388 --- /dev/null +++ b/testsuite/src/test/java/org/keycloak/testsuite/forms/LoginTotpTest.java @@ -0,0 +1,119 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2012, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.keycloak.testsuite.forms; + +import java.net.MalformedURLException; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.keycloak.representations.idm.CredentialRepresentation; +import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.models.RealmModel; +import org.keycloak.services.models.UserCredentialModel; +import org.keycloak.services.models.UserModel; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.pages.LoginPage; +import org.keycloak.testsuite.pages.LoginTotpPage; +import org.keycloak.testsuite.rule.GreenMailRule; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup; +import org.keycloak.testsuite.rule.WebResource; +import org.keycloak.testsuite.rule.WebRule; +import org.openqa.selenium.WebDriver; +import org.picketlink.idm.credential.util.TimeBasedOTP; + +/** + * @author Stian Thorgersen + */ +public class LoginTotpTest { + + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakSetup() { + + @Override + public void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm) { + UserModel user = appRealm.getUser("test-user@localhost"); + + UserCredentialModel credentials = new UserCredentialModel(); + credentials.setType(CredentialRepresentation.TOTP); + credentials.setValue("totpSecret"); + appRealm.updateCredential(user, credentials); + + user.setTotp(true); + } + + }); + + @Rule + public WebRule webRule = new WebRule(this); + + @Rule + public GreenMailRule greenMail = new GreenMailRule(); + + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + @WebResource + protected LoginPage loginPage; + + @WebResource + private LoginTotpPage loginTotpPage; + + private TimeBasedOTP totp = new TimeBasedOTP(); + + @Before + public void before() throws MalformedURLException { + totp = new TimeBasedOTP(); + } + + @Test + public void loginWithTotpFailure() { + loginPage.open(); + loginPage.login("test-user@localhost", "password"); + + loginTotpPage.assertCurrent(); + + loginTotpPage.login("123456"); + + loginPage.assertCurrent(); + Assert.assertEquals("Invalid username or password", loginPage.getError()); + } + + @Test + public void loginWithTotpSuccess() { + loginPage.open(); + loginPage.login("test-user@localhost", "password"); + + loginTotpPage.assertCurrent(); + + loginTotpPage.login(totp.generate("totpSecret")); + + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); + } + +} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/RegisterTest.java b/testsuite/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java similarity index 55% rename from testsuite/src/test/java/org/keycloak/testsuite/RegisterTest.java rename to testsuite/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java index 1417262d36..dfff59c705 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/RegisterTest.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java @@ -19,80 +19,100 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.keycloak.testsuite; +package org.keycloak.testsuite.forms; -import org.jboss.arquillian.junit.Arquillian; import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.pages.LoginPage; +import org.keycloak.testsuite.pages.RegisterPage; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.WebResource; +import org.keycloak.testsuite.rule.WebRule; +import org.openqa.selenium.WebDriver; /** * @author Stian Thorgersen */ -@RunWith(Arquillian.class) -public class RegisterTest extends AbstractDroneTest { +public class RegisterTest { + + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(); + + @Rule + public WebRule webRule = new WebRule(this); + + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + @WebResource + protected LoginPage loginPage; + + @WebResource + protected RegisterPage registerPage; @Test public void registerExistingUser() { - appPage.open(); - loginPage.register(); + loginPage.open(); + loginPage.clickRegister(); + registerPage.assertCurrent(); - Assert.assertTrue(registerPage.isCurrent()); + registerPage.register("name", "email", "test-user@localhost", "password", "password"); - registerPage.register("name", "email", "registerExistingUser", null, null); - - Assert.assertTrue(registerPage.isCurrent()); - Assert.assertEquals("Please specify password", registerPage.getError()); + registerPage.assertCurrent(); + Assert.assertEquals("Username already exists", registerPage.getError()); } @Test public void registerUserInvalidPasswordConfirm() { - appPage.open(); - loginPage.register(); - - Assert.assertTrue(registerPage.isCurrent()); + loginPage.open(); + loginPage.clickRegister(); + registerPage.assertCurrent(); registerPage.register("name", "email", "registerUserInvalidPasswordConfirm", "password", "invalid"); - Assert.assertTrue(registerPage.isCurrent()); + registerPage.assertCurrent(); Assert.assertEquals("Password confirmation doesn't match", registerPage.getError()); } @Test public void registerUserMissingPassword() { - appPage.open(); - loginPage.register(); - - Assert.assertTrue(registerPage.isCurrent()); + loginPage.open(); + loginPage.clickRegister(); + registerPage.assertCurrent(); registerPage.register("name", "email", "registerUserMissingPassword", null, null); - Assert.assertTrue(registerPage.isCurrent()); + registerPage.assertCurrent(); Assert.assertEquals("Please specify password", registerPage.getError()); } @Test public void registerUserMissingUsername() { - appPage.open(); - loginPage.register(); - - Assert.assertTrue(registerPage.isCurrent()); + loginPage.open(); + loginPage.clickRegister(); + registerPage.assertCurrent(); registerPage.register("name", "email", null, "password", "password"); - Assert.assertTrue(registerPage.isCurrent()); + registerPage.assertCurrent(); Assert.assertEquals("Please specify username", registerPage.getError()); } @Test public void registerUserSuccess() { - appPage.open(); - loginPage.register(); - - Assert.assertTrue(registerPage.isCurrent()); + loginPage.open(); + loginPage.clickRegister(); + registerPage.assertCurrent(); registerPage.register("name", "email", "registerUserSuccess", "password", "password"); - Assert.assertTrue(appPage.isCurrent()); + + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/ResetPasswordTest.java b/testsuite/src/test/java/org/keycloak/testsuite/forms/ResetPasswordTest.java similarity index 59% rename from testsuite/src/test/java/org/keycloak/testsuite/ResetPasswordTest.java rename to testsuite/src/test/java/org/keycloak/testsuite/forms/ResetPasswordTest.java index f220853d91..5ccc1bfdde 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/ResetPasswordTest.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/forms/ResetPasswordTest.java @@ -19,60 +19,66 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.keycloak.testsuite; +package org.keycloak.testsuite.forms; import java.io.IOException; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.pages.LoginPage; import org.keycloak.testsuite.pages.LoginPasswordResetPage; import org.keycloak.testsuite.pages.LoginPasswordUpdatePage; import org.keycloak.testsuite.rule.GreenMailRule; -import org.keycloak.testsuite.rule.Page; +import org.keycloak.testsuite.rule.KeycloakRule; +import org.keycloak.testsuite.rule.WebResource; +import org.keycloak.testsuite.rule.WebRule; +import org.openqa.selenium.WebDriver; /** * @author Stian Thorgersen */ -@RunWith(Arquillian.class) -public class ResetPasswordTest extends AbstractDroneTest { +public class ResetPasswordTest { - @Deployment(name = "properties", testable = false, order = 1) - public static WebArchive propertiesDeployment() { - return ShrinkWrap.create(WebArchive.class, "properties.war").addClass(SystemPropertiesSetter.class) - .addAsWebInfResource("web-properties-email-verfication.xml", "web.xml"); - } + @ClassRule + public static KeycloakRule keycloakRule = new KeycloakRule(); + + @Rule + public WebRule webRule = new WebRule(this); @Rule public GreenMailRule greenMail = new GreenMailRule(); - @Page + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + @WebResource + protected LoginPage loginPage; + + @WebResource protected LoginPasswordResetPage resetPasswordPage; - @Page + @WebResource protected LoginPasswordUpdatePage updatePasswordPage; @Test public void resetPassword() throws IOException, MessagingException { - appPage.open(); - - Assert.assertTrue(loginPage.isCurrent()); - + loginPage.open(); loginPage.resetPassword(); - Assert.assertTrue(resetPasswordPage.isCurrent()); + resetPasswordPage.assertCurrent(); - resetPasswordPage.changePassword("bburke@redhat.com", "bburke@redhat.com"); + resetPasswordPage.changePassword("test-user@localhost", "test-user@localhost"); - Assert.assertTrue(resetPasswordPage.isCurrent()); + resetPasswordPage.assertCurrent(); Assert.assertEquals(1, greenMail.getReceivedMessages().length); @@ -83,22 +89,19 @@ public class ResetPasswordTest extends AbstractDroneTest { driver.navigate().to(changePasswordUrl.trim()); - Assert.assertTrue(updatePasswordPage.isCurrent()); + updatePasswordPage.assertCurrent(); updatePasswordPage.changePassword("new-password", "new-password"); - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("bburke@redhat.com", appPage.getUser()); + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); - appPage.logout(); - appPage.open(); + oauth.openLogout(); - Assert.assertTrue(loginPage.isCurrent()); + loginPage.open(); - loginPage.login("bburke@redhat.com", "new-password"); + loginPage.login("test-user@localhost", "new-password"); - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals("bburke@redhat.com", appPage.getUser()); + Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse()); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/ChangePasswordPage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/AccountPasswordPage.java similarity index 87% rename from testsuite/src/test/java/org/keycloak/testsuite/pages/ChangePasswordPage.java rename to testsuite/src/test/java/org/keycloak/testsuite/pages/AccountPasswordPage.java index 4d7c4cb3f5..dc93fcb321 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/ChangePasswordPage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/AccountPasswordPage.java @@ -1,16 +1,16 @@ package org.keycloak.testsuite.pages; import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.rule.Driver; +import org.keycloak.testsuite.rule.WebResource; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class ChangePasswordPage { +public class AccountPasswordPage extends Page { - private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/demo/account/password"; + private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/test/account/password"; - @Driver + @WebResource private WebDriver browser; @FindBy(id = "password") diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/TotpPage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/AccountTotpPage.java similarity index 86% rename from testsuite/src/test/java/org/keycloak/testsuite/pages/TotpPage.java rename to testsuite/src/test/java/org/keycloak/testsuite/pages/AccountTotpPage.java index 53474c1d12..3148d5633f 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/TotpPage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/AccountTotpPage.java @@ -1,16 +1,16 @@ package org.keycloak.testsuite.pages; import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.rule.Driver; +import org.keycloak.testsuite.rule.WebResource; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class TotpPage { +public class AccountTotpPage extends Page { - private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/demo/account/totp"; + private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/test/account/totp"; - @Driver + @WebResource private WebDriver browser; @FindBy(id = "totpSecret") diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/UpdateProfilePage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/AccountUpdateProfilePage.java similarity index 90% rename from testsuite/src/test/java/org/keycloak/testsuite/pages/UpdateProfilePage.java rename to testsuite/src/test/java/org/keycloak/testsuite/pages/AccountUpdateProfilePage.java index e6dbfcb721..0b104b684b 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/UpdateProfilePage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/AccountUpdateProfilePage.java @@ -1,16 +1,16 @@ package org.keycloak.testsuite.pages; import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.rule.Driver; +import org.keycloak.testsuite.rule.WebResource; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class UpdateProfilePage { +public class AccountUpdateProfilePage extends Page { - private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/demo/account"; + private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/test/account"; - @Driver + @WebResource private WebDriver browser; @FindBy(id = "firstName") diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/AppPage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/AppPage.java deleted file mode 100644 index 18cc3ae2ee..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/AppPage.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.keycloak.testsuite.pages; - -import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.rule.Driver; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; - -public class AppPage { - - private static String PATH = Constants.APP_ROOT + "/user.jsp"; - - @Driver - private WebDriver browser; - - @FindBy(id = "logout") - private WebElement logoutLink; - - @FindBy(id = "user") - private WebElement user; - - public void open() { - browser.navigate().to(PATH); - } - - public String getUser() { - return user.getText(); - } - - public boolean isCurrent() { - return browser.getCurrentUrl().equals(PATH); - } - - public void logout() { - logoutLink.click(); - } - -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginConfigTotpPage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginConfigTotpPage.java index 5a16097dd5..e9e5d965a5 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginConfigTotpPage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginConfigTotpPage.java @@ -1,16 +1,13 @@ package org.keycloak.testsuite.pages; -import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.rule.Driver; +import org.keycloak.testsuite.rule.WebResource; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class LoginConfigTotpPage { +public class LoginConfigTotpPage extends Page { - private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/demo/account/totp"; - - @Driver + @WebResource private WebDriver browser; @FindBy(id = "totpSecret") @@ -36,7 +33,7 @@ public class LoginConfigTotpPage { } public void open() { - browser.navigate().to(PATH); + throw new UnsupportedOperationException(); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPage.java index 847786343a..cacd0d97da 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPage.java @@ -1,14 +1,9 @@ package org.keycloak.testsuite.pages; -import org.keycloak.testsuite.rule.Driver; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class LoginPage { - - @Driver - private WebDriver browser; +public class LoginPage extends Page { @FindBy(id = "username") private WebElement usernameInput; @@ -43,10 +38,10 @@ public class LoginPage { } public boolean isCurrent() { - return browser.getTitle().equals("Log in to demo"); + return driver.getTitle().equals("Log in to test"); } - public void register() { + public void clickRegister() { registerLink.click(); } @@ -54,4 +49,10 @@ public class LoginPage { resetPasswordLink.click(); } + @Override + public void open() { + oauth.openLoginForm(); + assertCurrent(); + } + } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPasswordResetPage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPasswordResetPage.java index 14da7d4084..7cbb2131db 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPasswordResetPage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPasswordResetPage.java @@ -1,16 +1,13 @@ package org.keycloak.testsuite.pages; -import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.rule.Driver; +import org.keycloak.testsuite.rule.WebResource; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class LoginPasswordResetPage { +public class LoginPasswordResetPage extends Page { - private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/demo/account/password"; - - @Driver + @WebResource private WebDriver browser; @FindBy(id = "username") @@ -34,7 +31,7 @@ public class LoginPasswordResetPage { } public void open() { - browser.navigate().to(PATH); + throw new UnsupportedOperationException(); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPasswordUpdatePage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPasswordUpdatePage.java index 7136a2cb6d..b06f5e270e 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPasswordUpdatePage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginPasswordUpdatePage.java @@ -1,16 +1,13 @@ package org.keycloak.testsuite.pages; -import org.keycloak.testsuite.Constants; -import org.keycloak.testsuite.rule.Driver; +import org.keycloak.testsuite.rule.WebResource; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class LoginPasswordUpdatePage { +public class LoginPasswordUpdatePage extends Page { - private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/demo/account/password"; - - @Driver + @WebResource private WebDriver browser; @FindBy(id = "password-new") @@ -34,7 +31,7 @@ public class LoginPasswordUpdatePage { } public void open() { - browser.navigate().to(PATH); + throw new UnsupportedOperationException(); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginTotpPage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginTotpPage.java index 18b6423e6d..f0f242137f 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginTotpPage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginTotpPage.java @@ -1,13 +1,14 @@ package org.keycloak.testsuite.pages; -import org.keycloak.testsuite.rule.Driver; +import org.keycloak.testsuite.rule.WebResource; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class LoginTotpPage { +public class LoginTotpPage extends Page { - @Driver + @WebResource private WebDriver browser; @FindBy(id = "totp") @@ -16,9 +17,6 @@ public class LoginTotpPage { @FindBy(css = "input[type=\"submit\"]") private WebElement submitButton; - @FindBy(linkText = "Register") - private WebElement registerLink; - @FindBy(id = "loginError") private WebElement loginErrorMessage; @@ -33,7 +31,19 @@ public class LoginTotpPage { } public boolean isCurrent() { - return browser.getTitle().equals("Log in to demo"); + if (browser.getTitle().equals("Log in to test")) { + try { + browser.findElement(By.id("totp")); + return true; + } catch (Throwable t) { + } + } + return false; + } + + @Override + public void open() { + throw new UnsupportedOperationException(); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginUpdateProfilePage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginUpdateProfilePage.java index 73950f3a99..4020729987 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginUpdateProfilePage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/LoginUpdateProfilePage.java @@ -1,13 +1,13 @@ package org.keycloak.testsuite.pages; -import org.keycloak.testsuite.rule.Driver; +import org.keycloak.testsuite.rule.WebResource; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class LoginUpdateProfilePage { +public class LoginUpdateProfilePage extends Page { - @Driver + @WebResource private WebDriver browser; @FindBy(id = "firstName") @@ -26,8 +26,11 @@ public class LoginUpdateProfilePage { private WebElement loginErrorMessage; public void update(String firstName, String lastName, String email) { + firstNameInput.clear(); firstNameInput.sendKeys(firstName); + lastNameInput.clear(); lastNameInput.sendKeys(lastName); + emailInput.clear(); emailInput.sendKeys(email); submitButton.click(); @@ -41,4 +44,9 @@ public class LoginUpdateProfilePage { return browser.getTitle().equals("Update profile"); } + @Override + public void open() { + throw new UnsupportedOperationException(); + } + } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/Page.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/Page.java new file mode 100644 index 0000000000..31836d2f6a --- /dev/null +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/Page.java @@ -0,0 +1,26 @@ +package org.keycloak.testsuite.pages; + +import org.junit.Assert; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.rule.WebResource; +import org.openqa.selenium.WebDriver; + +public abstract class Page { + + @WebResource + protected WebDriver driver; + + @WebResource + protected OAuthClient oauth; + + public void assertCurrent() { + String name = getClass().getSimpleName(); + Assert.assertTrue("Exptected " + name + " but was " + driver.getTitle() + " (" + driver.getCurrentUrl() + ")", + isCurrent()); + } + + abstract boolean isCurrent(); + + abstract void open(); + +} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/RegisterPage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/RegisterPage.java index 6012a56fab..948da3a5f0 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/RegisterPage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/RegisterPage.java @@ -1,13 +1,13 @@ package org.keycloak.testsuite.pages; -import org.keycloak.testsuite.rule.Driver; +import org.keycloak.testsuite.rule.WebResource; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -public class RegisterPage { +public class RegisterPage extends Page { - @Driver + @WebResource private WebDriver browser; @FindBy(id = "name") @@ -60,7 +60,12 @@ public class RegisterPage { } public boolean isCurrent() { - return browser.getTitle().equals("Register with demo"); + return browser.getTitle().equals("Register with test"); + } + + @Override + public void open() { + throw new UnsupportedOperationException(); } } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/rule/GreenMailRule.java b/testsuite/src/test/java/org/keycloak/testsuite/rule/GreenMailRule.java index da659d4cf7..f57d666aa9 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/rule/GreenMailRule.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/rule/GreenMailRule.java @@ -2,6 +2,9 @@ package org.keycloak.testsuite.rule; import java.lang.Thread.UncaughtExceptionHandler; import java.net.SocketException; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Properties; import javax.mail.internet.MimeMessage; @@ -14,8 +17,23 @@ public class GreenMailRule extends ExternalResource { private GreenMail greenMail; + private Properties originalProperties = new Properties(); + @Override protected void before() throws Throwable { + Iterator> itr = System.getProperties().entrySet().iterator(); + while (itr.hasNext()) { + Entry e = itr.next(); + if (((String) e.getKey()).startsWith("keycloak.mail")) { + originalProperties.put(e.getKey(), e.getValue()); + itr.remove(); + } + } + + System.setProperty("keycloak.mail.smtp.from", "auto@keycloak.org"); + System.setProperty("keycloak.mail.smtp.host", "localhost"); + System.setProperty("keycloak.mail.smtp.port", "3025"); + ServerSetup setup = new ServerSetup(3025, "localhost", "smtp"); greenMail = new GreenMail(setup); @@ -39,6 +57,11 @@ public class GreenMailRule extends ExternalResource { greenMail.stop(); } + + System.getProperties().remove("keycloak.mail.smtp.from"); + System.getProperties().remove("keycloak.mail.smtp.host"); + System.getProperties().remove("keycloak.mail.smtp.port"); + System.getProperties().putAll(originalProperties); } public MimeMessage[] getReceivedMessages() { diff --git a/testsuite/src/test/java/org/keycloak/testsuite/rule/KeycloakRule.java b/testsuite/src/test/java/org/keycloak/testsuite/rule/KeycloakRule.java new file mode 100644 index 0000000000..d69d8cd4a1 --- /dev/null +++ b/testsuite/src/test/java/org/keycloak/testsuite/rule/KeycloakRule.java @@ -0,0 +1,179 @@ +package org.keycloak.testsuite.rule; + +import io.undertow.server.handlers.resource.ClassPathResourceManager; +import io.undertow.servlet.Servlets; +import io.undertow.servlet.api.DeploymentInfo; +import io.undertow.servlet.api.FilterInfo; +import io.undertow.servlet.api.ServletInfo; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.servlet.DispatcherType; + +import org.jboss.resteasy.jwt.JsonSerialization; +import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer; +import org.jboss.resteasy.spi.ResteasyDeployment; +import org.junit.rules.ExternalResource; +import org.keycloak.representations.idm.CredentialRepresentation; +import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.services.filters.KeycloakSessionServletFilter; +import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.models.KeycloakSession; +import org.keycloak.services.models.KeycloakSessionFactory; +import org.keycloak.services.models.RealmModel; +import org.keycloak.services.models.RoleModel; +import org.keycloak.services.models.UserModel; +import org.keycloak.services.resources.KeycloakApplication; +import org.keycloak.services.resources.SaasService; +import org.keycloak.testsuite.ApplicationServlet; + +public class KeycloakRule extends ExternalResource { + + private String testRealm = "testrealm.json"; + + private UndertowJaxrsServer server; + private KeycloakSessionFactory factory; + + private KeycloakSetup setup; + + public KeycloakRule() { + } + + public KeycloakRule(String testRealm) { + this.testRealm = testRealm; + } + + public KeycloakRule(KeycloakSetup setup) { + this.setup = setup; + } + + protected void before() throws Throwable { + ResteasyDeployment deployment = new ResteasyDeployment(); + deployment.setApplicationClass(KeycloakApplication.class.getName()); + server = new UndertowJaxrsServer().start(); + + DeploymentInfo di = server.undertowDeployment(deployment, "rest"); + di.setClassLoader(getClass().getClassLoader()); + di.setContextPath("/auth-server"); + di.setDeploymentName("Keycloak"); + di.setResourceManager(new ClassPathResourceManager(getClass().getClassLoader(), "META-INF/resources")); + + FilterInfo filter = Servlets.filter("SessionFilter", KeycloakSessionServletFilter.class); + di.addFilter(filter); + di.addFilterUrlMapping("SessionFilter", "/rest/*", DispatcherType.REQUEST); + + server.deploy(di); + + factory = KeycloakApplication.buildSessionFactory(); + + setupDefaultRealm(); + + importRealm(testRealm); + + if (setup != null) { + configure(setup); + } + + DeploymentInfo deploymentInfo = new DeploymentInfo(); + deploymentInfo.setClassLoader(getClass().getClassLoader()); + deploymentInfo.setDeploymentName("app"); + deploymentInfo.setContextPath("/app"); + + ServletInfo servlet = new ServletInfo(ApplicationServlet.class.getSimpleName(), ApplicationServlet.class); + servlet.addMapping("/*"); + + deploymentInfo.addServlet(servlet); + server.deploy(deploymentInfo); + } + + @Override + protected void after() { + factory.close(); + server.stop(); + } + + public RealmRepresentation loadJson(String path) throws IOException { + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + int c; + while ((c = is.read()) != -1) { + os.write(c); + } + byte[] bytes = os.toByteArray(); + System.out.println(new String(bytes)); + + return JsonSerialization.fromBytes(RealmRepresentation.class, bytes); + } + + public void setupDefaultRealm() { + KeycloakSession session = createSession(); + session.getTransaction().begin(); + + RealmManager manager = new RealmManager(session); + + RealmModel defaultRealm = manager.createRealm(RealmModel.DEFAULT_REALM, RealmModel.DEFAULT_REALM); + defaultRealm.setName(RealmModel.DEFAULT_REALM); + defaultRealm.setEnabled(true); + defaultRealm.setTokenLifespan(300); + defaultRealm.setAccessCodeLifespan(60); + defaultRealm.setAccessCodeLifespanUserAction(600); + defaultRealm.setSslNotRequired(false); + defaultRealm.setCookieLoginAllowed(true); + defaultRealm.setRegistrationAllowed(true); + defaultRealm.setAutomaticRegistrationAfterSocialLogin(false); + manager.generateRealmKeys(defaultRealm); + defaultRealm.addRequiredCredential(CredentialRepresentation.PASSWORD); + RoleModel role = defaultRealm.addRole(SaasService.REALM_CREATOR_ROLE); + UserModel admin = defaultRealm.addUser("admin"); + defaultRealm.grantRole(admin, role); + + session.getTransaction().commit(); + session.close(); + } + + public void importRealm(String name) throws IOException { + KeycloakSession session = createSession(); + session.getTransaction().begin(); + + RealmManager manager = new RealmManager(session); + + RealmModel defaultRealm = manager.getRealm(RealmModel.DEFAULT_REALM); + UserModel admin = defaultRealm.getUser("admin"); + + RealmRepresentation rep = loadJson(name); + RealmModel realm = manager.createRealm("test", rep.getRealm()); + manager.importRealm(rep, realm); + realm.addRealmAdmin(admin); + + session.getTransaction().commit(); + session.close(); + } + + public void configure(KeycloakSetup configurer) { + KeycloakSession session = createSession(); + session.getTransaction().begin(); + + RealmManager manager = new RealmManager(session); + + RealmModel defaultRealm = manager.getRealm(RealmModel.DEFAULT_REALM); + RealmModel appRealm = manager.getRealm("test"); + + configurer.config(manager, defaultRealm, appRealm); + + session.getTransaction().commit(); + session.close(); + } + + public KeycloakSession createSession() { + return factory.createSession(); + } + + public interface KeycloakSetup { + + void config(RealmManager manager, RealmModel defaultRealm, RealmModel appRealm); + + } + +} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/rule/Page.java b/testsuite/src/test/java/org/keycloak/testsuite/rule/Page.java deleted file mode 100644 index c3009ee099..0000000000 --- a/testsuite/src/test/java/org/keycloak/testsuite/rule/Page.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.keycloak.testsuite.rule; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface Page { - -} diff --git a/testsuite/src/test/java/org/keycloak/testsuite/rule/Driver.java b/testsuite/src/test/java/org/keycloak/testsuite/rule/WebResource.java similarity index 89% rename from testsuite/src/test/java/org/keycloak/testsuite/rule/Driver.java rename to testsuite/src/test/java/org/keycloak/testsuite/rule/WebResource.java index 5b7d1d9f24..66b6de210c 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/rule/Driver.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/rule/WebResource.java @@ -7,6 +7,5 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) -public @interface Driver { - +public @interface WebResource { } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/rule/WebRule.java b/testsuite/src/test/java/org/keycloak/testsuite/rule/WebRule.java index 1adcfa2d3f..7b8d7213e6 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/rule/WebRule.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/rule/WebRule.java @@ -3,6 +3,8 @@ package org.keycloak.testsuite.rule; import java.lang.reflect.Field; import org.junit.rules.ExternalResource; +import org.keycloak.testsuite.OAuthClient; +import org.keycloak.testsuite.pages.Page; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; @@ -13,6 +15,7 @@ import com.gargoylesoftware.htmlunit.WebClient; public class WebRule extends ExternalResource { private WebDriver driver; + private OAuthClient oauth; private Object test; public WebRule(Object test) { @@ -28,7 +31,7 @@ public class WebRule extends ExternalResource { if (browser.equals("htmlunit")) { HtmlUnitDriver d = new HtmlUnitDriver(); - d.getWebClient().setCssEnabled(false); + d.getWebClient().getOptions().setCssEnabled(false); driver = d; } else if (browser.equals("chrome")) { driver = new ChromeDriver(); @@ -38,29 +41,26 @@ public class WebRule extends ExternalResource { throw new RuntimeException("Unsupported browser " + browser); } - initDriver(test); - initPages(test); + oauth = new OAuthClient(driver); + + initWebResources(test); } - protected void initDriver(Object o) { + protected void initWebResources(Object o) { Class c = o.getClass(); while (c != null) { for (Field f : c.getDeclaredFields()) { - if (f.getAnnotation(Driver.class) != null) { - set(f, o, driver); - } - } - - c = c.getSuperclass(); - } - } - - protected void initPages(Object o) { - Class c = o.getClass(); - while (c != null) { - for (Field f : c.getDeclaredFields()) { - if (f.getAnnotation(Page.class) != null) { - set(f, o, getPage(f.getType())); + if (f.getAnnotation(WebResource.class) != null) { + Class type = f.getType(); + if (type.equals(WebDriver.class)) { + set(f, o, driver); + } else if (Page.class.isAssignableFrom(type)) { + set(f, o, getPage(f.getType())); + } else if (type.equals(OAuthClient.class)) { + set(f, o, oauth); + } else { + throw new RuntimeException("Unsupported type " + f); + } } } @@ -84,7 +84,7 @@ public class WebRule extends ExternalResource { public T getPage(Class pageClass) { try { T instance = pageClass.newInstance(); - initDriver(instance); + initWebResources(instance); PageFactory.initElements(driver, instance); return instance; } catch (Exception e) { @@ -94,6 +94,7 @@ public class WebRule extends ExternalResource { @Override protected void after() { + driver.manage().deleteAllCookies(); driver.close(); } diff --git a/testsuite/src/test/resources/persistence.xml b/testsuite/src/test/resources/META-INF/persistence.xml similarity index 81% rename from testsuite/src/test/resources/persistence.xml rename to testsuite/src/test/resources/META-INF/persistence.xml index ad40046847..0c8ed9eade 100755 --- a/testsuite/src/test/resources/persistence.xml +++ b/testsuite/src/test/resources/META-INF/persistence.xml @@ -3,8 +3,8 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> - java:jboss/datasources/ExampleDS - + org.hibernate.ejb.HibernatePersistence + org.picketlink.idm.jpa.model.sample.simple.AttributedTypeEntity org.picketlink.idm.jpa.model.sample.simple.AccountTypeEntity org.picketlink.idm.jpa.model.sample.simple.RoleTypeEntity @@ -22,12 +22,17 @@ org.keycloak.services.models.picketlink.mappings.ApplicationEntity true - + + + + + - + + diff --git a/testsuite/src/test/resources/app-jboss-web.xml b/testsuite/src/test/resources/app-jboss-web.xml deleted file mode 100755 index 3cec19cc47..0000000000 --- a/testsuite/src/test/resources/app-jboss-web.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - org.keycloak.adapters.as7.OAuthManagedResourceValve - - \ No newline at end of file diff --git a/testsuite/src/test/resources/app-resteasy-oauth.json b/testsuite/src/test/resources/app-resteasy-oauth.json deleted file mode 100755 index a36b5cf397..0000000000 --- a/testsuite/src/test/resources/app-resteasy-oauth.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "realm" : "demo", - "resource" : "customer-portal", - "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-url" : "http://localhost:8080/auth-server/rest/realms/demo/tokens/login", - "code-url" : "http://localhost:8080/auth-server/rest/realms/demo/tokens/access/codes", - "ssl-not-required" : true, - "credentials" : { - "password" : "password" - } -} diff --git a/testsuite/src/test/resources/app-web.xml b/testsuite/src/test/resources/app-web.xml deleted file mode 100755 index 4ab9fac129..0000000000 --- a/testsuite/src/test/resources/app-web.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - app - - - - Customers - /user.jsp - - - user - - - - - BASIC - commerce - - - - user - - diff --git a/testsuite/src/test/resources/arquillian.xml b/testsuite/src/test/resources/arquillian.xml deleted file mode 100644 index 989cb9fc70..0000000000 --- a/testsuite/src/test/resources/arquillian.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - ${browser:phantomjs} - - diff --git a/testsuite/src/test/resources/jboss-deployment-structure.xml b/testsuite/src/test/resources/jboss-deployment-structure.xml deleted file mode 100755 index b4aedd49c0..0000000000 --- a/testsuite/src/test/resources/jboss-deployment-structure.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/testsuite/src/test/resources/testrealm-email.json b/testsuite/src/test/resources/testrealm-email.json deleted file mode 100755 index 79e1a94f25..0000000000 --- a/testsuite/src/test/resources/testrealm-email.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "realm": "demo", - "enabled": true, - "tokenLifespan": 300, - "accessCodeLifespan": 10, - "accessCodeLifespanUserAction": 600, - "sslNotRequired": true, - "cookieLoginAllowed": true, - "registrationAllowed": true, - "verifyEmail": true, - "privateKey": "MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=", - "publicKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "requiredCredentials": [ "password" ], - "requiredApplicationCredentials": [ "password" ], - "requiredOAuthClientCredentials": [ "password" ], - "defaultRoles": [ "user" ], - "users" : [ - { - "username" : "bburke@redhat.com", - "enabled": true, - "email" : "bburke@redhat.com", - "credentials" : [ - { "type" : "password", - "value" : "password" } - ] - }, - { - "username" : "third-party", - "enabled": true, - "credentials" : [ - { "type" : "password", - "value" : "password" } - ] - } - ], - "roles": [ - { - "name": "user", - "description": "Have User privileges" - }, - { - "name": "admin", - "description": "Have Administrator privileges" - } - ], - "roleMappings": [ - { - "username": "bburke@redhat.com", - "roles": ["user"] - }, - { - "username": "third-party", - "roles": ["KEYCLOAK_IDENTITY_REQUESTER"] - } - ], - "scopeMappings": [ - { - "username": "third-party", - "roles": ["user"] - } - ], - "applications": [ - { - "name": "customer-portal", - "enabled": true, - "adminUrl": "http://localhost:8080/app/j_admin_request", - "useRealmMappings": true, - "credentials": [ - { - "type": "password", - "value": "password" - } - ] - } - ] -} \ No newline at end of file diff --git a/testsuite/src/test/resources/testrealm-totp.json b/testsuite/src/test/resources/testrealm-totp.json deleted file mode 100755 index d73f805e02..0000000000 --- a/testsuite/src/test/resources/testrealm-totp.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "realm": "demo", - "enabled": true, - "tokenLifespan": 300, - "accessCodeLifespan": 10, - "accessCodeLifespanUserAction": 600, - "sslNotRequired": true, - "cookieLoginAllowed": true, - "registrationAllowed": true, - "privateKey": "MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=", - "publicKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "requiredCredentials": [ "password", "totp" ], - "requiredApplicationCredentials": [ "password" ], - "requiredOAuthClientCredentials": [ "password" ], - "defaultRoles": [ "user" ], - "users" : [ - { - "username" : "bburke@redhat.com", - "enabled": true, - "email" : "bburke@redhat.com", - "credentials" : [ - { "type" : "password", - "value" : "password" } - ] - }, - { - "username" : "third-party", - "enabled": true, - "credentials" : [ - { "type" : "password", - "value" : "password" } - ] - } - ], - "roles": [ - { - "name": "user", - "description": "Have User privileges" - }, - { - "name": "admin", - "description": "Have Administrator privileges" - } - ], - "roleMappings": [ - { - "username": "bburke@redhat.com", - "roles": ["user"] - }, - { - "username": "third-party", - "roles": ["KEYCLOAK_IDENTITY_REQUESTER"] - } - ], - "scopeMappings": [ - { - "username": "third-party", - "roles": ["user"] - } - ], - "applications": [ - { - "name": "customer-portal", - "enabled": true, - "adminUrl": "http://localhost:8080/app/j_admin_request", - "useRealmMappings": true, - "credentials": [ - { - "type": "password", - "value": "password" - } - ] - } - ] -} \ No newline at end of file diff --git a/testsuite/src/test/resources/testrealm.json b/testsuite/src/test/resources/testrealm.json index fea7ab60a3..383b425131 100755 --- a/testsuite/src/test/resources/testrealm.json +++ b/testsuite/src/test/resources/testrealm.json @@ -1,5 +1,5 @@ { - "realm": "demo", + "realm": "test", "enabled": true, "tokenLifespan": 300, "accessCodeLifespan": 10, @@ -16,47 +16,9 @@ "defaultRoles": [ "user" ], "users" : [ { - "username" : "bburke@redhat.com", - "enabled": true, - "email" : "bburke@redhat.com", - "credentials" : [ - { "type" : "password", - "value" : "password" } - ] - }, - { - "username" : "reset@pass.com", - "enabled": true, - "requiredActions" : [ "UPDATE_PASSWORD" ], - "email" : "reset@pass.com", - "credentials" : [ - { "type" : "password", - "value" : "temp-password" } - ] - }, - { - "username" : "updateprof@pass.com", - "enabled": true, - "requiredActions" : [ "UPDATE_PROFILE" ], - "email" : "reset@pass.com", - "credentials" : [ - { "type" : "password", - "value" : "password" } - ] - }, - { - "username" : "multiple@actions.com", - "enabled": true, - "requiredActions" : [ "UPDATE_PROFILE", "UPDATE_PASSWORD" ], - "email" : "multiple@actions.com", - "credentials" : [ - { "type" : "password", - "value" : "temp-password" } - ] - }, - { - "username" : "third-party", + "username" : "test-user@localhost", "enabled": true, + "email" : "test-user@localhost", "credentials" : [ { "type" : "password", "value" : "password" } @@ -75,37 +37,15 @@ ], "roleMappings": [ { - "username": "bburke@redhat.com", - "roles": ["user"] - }, - { - "username": "reset@pass.com", - "roles": ["user"] - }, - { - "username": "updateprof@pass.com", - "roles": ["user"] - }, - { - "username": "multiple@actions.com", - "roles": ["user"] - }, - { - "username": "third-party", - "roles": ["KEYCLOAK_IDENTITY_REQUESTER"] - } - ], - "scopeMappings": [ - { - "username": "third-party", + "username": "test-user@localhost", "roles": ["user"] } ], "applications": [ { - "name": "customer-portal", + "name": "test-app", "enabled": true, - "adminUrl": "http://localhost:8080/app/j_admin_request", + "adminUrl": "http://localhost:8081/app/logout", "useRealmMappings": true, "credentials": [ { diff --git a/testsuite/src/test/resources/user.jsp b/testsuite/src/test/resources/user.jsp deleted file mode 100755 index 75afd76755..0000000000 --- a/testsuite/src/test/resources/user.jsp +++ /dev/null @@ -1,14 +0,0 @@ -<%@ page import="javax.ws.rs.core.*" language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> - - -User - - - <% - String user = request.getUserPrincipal() != null ? request.getUserPrincipal().getName() : "not logged in"; - String redirectUri = request.getRequestURL().toString(); - %> - logout - <%=user%> - - \ No newline at end of file diff --git a/testsuite/src/test/resources/web-properties-email-verfication.xml b/testsuite/src/test/resources/web-properties-email-verfication.xml deleted file mode 100755 index 10896305d0..0000000000 --- a/testsuite/src/test/resources/web-properties-email-verfication.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - properties - - - SystemPropertiesSetter - org.keycloak.testsuite.SystemPropertiesSetter - - keycloak.mail.smtp.from - auto@keycloak.org - - - keycloak.mail.smtp.host - localhost - - - keycloak.mail.smtp.port - 3025 - - 1 - - - diff --git a/testsuite/src/test/resources/web.xml b/testsuite/src/test/resources/web.xml deleted file mode 100755 index 243f73a3ed..0000000000 --- a/testsuite/src/test/resources/web.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - auth-server - - - Resteasy - org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher - - javax.ws.rs.Application - org.keycloak.testsuite.TestApplication - - - resteasy.servlet.mapping.prefix - /rest - - 1 - true - - - - Keycloak Session Management - org.keycloak.services.filters.KeycloakSessionServletFilter - - - - Keycloak Session Management - /rest/* - - - - Resteasy - /rest/* - - - - -