Keycloak
Keycloak Arquillian Integration Testsuite
Overview
For overview see the Modules Overview section at the bottom of this README.
How to run tests
See the file HOW-TO-RUN.md .
Container Lifecycles
Auth Server
Keycloak server is automatically started by the testsuite on the
event and stopped on
event.
By default the server runs in embedded Undertow.
Cluster Setup
The cluster setup for server can be enabled by activating profile
.
The cluster setup is not supported for server on Undertow.
The setup includes:
- a
load balancer on Quarkusmod_cluster - two clustered nodes of Keycloak server on Quarkus
Clustering tests require MULTICAST to be enabled on machine's
network interface.
This can be done by running the following commands under root privileges:
route add -net 224.0.0.0 netmask 240.0.0.0 dev lo
ifconfig lo multicast
Quarkus
To run the tests against a Quarkus Server:
mvn -Pauth-server-quarkus -Dauth.server.ssl.required=false clean verify
NOTE: At the moment the Quarkus server does not support SSL, thus it must be disabled.
To debug the server:
mvn -Pauth-server-quarkus -Dauth.server.ssl.required=false -Dauth.server.debug=true clean verify
By default, debug port is
. To change it, set the
system property to another port.
NOTE: Not all tests are passing, this is a working in progress.
App Servers / Adapter Tests
Lifecycle of application server is always tied to a particular TestClass.
Each adapter test class is annotated by one or more
annotations
that links it to a particular Arquillian container.
The
then ensures the corresponding server is started during
event and stopped during
event for that particular test class.
The app-servers with installed Keycloak adapter are prepared in
submodules, activated by
or
More details.
NOTE: Some corresponding adapter test modules are in
submodules, and are activated by the same profiles. It will be tranferred into base testsuite.
SuiteContext and TestContext
These objects are injected into
class so they can be used everywhere.
They can be used to get information about the tested containers, and to store information that won't survive across test classes or test methods.
(Arquillian creates a new instance of test class for each test method run, so all data in the fields is always lost.)
REST Testing
The
has an initialized instance of AdminClient. Subclasses can use it to access any REST subresources.
UI Testing
Page Objects
Page Objects are used by tests to access and operate on UI.
They can be injected using annotation
provided by the Arquillian Graphene extension.
The base class for all page objects used throughout this Arquillian testsuite is
, and it's subclass
.
For the page objects for the adapter test apps the URLs are injected automatically by Arquillian depending on actual URL of the deployed app/example.
For the pages under the
context the URL is only injected to the
page object,
and the URL hierarchy is modeled by the class inheritance hierarchy (subclasses/extending of
).
Browsers
The default browser for UI testing is
which is used for fast "headless" testing.
Other browsers can be selected with the
property, for example
.
See HOW-TO-RUN.md and Arquillian Drone documentation for more details.
Utils classes
UI testing is sometimes very tricky due to different demands and behaviours of different browsers and their drivers. So there are some very useful Utils classes which are already dealing with some common stability issues while testing. See
,
and
classes in the Base Testsuite.
Test Modules
Base Testsuite
The base testsuite contains custom Arquillian extensions and most functional tests. The other test modules depend on this module.
Base UI Testsuite
Contains most of the UI-focused tests that don't cover Admin Console, i.e. all the parts of the server that are intended to be accessed by an end user. The tests placed here are exclusively covering the UI functionality of the server, i.e. checking if all the page elements are visible, links clickable etc., and are focused on simplicity and stability. This differs them from other integration tests and Admin Console UI tests.
They are designed to work with most of the desktop browsers (HtmlUnit included) as well as mobile browsers (Chrome on Android and Safari on iOS). Please see HOW-TO-RUN.md for details on supported browsers.
The tests are place in a separate module (
) and are disabled by default.
Types of adapter tests
- Using custom test servlets
- Using example demo apps from
modules.keycloak/examples
Relative vs Non-relative scenario
The test suite can handle both types. It automatically modifies imported test realms and deployments' adapter configs based on scenario type.
Scenario | Description | Realm config (server side) | Adapter config (client side) |
---|---|---|---|
Relative | auth server == app server | client , and can be relative | can be relative |
Non-relative | auth server != app server | client , and need to include FQDN of the app server | needs to include FQDN of the auth server |
Adapter Config Mode
Provided - InWIP
usingstandalone.xml
. Wildfly only.secure-deployment- Bundled - In the deployed war in
. Default./WEB-INF/keycloak.json
Custom Arquillian Extensions
Custom extensions are registered in
.
MultipleContainersExtension
- Replaces Arquillian's default container handling.
- Allows to manage multiple container instances of different types within a single test run.
- Allows to skip loading disabled containers based on
config property inenabled
.arquillian.xml
KeycloakArquillianExtension
- Handles lifecycle of auth server and migrated auth server.AuthServerTestEnricher
- Handles lifecycles of app servers.AppServerTestEnricher
- Custom container controller for JAX-RS-enabled Undertow with Keycloak Server.CustomUndertowContainer
- Modifies adapter configs before test apps are deployed.DeploymentArchiveProcessor
- Ensures all test app deployments are targeted at app server containers.DeploymentTargetModifier
- Fixes URLs injected by Arquillian Graphene which contain valueURLProvider
instead of required127.0.0.1
.localhost
Modules Overview
integration-arquillian
│
├──servers (preconfigured test servers)
│ │
│ ├──auth-server
│ │ ├──jboss (wildfly/eap)
│ │ └──undertow (arq. extension)
│ │
│ ├──app-server
│ │ ├──jboss (wildfly/eap/as)
│ │ ├──tomcat
│ │ └──karaf
│ │
│ └──wildfly-balancer
│
└──tests (common settings for all test modules)
│
├──base (custom ARQ extensions + base functional tests)
│
└──other (common settings for all test modules dependent on base)
│
├──adapters (common settings for all adapter test modules - will be moved into base)
│ ├──jboss
│ └──karaf
│
├──console
├──console_no_users
└──...