KEYCLOAK-8699 replace hostnames with nip.io ones to include cors tests by default
This commit is contained in:
parent
15478c83e4
commit
2e7eb92f43
7 changed files with 11 additions and 122 deletions
|
@ -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);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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",
|
||||
|
|
|
@ -45,8 +45,6 @@
|
|||
<exclude.x509>**/x509/*Test.java</exclude.x509>
|
||||
<!-- KEYCLOAK-6771 exclude Mutual TLS Holder of Key Token x509 tests by default, enabled by 'ssl' profile -->
|
||||
<exclude.HoK>**/hok/**/*Test.java</exclude.HoK>
|
||||
<!-- see include-CORS-tests profile -->
|
||||
<exclude.cors.tests>**/cors/*Test.java</exclude.cors.tests>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -188,7 +186,6 @@
|
|||
<exclude>${exclude.cluster}</exclude>
|
||||
<exclude>${exclude.crossdc}</exclude>
|
||||
<exclude>${exclude.x509}</exclude>
|
||||
<exclude>${exclude.cors.tests}</exclude>
|
||||
<exclude>${exclude.HoK}</exclude>
|
||||
</excludes>
|
||||
<systemPropertyVariables>
|
||||
|
@ -749,25 +746,6 @@
|
|||
<surefire.memory.settings>-Xms512m -Xmx1024m -XX:MetaspaceSize=96m -XX:MaxMetaspaceSize=256m</surefire.memory.settings>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>include-CORS-tests</id>
|
||||
<!--
|
||||
If you want to run CORS tests it is necessary to put
|
||||
|
||||
127.0.0.1 localhost-auth
|
||||
127.0.0.1 localhost-db
|
||||
|
||||
to your /etc/hosts file
|
||||
-->
|
||||
<activation>
|
||||
<property>
|
||||
<name>includeCorsTests</name>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<exclude.cors.tests>-</exclude.cors.tests>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <p>
|
||||
* 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("<td [^>]+>Server Version</td>" +
|
||||
"\\s+<td [^>]+>([^<]+)</td>");
|
||||
Matcher matcher = pattern.matcher(jsDriver.getPageSource());
|
||||
Matcher matcher = pattern.matcher(DroneUtils.getCurrentDriver().getPageSource());
|
||||
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1);
|
||||
|
|
|
@ -95,7 +95,6 @@
|
|||
<adapter.config.bundled>true</adapter.config.bundled>
|
||||
<examples.basedir>${keycloak-parent.basedir}/examples</examples.basedir>
|
||||
<exclude.test>-</exclude.test>
|
||||
<exclude.cors.tests>**/cors/*Test.java</exclude.cors.tests>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
|
@ -399,25 +398,6 @@
|
|||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>Include CORS tests</id>
|
||||
<!--
|
||||
If you want to run CORS tests it is necessary to put
|
||||
|
||||
127.0.0.1 localhost-auth
|
||||
127.0.0.1 localhost-db
|
||||
|
||||
to your /etc/hosts file
|
||||
-->
|
||||
<activation>
|
||||
<property>
|
||||
<name>includeCorsTests</name>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<exclude.cors.tests>-</exclude.cors.tests>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
|
|
Loading…
Reference in a new issue