KEYCLOAK-3367 Improve stability of Adapters Tests

This commit is contained in:
Vaclav Muzikar 2016-08-04 14:43:49 +02:00
parent f91907c8f9
commit 0d225f44de
10 changed files with 156 additions and 108 deletions

View file

@ -29,6 +29,7 @@
<button onclick="keycloak.register()">Register</button> <button onclick="keycloak.register()">Register</button>
<button onclick="refreshToken(9999)">Refresh Token</button> <button onclick="refreshToken(9999)">Refresh Token</button>
<button onclick="refreshToken(30)">Refresh Token (if <30s validity)</button> <button onclick="refreshToken(30)">Refresh Token (if <30s validity)</button>
<button onclick="showError()">Show Error Response</button>
<button onclick="loadProfile()">Get Profile</button> <button onclick="loadProfile()">Get Profile</button>
<button onclick="loadUserInfo()">Get User Info</button> <button onclick="loadUserInfo()">Get User Info</button>
<button onclick="output(keycloak.tokenParsed)">Show Token</button> <button onclick="output(keycloak.tokenParsed)">Show Token</button>
@ -108,6 +109,20 @@
output(o); output(o);
} }
function showError() {
output("Error: " + getParameterByName("error") + "\n" + "Error description: " + getParameterByName("error_description"));
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&#]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
function output(data) { function output(data) {
if (typeof data === 'object') { if (typeof data === 'object') {
data = JSON.stringify(data, null, ' '); data = JSON.stringify(data, null, ' ');

View file

@ -59,6 +59,8 @@ public class JSConsoleTestApp extends AbstractPageWithInjectedUrl {
@FindBy(xpath = "//button[text() = 'Get Profile']") @FindBy(xpath = "//button[text() = 'Get Profile']")
private WebElement getProfileButton; private WebElement getProfileButton;
@FindBy(xpath = "//button[text() = 'Show Error Response']")
private WebElement showErrorButton;
@FindBy(xpath = "//button[text() = 'Show Token']") @FindBy(xpath = "//button[text() = 'Show Token']")
private WebElement showTokenButton; private WebElement showTokenButton;
@FindBy(xpath = "//button[text() = 'Show Refresh Token']") @FindBy(xpath = "//button[text() = 'Show Refresh Token']")
@ -137,4 +139,8 @@ public class JSConsoleTestApp extends AbstractPageWithInjectedUrl {
public WebElement getInitButtonElement() { public WebElement getInitButtonElement() {
return initButton; return initButton;
} }
public void showErrorResponse() {
showErrorButton.click();
}
} }

View file

@ -23,21 +23,27 @@ import org.keycloak.testsuite.auth.page.login.OIDCLogin;
import org.keycloak.testsuite.page.AbstractPageWithInjectedUrl; import org.keycloak.testsuite.page.AbstractPageWithInjectedUrl;
import org.keycloak.testsuite.page.Form; import org.keycloak.testsuite.page.Form;
import org.keycloak.testsuite.pages.ConsentPage; import org.keycloak.testsuite.pages.ConsentPage;
import org.keycloak.testsuite.util.URLUtils;
import org.keycloak.testsuite.util.WaitUtils; import org.keycloak.testsuite.util.WaitUtils;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import static org.keycloak.testsuite.util.WaitUtils.IMPLICIT_ELEMENT_WAIT_MILLIS;
import static org.keycloak.testsuite.util.WaitUtils.pause; import static org.keycloak.testsuite.util.WaitUtils.pause;
import static org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad;
/** /**
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a> * @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
* @author Vaclav Muzikar <vmuzikar@redhat.com>
*/ */
public class PhotozClientAuthzTestApp extends AbstractPageWithInjectedUrl { public class PhotozClientAuthzTestApp extends AbstractPageWithInjectedUrl {
public static final String DEPLOYMENT_NAME = "photoz-html5-client"; public static final String DEPLOYMENT_NAME = "photoz-html5-client";
public static final int WAIT_AFTER_OPERATION = 2000;
@ArquillianResource @ArquillianResource
@OperateOnDeployment(DEPLOYMENT_NAME) @OperateOnDeployment(DEPLOYMENT_NAME)
@ -49,14 +55,16 @@ public class PhotozClientAuthzTestApp extends AbstractPageWithInjectedUrl {
@Page @Page
protected ConsentPage consentPage; protected ConsentPage consentPage;
@FindBy(xpath = "//a[@ng-click = 'Identity.logout()']")
WebElement signOutButton;
public void createAlbum(String name) { public void createAlbum(String name) {
navigateTo(); navigateTo();
By id = By.id("create-album"); this.driver.findElement(By.id("create-album")).click();
WaitUtils.waitUntilElement(id);
this.driver.findElement(id).click();
Form.setInputValue(this.driver.findElement(By.id("album.name")), name); Form.setInputValue(this.driver.findElement(By.id("album.name")), name);
pause(200); // We need to wait a bit for the form to "accept" the input (otherwise it registers the input as empty)
this.driver.findElement(By.id("save-album")).click(); this.driver.findElement(By.id("save-album")).click();
pause(500); pause(WAIT_AFTER_OPERATION);
} }
@Override @Override
@ -65,76 +73,44 @@ public class PhotozClientAuthzTestApp extends AbstractPageWithInjectedUrl {
} }
public void deleteAlbum(String name) { public void deleteAlbum(String name) {
By id = By.id("delete-" + name); driver.findElements(By.xpath("//a[text()='" + name + "']/following-sibling::a[text()='X']")).forEach(WebElement::click);
WaitUtils.waitUntilElement(id); pause(WAIT_AFTER_OPERATION);
this.driver.findElements(id).forEach(WebElement::click);
pause(500);
} }
public void navigateToAdminAlbum() { public void navigateToAdminAlbum() {
this.driver.navigate().to(this.getInjectedUrl().toString() + "/#/admin/album"); URLUtils.navigateToUri(driver, toString() + "/#/admin/album", true);
pause(500); driver.navigate().refresh(); // This is sometimes necessary for loading the new policy settings
waitForPageToLoad(driver);
pause(WAIT_AFTER_OPERATION);
} }
public void logOut() { public void logOut() {
navigateTo(); signOutButton.click(); // Sometimes doesn't work in PhantomJS!
By by = By.xpath("//a[text() = 'Sign Out']"); pause(WAIT_AFTER_OPERATION);
WaitUtils.waitUntilElement(by);
this.driver.findElement(by).click();
pause(500);
} }
public void login(String username, String password) throws InterruptedException { public void login(String username, String password, String... scopes) {
navigateTo(); if (scopes.length > 0) {
Thread.sleep(2000); StringBuilder scopesValue = new StringBuilder();
if (this.driver.getCurrentUrl().startsWith(getInjectedUrl().toString())) {
Thread.sleep(2000);
logOut();
navigateTo();
}
Thread.sleep(2000); for (String scope : scopes) {
if (scopesValue.length() != 0) {
this.loginPage.form().login(username, password); scopesValue.append(" ");
}
// simple check if we are at the consent page, if so just click 'Yes' scopesValue.append(scope);
if (this.consentPage.isCurrent()) {
consentPage.confirm();
Thread.sleep(2000);
}
}
public void loginWithScopes(String username, String password, String... scopes) throws Exception {
navigateTo();
Thread.sleep(2000);
if (this.driver.getCurrentUrl().startsWith(getInjectedUrl().toString())) {
Thread.sleep(2000);
logOut();
navigateTo();
}
Thread.sleep(2000);
StringBuilder scopesValue = new StringBuilder();
for (String scope : scopes) {
if (scopesValue.length() != 0) {
scopesValue.append(" ");
} }
scopesValue.append(scope);
URLUtils.navigateToUri(driver, this.driver.getCurrentUrl() + " " + scopesValue, true);
} }
this.driver.navigate().to(this.driver.getCurrentUrl() + " " + scopesValue);
Thread.sleep(2000);
this.loginPage.form().login(username, password); this.loginPage.form().login(username, password);
// simple check if we are at the consent page, if so just click 'Yes' // simple check if we are at the consent page, if so just click 'Yes'
if (this.consentPage.isCurrent()) { if (this.consentPage.isCurrent()) {
consentPage.confirm(); consentPage.confirm();
Thread.sleep(2000);
} }
pause(WAIT_AFTER_OPERATION);
} }
public boolean wasDenied() { public boolean wasDenied() {
@ -142,10 +118,20 @@ public class PhotozClientAuthzTestApp extends AbstractPageWithInjectedUrl {
} }
public void viewAlbum(String name) throws InterruptedException { public void viewAlbum(String name) throws InterruptedException {
Thread.sleep(2000); this.driver.findElement(By.xpath("//a[text() = '" + name + "']")).click();
By id = By.id("view-" + name); waitForPageToLoad(driver);
WaitUtils.waitUntilElement(id); driver.navigate().refresh(); // This is sometimes necessary for loading the new policy settings
this.driver.findElements(id).forEach(WebElement::click); pause(WAIT_AFTER_OPERATION);
pause(500); }
@Override
public void navigateTo(boolean waitForMatch) {
super.navigateTo(waitForMatch);
pause(WAIT_AFTER_OPERATION);
}
@Override
public boolean isCurrent() {
return URLUtils.currentUrlStartWith(driver, toString());
} }
} }

View file

@ -40,8 +40,12 @@ public final class URLUtils {
driver.navigate().to(uri); driver.navigate().to(uri);
if (waitForMatch) { if (waitForMatch) {
// Possible login URL; this is to eliminate unnecessary wait when navigating to a secured page and being
// redirected to the login page
String loginUrl = "^[^\\?]+/auth/realms/[^/]+/(protocol|login-actions).+$";
try { try {
(new WebDriverWait(driver, 3)).until(urlMatches("^" + Pattern.quote(uri) + ".*$")); (new WebDriverWait(driver, 3)).until(or(urlMatches("^" + Pattern.quote(uri) + ".*$"), urlMatches(loginUrl)));
} catch (TimeoutException e) { } catch (TimeoutException e) {
log.info("new current URL doesn't start with desired URL"); log.info("new current URL doesn't start with desired URL");
} }

View file

@ -101,10 +101,7 @@ public abstract class AbstractAuthTest extends AbstractKeycloakTest {
} }
public void deleteAllCookiesForTestRealm() { public void deleteAllCookiesForTestRealm() {
// testRealmPage.navigateTo(); deleteAllCookiesForRealm(testRealmAccountPage);
testRealmAccountPage.navigateTo(); // Because IE webdriver freezes when loading a JSON page (realm page), we need to use this alternative
log.debug("deleting cookies in test realm");
driver.manage().deleteAllCookies();
} }
public void listCookies() { public void listCookies() {

View file

@ -169,9 +169,13 @@ public abstract class AbstractKeycloakTest {
} }
public void deleteAllCookiesForMasterRealm() { public void deleteAllCookiesForMasterRealm() {
deleteAllCookiesForRealm(accountPage);
}
protected void deleteAllCookiesForRealm(Account realmAccountPage) {
// masterRealmPage.navigateTo(); // masterRealmPage.navigateTo();
accountPage.navigateTo(); // Because IE webdriver freezes when loading a JSON page (realm page), we need to use this alternative realmAccountPage.navigateTo(); // Because IE webdriver freezes when loading a JSON page (realm page), we need to use this alternative
log.debug("deleting cookies in master realm"); log.info("deleting cookies in '" + realmAccountPage.getAuthRealm() + "' realm");
driver.manage().deleteAllCookies(); driver.manage().deleteAllCookies();
} }

View file

@ -268,14 +268,14 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
jsConsoleTestAppPage.init(); jsConsoleTestAppPage.init();
jsConsoleTestAppPage.logIn(); jsConsoleTestAppPage.logIn();
assertTrue(driver.getPageSource().contains("Implicit flow is disabled for the client")); assertResponseError("Implicit flow is disabled for the client");
setImplicitFlowFroClient(); setImplicitFlowForClient();
jsConsoleTestAppPage.navigateTo(); jsConsoleTestAppPage.navigateTo();
jsConsoleTestAppPage.init(); jsConsoleTestAppPage.init();
jsConsoleTestAppPage.logIn(); jsConsoleTestAppPage.logIn();
assertTrue(driver.getPageSource().contains("Standard flow is disabled for the client")); assertResponseError("Standard flow is disabled for the client");
logInAndInit("implicit"); logInAndInit("implicit");
@ -284,19 +284,19 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
@Test @Test
public void implicitFlowQueryTest() { public void implicitFlowQueryTest() {
setImplicitFlowFroClient(); setImplicitFlowForClient();
jsConsoleTestAppPage.navigateTo(); jsConsoleTestAppPage.navigateTo();
jsConsoleTestAppPage.setFlow("implicit"); jsConsoleTestAppPage.setFlow("implicit");
jsConsoleTestAppPage.setResponseMode("query"); jsConsoleTestAppPage.setResponseMode("query");
jsConsoleTestAppPage.init(); jsConsoleTestAppPage.init();
jsConsoleTestAppPage.logIn(); jsConsoleTestAppPage.logIn();
assertTrue(driver.getPageSource().contains("Invalid parameter: response_mode")); assertResponseError("Response_mode 'query' not allowed");
} }
@Test @Test
public void implicitFlowRefreshTokenTest() { public void implicitFlowRefreshTokenTest() {
setImplicitFlowFroClient(); setImplicitFlowForClient();
logInAndInit("implicit"); logInAndInit("implicit");
@ -311,7 +311,7 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
realm.setAccessTokenLifespanForImplicitFlow(5); realm.setAccessTokenLifespanForImplicitFlow(5);
testRealmResource().update(realm); testRealmResource().update(realm);
setImplicitFlowFroClient(); setImplicitFlowForClient();
logInAndInit("implicit"); logInAndInit("implicit");
@ -351,7 +351,7 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Authenticated)"); waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Authenticated)");
} }
private void setImplicitFlowFroClient() { private void setImplicitFlowForClient() {
ClientResource clientResource = ApiUtil.findClientResourceByClientId(testRealmResource(), "js-console"); ClientResource clientResource = ApiUtil.findClientResourceByClientId(testRealmResource(), "js-console");
ClientRepresentation client = clientResource.toRepresentation(); ClientRepresentation client = clientResource.toRepresentation();
client.setImplicitFlowEnabled(true); client.setImplicitFlowEnabled(true);
@ -373,4 +373,9 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
logInAndInit(flow, "user"); logInAndInit(flow, "user");
} }
private void assertResponseError(String errorDescription) {
jsConsoleTestAppPage.showErrorResponse();
assertTrue(jsConsoleTestAppPage.getOutputElement().getText().contains(errorDescription));
}
} }

View file

@ -118,7 +118,7 @@ public abstract class AbstractSAMLExampleAdapterTest extends AbstractExampleAdap
waitUntilElement(By.xpath("//body")).text().contains("Welcome to the Employee Tool,"); waitUntilElement(By.xpath("//body")).text().contains("Welcome to the Employee Tool,");
samlRedirectSigExamplePage.logout(); samlRedirectSigExamplePage.logout();
waitUntilElement(By.xpath("//body")).text().contains("Logged out."); URLAssert.assertCurrentUrlStartsWith(testRealmSAMLRedirectLoginPage);
samlRedirectSigExamplePage.navigateTo(); samlRedirectSigExamplePage.navigateTo();
URLAssert.assertCurrentUrlStartsWith(testRealmSAMLRedirectLoginPage); URLAssert.assertCurrentUrlStartsWith(testRealmSAMLRedirectLoginPage);

View file

@ -21,6 +21,7 @@ import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.graphene.page.Page; import org.jboss.arquillian.graphene.page.Page;
import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.keycloak.admin.client.resource.AuthorizationResource; import org.keycloak.admin.client.resource.AuthorizationResource;
import org.keycloak.admin.client.resource.ClientResource; import org.keycloak.admin.client.resource.ClientResource;
@ -47,10 +48,8 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -74,6 +73,17 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
@Page @Page
private PhotozClientAuthzTestApp clientPage; private PhotozClientAuthzTestApp clientPage;
@Override
public void setDefaultPageUriParameters() {
super.setDefaultPageUriParameters();
testRealmPage.setAuthRealm(REALM_NAME);
}
@Before
public void beforePhotozExampleAdapterTest() {
deleteAllCookiesForClientPage();
}
@Override @Override
public void addAdapterTestRealms(List<RealmRepresentation> testRealms) { public void addAdapterTestRealms(List<RealmRepresentation> testRealms) {
RealmRepresentation realm = loadRealm(new File(TEST_APPS_HOME_DIR + "/photoz/photoz-realm.json")); RealmRepresentation realm = loadRealm(new File(TEST_APPS_HOME_DIR + "/photoz/photoz-realm.json"));
@ -104,7 +114,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.createAlbum("Alice Family Album"); this.clientPage.createAlbum("Alice Family Album");
List<ResourceRepresentation> resources = getAuthorizationResource().resources().resources(); List<ResourceRepresentation> resources = getAuthorizationResource().resources().resources();
@ -123,10 +133,10 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
public void testOnlyOwnerCanDeleteAlbum() throws Exception { public void testOnlyOwnerCanDeleteAlbum() throws Exception {
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.createAlbum("Alice-Family-Album"); this.clientPage.createAlbum("Alice-Family-Album");
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
List<ResourceRepresentation> resources = getAuthorizationResource().resources().resources(); List<ResourceRepresentation> resources = getAuthorizationResource().resources().resources();
@ -139,7 +149,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
} }
} }
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
this.clientPage.deleteAlbum("Alice-Family-Album"); this.clientPage.deleteAlbum("Alice-Family-Album");
@ -169,7 +179,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
assertTrue(this.clientPage.wasDenied()); assertTrue(this.clientPage.wasDenied());
} finally { } finally {
@ -182,7 +192,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
@ -206,10 +216,10 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.createAlbum("Alice Family Album"); this.clientPage.createAlbum("Alice Family Album");
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
@ -269,10 +279,10 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.createAlbum("Alice Family Album"); this.clientPage.createAlbum("Alice Family Album");
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
@ -288,10 +298,10 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
} }
} }
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.createAlbum("Alice Family Album"); this.clientPage.createAlbum("Alice Family Album");
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
this.clientPage.viewAlbum("Alice Family Album"); this.clientPage.viewAlbum("Alice Family Album");
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
@ -324,7 +334,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
UsersResource usersResource = realmsResouce().realm(REALM_NAME).users(); UsersResource usersResource = realmsResouce().realm(REALM_NAME).users();
@ -347,10 +357,10 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
roleResource.update(roleRepresentation); roleResource.update(roleRepresentation);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
assertTrue(this.clientPage.wasDenied()); assertTrue(this.clientPage.wasDenied());
this.clientPage.loginWithScopes("alice", "alice", RESOURCE_SERVER_ID + "/manage-albums"); loginToClientPage("alice", "alice", RESOURCE_SERVER_ID + "/manage-albums");
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
} finally { } finally {
this.deployer.undeploy(RESOURCE_SERVER_ID); this.deployer.undeploy(RESOURCE_SERVER_ID);
@ -362,7 +372,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
@ -386,7 +396,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
manageAlbumRole.update(roleRepresentation); manageAlbumRole.update(roleRepresentation);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
assertTrue(this.clientPage.wasDenied()); assertTrue(this.clientPage.wasDenied());
for (PolicyRepresentation policy : getAuthorizationResource().policies().policies()) { for (PolicyRepresentation policy : getAuthorizationResource().policies().policies()) {
@ -405,7 +415,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
} }
} }
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
} finally { } finally {
this.deployer.undeploy(RESOURCE_SERVER_ID); this.deployer.undeploy(RESOURCE_SERVER_ID);
@ -417,7 +427,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
String resourceName = "My Resource Instance"; String resourceName = "My Resource Instance";
this.clientPage.createAlbum(resourceName); this.clientPage.createAlbum(resourceName);
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
@ -431,7 +441,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
this.clientPage.createAlbum(resourceName); this.clientPage.createAlbum(resourceName);
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
this.clientPage.viewAlbum(resourceName); this.clientPage.viewAlbum(resourceName);
@ -441,7 +451,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
this.clientPage.deleteAlbum(resourceName); this.clientPage.deleteAlbum(resourceName);
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.createAlbum(resourceName); this.clientPage.createAlbum(resourceName);
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
@ -466,7 +476,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
} }
}); });
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
this.clientPage.viewAlbum(resourceName); this.clientPage.viewAlbum(resourceName);
@ -476,7 +486,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
this.clientPage.deleteAlbum(resourceName); this.clientPage.deleteAlbum(resourceName);
assertTrue(this.clientPage.wasDenied()); assertTrue(this.clientPage.wasDenied());
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.deleteAlbum(resourceName); this.clientPage.deleteAlbum(resourceName);
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
@ -493,7 +503,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
try { try {
this.deployer.deploy(RESOURCE_SERVER_ID); this.deployer.deploy(RESOURCE_SERVER_ID);
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
String resourceName = "My Resource Instance"; String resourceName = "My Resource Instance";
this.clientPage.createAlbum(resourceName); this.clientPage.createAlbum(resourceName);
@ -508,7 +518,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
this.clientPage.createAlbum(resourceName); this.clientPage.createAlbum(resourceName);
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
this.clientPage.viewAlbum(resourceName); this.clientPage.viewAlbum(resourceName);
@ -518,7 +528,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
this.clientPage.deleteAlbum(resourceName); this.clientPage.deleteAlbum(resourceName);
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.createAlbum(resourceName); this.clientPage.createAlbum(resourceName);
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
@ -544,7 +554,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
} }
}); });
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
this.clientPage.viewAlbum(resourceName); this.clientPage.viewAlbum(resourceName);
@ -561,7 +571,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
} }
}); });
this.clientPage.login("admin", "admin"); loginToClientPage("admin", "admin");
this.clientPage.navigateToAdminAlbum(); this.clientPage.navigateToAdminAlbum();
this.clientPage.viewAlbum(resourceName); this.clientPage.viewAlbum(resourceName);
@ -571,7 +581,7 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
this.clientPage.deleteAlbum(resourceName); this.clientPage.deleteAlbum(resourceName);
assertTrue(this.clientPage.wasDenied()); assertTrue(this.clientPage.wasDenied());
this.clientPage.login("alice", "alice"); loginToClientPage("alice", "alice");
this.clientPage.deleteAlbum(resourceName); this.clientPage.deleteAlbum(resourceName);
assertFalse(this.clientPage.wasDenied()); assertFalse(this.clientPage.wasDenied());
List<ResourceRepresentation> resources = resourcesResource.resources(); List<ResourceRepresentation> resources = resourcesResource.resources();
@ -601,4 +611,17 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
ClientRepresentation resourceServer = clients.findByClientId(clientId).get(0); ClientRepresentation resourceServer = clients.findByClientId(clientId).get(0);
return clients.get(resourceServer.getId()); return clients.get(resourceServer.getId());
} }
private void deleteAllCookiesForClientPage() {
clientPage.navigateTo();
driver.manage().deleteAllCookies();
}
private void loginToClientPage(String username, String password, String... scopes) {
// We need to log out by deleting cookies because the log out button sometimes doesn't work in PhantomJS
deleteAllCookiesForClientPage();
deleteAllCookiesForTestRealm();
clientPage.navigateTo();
clientPage.login(username, password, scopes);
}
} }

View file

@ -21,6 +21,7 @@ import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.graphene.page.Page; import org.jboss.arquillian.graphene.page.Page;
import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.keycloak.OAuth2Constants; import org.keycloak.OAuth2Constants;
@ -118,6 +119,13 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd
return servletDeployment(TokenMinTTLPage.DEPLOYMENT_NAME, AdapterActionsFilter.class, AbstractShowTokensServlet.class, TokenMinTTLServlet.class, ErrorServlet.class); return servletDeployment(TokenMinTTLPage.DEPLOYMENT_NAME, AdapterActionsFilter.class, AbstractShowTokensServlet.class, TokenMinTTLServlet.class, ErrorServlet.class);
} }
@Before
public void beforeDemoServletsAdapterTest() {
// Delete all cookies from token-min-ttl page to be sure we are logged out
tokenMinTTLPage.navigateTo();
driver.manage().deleteAllCookies();
}
@Test @Test
public void testCustomerPortalWithSubsystemSettings() { public void testCustomerPortalWithSubsystemSettings() {
customerPortalSubsystem.navigateTo(); customerPortalSubsystem.navigateTo();