Merge pull request #4554 from vramik/KEYCLOAK-5672

KEYCLOAK-5672 rewrite server-config-migration module to use offline mode
This commit is contained in:
Pavel Drozd 2017-10-17 07:42:29 +02:00 committed by GitHub
commit 9c16a58d52
12 changed files with 490 additions and 347 deletions

View file

@ -229,14 +229,24 @@
</executions> </executions>
</plugin> </plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>auth-servers-crossdc-undertow</id>
<properties>
<skip.clean.second.cache>false</skip.clean.second.cache>
</properties>
</profile>
<profile>
<id>auth-servers-crossdc-jboss</id>
<properties>
<skip.clean.second.cache>false</skip.clean.second.cache>
<skip.copy.auth.crossdc.nodes>false</skip.copy.auth.crossdc.nodes>
</properties>
</profile>
</profiles>
</project> </project>

View file

@ -42,6 +42,10 @@
<module>springboot-tests</module> <module>springboot-tests</module>
</modules> </modules>
<properties>
<skip.unpack.test.resources>false</skip.unpack.test.resources>
</properties>
<build> <build>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
@ -55,6 +59,7 @@
<goal>unpack</goal> <goal>unpack</goal>
</goals> </goals>
<configuration> <configuration>
<skip>${skip.unpack.test.resources}</skip>
<artifactItems> <artifactItems>
<artifactItem> <artifactItem>
<groupId>org.keycloak.testsuite</groupId> <groupId>org.keycloak.testsuite</groupId>
@ -78,6 +83,7 @@
<goal>copy-resources</goal> <goal>copy-resources</goal>
</goals> </goals>
<configuration> <configuration>
<skip>${skip.add.user.json}</skip>
<outputDirectory>${auth.server.config.dir}</outputDirectory> <outputDirectory>${auth.server.config.dir}</outputDirectory>
<resources> <resources>
<resource> <resource>

View file

@ -0,0 +1,56 @@
# Keycloak Server Config Migration Testsuite
## Test workflow
There are performed several steps before actual test is executed. The steps are divided into different maven lifecycle phases to make sure it goes in specified wanted order.
### `process-resources`
Unpack clean keycloak-server-dist
### `compile`
Copy standalone/domain resources to `${jbossHome}/standalone/configuration` and `${jbossHome}/domain/configuration`
### `process-classes`
`maven-exec-plugin` is used to read current master configs and saves the output to `${project.build.directory}/master-${config.name}.txt`
### `generate-test-sources`
Files `${jbossHome}/standalone/configuration/keycloak-server.json` and `${jbossHome}/domain/configuration/keycloak-server.json` are created.
Configuration files (`standalone.xml`, `standalone-ha.xml`, `domain.xml`, `host-master.xml`) are overwritten by those from previous version.
### `process-test-sources`
Migration scripts are applied using **offline mode**. Temporary data are removed.
### `generate-test-resources`
`wildfly-maven-plugin` is used to start and shutdown container with different configs. It is done to let subsystems to upgrade themselves during first run.
### `process-test-resources`
`maven-exec-plugin` is used to read migrated configs and saves the output to `${project.build.directory}/migrated-${config.name}.txt`
### `default-test`
`org.keycloak.test.config.migrationConfigMigrationTest` is executed. It compares generated outputs from ${project.build.directory}
If config outputs don't equal to each other, **by default** the test will compare outputs more deeply to get more readable output. It fails on first found difference.
This can be overwritten by adding property: `-Dget.simple.full.comparison=true` to the test command. In that case it'll perform assert on the two config outputs.
## Properties
### maven
* jbossHome
* default: `${project.build.directory}/keycloak-${project.version}`
* specifies path to jbossHome dir
* migrated.version
* default: `1.8.1`
* specifies version it is migrated from
* master.version
* default: `${project.version}`
* specifies version it is migrated to
## How to run tests
note: `keycloak-server-dist` module has to be build first (`mvn install -f keycloak/pom.xml -Pdistribution`)
* `mvn clean install` tests migration from 1.8.1.Final to current master. It goes thru whole test workflow. Deep comparison is done.
* `mvn clean install -Dget.simple.full.comparison=true` does assert on outputs instead of deep comparison.
* `mvn clean process-test-sources -Dskip.rename.configs=true` applies migration scripts to current master. It can be used to make sure the current keycloak version doesn't break the scripts.
* `mvn clean install -Dskip.rename.configs=true` applies scripts to current master **and** verifies the scripts doesn't actually change anything.

View file

@ -34,8 +34,19 @@
<name>Keycloak Migration TestSuite For Server Config</name> <name>Keycloak Migration TestSuite For Server Config</name>
<properties> <properties>
<skip.add.user.json>true</skip.add.user.json>
<skip.unpack.test.resources>true</skip.unpack.test.resources>
<skip.rename.configs>false</skip.rename.configs>
<jbossHome>${project.build.directory}/keycloak-${project.version}</jbossHome> <jbossHome>${project.build.directory}/keycloak-${project.version}</jbossHome>
<migrated.version>1.8.1</migrated.version> <migrated.version>1.8.1</migrated.version>
<master.version>${project.version}</master.version>
<!-- example how to test 'product' config migration
<jbossHome>${project.build.directory}/rh-sso-7.1</jbossHome>
<migrated.version>1.9.8.Final-redhat-1</migrated.version>
<master.version>3.3.0.CR2-redhat-1</master.version>
-->
</properties> </properties>
<dependencies> <dependencies>
@ -64,7 +75,7 @@
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<id>unpack</id> <id>unpack-keycloak-server-dist</id>
<phase>process-resources</phase> <phase>process-resources</phase>
<goals> <goals>
<goal>unpack</goal> <goal>unpack</goal>
@ -74,7 +85,7 @@
<artifactItem> <artifactItem>
<groupId>org.keycloak</groupId> <groupId>org.keycloak</groupId>
<artifactId>keycloak-server-dist</artifactId> <artifactId>keycloak-server-dist</artifactId>
<version>${project.version}</version> <version>${master.version}</version>
<type>zip</type> <type>zip</type>
<overWrite>true</overWrite> <overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory> <outputDirectory>${project.build.directory}</outputDirectory>
@ -89,7 +100,7 @@
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<id>copy-standalone</id> <id>copy-standalone-resources</id>
<phase>compile</phase> <phase>compile</phase>
<goals> <goals>
<goal>copy-resources</goal> <goal>copy-resources</goal>
@ -106,7 +117,7 @@
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>copy-domain</id> <id>copy-domain-resources</id>
<phase>compile</phase> <phase>compile</phase>
<goals> <goals>
<goal>copy-resources</goal> <goal>copy-resources</goal>
@ -126,350 +137,312 @@
</plugin> </plugin>
<plugin> <plugin>
<groupId>com.coderplus.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions> <executions>
<execution> <execution>
<id>rename-keycloak-server-json-standalone</id> <id>rename-migrated-resources</id>
<phase>generate-test-sources</phase> <phase>generate-test-sources</phase>
<goals> <goals>
<goal>rename</goal> <goal>run</goal>
</goals> </goals>
<configuration> <configuration>
<sourceFile>${jbossHome}/standalone/configuration/keycloak-server-${migrated.version}.json</sourceFile> <skip>${skip.rename.configs}</skip>
<destinationFile>${jbossHome}/standalone/configuration/keycloak-server.json</destinationFile> <target>
</configuration> <echo>For migration from versions above 2.1.0 there is no keycloak-server.json supported.</echo>
</execution> <move file="${jbossHome}/standalone/configuration/keycloak-server-${migrated.version}.json"
<execution> tofile="${jbossHome}/standalone/configuration/keycloak-server.json"
<id>rename-keycloak-server-json-domain</id> verbose="true"
<phase>generate-test-sources</phase> failonerror="false"/>
<goals> <move file="${jbossHome}/domain/configuration/keycloak-server-${migrated.version}.json"
<goal>rename</goal> tofile="${jbossHome}/domain/configuration/keycloak-server.json"
</goals> verbose="true"
<configuration> failonerror="false"/>
<sourceFile>${jbossHome}/domain/configuration/keycloak-server-${migrated.version}.json</sourceFile> <move file="${jbossHome}/standalone/configuration/standalone-${migrated.version}.xml"
<destinationFile>${jbossHome}/domain/configuration/keycloak-server.json</destinationFile> tofile="${jbossHome}/standalone/configuration/standalone.xml"
verbose="true"/>
<move file="${jbossHome}/standalone/configuration/standalone-ha-${migrated.version}.xml"
tofile="${jbossHome}/standalone/configuration/standalone-ha.xml"
verbose="true"/>
<move file="${jbossHome}/domain/configuration/domain-${migrated.version}.xml"
tofile="${jbossHome}/domain/configuration/domain.xml"
verbose="true"/>
<move file="${jbossHome}/domain/configuration/host-master-${migrated.version}.xml"
tofile="${jbossHome}/domain/configuration/host-master.xml"
verbose="true"/>
</target>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>maven-replacer-plugin</artifactId> <artifactId>exec-maven-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<id>replaceTokens</id> <id>read-master-standalone</id>
<phase>process-test-sources</phase> <phase>process-classes</phase>
<goals> <goals>
<goal>replace</goal> <goal>exec</goal>
</goals> </goals>
<configuration> <configuration>
<!-- Comment out embeds. For wildfly-maven-plugin, <executable>./jboss-cli.sh</executable>
CLI commands have to execute against a running <workingDirectory>${jbossHome}/bin</workingDirectory>
server. BTW, CLI Comments only work if the # is in the <arguments>
first column. <argument>--file=${project.build.directory}/classes/cli/read-standalone.cli</argument>
--> </arguments>
<replacements> <outputFile>${project.build.directory}/master-standalone.txt</outputFile>
<replacement>
<token>embed-server</token>
<value>#embed-server</value>
</replacement>
<replacement>
<token>embed-host-controller</token>
<value>#embed-host-controller</value>
</replacement>
<replacement>
<token>:migrate-json(file=$pathToJson)</token>
<value>:migrate-json</value>
</replacement>
</replacements>
</configuration> </configuration>
</execution> </execution>
</executions> <execution>
<id>read-master-standalone-ha</id>
<phase>process-classes</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration> <configuration>
<regex>false</regex> <executable>./jboss-cli.sh</executable>
<basedir>${jbossHome}</basedir> <workingDirectory>${jbossHome}/bin</workingDirectory>
<filesToInclude>bin\migrate**.cli</filesToInclude> <arguments>
<argument>--file=${project.build.directory}/classes/cli/read-standalone-ha.cli</argument>
</arguments>
<outputFile>${project.build.directory}/master-standalone-ha.txt</outputFile>
</configuration> </configuration>
</plugin> </execution>
<execution>
<plugin> <id>read-master-domain-standalone</id>
<groupId>org.wildfly.plugins</groupId> <phase>process-classes</phase>
<artifactId>wildfly-maven-plugin</artifactId> <goals>
<goal>exec</goal>
</goals>
<configuration> <configuration>
<skip>false</skip> <executable>./jboss-cli.sh</executable>
<jbossHome>${jbossHome}</jbossHome> <workingDirectory>${jbossHome}/bin</workingDirectory>
<port>10990</port> <arguments>
<argument>--file=${project.build.directory}/classes/cli/read-domain-standalone.cli</argument>
</arguments>
<outputFile>${project.build.directory}/master-domain-standalone.txt</outputFile>
</configuration> </configuration>
</execution>
<execution>
<id>read-master-domain-clustered</id>
<phase>process-classes</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./jboss-cli.sh</executable>
<workingDirectory>${jbossHome}/bin</workingDirectory>
<arguments>
<argument>--file=${project.build.directory}/classes/cli/read-domain-clustered.cli</argument>
</arguments>
<outputFile>${project.build.directory}/master-domain-clustered.txt</outputFile>
</configuration>
</execution>
<executions>
<!-- standalone.xml -->
<execution> <execution>
<id>migrate-standalone</id> <id>migrate-standalone</id>
<phase>generate-test-resources</phase> <phase>process-test-sources</phase>
<goals> <goals>
<goal>start</goal> <goal>exec</goal>
<goal>execute-commands</goal>
<goal>shutdown</goal>
</goals> </goals>
<configuration> <configuration>
<serverConfig>standalone-${migrated.version}.xml</serverConfig> <executable>./jboss-cli.sh</executable>
<java-opts> <workingDirectory>${jbossHome}/bin</workingDirectory>
<java-opt>-Djboss.socket.binding.port-offset=1000</java-opt> <arguments>
</java-opts> <argument>--file=migrate-standalone.cli</argument>
<execute-commands> </arguments>
<scripts>
<script>${jbossHome}/bin/migrate-standalone.cli</script>
</scripts>
</execute-commands>
</configuration> </configuration>
</execution> </execution>
<execution>
<id>migrate-standalone-ha</id>
<phase>process-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./jboss-cli.sh</executable>
<workingDirectory>${jbossHome}/bin</workingDirectory>
<arguments>
<argument>--file=migrate-standalone-ha.cli</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>migrate-domain-standalone</id>
<phase>process-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./jboss-cli.sh</executable>
<workingDirectory>${jbossHome}/bin</workingDirectory>
<arguments>
<argument>--file=migrate-domain-standalone.cli</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>migrate-domain-clustered</id>
<phase>process-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./jboss-cli.sh</executable>
<workingDirectory>${jbossHome}/bin</workingDirectory>
<arguments>
<argument>--file=migrate-domain-clustered.cli</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>remove-temp-data-standalone</id>
<phase>process-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>rm</executable>
<workingDirectory>${jbossHome}/standalone</workingDirectory>
<arguments>
<argument>-rf</argument>
<argument>data</argument>
<argument>log</argument>
<argument>tmp</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>remove-temp-data-domain</id>
<phase>process-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>rm</executable>
<workingDirectory>${jbossHome}/domain</workingDirectory>
<arguments>
<argument>-rf</argument>
<argument>data/auto-start</argument>
<argument>data/kernel</argument>
<argument>log</argument>
<argument>servers</argument>
</arguments>
</configuration>
</execution>
<execution> <execution>
<id>read-migrated-standalone</id> <id>read-migrated-standalone</id>
<phase>process-test-resources</phase> <phase>process-test-resources</phase>
<goals> <goals>
<goal>start</goal> <goal>exec</goal>
<goal>execute-commands</goal>
<goal>shutdown</goal>
</goals> </goals>
<configuration> <configuration>
<serverConfig>standalone-${migrated.version}.xml</serverConfig> <executable>./jboss-cli.sh</executable>
<java-opts> <workingDirectory>${jbossHome}/bin</workingDirectory>
<java-opt>-Djboss.socket.binding.port-offset=1000</java-opt> <arguments>
</java-opts> <argument>--file=${project.build.directory}/classes/cli/read-standalone.cli</argument>
<execute-commands> </arguments>
<commands> <outputFile>${project.build.directory}/migrated-standalone.txt</outputFile>
<command>echo Reading subsystems for migrated standalone-${migrated.version}.xml</command>
<command>/subsystem=*/:read-resource(recursive=true)>${project.build.directory}/migrated-standalone-${migrated.version}.txt</command>
</commands>
</execute-commands>
</configuration>
</execution>
<execution>
<id>read-master-standalone</id>
<phase>process-test-resources</phase>
<goals>
<goal>start</goal>
<goal>execute-commands</goal>
<goal>shutdown</goal>
</goals>
<configuration>
<serverConfig>standalone.xml</serverConfig>
<java-opts>
<java-opt>-Djboss.socket.binding.port-offset=1000</java-opt>
</java-opts>
<execute-commands>
<commands>
<command>echo Reading subsystems for master standalone.xml</command>
<command>/subsystem=*/:read-resource(recursive=true)>${project.build.directory}/master-standalone.txt</command>
</commands>
</execute-commands>
</configuration>
</execution>
<!-- standalone-ha.xml -->
<execution>
<id>migrate-standalone-ha</id>
<phase>generate-test-resources</phase>
<goals>
<goal>start</goal>
<goal>execute-commands</goal>
<goal>shutdown</goal>
</goals>
<configuration>
<serverConfig>standalone-ha-${migrated.version}.xml</serverConfig>
<java-opts>
<java-opt>-Djboss.socket.binding.port-offset=1000</java-opt>
</java-opts>
<execute-commands>
<scripts>
<script>${jbossHome}/bin/migrate-standalone-ha.cli</script>
</scripts>
</execute-commands>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>read-migrated-standalone-ha</id> <id>read-migrated-standalone-ha</id>
<phase>process-test-resources</phase> <phase>process-test-resources</phase>
<goals> <goals>
<goal>start</goal> <goal>exec</goal>
<goal>execute-commands</goal>
<goal>shutdown</goal>
</goals> </goals>
<configuration> <configuration>
<serverConfig>standalone-ha-${migrated.version}.xml</serverConfig> <executable>./jboss-cli.sh</executable>
<java-opts> <workingDirectory>${jbossHome}/bin</workingDirectory>
<java-opt>-Djboss.socket.binding.port-offset=1000</java-opt> <arguments>
</java-opts> <argument>--file=${project.build.directory}/classes/cli/read-standalone-ha.cli</argument>
<execute-commands> </arguments>
<commands> <outputFile>${project.build.directory}/migrated-standalone-ha.txt</outputFile>
<command>echo Reading subsystems for migrated standalone-ha-${migrated.version}.xml</command>
<command>/subsystem=*/:read-resource(recursive=true)>${project.build.directory}/migrated-standalone-ha-${migrated.version}.txt</command>
</commands>
</execute-commands>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>read-master-standalone-ha</id> <id>read-migrated-domain-standalone</id>
<phase>process-test-resources</phase> <phase>process-test-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./jboss-cli.sh</executable>
<workingDirectory>${jbossHome}/bin</workingDirectory>
<arguments>
<argument>--file=${project.build.directory}/classes/cli/read-domain-standalone.cli</argument>
</arguments>
<outputFile>${project.build.directory}/migrated-domain-standalone.txt</outputFile>
</configuration>
</execution>
<execution>
<id>read-migrated-domain-clustered</id>
<phase>process-test-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./jboss-cli.sh</executable>
<workingDirectory>${jbossHome}/bin</workingDirectory>
<arguments>
<argument>--file=${project.build.directory}/classes/cli/read-domain-clustered.cli</argument>
</arguments>
<outputFile>${project.build.directory}/migrated-domain-clustered.txt</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<jbossHome>${jbossHome}</jbossHome>
</configuration>
<executions>
<execution>
<id>start-stop-standalone</id>
<phase>generate-test-resources</phase>
<goals>
<goal>start</goal>
<goal>shutdown</goal>
</goals>
<configuration>
<serverConfig>standalone.xml</serverConfig>
</configuration>
</execution>
<execution>
<id>start-stop-standalone-ha</id>
<phase>generate-test-resources</phase>
<goals> <goals>
<goal>start</goal> <goal>start</goal>
<goal>execute-commands</goal>
<goal>shutdown</goal> <goal>shutdown</goal>
</goals> </goals>
<configuration> <configuration>
<serverConfig>standalone-ha.xml</serverConfig> <serverConfig>standalone-ha.xml</serverConfig>
<java-opts>
<java-opt>-Djboss.socket.binding.port-offset=1000</java-opt>
</java-opts>
<execute-commands>
<commands>
<command>echo Reading subsystems for master standalone-ha.xml</command>
<command>/subsystem=*/:read-resource(recursive=true)>${project.build.directory}/master-standalone-ha.txt</command>
</commands>
</execute-commands>
</configuration> </configuration>
</execution> </execution>
<!-- domain.xml -->
<execution> <execution>
<id>migrate-domain</id> <id>start-stop-domain</id>
<phase>generate-test-resources</phase> <phase>generate-test-resources</phase>
<goals> <goals>
<goal>start</goal> <goal>start</goal>
<goal>execute-commands</goal>
<goal>shutdown</goal>
</goals>
<configuration>
<serverType>DOMAIN</serverType>
<domainConfig>domain-${migrated.version}.xml</domainConfig>
<server-args>
<server-arg>--host-config=host-master-${migrated.version}.xml</server-arg>
</server-args>
<!-- jboss.server.config.dir is set to trick the migrate-json operation into -->
<!-- finding keycloak-server.json. Normally, that would be uploaded using -->
<!-- a file=<localfile> parameter. -->
<!-- Ports are set to avoid conflicts with other server instances. -->
<java-opts>
<java-opt>-Djboss.management.http.port=10990</java-opt>
<java-opt>-Djboss.management.native.port=10999</java-opt>
<java-opt>-Djboss.server.config.dir=${jbossHome}/domain/configuration/</java-opt>
</java-opts>
<execute-commands>
<scripts>
<script>${jbossHome}/bin/migrate-domain-standalone.cli</script>
<script>${jbossHome}/bin/migrate-domain-clustered.cli</script>
</scripts>
</execute-commands>
</configuration>
</execution>
<execution>
<id>read-migrated-domain</id>
<phase>process-test-resources</phase>
<goals>
<goal>start</goal>
<goal>execute-commands</goal>
<goal>shutdown</goal>
</goals>
<configuration>
<serverType>DOMAIN</serverType>
<domainConfig>domain-${migrated.version}.xml</domainConfig>
<server-args>
<server-arg>--host-config=host-master-${migrated.version}.xml</server-arg>
</server-args>
<java-opts>
<java-opt>-Djboss.management.http.port=10990</java-opt>
<java-opt>-Djboss.management.native.port=10999</java-opt>
</java-opts>
<execute-commands>
<commands>
<command>echo Reading subsystems for migrated domain-${migrated.version}.xml</command>
<command>/profile=auth-server-standalone/subsystem=*/:read-resource(recursive=true)>${project.build.directory}/migrated-domain-standalone-${migrated.version}.txt</command>
<command>/profile=auth-server-clustered/subsystem=*/:read-resource(recursive=true)>${project.build.directory}/migrated-domain-clustered-${migrated.version}.txt</command>
</commands>
</execute-commands>
</configuration>
</execution>
<execution>
<id>read-master-domain</id>
<phase>process-test-resources</phase>
<goals>
<goal>start</goal>
<goal>execute-commands</goal>
<goal>shutdown</goal> <goal>shutdown</goal>
</goals> </goals>
<configuration> <configuration>
<serverType>DOMAIN</serverType> <serverType>DOMAIN</serverType>
<domainConfig>domain.xml</domainConfig> <domainConfig>domain.xml</domainConfig>
<java-opts>
<java-opt>-Djboss.management.http.port=10990</java-opt>
<java-opt>-Djboss.management.native.port=10999</java-opt>
</java-opts>
<server-args> <server-args>
<server-arg>--host-config=host-master.xml</server-arg> <server-arg>--host-config=host-master.xml</server-arg>
</server-args> </server-args>
<execute-commands>
<commands>
<command>echo Reading subsystems for master domain.xml</command>
<command>/profile=auth-server-standalone/subsystem=*/:read-resource(recursive=true)>${project.build.directory}/master-domain-standalone.txt</command>
<command>/profile=auth-server-clustered/subsystem=*/:read-resource(recursive=true)>${project.build.directory}/master-domain-clustered.txt</command>
</commands>
</execute-commands>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<migrated.version>${migrated.version}</migrated.version>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>product</id>
<properties>
<jbossHome>${project.build.directory}/rh-sso-7.1</jbossHome>
<migrated.version>1.9.8.Final-redhat-1</migrated.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-dist</artifactId>
<version>2.5.4.Final-redhat-1</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</profile>
</profiles>
</project> </project>

View file

@ -0,0 +1,3 @@
embed-host-controller --domain-config=domain.xml
/profile=auth-server-clustered/subsystem=*/:read-resource(recursive=true)

View file

@ -0,0 +1,3 @@
embed-host-controller --domain-config=domain.xml
/profile=auth-server-standalone/subsystem=*/:read-resource(recursive=true)

View file

@ -0,0 +1,3 @@
embed-server --server-config=standalone-ha.xml
/subsystem=*/:read-resource(recursive=true)

View file

@ -0,0 +1,3 @@
embed-server --server-config=standalone.xml
/subsystem=*/:read-resource(recursive=true)

View file

@ -20,10 +20,23 @@ package org.keycloak.test.config.migration;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/** /**
* Compare outputs from jboss-cli read-resource operations. This compare the total * Compare outputs from jboss-cli read-resource operations. This compare the total
* configuration of all subsystems to make sure that the version in master * configuration of all subsystems to make sure that the version in master
@ -34,22 +47,23 @@ import org.junit.Test;
public class ConfigMigrationTest { public class ConfigMigrationTest {
private static final File TARGET_DIR = new File("./target"); private static final File TARGET_DIR = new File("./target");
private final String migratedVersion = System.getProperty("migrated.version"); private final Logger log = Logger.getLogger(ConfigMigrationTest.class);
private final Deque<String> nav = new LinkedList<>();
@Test @Test
public void testStandalone() throws IOException { public void testStandalone() throws IOException {
compareConfigs("master-standalone.txt", "migrated-standalone-" + migratedVersion + ".txt"); compareConfigs("master-standalone.txt", "migrated-standalone.txt");
} }
@Test @Test
public void testStandaloneHA() throws IOException { public void testStandaloneHA() throws IOException {
compareConfigs("master-standalone-ha.txt", "migrated-standalone-ha-" + migratedVersion + ".txt"); compareConfigs("master-standalone-ha.txt", "migrated-standalone-ha.txt");
} }
@Test @Test
public void testDomain() throws IOException { public void testDomain() throws IOException {
compareConfigs("master-domain-standalone.txt", "migrated-domain-standalone-" + migratedVersion + ".txt"); compareConfigs("master-domain-standalone.txt", "migrated-domain-standalone.txt");
compareConfigs("master-domain-clustered.txt", "migrated-domain-clustered-" + migratedVersion + ".txt"); compareConfigs("master-domain-clustered.txt", "migrated-domain-clustered.txt");
} }
private void compareConfigs(String masterConfig, String migratedConfig) throws IOException { private void compareConfigs(String masterConfig, String migratedConfig) throws IOException {
@ -66,7 +80,117 @@ public class ConfigMigrationTest {
// A textual diff might have things out of order. // A textual diff might have things out of order.
ModelNode master = ModelNode.fromStream(masterStream); ModelNode master = ModelNode.fromStream(masterStream);
ModelNode migrated = ModelNode.fromStream(migratedStream); ModelNode migrated = ModelNode.fromStream(migratedStream);
Assert.assertEquals(master, migrated);
if (master.equals(migrated)) {
// ok
} else {
if (Boolean.parseBoolean(System.getProperty("get.simple.full.comparison"))) {
assertThat(migrated, is(equalTo(master)));
} }
compareConfigsDeeply("root", master, migrated);
}
}
}
private void compareConfigsDeeply(String id, ModelNode master, ModelNode migrated) {
nav.add(id);
master.protect();
migrated.protect();
assertEquals(getMessage(), master.getType(), migrated.getType());
switch (master.getType()) {
case OBJECT:
//check nodes are equal
if (master.equals(migrated)) {
break;
}
//check keys are equal
assertThat(getMessage(), migrated.keys(), is(equalTo(master.keys())));
for (String key : master.keys()) {
compareConfigsDeeply(key, master.get(key), migrated.get(key));
}
break;
case LIST:
List<ModelNode> masterAsList = new ArrayList<>(master.asList());
List<ModelNode> migratedAsList = new ArrayList<>(migrated.asList());
if (masterAsList.equals(migratedAsList)) {
break;
}
masterAsList.sort(nodeStringComparator);
migratedAsList.sort(nodeStringComparator);
if (masterAsList.toString().contains("subsystem")) {
assertEquals("Subsystem names are not equal.",
getSubsystemNames(masterAsList).toString(),
getSubsystemNames(migratedAsList).toString());
}
//remove equaled nodes and keep just different ones
List<ModelNode> diffNodesInMaster = new ArrayList<>(masterAsList);
diffNodesInMaster.removeAll(migratedAsList);
for (ModelNode diffNodeInMaster : diffNodesInMaster) {
String navigation = diffNodeInMaster.getType().toString();
if (diffNodeInMaster.toString().contains("subsystem")) {
navigation = getSubsystemNames(Arrays.asList(diffNodeInMaster)).toString();
}
compareConfigsDeeply(navigation,
diffNodeInMaster,
migratedAsList.get(masterAsList.indexOf(diffNodeInMaster)));
}
break;
case BOOLEAN:
assertEquals(getMessage(), master.asBoolean(), migrated.asBoolean());
break;
case STRING:
assertEquals(getMessage(), master.asString(), migrated.asString());
break;
case UNDEFINED:
//nothing to test
break;
case LONG:
assertEquals(getMessage(), master.asLong(), migrated.asLong());
break;
case EXPRESSION:
assertEquals(getMessage(), master.asExpression(), migrated.asExpression());
break;
case INT:
assertEquals(getMessage(), master.asInt(), migrated.asInt());
break;
case DOUBLE:
assertEquals(getMessage(), master.asDouble(), migrated.asDouble(), new Double("0.0"));
break;
default:
assertThat(getMessage(), migrated, is(equalTo(master)));
throw new UnsupportedOperationException(getMessage() + ". There is missing case " + master.getType().name());
}
nav.pollLast();
}
private static final Comparator<ModelNode> nodeStringComparator = (n1, n2) -> {
//ascending order
return n1.toString().compareTo(n2.toString());
};
private String getMessage() {
return "* navigation -> " + nav.toString() + " * ";
}
private List<String> getSubsystemNames(List<ModelNode> modelNodes) {
int index;
if (modelNodes.toString().contains("profile")) {
index = 9; //domain
} else {
index = 5; //standalone
}
return modelNodes
.stream()
.map(ModelNode::toString)
.map(s -> s.split("\"")[index])
.collect(Collectors.toList());
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"providers": [ "providers": [
"classpath:${jboss.home.dir}/providers/*" "classpath:${jboss.server.config.dir}/providers/*"
], ],
"admin": { "admin": {
@ -22,30 +22,21 @@
"provider": "jpa" "provider": "jpa"
}, },
"userCache": {
"default" : {
"enabled": true
}
},
"userSessionPersister": { "userSessionPersister": {
"provider": "jpa" "provider": "jpa"
}, },
"authorizationPersister": {
"provider": "jpa"
},
"timer": { "timer": {
"provider": "basic" "provider": "basic"
}, },
"theme": { "theme": {
"default": "keycloak",
"staticMaxAge": 2592000, "staticMaxAge": 2592000,
"cacheTemplates": true, "cacheTemplates": true,
"cacheThemes": true, "cacheThemes": true,
"folder": { "folder": {
"dir": "${jboss.home.dir}/themes" "dir": "${jboss.server.config.dir}/themes"
} }
}, },
@ -64,15 +55,8 @@
} }
}, },
"realmCache": {
"default" : {
"enabled": true
}
},
"connectionsInfinispan": { "connectionsInfinispan": {
"provider": "default", "default" : {
"default": {
"cacheContainer" : "java:comp/env/infinispan/Keycloak" "cacheContainer" : "java:comp/env/infinispan/Keycloak"
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"providers": [ "providers": [
"classpath:${jboss.home.dir}/providers/*" "classpath:${jboss.server.config.dir}/providers/*"
], ],
"admin": { "admin": {
@ -22,30 +22,21 @@
"provider": "jpa" "provider": "jpa"
}, },
"userCache": {
"default" : {
"enabled": true
}
},
"userSessionPersister": { "userSessionPersister": {
"provider": "jpa" "provider": "jpa"
}, },
"authorizationPersister": {
"provider": "jpa"
},
"timer": { "timer": {
"provider": "basic" "provider": "basic"
}, },
"theme": { "theme": {
"default": "keycloak",
"staticMaxAge": 2592000, "staticMaxAge": 2592000,
"cacheTemplates": true, "cacheTemplates": true,
"cacheThemes": true, "cacheThemes": true,
"folder": { "folder": {
"dir": "${jboss.home.dir}/themes" "dir": "${jboss.server.config.dir}/themes"
} }
}, },
@ -64,15 +55,8 @@
} }
}, },
"realmCache": {
"default" : {
"enabled": true
}
},
"connectionsInfinispan": { "connectionsInfinispan": {
"provider": "default", "default" : {
"default": {
"cacheContainer" : "java:comp/env/infinispan/Keycloak" "cacheContainer" : "java:comp/env/infinispan/Keycloak"
} }
} }

View file

@ -113,6 +113,8 @@
<testsuite.constants>${project.build.directory}/dependency/test-constants.properties</testsuite.constants> <testsuite.constants>${project.build.directory}/dependency/test-constants.properties</testsuite.constants>
<skip.add.user.json>false</skip.add.user.json> <skip.add.user.json>false</skip.add.user.json>
<skip.clean.second.cache>true</skip.clean.second.cache>
<skip.copy.auth.crossdc.nodes>true</skip.copy.auth.crossdc.nodes>
<client.certificate.keystore>${auth.server.config.dir}/client.jks</client.certificate.keystore> <client.certificate.keystore>${auth.server.config.dir}/client.jks</client.certificate.keystore>
<client.certificate.keystore.passphrase>secret</client.certificate.keystore.passphrase> <client.certificate.keystore.passphrase>secret</client.certificate.keystore.passphrase>
<client.truststore>${auth.server.config.dir}/keycloak.truststore</client.truststore> <client.truststore>${auth.server.config.dir}/keycloak.truststore</client.truststore>
@ -204,6 +206,7 @@
<phase>process-test-resources</phase> <phase>process-test-resources</phase>
<goals><goal>run</goal></goals> <goals><goal>run</goal></goals>
<configuration> <configuration>
<skip>${skip.clean.second.cache}</skip>
<target> <target>
<echo>${cache.server.home}/standalone-dc-2</echo> <echo>${cache.server.home}/standalone-dc-2</echo>
<delete failonerror="false" dir="${cache.server.home}/standalone-dc-2" /> <delete failonerror="false" dir="${cache.server.home}/standalone-dc-2" />
@ -509,6 +512,7 @@
<goal>run</goal> <goal>run</goal>
</goals> </goals>
<configuration> <configuration>
<skip>${skip.copy.auth.crossdc.nodes}</skip>
<target> <target>
<move todir="${auth.server.crossdc01.home}"> <move todir="${auth.server.crossdc01.home}">
<fileset dir="${auth.server.home}"/> <fileset dir="${auth.server.home}"/>
@ -608,16 +612,6 @@
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<!--
skipping execution for <artifactId>integration-arquillian-tests</artifactId>,
it's re-enabled in <artifactId>integration-arquillian-tests-base</artifactId>
-->
<skip>true</skip>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</profile> </profile>