diff --git a/testsuite/integration-arquillian/test-apps/js-console/example-realm.json b/testsuite/integration-arquillian/test-apps/js-console/example-realm.json index 3bc609ef84..4e3adca45e 100755 --- a/testsuite/integration-arquillian/test-apps/js-console/example-realm.json +++ b/testsuite/integration-arquillian/test-apps/js-console/example-realm.json @@ -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": { diff --git a/testsuite/integration-arquillian/test-apps/js-console/src/main/webapp/index.html b/testsuite/integration-arquillian/test-apps/js-console/src/main/webapp/index.html index 04d7a8e202..cff5862875 100755 --- a/testsuite/integration-arquillian/test-apps/js-console/src/main/webapp/index.html +++ b/testsuite/integration-arquillian/test-apps/js-console/src/main/webapp/index.html @@ -39,6 +39,7 @@ + +

Result

@@ -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 () { diff --git a/testsuite/integration-arquillian/test-apps/js-database/pom.xml b/testsuite/integration-arquillian/test-apps/js-database/pom.xml new file mode 100644 index 0000000000..24e20c7917 --- /dev/null +++ b/testsuite/integration-arquillian/test-apps/js-database/pom.xml @@ -0,0 +1,71 @@ + + + + integration-arquillian-test-apps + org.keycloak.testsuite + 2.0.0.CR1-SNAPSHOT + + + 4.0.0 + integration-arquillian-test-apps-js-database + JAX-RS Database Service Using OAuth Bearer Tokens + war + + + + jboss + jboss repo + http://repository.jboss.org/nexus/content/groups/public/ + + + + + + org.jboss.resteasy + resteasy-jaxrs + provided + + + org.jboss.spec.javax.servlet + jboss-servlet-api_3.0_spec + provided + + + org.keycloak + keycloak-core + provided + + + org.keycloak + keycloak-adapter-core + provided + + + org.apache.httpcomponents + httpclient + provided + + + + + js-database + + + org.jboss.as.plugins + jboss-as-maven-plugin + + false + + + + org.wildfly.plugins + wildfly-maven-plugin + + false + + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/test-apps/js-database/src/main/java/org/keycloak/example/oauth/CustomerService.java b/testsuite/integration-arquillian/test-apps/js-database/src/main/java/org/keycloak/example/oauth/CustomerService.java new file mode 100755 index 0000000000..d2b193eb60 --- /dev/null +++ b/testsuite/integration-arquillian/test-apps/js-database/src/main/java/org/keycloak/example/oauth/CustomerService.java @@ -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 Bill Burke + * @version $Revision: 1 $ + */ +@Path("customers") +public class CustomerService { + + @Context + private HttpRequest httpRequest; + + @GET + @Produces("application/json") + @NoCache + public List 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 rtn = new ArrayList(); + 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; + } +} diff --git a/testsuite/integration-arquillian/test-apps/js-database/src/main/java/org/keycloak/example/oauth/DataApplication.java b/testsuite/integration-arquillian/test-apps/js-database/src/main/java/org/keycloak/example/oauth/DataApplication.java new file mode 100755 index 0000000000..6456904af6 --- /dev/null +++ b/testsuite/integration-arquillian/test-apps/js-database/src/main/java/org/keycloak/example/oauth/DataApplication.java @@ -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 Bill Burke + * @version $Revision: 1 $ + */ +@ApplicationPath("/") +public class DataApplication extends Application +{ +} diff --git a/testsuite/integration-arquillian/test-apps/js-database/src/main/webapp/WEB-INF/keycloak.json b/testsuite/integration-arquillian/test-apps/js-database/src/main/webapp/WEB-INF/keycloak.json new file mode 100755 index 0000000000..9f94148a6d --- /dev/null +++ b/testsuite/integration-arquillian/test-apps/js-database/src/main/webapp/WEB-INF/keycloak.json @@ -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" +} diff --git a/testsuite/integration-arquillian/test-apps/js-database/src/main/webapp/WEB-INF/web.xml b/testsuite/integration-arquillian/test-apps/js-database/src/main/webapp/WEB-INF/web.xml new file mode 100755 index 0000000000..599f6679ed --- /dev/null +++ b/testsuite/integration-arquillian/test-apps/js-database/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,46 @@ + + + + + + js-database + + + + /* + + + + user + + + + + KEYCLOAK + example + + + + user + + diff --git a/testsuite/integration-arquillian/test-apps/pom.xml b/testsuite/integration-arquillian/test-apps/pom.xml index 12c89a06c6..5f13130e21 100644 --- a/testsuite/integration-arquillian/test-apps/pom.xml +++ b/testsuite/integration-arquillian/test-apps/pom.xml @@ -17,5 +17,6 @@ js-console test-apps-dist + js-database \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/JSConsoleExample.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/JSConsoleTestApp.java similarity index 90% rename from testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/JSConsoleExample.java rename to testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/JSConsoleTestApp.java index b1645baf6b..fef0d114fc 100755 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/JSConsoleExample.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/JSConsoleTestApp.java @@ -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); } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/JSDatabaseTestApp.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/JSDatabaseTestApp.java new file mode 100644 index 0000000000..83afdb2893 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/JSDatabaseTestApp.java @@ -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; + } + +} \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/AbstractJSConsoleExampleAdapterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/AbstractJSConsoleExampleAdapterTest.java index 6100b13821..7be3cbd2c7 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/AbstractJSConsoleExampleAdapterTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/AbstractJSConsoleExampleAdapterTest.java @@ -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"); } } diff --git a/testsuite/integration-arquillian/tests/other/adapters/pom.xml b/testsuite/integration-arquillian/tests/other/adapters/pom.xml index 08e06382f3..b53c73902a 100644 --- a/testsuite/integration-arquillian/tests/other/adapters/pom.xml +++ b/testsuite/integration-arquillian/tests/other/adapters/pom.xml @@ -214,22 +214,22 @@ org.keycloak.example.demo - product-portal-example + product-portal-example ${project.version} war org.keycloak.example.demo - customer-portal-example + customer-portal-example ${project.version} war - + org.keycloak.example.demo - database-service + database-service ${project.version} war - + org.keycloak.testsuite integration-arquillian-test-apps-js-console @@ -237,14 +237,20 @@ war - org.keycloak - examples-multitenant + org.keycloak.testsuite + integration-arquillian-test-apps-js-database ${project.version} war - + org.keycloak - examples-basicauth + examples-multitenant + ${project.version} + war + + + org.keycloak + examples-basicauth ${project.version} war @@ -293,7 +299,7 @@ org.keycloak - keycloak-examples-dist + keycloak-examples-dist ${project.version} zip **/*realm.json,**/testsaml.json