add installing adapter tests via cli scripts, checking server log

This commit is contained in:
Vlasta Ramik 2016-01-12 14:31:28 +01:00
parent 554da73398
commit 6c3c08e711
12 changed files with 151 additions and 153 deletions

View file

@ -209,31 +209,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<executions>
<execution>
<id>configure-adapter-subsystem</id>
<phase>process-resources</phase>
<goals>
<goal>transform</goal>
</goals>
<configuration>
<transformationSets>
<transformationSet>
<dir>${keycloak.server.home}/standalone/configuration</dir>
<includes>
<include>standalone.xml</include>
</includes>
<stylesheet>src/main/xslt/standalone.xsl</stylesheet>
<outputDir>${keycloak.server.home}/standalone/configuration</outputDir>
</transformationSet>
</transformationSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

View file

@ -1,53 +0,0 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:j="urn:jboss:domain:4.0"
xmlns:ds="urn:jboss:domain:datasources:4.0"
xmlns:k="urn:jboss:domain:keycloak:1.1"
xmlns:sec="urn:jboss:domain:security:1.2"
version="2.0"
exclude-result-prefixes="xalan j ds k sec">
<xsl:param name="config"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" xalan:indent-amount="4" standalone="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="//j:extensions">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<extension module="org.keycloak.keycloak-adapter-subsystem"/>
<extension module="org.keycloak.keycloak-saml-adapter-subsystem"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//j:profile">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<subsystem xmlns="urn:jboss:domain:keycloak:1.1"/>
<subsystem xmlns="urn:jboss:domain:keycloak-saml:1.1"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//sec:security-domains">
<xsl:copy>
<xsl:apply-templates select="node()[name(.)='security-domain']"/>
<security-domain name="keycloak">
<authentication>
<login-module code="org.keycloak.adapters.jboss.KeycloakLoginModule" flag="required"/>
</authentication>
</security-domain>
<security-domain name="sp" cache-type="default">
<authentication>
<login-module code="org.picketlink.identity.federation.bindings.wildfly.SAML2LoginModule" flag="required"/>
</authentication>
</security-domain>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View file

@ -40,6 +40,11 @@
<artifactId>keycloak-as7-adapter-dist</artifactId>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-saml-as7-adapter-dist</artifactId>
<type>zip</type>
</dependency>
</dependencies>
<build>
@ -77,6 +82,13 @@
<type>zip</type>
<outputDirectory>${adapter.libs.as7}</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-saml-as7-adapter-dist</artifactId>
<version>${project.version}</version>
<type>zip</type>
<outputDirectory>${adapter.libs.as7}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>

View file

@ -40,6 +40,11 @@
<artifactId>keycloak-eap6-adapter-dist</artifactId>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-saml-eap6-adapter-dist</artifactId>
<type>zip</type>
</dependency>
</dependencies>
<build>
@ -67,7 +72,7 @@
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-eap6-with-adapter</id>
<id>unpack-eap6-with-adapters</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
@ -88,6 +93,13 @@
<type>zip</type>
<outputDirectory>${adapter.libs.eap6}</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-saml-eap6-adapter-dist</artifactId>
<version>${version.adapter.dist}</version>
<type>zip</type>
<outputDirectory>${adapter.libs.eap6}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>

View file

@ -23,6 +23,7 @@
<exclude.adapters>-</exclude.adapters>
<arquillian.xml.stylesheet>src/main/xslt/arquillian.xsl</arquillian.xml.stylesheet>
<skip.install.adapters>false</skip.install.adapters>
</properties>
<build>
@ -50,6 +51,24 @@
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack-add-user-json</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.keycloak.testsuite</groupId>
<artifactId>integration-arquillian-tests-base</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<includes>**/keycloak-add-user.json</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
@ -108,6 +127,31 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-admin-user-json-file</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jboss.server.config.dir}</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/dependency</directory>
<includes>
<include>keycloak-add-user.json</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

View file

@ -31,6 +31,11 @@
<artifactId>keycloak-wildfly-adapter-dist</artifactId>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-saml-wildfly-adapter-dist</artifactId>
<type>zip</type>
</dependency>
</dependencies>
<build>
@ -68,6 +73,13 @@
<type>zip</type>
<outputDirectory>${adapter.libs.wildfly}</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-saml-wildfly-adapter-dist</artifactId>
<version>${project.version}</version>
<type>zip</type>
<outputDirectory>${adapter.libs.wildfly}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
@ -77,7 +89,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<app.server.wildfly>true</app.server.wildfly>
@ -145,20 +156,20 @@
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${app.server.wildfly.home}/standalone/configuration</outputDirectory>
<resources>
<resource>
<directory>src/main/keystore</directory>
<includes>
<include>adapter.jks</include>
<include>keycloak.truststore</include>
</includes>
</resource>
</resources>
<nonFilteredFileExtensions>
<outputDirectory>${app.server.wildfly.home}/standalone/configuration</outputDirectory>
<resources>
<resource>
<directory>src/main/keystore</directory>
<includes>
<include>adapter.jks</include>
<include>keycloak.truststore</include>
</includes>
</resource>
</resources>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jks</nonFilteredFileExtension>
<nonFilteredFileExtension>truststore</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</nonFilteredFileExtensions>
</configuration>
</execution>
</executions>

View file

@ -73,6 +73,13 @@
<exclude.account>**/account/**/*Test.java</exclude.account>
</properties>
</profile>
<profile>
<id>no-client</id>
<properties>
<!-- Exclude all account management tests. -->
<exclude.account>**/client/**/*Test.java</exclude.account>
</properties>
</profile>
<profile>
<id>adapters-only</id>
<properties>

View file

@ -23,7 +23,6 @@ import org.jboss.arquillian.core.api.annotation.Observes;
import org.jboss.arquillian.test.spi.annotation.ClassScoped;
import org.jboss.arquillian.test.spi.annotation.SuiteScoped;
import org.jboss.arquillian.container.spi.event.container.AfterStart;
import org.jboss.arquillian.container.spi.event.container.BeforeStart;
import org.jboss.arquillian.test.spi.event.suite.BeforeClass;
import org.jboss.arquillian.test.spi.event.suite.BeforeSuite;
import org.jboss.logging.Logger;
@ -35,6 +34,7 @@ import org.keycloak.testsuite.util.OAuthClient;
import static org.keycloak.testsuite.auth.page.AuthRealm.ADMIN;
import static org.keycloak.testsuite.auth.page.AuthRealm.MASTER;
import static org.keycloak.testsuite.util.WaitUtils.pause;
/**
*
@ -78,7 +78,10 @@ public class ContainersTestEnricher {
private ContainerController controller;
private LinkedList<Container> containers;
private String jbossHomePath;
private final boolean migrationTests = System.getProperty("migration", "false").equals("true");
private final boolean skipInstallAdapters = System.getProperty("skip.install.adapters", "false").equals("true");
private boolean alreadyInstalled = false;
private boolean alreadyStopped = false;
private boolean init = false;
@ -110,16 +113,12 @@ public class ContainersTestEnricher {
*/
public void afterStart(@Observes AfterStart event) throws IOException, InterruptedException {
Container container = containers.pollFirst();
String jbossHomePath = null;
if (isJBossBased(container)) {
jbossHomePath = container.getContainerConfiguration().getContainerProperties().get("jbossHome");
log.debug("jbossHome: " + jbossHomePath + "\n");
if (System.getProperty("check.server.log", "true").equals("true")) {
checkServerLog(jbossHomePath);
}
}
checkServerLog(jbossHomePath);
if (migrationTests && !alreadyStopped) {
log.info("\n\n### Stopping keycloak " + System.getProperty("version", "- previous") + " ###\n");
@ -128,43 +127,51 @@ public class ContainersTestEnricher {
alreadyStopped = true;
}
if (isJBossBased(container) && container.getName().startsWith("app-server")) {
log.info("Installing adapter to app server via cli script");
if (!alreadyInstalled && !skipInstallAdapters && isJBossBased(container)) {
String jbossCliPath = jbossHomePath + "/bin/jboss-cli.sh";
String scriptPathArg = "--file=" + jbossHomePath + "/bin/adapter-install.cli";
String adapterScriptPathArg = "--file=" + jbossHomePath + "/bin/adapter-install.cli";
String samlAdapterScriptPathArg = "--file=" + jbossHomePath + "/bin/adapter-install-saml.cli";
String managementPort = container.getContainerConfiguration().getContainerProperties().get("managementPort");
String controllerArg = "--controller=localhost:" + managementPort;
execCommand(new String[]{"/bin/sh", jbossCliPath, "--connect", scriptPathArg, controllerArg});
log.debug("Restarting container");
log.info("Installing adapter to app server via cli script");
execCommand(new String[]{"/bin/sh", jbossCliPath, "--connect", adapterScriptPathArg, controllerArg});
log.info("Installing saml adapter to app server via cli script");
execCommand(new String[]{"/bin/sh", jbossCliPath, "--connect", samlAdapterScriptPathArg, controllerArg});
log.info("Restarting container");
execCommand(new String[]{"/bin/sh", jbossCliPath, "--connect", "--command=:reload", controllerArg});
pause(5000);
log.info("Container restarted");
checkServerLog(jbossHomePath);
if (container.getName().startsWith("app-server")) {
alreadyInstalled = true;
}
}
}
private void execCommand(String... command) throws IOException, InterruptedException {
Process process = Runtime.getRuntime().exec(command);
printOutput(process.getInputStream());
if (process.waitFor(10, TimeUnit.SECONDS)) {
if (process.exitValue() != 0) {
log.error("Std Error:");
printOutput(process.getErrorStream());
throw new RuntimeException("Adapter installation failed.");
throw new RuntimeException("Adapter installation failed. Process exitValue: "
+ process.exitValue() + "; <error output>\n" + getOutput(process.getErrorStream())
+ "</error output>");
}
log.debug("process.isAlive(): " + process.isAlive());
} else {
process.destroy();
process.destroyForcibly();
throw new RuntimeException("Timeout after 10 seconds.");
}
}
private void printOutput(InputStream is) throws IOException {
private String getOutput(InputStream is) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder builder = new StringBuilder();
while (reader.ready()) {
builder.append(reader.readLine());
}
log.info(builder);
return builder.toString();
}
private boolean isJBossBased(Container container) {
@ -182,18 +189,21 @@ public class ContainersTestEnricher {
* check server logs whether there are no ERRORs or SEVEREs
*/
private void checkServerLog(String jbossHomePath) throws IOException {
File serverLog = new File(jbossHomePath + "/standalone/log/server.log");
String serverLogContent = FileUtils.readFileToString(serverLog);
if (jbossHomePath != null && System.getProperty("check.server.log", "true").equals("true")) {
File serverLog = new File(jbossHomePath + "/standalone/log/server.log");
String serverLogContent = FileUtils.readFileToString(serverLog);
boolean containsError
= serverLogContent.contains("ERROR")
|| serverLogContent.contains("SEVERE")
|| serverLogContent.contains("Exception ");
//There is expected string "Exception" in server log: Adding provider
//singleton org.keycloak.services.resources.ModelExceptionMapper
boolean containsError
= serverLogContent.contains("ERROR")
|| serverLogContent.contains("SEVERE")
|| serverLogContent.contains("Exception ");
//There is expected string "Exception" in server log: Adding provider
//singleton org.keycloak.services.resources.ModelExceptionMapper
if (containsError) {
throw new RuntimeException(serverLog.getPath() + " contains ERROR.");
if (containsError) {
throw new RuntimeException(serverLog.getPath() + " contains ERROR.");
}
log.info(serverLog.getPath() + " doesn't contain Error");
}
}

View file

@ -10,24 +10,14 @@ import static org.keycloak.testsuite.util.MailServerConfiguration.*;
*/
public final class SuiteContext {
private boolean adminPasswordUpdated;
private final Map<String, String> smtpServer = new HashMap<>();
public SuiteContext() {
this.adminPasswordUpdated = false;
smtpServer.put("from", FROM);
smtpServer.put("host", HOST);
smtpServer.put("port", PORT);
}
public boolean isAdminPasswordUpdated() {
return adminPasswordUpdated;
}
public void setAdminPasswordUpdated(boolean adminPasswordUpdated) {
this.adminPasswordUpdated = adminPasswordUpdated;
}
public Map<String, String> getSmtpServer() {
return smtpServer;
}

View file

@ -25,7 +25,6 @@ import org.keycloak.testsuite.util.OAuthClient;
import org.openqa.selenium.WebDriver;
import org.keycloak.testsuite.auth.page.AuthServer;
import org.keycloak.testsuite.auth.page.AuthServerContextRoot;
import static org.keycloak.testsuite.util.URLAssert.*;
import org.keycloak.testsuite.auth.page.AuthRealm;
import static org.keycloak.testsuite.auth.page.AuthRealm.ADMIN;
import static org.keycloak.testsuite.auth.page.AuthRealm.MASTER;
@ -90,12 +89,6 @@ public abstract class AbstractKeycloakTest {
driverSettings();
if (!suiteContext.isAdminPasswordUpdated()) {
log.debug("updating admin password");
updateMasterAdminPassword();
suiteContext.setAdminPasswordUpdated(true);
}
importTestRealms();
}
@ -106,13 +99,6 @@ public abstract class AbstractKeycloakTest {
Timer.printStats();
}
private void updateMasterAdminPassword() {
welcomePage.navigateTo();
if (!welcomePage.isPasswordSet()) {
welcomePage.setPassword("admin", "admin");
}
}
public void deleteAllCookiesForMasterRealm() {
masterRealmPage.navigateTo();
log.debug("deleting cookies in master realm");

View file

@ -5,12 +5,11 @@
"enabled" : true,
"credentials" : [ {
"type" : "password",
"hashedSaltedValue" : "6K5rvcPu3dXndZOhpzLAVbFtcdlUhbGCrUyV0NNzeS61IdhMpjH8Mf4y/Ag/vHZkw4Ayvtvb9/1iMNOzxR0M6g==",
"salt" : "/6M1jTMUB0uR8EOkksFn/A==",
"hashedSaltedValue" : "dqalJHLkWhUJZO/q6+z1fvXOohTcGCXcvoU8xCEyvTxGN4wmLx7DtyhKuefggh6Bkx1I2eBTEX4tiWggwyXMDw==",
"salt" : "3fBAt5GAGGxFrV9fznpZHQ==",
"hashIterations" : 100000,
"algorithm" : "pbkdf2"
} ],
"realmRoles" : [ "admin" ]
} ],
"identityFederationEnabled" : false
} ]
} ]

View file

@ -41,6 +41,7 @@
<version.shrinkwrap.resolvers>2.1.1</version.shrinkwrap.resolvers>
<skip.unpack.server>true</skip.unpack.server>
<skip.unpack.previous>true</skip.unpack.previous>
<skip.install.adapters>true</skip.install.adapters>
</properties>
<dependencyManagement>
@ -95,6 +96,7 @@
<auth.server.ssl.required>${auth.server.ssl.required}</auth.server.ssl.required>
<startup.timeout.sec>${startup.timeout.sec}</startup.timeout.sec>
<jboss.server.config.dir>${project.build.directory}/undertow-configuration</jboss.server.config.dir>
<skip.install.adapters>${skip.install.adapters}</skip.install.adapters>
</systemPropertyVariables>
<properties>
<property>
@ -152,6 +154,7 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
@ -416,6 +419,7 @@
<startup.timeout.sec>300</startup.timeout.sec>
<adapter.test.props/>
<keycloak.home>${containers.home}/keycloak-${project.version}</keycloak.home>
<jboss.server.config.dir>${keycloak.home}/standalone/configuration</jboss.server.config.dir>
</properties>
<dependencies>
<dependency>
@ -448,7 +452,7 @@
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${keycloak.home}/standalone/configuration</outputDirectory>
<outputDirectory>${jboss.server.config.dir}</outputDirectory>
<resources>
<resource>
<directory>src/test/resources</directory>
@ -512,6 +516,7 @@
<startup.timeout.sec>300</startup.timeout.sec>
<adapter.test.props/>
<keycloak.home>${containers.home}/keycloak-${version.eap6.server.dist}</keycloak.home>
<jboss.server.config.dir>${keycloak.home}/standalone/configuration</jboss.server.config.dir>
</properties>
<dependencies>
<dependency>
@ -570,7 +575,7 @@
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${keycloak.home}/standalone/configuration</outputDirectory>
<outputDirectory>${jboss.server.config.dir}</outputDirectory>
<resources>
<resource>
<directory>src/test/resources</directory>