Merge pull request #2938 from mhajas/addJSConsoleTests-master
KEYCLOAK-3121 Add JS adapter tests
This commit is contained in:
commit
8ae08f0432
12 changed files with 478 additions and 100 deletions
|
@ -21,6 +21,20 @@
|
|||
"clientRoles": {
|
||||
"account": ["view-profile", "manage-account"]
|
||||
}
|
||||
},{
|
||||
"username" : "unauthorized",
|
||||
"enabled": true,
|
||||
"email" : "sample-user2@example",
|
||||
"firstName": "Sample",
|
||||
"lastName": "User",
|
||||
"credentials" : [
|
||||
{ "type" : "password",
|
||||
"value" : "password" }
|
||||
],
|
||||
"realmRoles": [],
|
||||
"clientRoles": {
|
||||
"account": ["view-profile", "manage-account"]
|
||||
}
|
||||
}
|
||||
],
|
||||
"roles" : {
|
||||
|
@ -54,6 +68,12 @@
|
|||
"http://localhost:8280",
|
||||
"https://localhost:8643"
|
||||
]
|
||||
},{
|
||||
"clientId": "js-database",
|
||||
"enabled": true,
|
||||
"adminUrl": "/database",
|
||||
"baseUrl": "/database",
|
||||
"bearerOnly": true
|
||||
}
|
||||
],
|
||||
"clientScopeMappings": {
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
<button onclick="output(keycloak.createLoginUrl())">Show Login URL</button>
|
||||
<button onclick="output(keycloak.createLogoutUrl())">Show Logout URL</button>
|
||||
<button onclick="output(keycloak.createRegisterUrl())">Show Register URL</button>
|
||||
<button onclick="createBearerRequest()">Create Bearer Request</button>
|
||||
<select id="flowSelect">
|
||||
<option value="standard">standard</option>
|
||||
<option value="implicit">implicit</option>
|
||||
|
@ -48,6 +49,10 @@
|
|||
<option value="fragment">fragment</option>
|
||||
<option value="query">query</option>
|
||||
</select>
|
||||
<select id="onLoad">
|
||||
<option value="check-sso">check-sso</option>
|
||||
<option value="login-required">login-required</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<h2>Result</h2>
|
||||
|
@ -115,6 +120,34 @@
|
|||
document.getElementById('events').innerHTML = new Date().toLocaleString() + "\t" + event + "\n" + e;
|
||||
}
|
||||
|
||||
function createBearerRequest() {
|
||||
|
||||
var url = 'http://localhost:8280/js-database/customers';
|
||||
if (window.location.href.indexOf("8643") > -1) {
|
||||
url = url.replace("8280","8643");
|
||||
url = url.replace("http","https");
|
||||
}
|
||||
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('GET', url, true);
|
||||
req.setRequestHeader('Accept', 'application/json');
|
||||
req.setRequestHeader('Authorization', 'Bearer ' + keycloak.token);
|
||||
|
||||
req.onreadystatechange = function () {
|
||||
if (req.readyState == 4) {
|
||||
if (req.status == 200) {
|
||||
output(req.responseText);
|
||||
} else if (req.status == 403) {
|
||||
output('Forbidden');
|
||||
} else if (req.status == 401) {
|
||||
output('Unauthorized');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
req.send();
|
||||
}
|
||||
|
||||
var keycloak;
|
||||
|
||||
function keycloakInit() {
|
||||
|
@ -144,7 +177,7 @@
|
|||
event('Access token expired.');
|
||||
};
|
||||
|
||||
var initOptions = {flow: document.getElementById("flowSelect").value, responseMode: document.getElementById("responseModeSelect").value}
|
||||
var initOptions = {onLoad: document.getElementById("onLoad").value, flow: document.getElementById("flowSelect").value, responseMode: document.getElementById("responseModeSelect").value};
|
||||
keycloak.init(initOptions).success(function (authenticated) {
|
||||
output('Init Success (' + (authenticated ? 'Authenticated' : 'Not Authenticated') + ')');
|
||||
}).error(function () {
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>integration-arquillian-test-apps</artifactId>
|
||||
<groupId>org.keycloak.testsuite</groupId>
|
||||
<version>2.0.0.CR1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>integration-arquillian-test-apps-js-database</artifactId>
|
||||
<name>JAX-RS Database Service Using OAuth Bearer Tokens</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jboss</id>
|
||||
<name>jboss repo</name>
|
||||
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxrs</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.spec.javax.servlet</groupId>
|
||||
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-adapter-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>js-database</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jboss.as.plugins</groupId>
|
||||
<artifactId>jboss-as-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.wildfly.plugins</groupId>
|
||||
<artifactId>wildfly-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.example.oauth;
|
||||
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.HttpRequest;
|
||||
import org.keycloak.KeycloakSecurityContext;
|
||||
import org.keycloak.representations.AccessToken;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
@Path("customers")
|
||||
public class CustomerService {
|
||||
|
||||
@Context
|
||||
private HttpRequest httpRequest;
|
||||
|
||||
@GET
|
||||
@Produces("application/json")
|
||||
@NoCache
|
||||
public List<String> getCustomers() {
|
||||
// Just to show how to user info from access token in REST endpoint
|
||||
KeycloakSecurityContext securityContext = (KeycloakSecurityContext) httpRequest.getAttribute(KeycloakSecurityContext.class.getName());
|
||||
AccessToken accessToken = securityContext.getToken();
|
||||
System.out.println(String.format("User '%s' with email '%s' made request to CustomerService REST endpoint", accessToken.getPreferredUsername(), accessToken.getEmail()));
|
||||
|
||||
ArrayList<String> rtn = new ArrayList<String>();
|
||||
rtn.add("Bill Burke");
|
||||
rtn.add("Stian Thorgersen");
|
||||
rtn.add("Stan Silvert");
|
||||
rtn.add("Gabriel Cardoso");
|
||||
rtn.add("Viliam Rockai");
|
||||
rtn.add("Marek Posolda");
|
||||
rtn.add("Boleslaw Dawidowicz");
|
||||
return rtn;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.example.oauth;
|
||||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
@ApplicationPath("/")
|
||||
public class DataApplication extends Application
|
||||
{
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"realm" : "example",
|
||||
"resource" : "js-database",
|
||||
"realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB",
|
||||
"auth-server-url": "http://localhost:8180/auth",
|
||||
"bearer-only" : true,
|
||||
"ssl-required" : "external"
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
~ and other contributors as indicated by the @author tags.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<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-database</module-name>
|
||||
|
||||
<security-constraint>
|
||||
<web-resource-collection>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</web-resource-collection>
|
||||
<!-- <user-data-constraint>
|
||||
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
|
||||
</user-data-constraint> -->
|
||||
<auth-constraint>
|
||||
<role-name>user</role-name>
|
||||
</auth-constraint>
|
||||
</security-constraint>
|
||||
|
||||
<login-config>
|
||||
<auth-method>KEYCLOAK</auth-method>
|
||||
<realm-name>example</realm-name>
|
||||
</login-config>
|
||||
|
||||
<security-role>
|
||||
<role-name>user</role-name>
|
||||
</security-role>
|
||||
</web-app>
|
|
@ -17,5 +17,6 @@
|
|||
<modules>
|
||||
<module>js-console</module>
|
||||
<module>test-apps-dist</module>
|
||||
<module>js-database</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -30,7 +30,7 @@ import java.net.URL;
|
|||
*
|
||||
* @author tkyjovsk
|
||||
*/
|
||||
public class JSConsoleExample extends AbstractPageWithInjectedUrl {
|
||||
public class JSConsoleTestApp extends AbstractPageWithInjectedUrl {
|
||||
|
||||
public static final String DEPLOYMENT_NAME = "js-console-example";
|
||||
public static final String CLIENT_ID = "integration-arquillian-test-apps-js-console";
|
||||
|
@ -69,11 +69,16 @@ public class JSConsoleExample extends AbstractPageWithInjectedUrl {
|
|||
private WebElement showExpiresButton;
|
||||
@FindBy(xpath = "//button[text() = 'Show Details']")
|
||||
private WebElement showDetailsButton;
|
||||
@FindBy(xpath = "//button[text() = 'Create Bearer Request']")
|
||||
private WebElement createBearerRequest;
|
||||
|
||||
@FindBy(id = "flowSelect")
|
||||
private Select flowSelect;
|
||||
@FindBy(id = "responseModeSelect")
|
||||
private Select responseModeSelect;
|
||||
@FindBy(id = "onLoad")
|
||||
private Select onLoad;
|
||||
|
||||
|
||||
@FindBy(id = "output")
|
||||
private WebElement outputArea;
|
||||
|
@ -105,10 +110,18 @@ public class JSConsoleExample extends AbstractPageWithInjectedUrl {
|
|||
flowSelect.selectByValue(value);
|
||||
}
|
||||
|
||||
public void setOnLoad(String value) {
|
||||
onLoad.selectByValue(value);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
initButton.click();
|
||||
}
|
||||
|
||||
public void createBearerRequest() {
|
||||
createBearerRequest.click();
|
||||
}
|
||||
|
||||
public void setResponseMode(String value) {
|
||||
responseModeSelect.selectByValue(value);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.testsuite.adapter.page;
|
||||
|
||||
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
|
||||
import org.jboss.arquillian.test.api.ArquillianResource;
|
||||
import org.keycloak.testsuite.page.AbstractPageWithInjectedUrl;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tkyjovsk
|
||||
*/
|
||||
public class JSDatabaseTestApp extends AbstractPageWithInjectedUrl {
|
||||
|
||||
public static final String DEPLOYMENT_NAME = "js-database-example";
|
||||
public static final String CLIENT_ID = "integration-arquillian-test-apps-js-database";
|
||||
|
||||
@ArquillianResource
|
||||
@OperateOnDeployment(DEPLOYMENT_NAME)
|
||||
private URL url;
|
||||
|
||||
@Override
|
||||
public URL getInjectedUrl() {
|
||||
//EAP6 URL fix
|
||||
URL fixedUrl = createInjectedURL("js-database");
|
||||
return fixedUrl != null ? fixedUrl : url;
|
||||
}
|
||||
|
||||
}
|
|
@ -25,7 +25,8 @@ import org.keycloak.admin.client.resource.ClientResource;
|
|||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.testsuite.adapter.AbstractExampleAdapterTest;
|
||||
import org.keycloak.testsuite.adapter.page.JSConsoleExample;
|
||||
import org.keycloak.testsuite.adapter.page.JSConsoleTestApp;
|
||||
import org.keycloak.testsuite.adapter.page.JSDatabaseTestApp;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
import org.keycloak.testsuite.auth.page.account.Applications;
|
||||
import org.keycloak.testsuite.auth.page.login.OAuthGrant;
|
||||
|
@ -51,7 +52,7 @@ import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
|
|||
public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampleAdapterTest {
|
||||
|
||||
@Page
|
||||
private JSConsoleExample jsConsoleExamplePage;
|
||||
private JSConsoleTestApp jsConsoleTestAppPage;
|
||||
|
||||
@Page
|
||||
private Config configPage;
|
||||
|
@ -67,9 +68,14 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
|||
|
||||
public static int TOKEN_LIFESPAN_LEEWAY = 3; // seconds
|
||||
|
||||
@Deployment(name = JSConsoleExample.DEPLOYMENT_NAME)
|
||||
private static WebArchive jsConsoleExample() throws IOException {
|
||||
return exampleDeployment(JSConsoleExample.CLIENT_ID);
|
||||
@Deployment(name = JSConsoleTestApp.DEPLOYMENT_NAME)
|
||||
private static WebArchive jsConsoleTestApp() throws IOException {
|
||||
return exampleDeployment(JSConsoleTestApp.CLIENT_ID);
|
||||
}
|
||||
|
||||
@Deployment(name = JSDatabaseTestApp.DEPLOYMENT_NAME)
|
||||
private static WebArchive jsDbApp() throws IOException {
|
||||
return exampleDeployment(JSDatabaseTestApp.CLIENT_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,7 +83,7 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
|||
RealmRepresentation jsConsoleRealm = loadRealm(new File(TEST_APPS_HOME_DIR + "/js-console/example-realm.json"));
|
||||
|
||||
fixClientUrisUsingDeploymentUrl(jsConsoleRealm,
|
||||
JSConsoleExample.CLIENT_ID, jsConsoleExamplePage.buildUri().toASCIIString());
|
||||
JSConsoleTestApp.CLIENT_ID, jsConsoleTestAppPage.buildUri().toASCIIString());
|
||||
|
||||
jsConsoleRealm.setAccessTokenLifespan(30 + TOKEN_LIFESPAN_LEEWAY); // seconds
|
||||
|
||||
|
@ -92,92 +98,93 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
|||
|
||||
@Test
|
||||
public void testJSConsoleAuth() {
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
assertCurrentUrlStartsWith(jsConsoleExamplePage);
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
assertCurrentUrlStartsWith(jsConsoleTestAppPage);
|
||||
|
||||
waitUntilElement(jsConsoleExamplePage.getInitButtonElement()).is().present();
|
||||
waitUntilElement(jsConsoleTestAppPage.getInitButtonElement()).is().present();
|
||||
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleExamplePage.logIn();
|
||||
jsConsoleTestAppPage.init();
|
||||
jsConsoleTestAppPage.logIn();
|
||||
testRealmLoginPage.form().login("user", "invalid-password");
|
||||
assertCurrentUrlDoesntStartWith(jsConsoleExamplePage);
|
||||
assertCurrentUrlDoesntStartWith(jsConsoleTestAppPage);
|
||||
|
||||
testRealmLoginPage.form().login("invalid-user", "password");
|
||||
assertCurrentUrlDoesntStartWith(jsConsoleExamplePage);
|
||||
assertCurrentUrlDoesntStartWith(jsConsoleTestAppPage);
|
||||
|
||||
testRealmLoginPage.form().login("user", "password");
|
||||
assertCurrentUrlStartsWith(jsConsoleExamplePage);
|
||||
jsConsoleExamplePage.init();
|
||||
assertCurrentUrlStartsWith(jsConsoleTestAppPage);
|
||||
jsConsoleTestAppPage.init();
|
||||
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("Init Success (Authenticated)");
|
||||
waitUntilElement(jsConsoleExamplePage.getEventsElement()).text().contains("Auth Success");
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Authenticated)");
|
||||
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Auth Success");
|
||||
|
||||
jsConsoleExamplePage.logOut();
|
||||
assertCurrentUrlStartsWith(jsConsoleExamplePage);
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleTestAppPage.logOut();
|
||||
assertCurrentUrlStartsWith(jsConsoleTestAppPage);
|
||||
waitUntilElement(jsConsoleTestAppPage.getInitButtonElement()).is().present();
|
||||
jsConsoleTestAppPage.init();
|
||||
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("Init Success (Not Authenticated)");
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Not Authenticated)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshToken() {
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
assertCurrentUrlStartsWith(jsConsoleExamplePage);
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
assertCurrentUrlStartsWith(jsConsoleTestAppPage);
|
||||
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleExamplePage.refreshToken();
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("Failed to refresh token");
|
||||
jsConsoleTestAppPage.init();
|
||||
jsConsoleTestAppPage.refreshToken();
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Failed to refresh token");
|
||||
|
||||
jsConsoleExamplePage.logIn();
|
||||
jsConsoleTestAppPage.logIn();
|
||||
testRealmLoginPage.form().login("user", "password");
|
||||
assertCurrentUrlStartsWith(jsConsoleExamplePage);
|
||||
jsConsoleExamplePage.init();
|
||||
waitUntilElement(jsConsoleExamplePage.getEventsElement()).text().contains("Auth Success");
|
||||
assertCurrentUrlStartsWith(jsConsoleTestAppPage);
|
||||
jsConsoleTestAppPage.init();
|
||||
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Auth Success");
|
||||
|
||||
jsConsoleExamplePage.refreshToken();
|
||||
waitUntilElement(jsConsoleExamplePage.getEventsElement()).text().contains("Auth Refresh Success");
|
||||
jsConsoleTestAppPage.refreshToken();
|
||||
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Auth Refresh Success");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshTokenIfUnder30s() {
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
assertCurrentUrlStartsWith(jsConsoleExamplePage);
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleExamplePage.refreshToken();
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("Failed to refresh token");
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
assertCurrentUrlStartsWith(jsConsoleTestAppPage);
|
||||
jsConsoleTestAppPage.init();
|
||||
jsConsoleTestAppPage.refreshToken();
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Failed to refresh token");
|
||||
|
||||
jsConsoleExamplePage.logIn();
|
||||
jsConsoleTestAppPage.logIn();
|
||||
testRealmLoginPage.form().login("user", "password");
|
||||
assertCurrentUrlStartsWith(jsConsoleExamplePage);
|
||||
jsConsoleExamplePage.init();
|
||||
waitUntilElement(jsConsoleExamplePage.getEventsElement()).text().contains("Auth Success");
|
||||
assertCurrentUrlStartsWith(jsConsoleTestAppPage);
|
||||
jsConsoleTestAppPage.init();
|
||||
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Auth Success");
|
||||
|
||||
jsConsoleExamplePage.refreshTokenIfUnder30s();
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("Token not refreshed, valid for");
|
||||
jsConsoleTestAppPage.refreshTokenIfUnder30s();
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Token not refreshed, valid for");
|
||||
|
||||
pause((TOKEN_LIFESPAN_LEEWAY + 2) * 1000);
|
||||
|
||||
jsConsoleExamplePage.refreshTokenIfUnder30s();
|
||||
waitUntilElement(jsConsoleExamplePage.getEventsElement()).text().contains("Auth Refresh Success");
|
||||
jsConsoleTestAppPage.refreshTokenIfUnder30s();
|
||||
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Auth Refresh Success");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProfile() {
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
assertCurrentUrlStartsWith(jsConsoleExamplePage);
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
assertCurrentUrlStartsWith(jsConsoleTestAppPage);
|
||||
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleExamplePage.getProfile();
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("Failed to load profile");
|
||||
jsConsoleTestAppPage.init();
|
||||
jsConsoleTestAppPage.getProfile();
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Failed to load profile");
|
||||
|
||||
jsConsoleExamplePage.logIn();
|
||||
jsConsoleTestAppPage.logIn();
|
||||
testRealmLoginPage.form().login("user", "password");
|
||||
assertCurrentUrlStartsWith(jsConsoleExamplePage);
|
||||
jsConsoleExamplePage.init();
|
||||
waitUntilElement(jsConsoleExamplePage.getEventsElement()).text().contains("Auth Success");
|
||||
assertCurrentUrlStartsWith(jsConsoleTestAppPage);
|
||||
jsConsoleTestAppPage.init();
|
||||
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Auth Success");
|
||||
|
||||
jsConsoleExamplePage.getProfile();
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("\"username\": \"user\"");
|
||||
jsConsoleTestAppPage.getProfile();
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("\"username\": \"user\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -188,7 +195,7 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
|||
loginEventsPage.setConsoleRealm(EXAMPLE);
|
||||
applicationsPage.setAuthRealm(EXAMPLE);
|
||||
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
driver.manage().deleteAllCookies();
|
||||
|
||||
ClientResource clientResource = ApiUtil.findClientResourceByClientId(testRealmResource(), "js-console");
|
||||
|
@ -201,26 +208,27 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
|||
realm.setEnabledEventTypes(Arrays.asList("REVOKE_GRANT", "LOGIN"));
|
||||
testRealmResource().update(realm);
|
||||
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleExamplePage.logIn();
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
jsConsoleTestAppPage.init();
|
||||
jsConsoleTestAppPage.logIn();
|
||||
|
||||
testRealmLoginPage.form().login("user", "password");
|
||||
|
||||
assertTrue(oAuthGrantPage.isCurrent());
|
||||
oAuthGrantPage.accept();
|
||||
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleTestAppPage.init();
|
||||
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("Init Success (Authenticated)");
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Authenticated)");
|
||||
|
||||
applicationsPage.navigateTo();
|
||||
applicationsPage.revokeGrantForApplication("js-console");
|
||||
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleExamplePage.logIn();
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
jsConsoleTestAppPage.setOnLoad("login-required");
|
||||
jsConsoleTestAppPage.init();
|
||||
|
||||
waitUntilElement(By.tagName("body")).is().visible();
|
||||
assertTrue(oAuthGrantPage.isCurrent());
|
||||
|
||||
loginEventsPage.navigateTo();
|
||||
|
@ -255,34 +263,34 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
|||
|
||||
@Test
|
||||
public void implicitFlowTest() {
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
jsConsoleExamplePage.setFlow("implicit");
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
jsConsoleTestAppPage.setFlow("implicit");
|
||||
jsConsoleTestAppPage.init();
|
||||
|
||||
jsConsoleExamplePage.logIn();
|
||||
jsConsoleTestAppPage.logIn();
|
||||
assertTrue(driver.getPageSource().contains("Implicit flow is disabled for the client"));
|
||||
|
||||
setImplicitFlowFroClient();
|
||||
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleExamplePage.logIn();
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
jsConsoleTestAppPage.init();
|
||||
jsConsoleTestAppPage.logIn();
|
||||
assertTrue(driver.getPageSource().contains("Standard flow is disabled for the client"));
|
||||
|
||||
logInAndInit("implicit");
|
||||
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("Init Success (Authenticated)");
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Authenticated)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void implicitFlowQueryTest() {
|
||||
setImplicitFlowFroClient();
|
||||
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
jsConsoleExamplePage.setFlow("implicit");
|
||||
jsConsoleExamplePage.setResponseMode("query");
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleExamplePage.logIn();
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
jsConsoleTestAppPage.setFlow("implicit");
|
||||
jsConsoleTestAppPage.setResponseMode("query");
|
||||
jsConsoleTestAppPage.init();
|
||||
jsConsoleTestAppPage.logIn();
|
||||
assertTrue(driver.getPageSource().contains("Invalid parameter: response_mode"));
|
||||
}
|
||||
|
||||
|
@ -292,9 +300,9 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
|||
|
||||
logInAndInit("implicit");
|
||||
|
||||
jsConsoleExamplePage.refreshToken();
|
||||
jsConsoleTestAppPage.refreshToken();
|
||||
|
||||
waitUntilElement(jsConsoleExamplePage.getOutputElement()).text().contains("Failed to refresh token");
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Failed to refresh token");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -309,7 +317,38 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
|||
|
||||
pause(6000);
|
||||
|
||||
waitUntilElement(jsConsoleExamplePage.getEventsElement()).text().contains("Access token expired");
|
||||
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Access token expired");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBearerRequest() {
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
jsConsoleTestAppPage.init();
|
||||
jsConsoleTestAppPage.createBearerRequest();
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Unauthorized");
|
||||
|
||||
logInAndInit("standard", "unauthorized");
|
||||
jsConsoleTestAppPage.createBearerRequest();
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Forbidden");
|
||||
|
||||
jsConsoleTestAppPage.logOut();
|
||||
logInAndInit("standard");
|
||||
jsConsoleTestAppPage.createBearerRequest();
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("[\"Bill Burke\",\"Stian Thorgersen\",\"Stan Silvert\",\"Gabriel Cardoso\",\"Viliam Rockai\",\"Marek Posolda\",\"Boleslaw Dawidowicz\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loginRequiredAction() {
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
jsConsoleTestAppPage.setOnLoad("login-required");
|
||||
jsConsoleTestAppPage.init();
|
||||
|
||||
assertCurrentUrlStartsWith(testRealmLoginPage);
|
||||
testRealmLoginPage.form().login("user", "password");
|
||||
|
||||
waitUntilElement(jsConsoleTestAppPage.getInitButtonElement()).is().present();
|
||||
jsConsoleTestAppPage.init();
|
||||
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Authenticated)");
|
||||
}
|
||||
|
||||
private void setImplicitFlowFroClient() {
|
||||
|
@ -320,14 +359,18 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
|||
clientResource.update(client);
|
||||
}
|
||||
|
||||
private void logInAndInit(String flow, String user) {
|
||||
jsConsoleTestAppPage.navigateTo();
|
||||
jsConsoleTestAppPage.setFlow(flow);
|
||||
jsConsoleTestAppPage.init();
|
||||
jsConsoleTestAppPage.logIn();
|
||||
testRealmLoginPage.form().login(user, "password");
|
||||
jsConsoleTestAppPage.setFlow(flow);
|
||||
jsConsoleTestAppPage.init();
|
||||
}
|
||||
|
||||
private void logInAndInit(String flow) {
|
||||
jsConsoleExamplePage.navigateTo();
|
||||
jsConsoleExamplePage.setFlow(flow);
|
||||
jsConsoleExamplePage.init();
|
||||
jsConsoleExamplePage.logIn();
|
||||
testRealmLoginPage.form().login("user", "password");
|
||||
jsConsoleExamplePage.setFlow(flow);
|
||||
jsConsoleExamplePage.init();
|
||||
logInAndInit(flow, "user");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -236,6 +236,12 @@
|
|||
<version>${project.version}</version>
|
||||
<type>war</type>
|
||||
</artifactItem>
|
||||
<artifactItem>
|
||||
<groupId>org.keycloak.testsuite</groupId>
|
||||
<artifactId>integration-arquillian-test-apps-js-database</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>war</type>
|
||||
</artifactItem>
|
||||
<artifactItem>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>examples-multitenant</artifactId>
|
||||
|
|
Loading…
Reference in a new issue