Skip to content

Commit

Permalink
Add tests for access grant and revoking grant
Browse files Browse the repository at this point in the history
  • Loading branch information
mhajas committed Oct 16, 2015
1 parent 39f985e commit 32647d8
Show file tree
Hide file tree
Showing 10 changed files with 502 additions and 122 deletions.
8 changes: 8 additions & 0 deletions examples/js-console/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<module-name>js-console</module-name>
</web-app>
@@ -0,0 +1,14 @@
package org.keycloak.testsuite.adapter.example;

import org.keycloak.testsuite.arquillian.annotation.AdapterLibsLocationProperty;
import org.keycloak.testsuite.arquillian.annotation.AppServerContainer;

/**
*
* @author tkyjovsk
*/
@AppServerContainer("app-server-wildfly")
@AdapterLibsLocationProperty("adapter.libs.wildfly")
public class WildflyDemoExampleAdapterTest extends AbstractDemoExampleAdapterTest {

}
Expand Up @@ -17,21 +17,22 @@
*/ */
package org.keycloak.testsuite.admin; package org.keycloak.testsuite.admin;


import org.jboss.logging.Logger;
import org.keycloak.admin.client.resource.ClientResource;
import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.CredentialRepresentation;
import org.keycloak.representations.idm.RoleRepresentation;
import org.keycloak.representations.idm.UserRepresentation;


import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.jboss.logging.Logger;
import org.keycloak.admin.client.resource.ClientResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.representations.idm.CredentialRepresentation;
import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD; import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD;
import org.keycloak.representations.idm.RoleRepresentation;
import org.keycloak.representations.idm.UserRepresentation;


/** /**
* Created by st on 28.05.15. * Created by st on 28.05.15.
Expand All @@ -58,6 +59,15 @@ public static ClientResource findClientResourceByClientId(RealmResource realm, S
return null; return null;
} }


public static ClientResource findClientResourceByName(RealmResource realm, String name) {
for (ClientRepresentation c : realm.clients().findAll()) {
if (c.getName().equals(name)) {
return realm.clients().get(c.getId());
}
}
return null;
}

public static ClientRepresentation findClientByClientId(RealmResource realm, String clientId) { public static ClientRepresentation findClientByClientId(RealmResource realm, String clientId) {
ClientRepresentation client = null; ClientRepresentation client = null;
for (ClientRepresentation c : realm.clients().findAll()) { for (ClientRepresentation c : realm.clients().findAll()) {
Expand Down
@@ -1,15 +1,16 @@
package org.keycloak.testsuite.auth.page; package org.keycloak.testsuite.auth.page;


import org.keycloak.protocol.oidc.OIDCLoginProtocolService;
import org.keycloak.testsuite.auth.page.login.PageWithLoginUrl; import org.keycloak.testsuite.auth.page.login.PageWithLoginUrl;
import java.net.URI;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import org.keycloak.protocol.oidc.OIDCLoginProtocolService; import java.net.URI;


/** /**
* Keycloak realm. * Keycloak realm.
* * <p>
* URL: http://localhost:${auth.server.http.port}/auth/realms/{authRealm} * URL: http://localhost:${auth.server.http.port}/auth/realms/{authRealm}
* *
* @author tkyjovsk * @author tkyjovsk
*/ */
public class AuthRealm extends AuthServer implements PageWithLoginUrl { public class AuthRealm extends AuthServer implements PageWithLoginUrl {
Expand All @@ -22,7 +23,7 @@ public class AuthRealm extends AuthServer implements PageWithLoginUrl {
public static final String EXAMPLE = "example"; public static final String EXAMPLE = "example";


public static final String ADMIN = "admin"; public static final String ADMIN = "admin";

public AuthRealm() { public AuthRealm() {
setUriParameter(AUTH_REALM, MASTER); setUriParameter(AUTH_REALM, MASTER);
} }
Expand All @@ -46,7 +47,6 @@ public String getAuthRealm() {
} }


/** /**
*
* @return OIDC Login URL for authRealm * @return OIDC Login URL for authRealm
*/ */
@Override @Override
Expand All @@ -55,4 +55,9 @@ public URI getOIDCLoginUrl() {
.build(getAuthRealm()); .build(getAuthRealm());
} }


public URI getOIDCLogoutUrl() {
return OIDCLoginProtocolService.logoutUrl(UriBuilder.fromPath(getAuthRoot()))
.build(getAuthRealm());
}

} }
Expand Up @@ -17,14 +17,16 @@
*/ */
package org.keycloak.testsuite.auth.page.account; package org.keycloak.testsuite.auth.page.account;


import java.util.List; import org.openqa.selenium.By;
import javax.ws.rs.core.UriBuilder;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;


import javax.ws.rs.core.UriBuilder;
import java.util.List;

/** /**
*
* @author Petr Mensik * @author Petr Mensik
* @author mhajas
*/ */
public class Applications extends AccountManagement { public class Applications extends AccountManagement {


Expand All @@ -39,26 +41,42 @@ public UriBuilder createUriBuilder() {
@FindBy(xpath = XPATH_APP_TABLE) @FindBy(xpath = XPATH_APP_TABLE)
protected WebElement appTable; protected WebElement appTable;


@FindBy(xpath = XPATH_APP_TABLE + "//a") @FindBy(xpath = XPATH_APP_TABLE + "//tr")
protected List<WebElement> applicationLinks; private List<WebElement> applicationRows;

public boolean containsApplication(String application) { public boolean containsApplication(String application) {
boolean contains = false; return getRowForLinkText(application) != null;
for (WebElement appLink : applicationLinks) {
if (appLink.getText().equals(application)) {
contains = true;
break;
}
}
return contains;
} }

public void clickApplication(String application) { public void clickApplication(String application) {
for (WebElement appLink : applicationLinks) { WebElement row = getRowForLinkText(application);
if (appLink.getText().equals(application)) { if (row == null) {
appLink.click(); log.error("Application: " + application + " doesn't exist");
throw new IllegalArgumentException("Application: " + application + " doesn't exist");
}

row.findElement(By.xpath(".//a")).click();
}

public void revokeGrantForApplication(String application) {
WebElement row = getRowForLinkText(application);
if (row == null) {
log.error("Application: " + application + " doesn't exist");
throw new IllegalArgumentException("Application: " + application + " doesn't exist");
}

row.findElement(By.xpath("//button[@id='revoke-" + application + "']")).click();
}

private WebElement getRowForLinkText(String appLink) {
for (WebElement appRow : applicationRows) {
if (appRow.findElement(By.xpath(".//td")).getText().equals(appLink)) {
return appRow;
} }
} }

return null;
} }



} }
@@ -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.auth.page.login;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class OAuthGrant extends LoginActions {

@FindBy(css = "input[name=\"accept\"]")
private WebElement acceptButton;
@FindBy(css = "input[name=\"cancel\"]")
private WebElement cancelButton;


public void accept() {
acceptButton.click();
}

public void cancel() {
cancelButton.click();
}

@Override
public boolean isCurrent() {
return driver.getTitle().equals("OAuth Grant");
}
}
@@ -1,15 +1,17 @@
package org.keycloak.testsuite.console.page.clients; package org.keycloak.testsuite.console.page.clients;


import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.testsuite.console.page.fragment.OnOffSwitch;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.keycloak.representations.idm.ClientRepresentation;
import static org.keycloak.testsuite.auth.page.login.Login.OIDC; import static org.keycloak.testsuite.auth.page.login.Login.OIDC;
import static org.keycloak.testsuite.util.WaitUtils.pause; import static org.keycloak.testsuite.util.WaitUtils.pause;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;


/** /**
*
* @author tkyjovsk * @author tkyjovsk
*/ */
public class ClientSettingsForm extends CreateClientForm { public class ClientSettingsForm extends CreateClientForm {
Expand All @@ -26,6 +28,9 @@ public class ClientSettingsForm extends CreateClientForm {
@FindBy(xpath = ".//i[contains(@data-ng-click, 'deleteWebOrigin')]") @FindBy(xpath = ".//i[contains(@data-ng-click, 'deleteWebOrigin')]")
private List<WebElement> deleteWebOriginIcons; private List<WebElement> deleteWebOriginIcons;


@FindBy(xpath = ".//div[@class='onoffswitch' and ./input[@id='consentRequired']]")
private OnOffSwitch consentRequired;

public void setBaseUrl(String baseUrl) { public void setBaseUrl(String baseUrl) {
setInputValue(baseUrlInput, baseUrl); setInputValue(baseUrlInput, baseUrl);
} }
Expand Down Expand Up @@ -88,4 +93,8 @@ public ClientRepresentation getValues() {
return values; return values;
} }


public void setConsentRequired(boolean value) {
consentRequired.setOn(value);
}

} }

0 comments on commit 32647d8

Please sign in to comment.