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