Hide oauth details with non-oauth tests in testsuite

This commit is contained in:
Stian Thorgersen 2013-09-27 10:30:10 +01:00
parent 811493f61a
commit c96dd592d0
23 changed files with 150 additions and 90 deletions

View file

@ -22,12 +22,19 @@
package org.keycloak.testsuite;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
@ -35,7 +42,32 @@ public class ApplicationServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().print("Hello world!");
String title = "";
String body = "";
StringBuffer sb = req.getRequestURL();
sb.append("?");
sb.append(req.getQueryString());
List<NameValuePair> query = null;
try {
query = URLEncodedUtils.parse(new URI(sb.toString()), "UTF-8");
} catch (URISyntaxException e) {
throw new ServletException(e);
}
if (req.getRequestURI().endsWith("auth")) {
title = "AUTH_RESPONSE";
} else if (req.getRequestURI().endsWith("logout")) {
title = "LOGOUT_REQUEST";
} else {
title = "APP_REQUEST";
}
PrintWriter pw = resp.getWriter();
pw.printf("<html><head><title>%s</title></head><body>%s</body>", title, body);
pw.flush();
}
}

View file

@ -36,7 +36,8 @@ 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.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.pages.RegisterPage;
import org.keycloak.testsuite.rule.GreenMailRule;
@ -74,7 +75,7 @@ public class RequiredActionEmailVerificationTest {
protected WebDriver driver;
@WebResource
protected OAuthClient oauth;
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -101,7 +102,7 @@ public class RequiredActionEmailVerificationTest {
driver.navigate().to(verificationUrl.trim());
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
@Test
@ -124,7 +125,7 @@ public class RequiredActionEmailVerificationTest {
driver.navigate().to(verificationUrl.trim());
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
}

View file

@ -29,7 +29,8 @@ 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.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.pages.LoginPasswordUpdatePage;
import org.keycloak.testsuite.pages.LoginUpdateProfilePage;
@ -63,7 +64,7 @@ public class RequiredActionMultipleActionsTest {
protected WebDriver driver;
@WebResource
protected OAuthClient oauth;
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -93,7 +94,7 @@ public class RequiredActionMultipleActionsTest {
Assert.fail("Expected to update password and profile before login");
}
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
public void updatePassword() {

View file

@ -30,6 +30,8 @@ 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.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.pages.LoginPasswordUpdatePage;
import org.keycloak.testsuite.rule.GreenMailRule;
@ -69,6 +71,9 @@ public class RequiredActionResetPasswordTest {
@WebResource
protected OAuthClient oauth;
@WebResource
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -83,7 +88,7 @@ public class RequiredActionResetPasswordTest {
changePasswordPage.assertCurrent();
changePasswordPage.changePassword("new-password", "new-password");
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
oauth.openLogout();

View file

@ -30,7 +30,8 @@ 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.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginConfigTotpPage;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.pages.RegisterPage;
@ -67,7 +68,7 @@ public class RequiredActionTotpSetupTest {
protected WebDriver driver;
@WebResource
protected OAuthClient oauth;
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -90,7 +91,7 @@ public class RequiredActionTotpSetupTest {
totpPage.configure(totp.generate(totpPage.getTotpSecret()));
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
@Test
@ -102,7 +103,7 @@ public class RequiredActionTotpSetupTest {
totpPage.configure(totp.generate(totpPage.getTotpSecret()));
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
}

View file

@ -29,7 +29,8 @@ 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.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.pages.LoginUpdateProfilePage;
import org.keycloak.testsuite.rule.KeycloakRule;
@ -61,7 +62,7 @@ public class RequiredActionUpdateProfileTest {
protected WebDriver driver;
@WebResource
protected OAuthClient oauth;
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -79,7 +80,7 @@ public class RequiredActionUpdateProfileTest {
updateProfilePage.update("New first", "New last", "new@email.com");
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
}

View file

@ -35,6 +35,8 @@ 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.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.rule.KeycloakRule;
import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup;
@ -60,6 +62,9 @@ public class AccountTest {
@WebResource
protected OAuthClient oauth;
@WebResource
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -108,7 +113,7 @@ public class AccountTest {
loginPage.open();
loginPage.login("test-user@localhost", "new-password");
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
@Test

View file

@ -25,7 +25,8 @@ import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.keycloak.testsuite.OAuthClient;
import org.keycloak.testsuite.pages.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.rule.KeycloakRule;
import org.keycloak.testsuite.rule.WebResource;
@ -47,7 +48,7 @@ public class LoginTest {
protected WebDriver driver;
@WebResource
protected OAuthClient oauth;
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -77,7 +78,7 @@ public class LoginTest {
loginPage.open();
loginPage.login("test-user@localhost", "password");
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
}

View file

@ -33,7 +33,8 @@ 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.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.pages.LoginTotpPage;
import org.keycloak.testsuite.rule.GreenMailRule;
@ -76,7 +77,7 @@ public class LoginTotpTest {
protected WebDriver driver;
@WebResource
protected OAuthClient oauth;
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -113,7 +114,7 @@ public class LoginTotpTest {
loginTotpPage.login(totp.generate("totpSecret"));
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
}

View file

@ -25,7 +25,8 @@ import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.keycloak.testsuite.OAuthClient;
import org.keycloak.testsuite.pages.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.pages.RegisterPage;
import org.keycloak.testsuite.rule.KeycloakRule;
@ -48,7 +49,7 @@ public class RegisterTest {
protected WebDriver driver;
@WebResource
protected OAuthClient oauth;
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -112,7 +113,7 @@ public class RegisterTest {
registerPage.register("name", "email", "registerUserSuccess", "password", "password");
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
}

View file

@ -31,6 +31,8 @@ import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.keycloak.testsuite.OAuthClient;
import org.keycloak.testsuite.pages.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.pages.LoginPasswordResetPage;
import org.keycloak.testsuite.pages.LoginPasswordUpdatePage;
@ -60,6 +62,9 @@ public class ResetPasswordTest {
@WebResource
protected OAuthClient oauth;
@WebResource
protected AppPage appPage;
@WebResource
protected LoginPage loginPage;
@ -93,7 +98,7 @@ public class ResetPasswordTest {
updatePasswordPage.changePassword("new-password", "new-password");
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
oauth.openLogout();
@ -101,7 +106,7 @@ public class ResetPasswordTest {
loginPage.login("test-user@localhost", "new-password");
Assert.assertTrue("Expected authorization response", oauth.isAuthorizationResponse());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
}

View file

@ -22,8 +22,6 @@
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.Constants;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -34,9 +32,6 @@ public class AccountPasswordPage extends Page {
private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/test/account/password";
@WebResource
private WebDriver browser;
@FindBy(id = "password")
private WebElement passwordInput;
@ -58,11 +53,11 @@ public class AccountPasswordPage extends Page {
}
public boolean isCurrent() {
return browser.getPageSource().contains("Change Password");
return driver.getPageSource().contains("Change Password");
}
public void open() {
browser.navigate().to(PATH);
driver.navigate().to(PATH);
}
}

View file

@ -22,8 +22,6 @@
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.Constants;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -34,9 +32,6 @@ public class AccountTotpPage extends Page {
private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/test/account/totp";
@WebResource
private WebDriver browser;
@FindBy(id = "totpSecret")
private WebElement totpSecret;
@ -56,11 +51,11 @@ public class AccountTotpPage extends Page {
}
public boolean isCurrent() {
return browser.getPageSource().contains("Google Authenticator Setup");
return driver.getPageSource().contains("Google Authenticator Setup");
}
public void open() {
browser.navigate().to(PATH);
driver.navigate().to(PATH);
}
}

View file

@ -22,8 +22,6 @@
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.Constants;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -34,9 +32,6 @@ public class AccountUpdateProfilePage extends Page {
private static String PATH = Constants.AUTH_SERVER_ROOT + "/rest/realms/test/account";
@WebResource
private WebDriver browser;
@FindBy(id = "firstName")
private WebElement firstNameInput;
@ -73,11 +68,11 @@ public class AccountUpdateProfilePage extends Page {
}
public boolean isCurrent() {
return browser.getPageSource().contains("Edit Account");
return driver.getPageSource().contains("Edit Account");
}
public void open() {
browser.navigate().to(PATH);
driver.navigate().to(PATH);
}
}

View file

@ -0,0 +1,50 @@
/*
* 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.pages;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class AppPage extends Page {
private String baseUrl = "http://localhost:8081/app";
@Override
public void open() {
driver.navigate().to(baseUrl);
}
@Override
public boolean isCurrent() {
return driver.getCurrentUrl().startsWith(baseUrl);
}
public RequestType getRequestType() {
return RequestType.valueOf(driver.getTitle());
}
public enum RequestType {
AUTH_RESPONSE, LOGOUT_REQUEST, APP_REQUEST
}
}

View file

@ -21,8 +21,6 @@
*/
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -31,9 +29,6 @@ import org.openqa.selenium.support.FindBy;
*/
public class LoginConfigTotpPage extends Page {
@WebResource
private WebDriver browser;
@FindBy(id = "totpSecret")
private WebElement totpSecret;
@ -53,7 +48,7 @@ public class LoginConfigTotpPage extends Page {
}
public boolean isCurrent() {
return browser.getTitle().equals("Config TOTP");
return driver.getTitle().equals("Config TOTP");
}
public void open() {

View file

@ -21,6 +21,8 @@
*/
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.OAuthClient;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -29,6 +31,9 @@ import org.openqa.selenium.support.FindBy;
*/
public class LoginPage extends Page {
@WebResource
protected OAuthClient oauth;
@FindBy(id = "username")
private WebElement usernameInput;

View file

@ -21,8 +21,6 @@
*/
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -31,9 +29,6 @@ import org.openqa.selenium.support.FindBy;
*/
public class LoginPasswordResetPage extends Page {
@WebResource
private WebDriver browser;
@FindBy(id = "username")
private WebElement usernameInput;
@ -51,7 +46,7 @@ public class LoginPasswordResetPage extends Page {
}
public boolean isCurrent() {
return browser.getTitle().equals("Reset password");
return driver.getTitle().equals("Reset password");
}
public void open() {

View file

@ -21,8 +21,6 @@
*/
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -31,9 +29,6 @@ import org.openqa.selenium.support.FindBy;
*/
public class LoginPasswordUpdatePage extends Page {
@WebResource
private WebDriver browser;
@FindBy(id = "password-new")
private WebElement newPasswordInput;
@ -51,7 +46,7 @@ public class LoginPasswordUpdatePage extends Page {
}
public boolean isCurrent() {
return browser.getTitle().equals("Update password");
return driver.getTitle().equals("Update password");
}
public void open() {

View file

@ -21,9 +21,7 @@
*/
package org.keycloak.testsuite.pages;
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;
@ -32,9 +30,6 @@ import org.openqa.selenium.support.FindBy;
*/
public class LoginTotpPage extends Page {
@WebResource
private WebDriver browser;
@FindBy(id = "totp")
private WebElement totpInput;
@ -55,9 +50,9 @@ public class LoginTotpPage extends Page {
}
public boolean isCurrent() {
if (browser.getTitle().equals("Log in to test")) {
if (driver.getTitle().equals("Log in to test")) {
try {
browser.findElement(By.id("totp"));
driver.findElement(By.id("totp"));
return true;
} catch (Throwable t) {
}

View file

@ -21,8 +21,6 @@
*/
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -31,9 +29,6 @@ import org.openqa.selenium.support.FindBy;
*/
public class LoginUpdateProfilePage extends Page {
@WebResource
private WebDriver browser;
@FindBy(id = "firstName")
private WebElement firstNameInput;
@ -65,7 +60,7 @@ public class LoginUpdateProfilePage extends Page {
}
public boolean isCurrent() {
return browser.getTitle().equals("Update profile");
return driver.getTitle().equals("Update profile");
}
@Override

View file

@ -22,7 +22,6 @@
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;
@ -34,9 +33,6 @@ 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() + ")",

View file

@ -21,8 +21,6 @@
*/
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -31,9 +29,6 @@ import org.openqa.selenium.support.FindBy;
*/
public class RegisterPage extends Page {
@WebResource
private WebDriver browser;
@FindBy(id = "name")
private WebElement nameInput;
@ -84,7 +79,7 @@ public class RegisterPage extends Page {
}
public boolean isCurrent() {
return browser.getTitle().equals("Register with test");
return driver.getTitle().equals("Register with test");
}
@Override