2017-01-30 16:27:32 +00:00
How To Run various testsuite configurations
===========================================
## Base steps
2019-11-14 13:45:05 +00:00
It's recommended to build the workspace including distribution.
2017-01-30 16:27:32 +00:00
2017-01-31 13:49:54 +00:00
cd $KEYCLOAK_SOURCES
mvn clean install -DskipTests=true
cd distribution
mvn clean install
2019-11-14 13:45:05 +00:00
2020-08-18 15:12:33 +00:00
### Running tests in the development mode (Keycloak on embedded undertow)
After build sources and distribution, it is possible to run the base testsuite
mvn -f testsuite/integration-arquillian/pom.xml clean install
Running single test can be achieved for example like this
mvn -f testsuite/integration-arquillian/pom.xml clean install -Dtest=LoginTest
By default, the development setup is used with the Keycloak server deployed on
embedded undertow server. That setup doesn't even require to build the distribution or re-build
the distribution after doing changes in the code.
For example when you do some fix in some class in the `services` module, you can re-build just that module
mvn -f services/pom.xml clean install
And then re-run the LoginTest (or any other test you wish) and the changes should be applied when running the tests.
If you use Intellij Idea, you don't even need to re-build anything with the maven. After doing any
change in the codebase, the change is immediately effective when running the test with Junit runner.
2022-09-30 07:41:57 +00:00
### Running tests in the production mode (Keycloak on Quarkus)
2020-08-18 15:12:33 +00:00
2022-09-30 07:41:57 +00:00
For the "production" testing, it is possible to run the Keycloak server deployed on real Quarkus server.
This can be achieved by add the `auth-server-quarkus` profile when running the testsuite.
2020-08-18 15:12:33 +00:00
2022-09-30 07:41:57 +00:00
mvn -f testsuite/integration-arquillian/pom.xml -Pauth-server-quarkus clean install
2020-08-18 15:12:33 +00:00
Unlike the "development" setup described above, this requires re-build the whole distribution
after doing any change in the code.
2017-01-31 13:49:54 +00:00
2023-01-11 21:30:04 +00:00
### Running tests using an embedded server
For test driven development, it is possible to run the Keycloak server deployed on real Quarkus server.
This can be achieved by add the `auth-server-quarkus-embedded` profile when running the testsuite.
mvn -f testsuite/integration-arquillian/pom.xml -Pauth-server-quarkus-embedded clean install -Dtest=LoginTest
After running this command, you should also be able to run tests from your IDE. For that, make sure you have the `auth-server-quarkus-embedded` profile enabled.
When running in embedded mode, the `build` phase happens every time the server is started, and it is based on the same configuration used during a full-distribution test run(e.g.: `auth-server-quarkus` profile is active).
There are a few limitations when running tests. The well-known limitations are:
* FIPS tests not working
* Deploying script providers not working. Probably any test deploying JAR files.
* Re-starting the server during a test execution is taking too much metaspace. Need more investigation.
2017-01-31 13:49:54 +00:00
## Debugging - tips & tricks
### Arquillian debugging
Adding this system property when running any test:
2019-11-14 13:45:05 +00:00
2017-01-31 13:49:54 +00:00
-Darquillian.debug=true
2019-11-14 13:45:05 +00:00
2017-02-21 14:06:56 +00:00
will add lots of info to the log. Especially about:
2019-11-14 13:45:05 +00:00
* The test method names, which will be executed for each test class, will be written at the proper running order to the log at the beginning of each test class(done by KcArquillian class).
2017-02-21 14:06:56 +00:00
* All the triggered arquillian lifecycle events and executed observers listening to those events will be written to the log
* The bootstrap of WebDriver will be unlimited. By default there is just 1 minute timeout and test is cancelled when WebDriver is not bootstrapped within it.
2017-01-31 13:49:54 +00:00
### WebDriver timeout
By default, WebDriver has 10 seconds timeout to load every page and it timeouts with error after that. Use this to increase timeout to 1 hour instead:
2019-11-14 13:45:05 +00:00
2017-01-31 13:49:54 +00:00
-Dpageload.timeout=3600000
2019-11-14 13:45:05 +00:00
2017-01-31 13:49:54 +00:00
### Surefire debugging
2019-11-14 13:45:05 +00:00
For debugging, the best is to run the test from IDE and debug it directly. When you use embedded Undertow (which is by default), then JUnit test, Keycloak server
2017-01-31 13:49:54 +00:00
and adapter are all in the same JVM and you can debug them easily. If it is not an option and you are forced to test with Maven and Wildfly (or EAP), you can use this:
2019-11-14 13:45:05 +00:00
2017-01-31 13:49:54 +00:00
-Dmaven.surefire.debug=true
2019-11-14 13:45:05 +00:00
2018-09-27 09:24:33 +00:00
Or slightly longer version (that allows you to specify debugging port as well as wait till you attach the debugger):
2019-11-14 13:45:05 +00:00
2020-02-18 17:09:40 +00:00
-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006 -Xnoagent -Djava.compiler=NONE"
2019-11-14 13:45:05 +00:00
and you will be able to attach remote debugger to the test. Unfortunately server and adapter are running in different JVMs, so this won't help to debug those.
2017-01-31 13:49:54 +00:00
2022-11-21 11:10:08 +00:00
### Auth server debugging
2017-06-07 11:44:18 +00:00
2022-11-21 11:10:08 +00:00
See below in the "Quarkus" section.
2017-06-07 11:44:18 +00:00
### JBoss app server debugging
Analogically, there is the same behaviour for JBoss based app server as for auth server. The default port is set to 5006. There are app server properties.
-Dapp.server.debug.port=$PORT
2016-09-21 17:02:22 +00:00
-Dapp.server.debug.suspend=y
2020-05-09 01:49:48 +00:00
When you are debugging cluster adapter tests (For example OIDCAdapterClusterTest) you may use ports 7901 and 7902 for the app
server nodes. Tests are usually using 2 cluster adapter nodes.
2017-01-31 13:49:54 +00:00
2017-03-02 09:27:31 +00:00
## Testsuite logging
It is configured in `testsuite/integration-arquillian/tests/base/src/test/resources/log4j.properties` . You can see that logging of testsuite itself (category `org.keycloak.testsuite` ) is debug by default.
2019-11-14 13:45:05 +00:00
When you run tests with undertow (which is by default), there is logging for Keycloak server and adapter (category `org.keycloak` ) in `info` when you run tests from IDE, but `off` when
2017-03-02 09:27:31 +00:00
you run tests with maven. The reason is that, we don't want huge logs when running mvn build. However using system property `keycloak.logging.level` will override it. This can be used for both IDE or maven.
2019-11-14 13:45:05 +00:00
So for example using `-Dkeycloak.logging.level=debug` will enable debug logging for keycloak server and adapter.
2017-03-02 09:27:31 +00:00
For more fine-tuning of individual categories, you can look at log4j.properties file and temporarily enable/disable them here.
2019-05-20 20:00:26 +00:00
### Wildfly server logging
When using Keycloak on Wildfly/EAP, there is INFO logging level enabled by default for most of the java packages.
You can use those system properties to enable DEBUG logging for particular packages:
* `-Dinfinispan.logging.level=DEBUG` - for package `org.infinispan`
* `-Dorg.keycloak.services.scheduled=DEBUG` - for package `org.keycloak.services.scheduled`
You can use value `TRACE` if you want to enable even TRACE logging.
There is no support for more packages ATM, you need to edit the file `testsuite/integration-arquillian/servers/auth-server/jboss/common/jboss-cli/add-log-level.cli`
and add packages manually.
2017-01-30 16:27:32 +00:00
## Run adapter tests
2018-04-18 11:31:04 +00:00
### Undertow
mvn -f testsuite/integration-arquillian/tests/base/pom.xml \
-Dtest=org.keycloak.testsuite.adapter.**.*Test
2023-04-19 15:42:34 +00:00
-Papp-server-undertow
2019-02-12 09:12:40 +00:00
### Jetty
2022-05-04 13:24:46 +00:00
At the moment we can run the testsuite with Jetty `9.4` .
2019-02-12 09:12:40 +00:00
Each version has its corresponding profile:
* Jetty `9.4` : `app-server-jetty94`
Here's how to run the tests with Jetty `9.4` :
2019-02-13 11:53:45 +00:00
mvn -f testsuite/integration-arquillian/pom.xml \
2019-02-12 09:12:40 +00:00
-Papp-server-jetty94 \
-Dtest=org.keycloak.testsuite.adapter.**.*Test
2017-01-30 16:27:32 +00:00
2018-04-18 11:31:04 +00:00
### Wildfly
2019-11-14 13:45:05 +00:00
2017-01-31 13:49:54 +00:00
# Run tests
2018-04-18 11:31:04 +00:00
mvn -f testsuite/integration-arquillian/pom.xml \
2017-01-31 13:49:54 +00:00
clean install \
2018-08-31 12:21:03 +00:00
-Papp-server-wildfly \
-Dtest=org.keycloak.testsuite.adapter.**
2019-11-14 13:45:05 +00:00
2019-02-13 11:53:45 +00:00
### Tomcat
2019-11-14 13:45:05 +00:00
We run testsuite with Tomcat 7, 8 and 9. For specific versions see properties `${tomcat[7,8,9].version}` in parent [pom.xml ](../../pom.xml ).
2019-02-13 11:53:45 +00:00
To run tests on Tomcat:
````
mvn -f testsuite/integration-arquillian/pom.xml \
clean install \
-Papp-server-tomcat[7,8,9] \
-Dtest=org.keycloak.testsuite.adapter.**
````
2019-11-14 13:45:05 +00:00
2023-05-22 11:26:17 +00:00
### JBoss Fuse 6.3
1) Download JBoss Fuse 6.3 to your filesystem. It can be downloaded from http://origin-repository.jboss.org/nexus/content/groups/m2-proxy/org/jboss/fuse/jboss-fuse-karaf
Assumed you downloaded `jboss-fuse-karaf-6.3.0.redhat-229.zip`
2) Install to your local maven repository and change the properties according to your env (This step can be likely avoided if you somehow configure your local maven settings to point directly to Fuse repo):
mvn install:install-file \
-DgroupId=org.jboss.fuse \
-DartifactId=jboss-fuse-karaf \
-Dversion=6.3.0.redhat-229 \
-Dpackaging=zip \
-Dfile=/mydownloads/jboss-fuse-karaf-6.3.0.redhat-229.zip
3) Prepare Fuse and run the tests (change props according to your environment, versions etc):
# Prepare Fuse server
mvn -f testsuite/integration-arquillian/servers/pom.xml \
clean install \
-Papp-server-fuse63 \
-Dfuse63.version=6.3.0.redhat-229
# Run the Fuse adapter tests
mvn -f testsuite/integration-arquillian/tests/base/pom.xml \
clean install \
-Pauth-server-wildfly \
-Papp-server-fuse63 \
-Dauth.server.ssl.required=false \
-Dadditional.fuse.repos=,$REPO \
-Dtest=*.fuse.*
### JBoss Fuse 7.X
1) Download JBoss Fuse 7 to your filesystem. It can be downloaded from http://origin-repository.jboss.org/nexus/content/groups/m2-proxy/org/jboss/fuse/fuse-karaf (Fuse 7.3 or higher is required)
Assumed you downloaded `fuse-karaf-7.3.0.fuse-730065-redhat-00002.zip`
2) Install to your local maven repository and change the properties according to your env (This step can be likely avoided if you somehow configure your local maven settings to point directly to Fuse repo):
mvn install:install-file \
-DgroupId=org.jboss.fuse \
-DartifactId=fuse-karaf \
-Dversion=7.3.0.fuse-730065-redhat-00002 \
-Dpackaging=zip \
-Dfile=/mydownloads/fuse-karaf-7.3.0.fuse-730065-redhat-00002.zip
3) Prepare Fuse and run the tests (change props according to your environment, versions etc):
# Prepare Fuse server
mvn -f testsuite/integration-arquillian/servers/pom.xml \
clean install \
-Papp-server-fuse7x \
-Dfuse7x.version=7.3.0.fuse-730065-redhat-00002
# Run the Fuse adapter tests
mvn -f testsuite/integration-arquillian/tests/base/pom.xml \
clean test \
-Papp-server-fuse7x \
-Dauth.server.ssl.required=false \
-Dadditional.fuse.repos=,$REPO \
-Dtest=*.fuse.*
### EAP6 with Hawtio
1) Download JBoss EAP 6.4.0.GA zip
2) Install to your local maven repository and change the properties according to your env (This step can be likely avoided if you somehow configure your local maven settings to point directly to EAP repo):
mvn install:install-file \
-DgroupId=org.jboss.as \
-DartifactId=jboss-as-dist \
-Dversion=7.5.21.Final-redhat-1 \
-Dpackaging=zip \
-Dfile=/mydownloads/jboss-eap-6.4.0.zip
3) Download Fuse EAP installer (for example from http://origin-repository.jboss.org/nexus/content/groups/m2-proxy/com/redhat/fuse/eap/fuse-eap-installer/6.3.0.redhat-220/ )
4) Install previously downloaded file manually
mvn install:install-file \
-DgroupId=com.redhat.fuse.eap \
-DartifactId=fuse-eap-installer \
-Dversion=6.3.0.redhat-347 \
-Dpackaging=jar \
-Dfile=/fuse-eap-installer-6.3.0.redhat-347.jar
5) Prepare EAP6 with Hawtio and run the test
# Prepare EAP6 and deploy hawtio
mvn -f testsuite/integration-arquillian/servers \
clean install \
-Pauth-server-wildfly \
-Papp-server-eap6 \
-Dapp.server.jboss.version=7.5.21.Final-redhat-1 \
-Dfuse63.version=6.3.0.redhat-347
# Run the test
mvn -f testsuite/integration-arquillian/tests/base/pom.xml \
clean install \
-Pauth-server-wildfly \
-Papp-server-eap6 \
-Dtest=EAP6Fuse6HawtioAdapterTest
2017-01-30 16:27:32 +00:00
## Migration test
### DB migration test
2023-04-25 15:39:39 +00:00
The `MigrationTest` test will:
- Start database on docker container. Docker/Podman on your laptop is a requirement for this test.
- Start Keycloak old version 19.0.3.
- Import realm and add some data to the database.
- Stop Keycloak 19.0.3.
- Start latest Keycloak, which automatically updates DB from 19.0.3.
- Perform a couple of tests to verify data after the update are correct.
2022-09-14 09:29:53 +00:00
- Stop MariaDB docker container. In case of a test failure, the MariaDB container is not stopped, so you can manually inspect the database.
2022-07-11 10:23:41 +00:00
2023-04-25 15:39:39 +00:00
The first version of Keycloak on Quarkus is version `17.0.0` , but the initial versions have a complete different set of boot options that make co-existance impossible.
Therefore the first version that can be tested is `19.0.3` .
2022-07-11 10:23:41 +00:00
You can execute those tests as follows:
```
2023-04-25 15:39:39 +00:00
export OLD_KEYCLOAK_VERSION=19.0.3
export DATABASE=mariadb
2022-07-11 10:23:41 +00:00
mvn -B -f testsuite/integration-arquillian/pom.xml \
clean install \
2023-04-25 15:39:39 +00:00
-Pjpa,auth-server-quarkus,db-$DATABASE,auth-server-migration \
2022-07-11 10:23:41 +00:00
-Dtest=MigrationTest \
-Dmigration.mode=auto \
-Dmigrated.auth.server.version=$OLD_KEYCLOAK_VERSION \
-Dmigration.import.file.name=migration-realm-$OLD_KEYCLOAK_VERSION.json \
-Dauth.server.ssl.required=false \
2023-04-25 15:39:39 +00:00
-Dauth.server.db.host=localhost
2022-07-11 10:23:41 +00:00
```
2023-04-25 15:39:39 +00:00
The `DATABASE` variable can be: `mariadb` , `mysql` , `postgres` , `mssql` or `oracle` .
As commented `OLD_KEYCLOAK_VERSION` can only be `19.0.3` right now.
2022-09-14 09:29:53 +00:00
For the available versions of old keycloak server, you can take a look to [this directory ](tests/base/src/test/resources/migration-test ) .
2017-04-25 07:18:17 +00:00
### DB migration test with manual mode
2019-11-14 13:45:05 +00:00
Same test as above, but it uses manual migration mode. During startup of the new Keycloak server, Liquibase won't automatically perform DB update, but it
2017-04-25 07:18:17 +00:00
just exports the needed SQL into the script. This SQL script then needs to be manually executed against the DB.
2019-06-03 20:11:47 +00:00
Then there is another startup of the new Keycloak server against the DB, which already has SQL changes applied and
the same test as in `auto` mode (MigrationTest) is executed to test that data are correct.
2017-01-31 13:49:54 +00:00
2019-06-03 20:11:47 +00:00
The test is executed in same way as the "auto" DB migration test with the only difference
that you need to use property `migration.mode` with the value `manual` .
2017-04-25 07:18:17 +00:00
2019-06-03 20:11:47 +00:00
-Dmigration.mode=manual
2017-01-31 13:49:54 +00:00
2019-04-16 13:58:10 +00:00
## Spring Boot adapter tests
2022-02-02 09:47:15 +00:00
Currently, we are testing Spring Boot with three different containers `Tomcat 8` , `Undertow` and `Jetty 9.4` .
2023-11-27 09:58:50 +00:00
We are testing with Spring Boot 2.7. The version is specified in [root pom.xml ](../../pom.xml ) (i.e. see property `spring-boot27.version` ).
To run tests execute following command. Default version of Spring Boot is 2.7.x, there is also a profile `-Pspringboot27` .
2019-04-16 13:58:10 +00:00
```
mvn -f testsuite/integration-arquillian/tests/other/springboot-tests/pom.xml \
clean test \
2022-02-02 09:47:15 +00:00
-Dadapter.container=[tomcat|undertow|jetty94] \
2023-11-27 09:58:50 +00:00
[-Pspringboot27]
2019-04-16 13:58:10 +00:00
```
2018-08-07 09:10:24 +00:00
## Base UI tests
Similarly to Admin Console tests, these tests are focused on UI, specifically on the parts of the server that are accessed by an end user (like Login page, or Account Console).
They are designed to work with mobile browsers (alongside the standard desktop browsers). For details on the supported browsers and their configuration please refer to [Different Browsers chapter ](#different-browsers ).
#### Execution example
```
mvn -f testsuite/integration-arquillian/tests/other/base-ui/pom.xml \
clean test \
-Pandroid \
-Dappium.avd=Nexus_5X_API_27
```
2021-04-15 08:50:33 +00:00
## Disabling features
Some features in Keycloak can be disabled. To run the testsuite with a specific feature disabled use the `auth.server.feature` system property. For example to run the tests with authorization disabled run:
```
mvn -f testsuite/integration-arquillian/tests/base/pom.xml clean test -Pauth-server-wildfly -Dauth.server.feature=-Dkeycloak.profile.feature.authorization=disabled
```
2019-10-18 08:50:28 +00:00
## WebAuthN tests
2021-10-14 11:33:49 +00:00
These tests cover feature W3C WebAuthn, which provides us a lot of possibilities how to include 2FA or MFA to our authentication flows.
For testing the feature, it's necessary to use various devices, which support WebAuthn.
However, we are not able to physically test those devices as in a real world, but we create a virtual authenticators, which should behave the same.
The support for the Virtual Authenticators came from Selenium 4.
2019-10-18 08:50:28 +00:00
#### Run all WebAuthN tests
```
2021-12-06 13:35:23 +00:00
mvn -f testsuite/integration-arquillian/tests/other/pom.xml clean test \
-Dbrowser=chrome -Pwebauthn
2019-10-18 08:50:28 +00:00
```
2021-11-23 09:22:24 +00:00
**Note:** You can also execute those tests with `chromeHeadless` browser in order to not open a new window.
2019-11-14 13:45:05 +00:00
#### Troubleshooting
2021-10-14 11:33:49 +00:00
If you try to run WebAuthn tests with Chrome browser and you see error like:
2019-11-14 13:45:05 +00:00
```
Caused by: java.lang.RuntimeException: Unable to instantiate Drone via org.openqa.selenium.chrome.ChromeDriver(Capabilities):
org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 78
```
It could be because version of your locally installed chrome browser is not compatible with the version of chrome driver. Check what is the version
of your chrome browser (You can open URL `chrome://version/` for the details) and then check available versions from the `https://chromedriver.chromium.org/downloads` .
Then run the WebAuthn tests as above with the additional system property for specifying version of your chrome driver. For example:
```
-DchromeDriverVersion=77.0.3865.40
```
2021-12-06 08:07:41 +00:00
**For Windows**: Probably, you encounter issues with execution those tests on the Windows platform due to Chrome Driver is not available.
In this case, please define the path to the local Chrome Driver by adding this property `-Dwebdriver.chrome.driver=C:/path/to/chromedriver.exe` .
2021-10-14 11:33:49 +00:00
**Warning:** Please, be aware the WebAuthn tests are still in a development phase and there is a high chance those tests will not be stable.
2017-01-30 11:03:37 +00:00
## Social Login
2019-11-14 13:45:05 +00:00
The social login tests require setup of all social networks including an example social user. These details can't be
2017-01-30 11:03:37 +00:00
shared as it would result in the clients and users eventually being blocked. By default these tests are skipped.
2019-11-14 13:45:05 +00:00
To run the full test you need to configure clients in Google, Facebook, GitHub, Twitter, LinkedIn, Microsoft, PayPal and
StackOverflow. See the server administration guide for details on how to do that. You have to use URLs like
`http://localhost:8180/auth/realms/social/broker/google/endpoint` (with `google` replaced by the name
of given provider) as an authorized redirect URL when configuring the client. Further, you also need to create a sample user
2018-04-13 06:09:27 +00:00
that can login to the social network.
2019-11-14 13:45:05 +00:00
2017-01-30 11:03:37 +00:00
The details should be added to a standard properties file. For some properties you can use shared common properties and
2019-11-14 13:45:05 +00:00
override when needed. Or you can specify these for all providers. All providers require at least clientId and
2017-01-30 11:03:37 +00:00
clientSecret (StackOverflow also requires clientKey).
2019-11-14 13:45:05 +00:00
2017-01-30 11:03:37 +00:00
An example social.properties file looks like:
common.username=sampleuser@example.org
common.password=commonpassword
common.profile.firstName=Foo
common.profile.lastName=Bar
common.profile.email=sampleuser@example.org
google.clientId=asdfasdfasdfasdfsadf
google.clientSecret=zxcvzxcvzxcvzxcv
facebook.clientId=asdfasdfasdfasdfsadf
facebook.clientSecret=zxcvzxcvzxcvzxcv
facebook.profile.lastName=Test
2019-11-14 13:45:05 +00:00
In the example above the common username, password and profile are shared for all providers, but Facebook has a
different last name. Profile informations are used for assertion after login, so you have to set them to be same as
user profile information returned by given social login provider for used sample user.
2017-01-30 16:27:32 +00:00
2017-01-30 11:03:37 +00:00
Some providers actively block bots so you need to use a proper browser to test. Either Firefox or Chrome should work.
2017-01-30 16:27:32 +00:00
2017-01-30 11:03:37 +00:00
To run the tests run:
mvn -f testsuite/integration-arquillian/pom.xml \
clean install \
-Pauth-server-wildfly \
-Dtest=SocialLoginTest \
-Dbrowser=chrome \
-Dsocial.config=/path/to/social.properties
2018-04-13 06:09:27 +00:00
To run individual social provider test only you can use option like `-Dtest=SocialLoginTest#linkedinLogin`
2017-01-30 11:03:37 +00:00
## Different Browsers
2018-08-07 09:10:24 +00:00
You can use many different real-world browsers to run the integration tests.
Although technically they can be run with almost every test in the testsuite, they can fail with some of them as the tests often require specific optimizations for given browser. Therefore, only some of the test modules have support to be run with specific browsers.
2018-09-06 11:14:12 +00:00
#### Mozilla Firefox
* **Supported test modules:** `console` , `base-ui`
* **Supported version:** latest stable
2017-08-23 13:36:29 +00:00
* **Driver download required:** [GeckoDriver ](https://github.com/mozilla/geckodriver/releases )
2018-09-06 11:14:12 +00:00
* **Run with:** `-Dbrowser=firefox -Dwebdriver.gecko.driver=path/to/geckodriver` ; optionally you can specify `-Dfirefox_binary=path/to/firefox/binary`
2017-08-23 13:36:29 +00:00
2017-03-10 10:26:21 +00:00
#### Google Chrome
2018-08-07 09:10:24 +00:00
* **Supported test modules:** `console` , `base-ui`
2017-03-10 10:26:21 +00:00
* **Supported version:** latest stable
2018-08-07 09:10:24 +00:00
* **Driver download required:** [ChromeDriver ](https://sites.google.com/a/chromium.org/chromedriver/ ) that corresponds with your version of the browser
2017-03-10 10:26:21 +00:00
* **Run with:** `-Dbrowser=chrome -Dwebdriver.chrome.driver=path/to/chromedriver`
2018-08-07 09:10:24 +00:00
#### Apple Safari
* **Supported test modules:** `base-ui`
* **Supported version:** latest stable
* **Driver download required:** no (the driver is bundled with macOS)
* **Run with:** `-Dbrowser=safari`
2018-09-06 11:14:12 +00:00
#### [DEPRECATED] Mozilla Firefox with legacy driver
* **Supported test modules:** `console`
* **Supported version:** [52 ESR ](http://ftp.mozilla.org/pub/firefox/releases/52.9.0esr/ ) ([Extended Support Release](https://www.mozilla.org/en-US/firefox/organizations/))
* **Driver download required:** no
* **Run with:** `-Dbrowser=firefox -DfirefoxLegacyDriver=true -Dfirefox_binary=path/to/firefox-52-esr/binary`
2017-08-23 13:36:29 +00:00
#### Automatic driver downloads
You can rely on automatic driver downloads which is provided by [Arquillian Drone ](http://arquillian.org/arquillian-extension-drone/#_automatic_download ). To do so just omit the `-Dwebdriver.{browser}.driver` CLI argument when running the tests.
2022-04-22 08:38:41 +00:00
By default latest driver version is always downloaded. To download a specific version, add `-DfirefoxDriverVersion` or `-DchromeDriverVersion` CLI argument.
2017-08-23 13:36:29 +00:00
2018-08-07 09:10:24 +00:00
#### Mobile browsers
The support for testing with the mobile browsers is implemented using the [Appium ](http://appium.io/ ) project.
This means the tests can be run with a real mobile browser in a real mobile OS. However, only emulators/simulators of mobile devices are supported at the moment (no physical devices) in our testsuite.
First, you need to install the Appium server. If you have Node.js and npm installed on your machine, you can do that with: `npm install -g appium` . For further details and requirements please refer to the [official Appium documentation ](http://appium.io/docs/en/about-appium/intro/ ).
The tests will try to start the Appium server automatically but you can do it manually as well (just by executing `appium` ).
To use a mobile browser you need to create a virtual device. The most convenient way to do so is to install the desired platform's IDE - either [Android Studio ](https://developer.android.com/studio/ ) (for Android devices) or [Xcode ](https://developer.apple.com/xcode/ ) (for iOS devices) - then you can create a device (smartphone/tablet) there. For details please refer to documentation of those IDEs.
#### Google Chrome on Android
* **Supported test modules:** `base-ui`
* **Supported host OS:** Windows, Linux, macOS
* **Supported browser version:** latest stable
* **Supported mobile OS version:** Android 7.x, 8.x
* **Run with:** `mvn clean test -Pandroid -Dappium.avd=name_of_the_AVD` where AVD is the name of your Android Virtual Device (e.g. `Nexus_5X_API_27` )
**Tips & tricks:**
* If the AVD name contains any spaces, you need to replace them with underscores when specifying the `-Dappium.avd=...` .
* It's probable that a freshly created device will contain an outdated Chrome version. To update to the latest version (without using the Play Store) you need to download an `.apk` for Chrome and install it with `adb install -r path/to/chrome.apk` .
* Chrome on Android uses ChromeDriver similarly to regular desktop Chrome. The ChromeDriver is bundled with the Appium server. To use a newer ChromeDriver please follow the [Appium documentation ](http://appium.io/docs/en/writing-running-appium/web/chromedriver/ ).
#### Apple Safari on iOS
* **Supported test modules:** `base-ui`
* **Supported host OS:** macOS
* **Supported browser version:** _depends on the mobile OS version_
* **Supported mobile OS version:** iOS 11.x
* **Run with:** `mvn clean test -Pios -Dappium.deviceName=device_name` where the device name is your device identification (e.g. `iPhone X` )
2018-09-27 09:24:33 +00:00
## Disabling TLS (SSL) in the tests
2018-06-05 00:30:09 +00:00
2018-09-27 09:24:33 +00:00
All tests are executed with TLS by default. In order to disable it, you need to switch the `auth.server.ssl.required` property off.
Here's an example:
2018-06-05 00:30:09 +00:00
mvn -f testsuite/integration-arquillian/pom.xml \
clean install \
2018-09-27 09:24:33 +00:00
-Dauth.server.ssl.required=false
2018-07-25 11:31:50 +00:00
2018-09-27 09:24:33 +00:00
NOTE: You can also do it ad-hoc from your IDE, however some tests (like AuthZ or JS Adapter tests) require rebuilt test applications.
so please make sure you rebuild all `testsuite/integration-arquillian` child modules.
2018-07-25 11:31:50 +00:00
2017-05-04 08:42:43 +00:00
## Cluster tests
2019-11-14 13:45:05 +00:00
Cluster tests use 2 backend servers (Keycloak on Wildfly/EAP or Keycloak on Undertow), 1 frontend loadbalancer server node and one shared DB. Invalidation tests don't use loadbalancer.
2017-05-04 08:42:43 +00:00
The browser usually communicates directly with the backend node1 and after doing some change here (eg. updating user), it verifies that the change is visible on node2 and user is updated here as well.
2019-11-14 13:45:05 +00:00
Failover tests use loadbalancer and they require the setup with the distributed infinispan caches switched to have 2 owners (default value is 1 owner). Otherwise failover won't reliably work.
2017-05-04 08:42:43 +00:00
The setup includes:
2018-09-24 08:49:47 +00:00
* a load balancer on embedded Undertow (SimpleUndertowLoadBalancer)
* two clustered nodes of Keycloak server on Wildfly/EAP or on embedded undertow
* shared DB
2020-06-08 20:57:22 +00:00
### Cluster tests with Keycloak on Quarkus
2020-07-22 19:47:47 +00:00
Make sure the `testsuite/integration-arquillian/servers/auth-server/quarkus` module was built as follows:
mvn -f testsuite/integration-arquillian/servers/auth-server/quarkus/pom.xml clean install \
-Pauth-server-cluster-quarkus
2020-06-08 20:57:22 +00:00
Run tests using the `auth-server-cluster-quarkus` profile:
mvn -f testsuite/integration-arquillian/tests/base/pom.xml clean install \
-Pauth-server-cluster-quarkus \
-Dsession.cache.owners=2 \
-Dtest=AuthenticationSessionFailoverClusterTest
2020-07-22 19:47:47 +00:00
Alternatively, you can perform both steps using the following command:
mvn -f testsuite/integration-arquillian/pom.xml clean install \
-Pauth-server-cluster-quarkus \
-Dsession.cache.owners=2 \
-Dtest=AuthenticationSessionFailoverClusterTest
2020-06-08 20:57:22 +00:00
---
**NOTE**
Right now, tests are using a H2 database.
2022-01-17 22:14:12 +00:00
To run tests using a different database such as PostgreSQL, add the following properties into the `testsuite/integration-arquillian/servers/auth-server/quarkus/src/main/content/conf/keycloak.conf` configuration file:
2020-06-08 20:57:22 +00:00
```
# HA using PostgreSQL
2023-03-14 17:42:35 +00:00
%ha.datasource.dialect=org.hibernate.dialect.PostgreSQLDialect
2020-06-08 20:57:22 +00:00
%ha.datasource.driver = org.postgresql.xa.PGXADataSource
%ha.datasource.url = jdbc:postgresql://localhost/keycloak
%ha.datasource.username = keycloak
%ha.datasource.password = password
```
The `ha` profile is automatically set when running clustering tests.
This is temporary and database configuration should be more integrated with the test suite once we review Quarkus configuration.
---
#### Run cluster tests from IDE on Quarkus
Activate the following profiles:
* `auth-server-cluster-quarkus`
Then run any cluster test as usual.
2019-02-15 20:00:46 +00:00
2018-09-24 08:49:47 +00:00
### Cluster tests with Keycloak on embedded undertow
mvn -f testsuite/integration-arquillian/tests/base/pom.xml \
2019-01-31 15:42:27 +00:00
-Pauth-server-cluster-undertow,db-mysql \
2018-09-24 08:49:47 +00:00
-Dsession.cache.owners=2 \
-Dkeycloak.connectionsInfinispan.sessionsOwners=2 \
-Dbackends.console.output=true \
-Dauth.server.log.check=false \
-Dfrontend.console.output=true \
-Dtest=org.keycloak.testsuite.cluster.**.*Test clean install
2017-05-04 08:42:43 +00:00
2019-02-15 20:00:46 +00:00
Note that after update, you might encounter `org.infinispan.commons.CacheException: Initial state transfer timed out for cache org.infinispan.CONFIG`
error in some environments. This can be fixed by adding `-Djava.net.preferIPv4Stack=true` parameter to the command above.
2018-09-24 08:49:47 +00:00
#### Run cluster tests from IDE on embedded undertow
2017-05-04 08:42:43 +00:00
The test uses Undertow loadbalancer on `http://localhost:8180` and two embedded backend Undertow servers with Keycloak on `http://localhost:8181` and `http://localhost:8182` .
You can use any cluster test (eg. AuthenticationSessionFailoverClusterTest) and run from IDE with those system properties (replace with your DB settings):
2019-11-14 13:45:05 +00:00
-Dauth.server.undertow=false -Dauth.server.undertow.cluster=true -Dauth.server.cluster=true
-Dkeycloak.connectionsJpa.url=jdbc:mysql://localhost/keycloak -Dkeycloak.connectionsJpa.driver=com.mysql.jdbc.Driver
-Dkeycloak.connectionsJpa.user=keycloak -Dkeycloak.connectionsJpa.password=keycloak -Dkeycloak.connectionsInfinispan.clustered=true -Dresources
-Dkeycloak.connectionsInfinispan.sessionsOwners=2 -Dsession.cache.owners=2
2017-05-04 08:42:43 +00:00
Invalidation tests (subclass of `AbstractInvalidationClusterTest` ) don't need last two properties.
#### Run cluster environment from IDE
2019-11-14 13:45:05 +00:00
This mode is useful for develop/manual tests of clustering features. You will need to manually run keycloak backend nodes and loadbalancer.
2017-05-04 08:42:43 +00:00
1) Run KeycloakServer server1 with:
2019-11-14 13:45:05 +00:00
-Dkeycloak.connectionsJpa.url=jdbc:mysql://localhost/keycloak -Dkeycloak.connectionsJpa.driver=com.mysql.jdbc.Driver
-Dkeycloak.connectionsJpa.user=keycloak -Dkeycloak.connectionsJpa.password=keycloak -Dkeycloak.connectionsInfinispan.clustered=true
2017-05-04 08:42:43 +00:00
-Dkeycloak.connectionsInfinispan.sessionsOwners=2 -Dresources
and argument: `-p 8181`
2) Run KeycloakServer server2 with same parameters but argument: `-p 8182`
2019-11-14 13:45:05 +00:00
3) Run loadbalancer (class `SimpleUndertowLoadBalancer` ) without arguments and system properties. Loadbalancer runs on port 8180, so you can access Keycloak on `http://localhost:8180/auth`
2017-05-04 08:42:43 +00:00
2017-05-29 07:02:57 +00:00
## Cross-DC tests
2016-07-26 15:47:28 +00:00
2019-11-14 13:45:05 +00:00
Cross-DC tests use 2 data centers, each with one automatically started and one manually controlled backend servers,
2017-09-21 13:01:01 +00:00
and 1 frontend loadbalancer server node that sits in front of all servers.
2017-05-29 07:02:57 +00:00
The browser usually communicates directly with the frontent node and the test controls where the HTTP requests
land by adjusting load balancer configuration (e.g. to direct the traffic to only a single DC).
For an example of a test, see [org.keycloak.testsuite.crossdc.ActionTokenCrossDCTest ](tests/base/src/test/java/org/keycloak/testsuite/crossdc/ActionTokenCrossDCTest.java ).
2020-08-20 14:51:01 +00:00
The cross DC requires setting a profile specifying the used cache server.
Use `cache-server-infinispan` Maven profile for Infinispan 10 or higher, or `cache-server-legacy-infinispan` profile for Infinispan 9 and lower.
Use `cache-server-datagrid` Maven profile for Datagrid 8 or higher, or `cache-server-legacy-datagrid` profile for Datagrid 7 and lower.
2017-05-29 07:02:57 +00:00
2020-08-20 14:51:01 +00:00
To specify a custom Java platform to run the cache server it is possible to set parameter: `-Dcache.server.java.home=<PATH_TO_JDK>` .
### Cache Authentication
With WildFLy/EAP based auth server option it is possible to enable authentication for the HotRod protocol by enabling profile `cache-auth` .
It is possible to specify additional parameters:
- `-Dhotrod.sasl.mechanism` : SASL mechanism used by the hotrod protocol. Default value is `DIGEST-MD5` .
- `-Dkeycloak.connectionsInfinispan.hotrodProtocolVersion` : Version of the hotrod protocol.
Example: `-Pauth-server-wildfly,cache-server-infinispan,cache-auth -Dhotrod.sasl.mechanism=SCRAM-SHA-512`
2021-06-15 23:11:49 +00:00
Note: The cache authentication is not implemented for `SAMLAdapterCrossDCTest` .
2020-08-20 14:51:01 +00:00
Note: The `cache-auth` profile currently doesn't work with the legacy Infinispan/Datagrid modules. See: [KEYCLOAK-18336 ](https://issues.redhat.com/browse/KEYCLOAK-18336 ).
### Data Grid
Since Datagrid does not distribute `infinispan-server` zip artifact, for `cache-server-datagrid` profile it is
necessary to download the artifact and install it to local Maven repository. For Red Hat Data Grid 8 and above, the command is the following:
2019-02-15 20:00:46 +00:00
mvn install:install-file \
2020-08-20 14:51:01 +00:00
-DgroupId=com.redhat -DartifactId=datagrid -Dpackaging=zip -Dclassifier=bin -DgeneratePom=true \
-Dversion=${DATAGRID_VERSION} -Dfile=redhat-datagrid-${DATAGRID_VERSION}-server.zip
For Data Grid 7 and older use: `-Dfile=jboss-datagrid-${DATAGRID_VERSION}-server.zip` .
2019-02-15 20:00:46 +00:00
2020-08-20 14:51:01 +00:00
### Run Cross-DC Tests from Maven
2022-09-30 07:41:57 +00:00
Warning: The Cross-DC tests doesn't work with Quarkus distribution
2020-08-20 14:51:01 +00:00
Note: Profile `auth-servers-crossdc-undertow` currently doesn't work (see [KEYCLOAK-18335 ](https://issues.redhat.com/browse/KEYCLOAK-18335 )).
Use `-Pauth-servers-crossdc-jboss,auth-server-wildfly` instead.
2017-05-29 07:02:57 +00:00
2017-11-08 10:15:02 +00:00
a) Prepare the environment. Compile the infinispan server and eventually Keycloak on JBoss server.
2019-11-14 13:45:05 +00:00
a1) If you want to use **Undertow** based Keycloak container, you just need to download and prepare the
2017-11-08 10:15:02 +00:00
Infinispan/JDG test server via the following command:
2017-06-13 13:25:49 +00:00
2017-10-03 14:19:47 +00:00
`mvn -Pcache-server-infinispan,auth-servers-crossdc-undertow -f testsuite/integration-arquillian -DskipTests clean install`
2017-06-13 13:25:49 +00:00
2020-08-20 14:51:01 +00:00
*note: 'cache-server-infinispan' can be replaced by 'cache-server-datagrid'*
2016-09-21 17:02:22 +00:00
2017-11-08 10:15:02 +00:00
a2) If you want to use **JBoss-based** Keycloak backend containers instead of containers on Embedded Undertow,
you need to prepare both the Infinispan/JDG test server and the Keycloak server on Wildfly/EAP. Run following command:
2017-06-15 09:39:38 +00:00
2017-11-08 10:15:02 +00:00
`mvn -Pcache-server-infinispan,auth-servers-crossdc-jboss,auth-server-wildfly -f testsuite/integration-arquillian -DskipTests clean install`
2017-05-29 07:02:57 +00:00
2020-08-20 14:51:01 +00:00
*note: 'cache-server-infinispan' can be replaced by 'cache-server-datagrid'*
2017-09-21 13:01:01 +00:00
*note: 'auth-server-wildfly' can be replaced by 'auth-server-eap'*
2019-01-31 15:42:27 +00:00
By default JBoss-based containers use TCP-based h2 database. It can be configured to use real DB spawn in Docker, e.g. with following command:
2017-10-04 08:35:42 +00:00
2019-01-31 15:42:27 +00:00
`mvn -Pcache-server-infinispan,auth-servers-crossdc-jboss,auth-server-wildfly,jpa,db-mariadb -f testsuite/integration-arquillian -DskipTests clean install`
2017-10-04 08:35:42 +00:00
2017-11-08 10:15:02 +00:00
b1) For **Undertow** Keycloak backend containers, you can run the tests using the following command (adjust the test specification according to your needs):
2017-09-21 13:01:01 +00:00
2020-06-10 12:50:45 +00:00
`mvn -Pcache-server-infinispan,auth-servers-crossdc-undertow -Dtest=org.keycloak.testsuite.crossdc.**.*Test -pl testsuite/integration-arquillian/tests/base clean install`
2017-05-29 07:02:57 +00:00
2020-08-20 14:51:01 +00:00
*note: 'cache-server-infinispan' can be replaced by 'cache-server-datagrid'*
2017-06-15 09:39:38 +00:00
2017-11-08 10:15:02 +00:00
*note: It can be useful to add additional system property to enable logging:*
2019-11-14 13:45:05 +00:00
2017-11-08 10:15:02 +00:00
`-Dkeycloak.infinispan.logging.level=debug`
2017-09-21 13:01:01 +00:00
2017-11-08 10:15:02 +00:00
b2) For **JBoss-based** Keycloak backend containers, you can run the tests like this:
2017-09-21 13:01:01 +00:00
2020-06-10 12:50:45 +00:00
`mvn -Pcache-server-infinispan,auth-servers-crossdc-jboss,auth-server-wildfly -Dtest=org.keycloak.testsuite.crossdc.**.*Test -pl testsuite/integration-arquillian/tests/base clean install`
2017-09-21 13:01:01 +00:00
2020-08-20 14:51:01 +00:00
*note: 'cache-server-infinispan' can be replaced by 'cache-server-datagrid'*
2017-09-21 13:01:01 +00:00
*note: 'auth-server-wildfly can be replaced by auth-server-eap'*
2017-11-08 10:15:02 +00:00
**note**:
For **JBoss-based** Keycloak backend containers on real DB, the previous commands from (a2) and (b2) can be "squashed" into one. E.g.:
2017-10-04 08:35:42 +00:00
2020-06-10 12:50:45 +00:00
`mvn -f testsuite/integration-arquillian -Dtest=org.keycloak.testsuite.crossdc.**.*Test -Pcache-server-infinispan,auth-servers-crossdc-jboss,auth-server-wildfly,jpa,db-mariadb clean install`
2019-11-14 13:45:05 +00:00
2017-05-29 19:25:44 +00:00
2020-08-20 14:51:01 +00:00
### Run Cross-DC Tests from Intellij IDEA
Note: Profile `auth-servers-crossdc-undertow` which is required in step (3) currently doesn't work (see [KEYCLOAK-18335 ](https://issues.redhat.com/browse/KEYCLOAK-18335 )).
2017-05-29 19:25:44 +00:00
2019-11-14 13:45:05 +00:00
First we will manually download, configure and run infinispan servers. Then we can run the tests from IDE against the servers.
2017-11-08 10:15:02 +00:00
It's more effective during development as there is no need to restart infinispan server(s) among test runs.
2017-05-29 19:25:44 +00:00
2019-11-14 13:45:05 +00:00
1) Download infinispan server of corresponding version (See "infinispan.version" property in [root pom.xml ](../../pom.xml ))
from http://infinispan.org/download/ and go through the steps from the
2019-02-18 08:19:39 +00:00
[Keycloak Cross-DC documentation ](http://www.keycloak.org/docs/latest/server_installation/index.html#jdgsetup ) for setup infinispan servers.
2017-05-29 19:25:44 +00:00
2017-12-05 09:30:19 +00:00
The difference to original docs is, that you need to have JDG servers available on localhost with port offsets. So:
2017-05-29 19:25:44 +00:00
2017-12-05 09:30:19 +00:00
* The TCPPING hosts should be like this:
```xml
< property name = "initial_hosts" > localhost[8610],localhost[9610]"< / property >
2019-11-14 13:45:05 +00:00
```
2017-12-05 09:30:19 +00:00
2019-11-14 13:45:05 +00:00
* The port offset when starting node `jdg1` should be like: `-Djboss.socket.binding.port-offset=1010` and when
2017-12-05 09:30:19 +00:00
starting the `jdg2` server, then `-Djboss.socket.binding.port-offset=2010` . In both cases, the bind address should be just
2019-11-14 13:45:05 +00:00
default `localhost` (In other words, the `-b` switch can be omitted).
2017-12-05 09:30:19 +00:00
So assume you have both Infinispan/JDG servers up and running.
2017-11-08 10:15:02 +00:00
2019-11-14 13:45:05 +00:00
2) Setup MySQL database or some other shared database.
2017-05-29 19:25:44 +00:00
2019-11-14 13:45:05 +00:00
3) Ensure that `org.wildfly.arquillian:wildfly-arquillian-container-managed` is on the classpath when running test. On Intellij, it can be
done by going to: `View` -> `Tool Windows` -> `Maven projects` . Then check profile `cache-server-infinispan` and `auth-servers-crossdc-undertow` .
2017-11-08 10:15:02 +00:00
The tests will use this profile when executed.
2017-08-09 14:38:57 +00:00
2019-11-14 13:45:05 +00:00
4) Run the LoginCrossDCTest (or any other test) with those properties. In shortcut, it's using MySQL database and
2017-05-29 19:25:44 +00:00
connects to the remoteStore provided by infinispan server configured in previous steps:
2019-11-14 13:45:05 +00:00
`-Dauth.server.crossdc=true -Dauth.server.undertow.crossdc=true -Dcache.server.lifecycle.skip=true -Dkeycloak.connectionsInfinispan.clustered=true -Dkeycloak.connectionsJpa.url.crossdc=jdbc:mysql://localhost/keycloak -Dkeycloak.connectionsJpa.driver.crossdc=com.mysql.jdbc.Driver -Dkeycloak.connectionsJpa.user=keycloak -Dkeycloak.connectionsJpa.password=keycloak -Dkeycloak.connectionsInfinispan.clustered=true -Dkeycloak.connectionsInfinispan.remoteStorePort=12232 -Dkeycloak.connectionsInfinispan.remoteStorePort.2=13232 -Dkeycloak.connectionsInfinispan.sessionsOwners=1 -Dsession.cache.owners=1 -Dkeycloak.infinispan.logging.level=debug -Dresources`
**NOTE**: Tests from package `manual` (eg. SessionsPreloadCrossDCTest) needs to be executed with managed containers.
So skip steps 1,2 and add property `-Dmanual.mode=true` and change "cache.server.lifecycle.skip" to false `-Dcache.server.lifecycle.skip=false` or remove it.
2017-11-08 10:15:02 +00:00
5) If you want to debug or test manually, the servers are running on these ports (Note that not all backend servers are running by default and some might be also unused by loadbalancer):
* *Loadbalancer* -> "http://localhost:8180/auth"
* *auth-server-undertow-cross-dc-0_1* -> "http://localhost:8101/auth"
* *auth-server-undertow-cross-dc-0_2-manual* -> "http://localhost:8102/auth"
* *auth-server-undertow-cross-dc-1_1* -> "http://localhost:8111/auth"
2017-05-29 19:25:44 +00:00
2017-11-08 10:15:02 +00:00
* *auth-server-undertow-cross-dc-1_2-manual* -> "http://localhost:8112/auth"
2017-06-15 09:39:38 +00:00
2016-09-21 17:02:22 +00:00
## Run Docker Authentication test
First, validate that your machine has a valid docker installation and that it is available to the JVM running the test.
The exact steps to configure Docker depend on the operating system.
By default, the test will run against Undertow based embedded Keycloak Server, thus no distribution build is required beforehand.
The exact command line arguments depend on the operating system.
2019-03-19 10:41:42 +00:00
2016-09-21 17:02:22 +00:00
### General guidelines
If docker daemon doesn't run locally, or if you're not running on Linux, you may need
2019-11-14 13:45:05 +00:00
to determine the IP of the bridge interface or local interface that Docker daemon can use to connect to Keycloak Server.
2016-09-21 17:02:22 +00:00
Then specify that IP as additional system property called *host.ip* , for example:
2019-11-14 13:45:05 +00:00
2016-09-21 17:02:22 +00:00
-Dhost.ip=192.168.64.1
If using Docker for Mac, you can create an alias for your local network interface:
sudo ifconfig lo0 alias 10.200.10.1/24
2019-11-14 13:45:05 +00:00
2016-09-21 17:02:22 +00:00
Then pass the IP as *host.ip* :
-Dhost.ip=10.200.10.1
2019-11-14 13:45:05 +00:00
If you're running a Docker fork that always lists a host component of an image on `docker images` (e.g. Fedora / RHEL Docker)
2016-09-21 17:02:22 +00:00
use `-Ddocker.io-prefix-explicit=true` argument when running the test.
### Fedora
On Fedora one way to set up Docker server is the following:
# install docker
sudo dnf install docker
# configure docker
# remove --selinux-enabled from OPTIONS
sudo vi /etc/sysconfig/docker
2019-11-14 13:45:05 +00:00
2016-09-21 17:02:22 +00:00
# create docker group and add your user (so docker wouldn't need root permissions)
sudo groupadd docker & & sudo gpasswd -a ${USER} docker & & sudo systemctl restart docker
newgrp docker
2019-11-14 13:45:05 +00:00
2016-09-21 17:02:22 +00:00
# you need to login again after this
2019-11-14 13:45:05 +00:00
2016-09-21 17:02:22 +00:00
# make sure Docker is available
docker pull registry:2
You may also need to add an iptables rule to allow container to host traffic
sudo iptables -I INPUT -i docker0 -j ACCEPT
Then, run the test passing `-Ddocker.io-prefix-explicit=true` :
mvn -f testsuite/integration-arquillian/tests/base/pom.xml \
clean test \
-Dtest=DockerClientTest \
-Dkeycloak.profile.feature.docker=enabled \
-Ddocker.io-prefix-explicit=true
### macOS
On macOS all you need to do is install Docker for Mac, start it up, and check that it works:
# make sure Docker is available
docker pull registry:2
Be especially careful to restart Docker server after every sleep / suspend to ensure system clock of Docker VM is synchronized with
that of the host operating system - Docker for Mac runs inside a VM.
Then, run the test passing `-Dhost.ip=IP` where IP corresponds to en0 interface or an alias for localhost:
mvn -f testsuite/integration-arquillian/tests/base/pom.xml \
clean test \
-Dtest=DockerClientTest \
-Dkeycloak.profile.feature.docker=enabled \
-Dhost.ip=10.200.10.1
### Running Docker test against Keycloak Server distribution
Make sure to build the distribution:
mvn clean install -f distribution
2019-11-14 13:45:05 +00:00
2016-09-21 17:02:22 +00:00
Then, before running the test, setup Keycloak Server distribution for the tests:
mvn -f testsuite/integration-arquillian/servers/pom.xml \
clean install \
2022-09-30 07:41:57 +00:00
-Pauth-server-quarkus
2016-09-21 17:02:22 +00:00
When running the test, add the following arguments to the command line:
2022-09-30 07:41:57 +00:00
-Pauth-server-quarkus -Pauth-server-enable-disable-feature -Dfeature.name=docker -Dfeature.value=enabled
2018-12-06 07:25:01 +00:00
## Java 11 support
Java 11 requires some arguments to be passed to JVM. Those can be activated using `-Pjava11-auth-server` and
2019-04-02 12:47:02 +00:00
`-Pjava11-app-server` profiles, respectively.
2020-06-05 22:23:12 +00:00
2020-06-08 20:57:22 +00:00
## Running tests using Quarkus distribution
### Before Everything
2020-06-05 22:23:12 +00:00
Make sure you build the project using the `quarkus` profile as follows:
mvn -Pdistribution,quarkus clean install
2020-06-08 20:57:22 +00:00
### Running tests
2020-06-05 22:23:12 +00:00
2020-06-08 20:57:22 +00:00
Run tests using the `auth-server-quarkus` profile:
2020-06-05 22:23:12 +00:00
2021-09-17 13:36:02 +00:00
mvn -f testsuite/integration-arquillian/pom.xml clean install -Pauth-server-quarkus
2020-06-08 20:57:22 +00:00
### Debug the Server
Right now, the server runs in a separate process. To debug the server set `auth.server.debug` system property to `true` .
2020-06-05 22:23:12 +00:00
2022-11-21 11:10:08 +00:00
To configure the debugger port, set the `auth.server.debug.port` system property with any valid port number. Default is `5005` .
Note you can also set port for example to `*:5005` or `my-host:5005` to set the bind host.
By default, quarkus server is started in the testsuite and you need to attach remote debugger to it during running. You can
use `auth.server.debug.suspend=y` to "suspend" server startup when running testsuite, which means that server startup is blocked
until debugger is attached.
More info: http://javahowto.blogspot.cz/2010/09/java-agentlibjdwp-for-attaching.html
2020-06-03 08:04:48 +00:00
## Cookies testing
In order to reproduce some specific cookies behaviour in browsers (like SameSite policies or 3rd party cookie blocking),
some subset of tests needs to be ran with different hosts for auth server and app/IdP server in order to simulate third
party contexts. Those hosts must be different from localhost as that host has some special treatment from browsers. At
the same time both hosts must use different domains to be considered cross-origin, e.g. `127.0.0.1.nip.io` and
`127.0.0.1.xip.io` . NOT `app1.127.0.0.1.nip.io` and `app2.127.0.0.1.nip.io` !!
Also, those new cookies policies are currently not yet enabled by default (which will change in the near future). To test
those policies, you need the latest stable Firefox together with `firefox-strict-cookies` profile. This profile sets the
browser to Firefox, configures the proper cookies behavior and makes Firefox to run in the headless mode (which is ok
because this is not UI testing). For debugging purposes you can override the headless mode with `-DfirefoxHeadless=false` .
**Broker tests:**
mvn clean install -f testsuite/integration-arquillian/tests/base \
-Pfirefox-strict-cookies \
-Dtest=**.broker.** \
2020-06-10 14:24:24 +00:00
-Dauth.server.host=[some_host] -Dauth.server.host2=[some_other_host]
**JS adapter tests:**
mvn clean install -f testsuite/integration-arquillian/tests/base \
-Pfirefox-strict-cookies \
-Dtest=**.javascript.** \
2020-06-29 07:03:56 +00:00
-Dauth.server.host=[some_host] -Dauth.server.host2=[some_other_host]
**General adapter tests**
mvn clean install -f testsuite/integration-arquillian/tests/base \
-Pfirefox-strict-cookies \
-Dtest=**.adapter.** \
2020-12-30 14:50:34 +00:00
-Dauth.server.host=[some_host] -Dauth.server.host2=[some_other_host]
2021-09-17 13:36:02 +00:00
## Hostname Tests
2021-11-03 14:40:15 +00:00
For changing the hostname in the hostname tests (e.g. [DefaultHostnameTest ](https://github.com/keycloak/keycloak/blob/main/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/url/DefaultHostnameTest.java )),
2021-09-17 13:36:02 +00:00
we rely on [nip.io ](https://nip.io ) for DNS switching, so tests will work everywhere without fiddling with `etc/hosts` locally.
2023-03-15 20:49:37 +00:00
### Tips & Tricks:
Although it _should_ work in general, you may experience an exception like this:
```
java.lang.RuntimeException: java.net.UnknownHostException: keycloak.127.0.0.1.nip.io: nodename nor servname provided,
or not known at org.keycloak.testsuite.util.OAuthClient.doWellKnownRequest(OAuthClient.java:1032)
at org.keycloak.testsuite.url.DefaultHostnameTest.assertBackendForcedToFrontendWithMatchingHostname(
DefaultHostnameTest.java:226)
...
```
when running these tests on your local machine. This happens when something on your machine or network is blocking DNS queries to [nip.io ](https://nip.io )
In order to avoid using external services for DNS resolution, the tests are executed using a local host file by setting the `-Djdk.net.hosts.file=${project.build.testOutputDirectory}/hosts_file`
system property.
2022-08-09 12:34:05 +00:00
## Running base testsuite with Map storage
To run base testsuite with new storage run the following command (this will execute testsuite with ConcurrentHashMap storage):
```shell
mvn clean install -f testsuite/integration-arquillian/tests/base \
2022-12-16 17:55:31 +00:00
-Pauth-server-quarkus -Pmap-storage-chm
2022-08-09 12:34:05 +00:00
```
### Running tests with JPA Map storage
2022-12-17 07:50:21 +00:00
By default, testing with the profile `map-storage-jpa-postgres` spawns a new Postgres container
with each test execution. The default image used is `postgres:alpine` . To spawn a different
version, use the system property `keycloak.map.storage.postgres.docker.image` .
In a similar way the profile `map-storage-jpa-cockroach` spawns a new CockroachDB container
with each test execution. It uses the official CockroachDB image in the version stated in the
class `CockroachdbContainerTestEnricher` . To spawn a different
version, use the system property `keycloak.map.storage.cockroachdb.docker.image` .
2022-08-09 12:34:05 +00:00
Execute tests:
```shell
mvn clean install -f testsuite/integration-arquillian/tests/base \
2022-12-16 17:55:31 +00:00
-Pmap-storage-jpa-postgres
2022-08-09 12:34:05 +00:00
```
2022-10-20 21:37:04 +00:00
It's also possible to configure tests to connect to an external database, it might be useful
for debugging purposes as the database is not removed after the testsuite run. On the other hand
it'll require manual cleaning between two runs.
PostgreSQL database can be started e.g. by following command:
```shell
podman run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=pass -e POSTGRES_USER=keycloak -e POSTGRES_DB=keycloak -d postgres:alpine
```
To run the tests without spawning the container for you, execute tests with the following command:
```shell
mvn clean install -f testsuite/integration-arquillian/tests/base \
2022-12-16 17:55:31 +00:00
-Pmap-storage-jpa-postgres \
2022-10-20 21:37:04 +00:00
-Dpostgres.start-container=false \
-Dkeycloak.map.storage.connectionsJpa.url=< jdbc_url > \
-Dkeycloak.map.storage.connectionsJpa.user=< user > \
-Dkeycloak.map.storage.connectionsJpa.password=< password >
```
2022-08-09 12:34:05 +00:00
### Running tests with HotRod Map storage
By default, Base testsuite with `map-storage-hotrod` profile spawn a new Infinispan container
with each test execution. To run the tests execute:
```shell
mvn clean install -f testsuite/integration-arquillian/tests/base \
2022-12-16 17:55:31 +00:00
-Pmap-storage-hotrod
2022-08-09 12:34:05 +00:00
```
Note: For running Infinispan server we are using Testcontainer, see section
_Usage of Testcontainers_ for details on how to set up your container engine.
It is also possible, to configure Base testsuite to
connect to an external instance of Infinispan. To do so, execute tests with
the following command:
```shell
mvn clean install -f testsuite/integration-arquillian/tests/base \
2022-12-16 17:55:31 +00:00
-Pmap-storage-hotrod
2022-08-09 12:34:05 +00:00
-Dkeycloak.testsuite.start-hotrod-container=false \
-Dkeycloak.connectionsHotRod.host=< host > \
-Dkeycloak.connectionsHotRod.port=< port > \
-Dkeycloak.connectionsHotRod.username=< username > \
-Dkeycloak.connectionsHotRod.password=< password >
```
### Usage of Testcontainers
Some profiles within model tests require running 3rd party software, for
example, database or Infinispan. For running these we are using
[Testcontainers ](https://www.testcontainers.org/ ). This may require some
additional configuration of your container engine.
#### Podman settings
For more details see the following [Podman guide from Quarkus webpage ](https://quarkus.io/guides/podman ).
Specifically, these steps are required:
```shell
# Enable the podman socket with Docker REST API (only needs to be done once)
systemctl --user enable podman.socket --now
# Set the required environment variables (need to be run everytime or added to profile)
export DOCKER_HOST=unix:///run/user/${UID}/podman/podman.sock
```
Testcontainers are using [ryuk ](https://hub.docker.com/r/testcontainers/ryuk )
to cleanup containers after tests. To make this work with Podman add the
following line to `~/.testcontainers.properties`
```shell
ryuk.container.privileged=true
```
Alternatively, disable usage of ryuk (using this may result in stale containers
still running after tests finish. This is not recommended especially if you are
executing tests from Intellij IDE as it [may not stop ](https://youtrack.jetbrains.com/issue/IDEA-190385 )
the containers created during test run).
```shell
export TESTCONTAINERS_RYUK_DISABLED=true #not recommended - see above!
```
#### Docker settings
To use Testcontainers with Docker it is necessary to
[make Docker available for non-root users ](https://docs.docker.com/engine/install/linux-postinstall/ ).
2023-03-15 20:49:37 +00:00
### Zero downtime tests
By default tests are enabled and runs when `map-storage-hotrod` , `map-storage-postgres` or `map-storage-jpa-cockroach` profile is enabled.
Other may be added in future. It supports both `auth-server-undertow` and `auth-server-quarkus` .
#### Default behavior
1. Before test current `auth-server` is stopped as well as ( postgres/crdb/hotrod ) container.
2. New ( postgres/crdb/hotrod ) container is spawned using testcontainers.
3. Legacy keycloak (latest from https://quay.io/) is started.
4. Test realm is imported into legacy keycloak.
5. Current `auth-server` is started.
#### Notes
- version of legacy keycloak could be specified by `keycloak.legacy.version.zero.downtime` property
- legacy keycloak is by default listening on http://localhost:8091
- when running only zero downtime tests, e.g. locally, it could be speeded up by skipping start of suite
( postgres/crdb/hotrod ) container by `-Dcockroachdb.start-container=false` , `-Dpostgres.start-container=false`
or `-Dkeycloak.testsuite.start-hotrod-container=false` and also suite `auth-server` by `-Dkeycloak.testsuite.skip.start.auth.server=true`
- to run tests with an external instance of ( postgres/crdb/hotrod ) container
`-Dpostgres.start-container-for-zero-downtime=false` ; `-Dcockroachdb.start-container-for-zero-downtime` ; `-Dstart-hotrod-container-for-zero-downtime`
together with appropriate properties (see sections above).
2022-10-17 21:33:22 +00:00
## FIPS 140-2 testing
2023-02-22 11:47:15 +00:00
### Unit tests
```
mvn clean install -f crypto/fips1402
```
To run unit tests with the BouncyCastle approved mode, which is more strict in the used crypto algorithms:
```
mvn clean install -f crypto/fips1402 -Dorg.bouncycastle.fips.approved_only=true
```
### Integration tests
On the FIPS enabled platform with FIPS enabled OpenJDK 17, you can run this to test against a Keycloak server on Quarkus
with FIPS 140-2 integration enabled
2022-10-17 21:33:22 +00:00
```
mvn -B -f testsuite/integration-arquillian/pom.xml \
clean install \
-Pauth-server-quarkus,auth-server-fips140-2 \
-Dcom.redhat.fips=false
```
NOTE 1: The property `com.redhat.fips` is needed so that testsuite itself is executed in the JVM with FIPS disabled. However
most important part is that Keycloak itself is running on the JVM with FIPS enabled. You can check log from server startup and
there should be messages similar to those:
```
2022-10-11 19:34:29,521 DEBUG [org.keycloak.common.crypto.CryptoIntegration] (main) Using the crypto provider: org.keycloak.crypto.fips.FIPS1402Provider
2022-10-11 19:34:31,072 TRACE [org.keycloak.common.crypto.CryptoIntegration] (main) Java security providers: [
2023-02-22 11:47:15 +00:00
KC(BCFIPS version 1.000203, FIPS-JVM: enabled) version 1.0 - class org.keycloak.crypto.fips.KeycloakFipsSecurityProvider,
2022-10-17 21:33:22 +00:00
BCFIPS version 1.000203 - class org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider,
BCJSSE version 1.001202 - class org.bouncycastle.jsse.provider.BouncyCastleJsseProvider,
]
```
2023-01-12 17:24:23 +00:00
### BCFIPS approved mode
For running testsuite with server using BCFIPS approved mode, those additional properties should be added when running tests:
```
-Dauth.server.fips.mode=strict \
-Dauth.server.supported.keystore.types=BCFKS \
2023-01-26 12:57:09 +00:00
-Dauth.server.keystore.type=bcfks \
2023-01-23 13:42:43 +00:00
-Dauth.server.supported.rsa.key.sizes=2048,4096
2023-01-12 17:24:23 +00:00
```
The log should contain `KeycloakFipsSecurityProvider` mentioning "Approved mode". Something like:
```
2023-02-14 17:57:18 +00:00
KC(BCFIPS version 1.000203 Approved Mode, FIPS-JVM: enabled) version 1.0 - class org.keycloak.crypto.fips.KeycloakFipsSecurityProvider,
2023-01-12 17:24:23 +00:00
```