From 2e7eb92f43a2d0e0b9e6a2e7e612ba3859b82708 Mon Sep 17 00:00:00 2001 From: vramik Date: Fri, 1 Mar 2019 12:49:21 +0100 Subject: [PATCH] KEYCLOAK-8699 replace hostnames with nip.io ones to include cors tests by default --- .../angular-product/src/main/webapp/js/app.js | 6 +- .../src/main/webapp/keycloak.json | 2 +- .../test-apps/cors/database-service/README.md | 71 ------------------- .../src/main/webapp/WEB-INF/keycloak.json | 2 +- .../integration-arquillian/tests/base/pom.xml | 22 ------ .../example/cors/CorsExampleAdapterTest.java | 10 +-- .../tests/other/adapters/pom.xml | 20 ------ 7 files changed, 11 insertions(+), 122 deletions(-) delete mode 100755 testsuite/integration-arquillian/test-apps/cors/database-service/README.md diff --git a/testsuite/integration-arquillian/test-apps/cors/angular-product/src/main/webapp/js/app.js b/testsuite/integration-arquillian/test-apps/cors/angular-product/src/main/webapp/js/app.js index 9b8424c834..6ee2ea1afc 100755 --- a/testsuite/integration-arquillian/test-apps/cors/angular-product/src/main/webapp/js/app.js +++ b/testsuite/integration-arquillian/test-apps/cors/angular-product/src/main/webapp/js/app.js @@ -18,7 +18,7 @@ var module = angular.module('product', []); function getAuthServerUrl() { - var url = 'https://localhost-auth:8543'; + var url = 'https://localhost-auth-127.0.0.1.nip.io:8543'; return url; } @@ -69,7 +69,7 @@ module.controller('GlobalCtrl', function($scope, $http) { $scope.realm = []; $scope.version = []; $scope.reloadData = function() { - $http.get(getAppServerUrl("localhost-db") + "/cors-database/products").success(function(data, status, headers, config) { + $http.get(getAppServerUrl("localhost-db-127.0.0.1.nip.io") + "/cors-database/products").success(function(data, status, headers, config) { $scope.products = angular.fromJson(data); $scope.headers = headers(); }); @@ -109,7 +109,7 @@ module.controller('GlobalCtrl', function($scope, $http) { }; $scope.loadVersion = function() { - $http.get(getAppServerUrl("localhost-db") + "/cors-database/products/k_version").success(function(data) { + $http.get(getAppServerUrl("localhost-db-127.0.0.1.nip.io") + "/cors-database/products/k_version").success(function(data) { $scope.version = angular.fromJson(data); }); }; diff --git a/testsuite/integration-arquillian/test-apps/cors/angular-product/src/main/webapp/keycloak.json b/testsuite/integration-arquillian/test-apps/cors/angular-product/src/main/webapp/keycloak.json index ee2f3a7b08..4f1d9a112c 100755 --- a/testsuite/integration-arquillian/test-apps/cors/angular-product/src/main/webapp/keycloak.json +++ b/testsuite/integration-arquillian/test-apps/cors/angular-product/src/main/webapp/keycloak.json @@ -1,7 +1,7 @@ { "realm" : "cors", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-server-url" : "http://localhost-auth:8180/auth", + "auth-server-url" : "http://localhost-auth-127.0.0.1.nip.io:8180/auth", "ssl-required" : "external", "disable-trust-manager" : "true", "resource" : "angular-cors-product", diff --git a/testsuite/integration-arquillian/test-apps/cors/database-service/README.md b/testsuite/integration-arquillian/test-apps/cors/database-service/README.md deleted file mode 100755 index 6506dd8129..0000000000 --- a/testsuite/integration-arquillian/test-apps/cors/database-service/README.md +++ /dev/null @@ -1,71 +0,0 @@ -Keycloak CORS support -=================================== -The following examples requires Wildfly 8.0.0, JBoss EAP 6.x, or JBoss AS 7.1.1. This example simulates Browser CORS -requests. While the examples will run on one machine, the servers/applications are configured to point to different domains: -* **localhost-auth** is where the Keycloak auth server lives -* **localhost-db** is where a database REST service lives -* **localhost** is where the Javascript application lives - -In the demo you will visit the Javascript application and be redirected to Keycloak to login. As part of the login process, -the javascript application will have to make a CORS request to the auth server (localhost-auth) to obtain a token. After it logs in, the -application will make another CORS request to the REST database service (localhost-db). - -Here are some of the configuration additions to this example to enable CORS: -1. The **angular-product** application in realm configuration has a Web Origin of **http://localhost:8080**. When you log into -the angular-product application, Keycloak will add the Web Origins for that application to the token. Any CORS request made -will check these allowed origins to make sure they match up with the Origin header the browser is sending -2. The **angular-product** application config (keycloak.json) points the auth-server at **http://localhost-auth:8080/auth** -3. The **database-service** config (keycloak.json) has an additional flag set **enable-cors** - -Step 1: Edit your hosts file --------------------------------------- -The demo expects additional host mappings for localhost. So, you need to edit your machine's host file (/etc/hosts or -C:\Windows\System32\drivers\etc\hosts) and add the following entries: - - -``` -127.0.0.1 localhost-auth -127.0.0.1 localhost-db -``` - - -Step 2: Make sure you've set up the Keycloak Server and have it running --------------------------------------- -You will run this demo on the same server as the keycloak server. Its best to use the appliance as everything is all set up. -See documentation on how to set this up. - -Step 3: Import the Test Realm ---------------------------------------- -Next thing you have to do is import the test realm for the demo. Clicking on the below link will bring you to the -create realm page in the Admin UI. The username/password is admin/admin to login in. Keycloak will ask you to -create a new admin password before you can go to the create realm page. - -[http://localhost-auth:8080/auth/admin/index.html#/create/realm](http://localhost-auth:8080/auth/admin/index.html#/create/realm) - -Import the cors-realm.json file that is in the cors/ example directory. Feel free to browse the setup of the realm, -particularly the angular-product application. - - -Step 4: Build and deploy ---------------------------------------- -next you must build and deploy - -``` -cd cors -mvn clean install wildfly:deploy -``` - -Step 5: Login and Observe Apps ---------------------------------------- -Try going to the customer app and view customer data: - -[http://localhost:8080/angular-cors-product/index.html](http://localhost:8080/angular-cors-product/index.html) - -This should take you to the auth-server login screen. Enter username: bburke@redhat.com and password: password. You -should be brought back to a simple and boring HTML page. Click the Reload button to show the product listing. Reload -causes an HTTP request to a different domain, this will trigger the browser's CORS protocol. - - - - - diff --git a/testsuite/integration-arquillian/test-apps/cors/database-service/src/main/webapp/WEB-INF/keycloak.json b/testsuite/integration-arquillian/test-apps/cors/database-service/src/main/webapp/WEB-INF/keycloak.json index 1b4d3dddb6..8686d186f6 100755 --- a/testsuite/integration-arquillian/test-apps/cors/database-service/src/main/webapp/WEB-INF/keycloak.json +++ b/testsuite/integration-arquillian/test-apps/cors/database-service/src/main/webapp/WEB-INF/keycloak.json @@ -2,7 +2,7 @@ "realm" : "cors", "resource" : "cors-database-service", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-server-url": "http://localhost-auth:8180/auth", + "auth-server-url": "http://localhost-auth-127.0.0.1.nip.io:8180/auth", "bearer-only" : true, "ssl-required": "external", "disable-trust-manager" : "true", diff --git a/testsuite/integration-arquillian/tests/base/pom.xml b/testsuite/integration-arquillian/tests/base/pom.xml index 84f0a67266..9a81ea55c3 100644 --- a/testsuite/integration-arquillian/tests/base/pom.xml +++ b/testsuite/integration-arquillian/tests/base/pom.xml @@ -45,8 +45,6 @@ **/x509/*Test.java **/hok/**/*Test.java - - **/cors/*Test.java @@ -188,7 +186,6 @@ ${exclude.cluster} ${exclude.crossdc} ${exclude.x509} - ${exclude.cors.tests} ${exclude.HoK} @@ -749,25 +746,6 @@ -Xms512m -Xmx1024m -XX:MetaspaceSize=96m -XX:MaxMetaspaceSize=256m - - include-CORS-tests - - - - includeCorsTests - - - - - - - diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/cors/CorsExampleAdapterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/cors/CorsExampleAdapterTest.java index 926ae06b2d..e107f79a71 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/cors/CorsExampleAdapterTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/example/cors/CorsExampleAdapterTest.java @@ -49,13 +49,14 @@ import java.util.regex.Pattern; import static junit.framework.TestCase.assertNotNull; import org.junit.Assume; +import org.keycloak.testsuite.util.DroneUtils; import static org.keycloak.testsuite.utils.io.IOUtil.loadRealm; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith; import static org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad; import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement; /** - * Tests CORS fuctionality in adapters. + * Tests CORS functionality in adapters. * *

* Note, for SSL this test disables TLS certificate verification. Since CORS uses different hostnames @@ -72,7 +73,7 @@ import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement; public class CorsExampleAdapterTest extends AbstractExampleAdapterTest { public static final String CORS = "cors"; - public static final String AUTH_SERVER_HOST = "localhost-auth"; + public static final String AUTH_SERVER_HOST = "localhost-auth-127.0.0.1.nip.io"; private static final String hostBackup; @ArquillianResource @@ -113,6 +114,7 @@ public class CorsExampleAdapterTest extends AbstractExampleAdapterTest { @Before public void onBefore() { + DroneUtils.addWebDriver(jsDriver); Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows")); deployer.deploy(CorsDatabaseServiceTestApp.DEPLOYMENT_NAME); deployer.deploy(AngularCorsProductTestApp.DEPLOYMENT_NAME); @@ -182,14 +184,14 @@ public class CorsExampleAdapterTest extends AbstractExampleAdapterTest { @Nullable private String getAuthServerVersion() { - jsDriver.navigate().to(suiteContext.getAuthServerInfo().getContextRoot().toString() + + DroneUtils.getCurrentDriver().navigate().to(suiteContext.getAuthServerInfo().getContextRoot().toString() + "/auth/admin/master/console/#/server-info"); jsDriverTestRealmLoginPage.form().login("admin", "admin"); WaitUtils.waitUntilElement(By.tagName("body")).is().visible(); Pattern pattern = Pattern.compile("]+>Server Version" + "\\s+]+>([^<]+)"); - Matcher matcher = pattern.matcher(jsDriver.getPageSource()); + Matcher matcher = pattern.matcher(DroneUtils.getCurrentDriver().getPageSource()); if (matcher.find()) { return matcher.group(1); diff --git a/testsuite/integration-arquillian/tests/other/adapters/pom.xml b/testsuite/integration-arquillian/tests/other/adapters/pom.xml index f93b80302b..e6a2b3879a 100644 --- a/testsuite/integration-arquillian/tests/other/adapters/pom.xml +++ b/testsuite/integration-arquillian/tests/other/adapters/pom.xml @@ -95,7 +95,6 @@ true ${keycloak-parent.basedir}/examples - - **/cors/*Test.java @@ -399,25 +398,6 @@ - - Include CORS tests - - - - includeCorsTests - - - - - - -