KEYCLOAK-6546 Run filter test on WebLogic and WebSphere

This commit is contained in:
mhajas 2017-11-27 18:04:33 +01:00 committed by Pavel Drozd
parent bde9210fa3
commit fe1c447d9a
12 changed files with 146 additions and 37 deletions

View file

@ -119,7 +119,24 @@ public class DeploymentArchiveProcessor implements ApplicationArchiveProcessor {
.addClass(org.keycloak.testsuite.arquillian.annotation.AppServerContainer.class) .addClass(org.keycloak.testsuite.arquillian.annotation.AppServerContainer.class)
.addClass(org.keycloak.testsuite.arquillian.annotation.UseServletFilter.class); .addClass(org.keycloak.testsuite.arquillian.annotation.UseServletFilter.class);
} }
if (isWASAppServer(testClass.getJavaClass())) {
// {
MavenResolverSystem resolver = Maven.resolver();
MavenFormatStage dependencies = resolver
.loadPomFromFile("pom.xml")
.importTestDependencies()
.resolve("org.apache.httpcomponents:httpclient")
.withTransitivity();
((WebArchive) archive)
.addAsLibraries(dependencies.asFile())
.addClass(org.keycloak.testsuite.arquillian.annotation.AppServerContainer.class)
.addClass(org.keycloak.testsuite.arquillian.annotation.UseServletFilter.class);
}
} }
public static boolean isAdapterTest(TestClass testClass) { public static boolean isAdapterTest(TestClass testClass) {
@ -294,30 +311,6 @@ public class DeploymentArchiveProcessor implements ApplicationArchiveProcessor {
removeElementsFromDoc(webXmlDoc, "web-app", "security-constraint"); removeElementsFromDoc(webXmlDoc, "web-app", "security-constraint");
removeElementsFromDoc(webXmlDoc, "web-app", "login-config"); removeElementsFromDoc(webXmlDoc, "web-app", "login-config");
removeElementsFromDoc(webXmlDoc, "web-app", "security-role"); removeElementsFromDoc(webXmlDoc, "web-app", "security-role");
if (isWASAppServer(testClass.getJavaClass())) {
removeElementsFromDoc(webXmlDoc, "web-app", "servlet-mapping");
removeElementsFromDoc(webXmlDoc, "web-app", "servlet");
}
if (isWLSAppServer(testClass.getJavaClass())) {
// add <servlet> tag in case it is missing
NodeList nodes = webXmlDoc.getElementsByTagName("servlet");
if (nodes.getLength() < 1) {
Element servlet = webXmlDoc.createElement("servlet");
Element servletName = webXmlDoc.createElement("servlet-name");
Element servletClass = webXmlDoc.createElement("servlet-class");
servletName.setTextContent("javax.ws.rs.core.Application");
servletClass.setTextContent(getServletClassName(archive));
servlet.appendChild(servletName);
servlet.appendChild(servletClass);
appendChildInDocument(webXmlDoc, "web-app", servlet);
}
}
} }
archive.add(new StringAsset((documentToString(webXmlDoc))), WEBXML_PATH); archive.add(new StringAsset((documentToString(webXmlDoc))), WEBXML_PATH);

View file

@ -37,9 +37,9 @@ public abstract class AbstractPageWithInjectedUrl extends AbstractPage {
} }
try { try {
if(Boolean.parseBoolean(System.getProperty("app.server.ssl.required"))) { if(Boolean.parseBoolean(System.getProperty("app.server.ssl.required"))) {
return new URL("https://localhost:" + System.getProperty("app.server.https.port", "8543") + "/" + url); return new URL("https://localhost:" + System.getProperty("app.server.https.port", "8643") + "/" + url);
}; };
return new URL("http://localhost:" + System.getProperty("app.server.http.port", "8180") + "/" + url); return new URL("http://localhost:" + System.getProperty("app.server.http.port", "8280") + "/" + url);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -207,6 +207,7 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
protected SalesPostAutodetectServlet salesPostAutodetectServletPage; protected SalesPostAutodetectServlet salesPostAutodetectServletPage;
public static final String FORBIDDEN_TEXT = "HTTP status code: 403"; public static final String FORBIDDEN_TEXT = "HTTP status code: 403";
public static final String WEBSPHERE_FORBIDDEN_TEXT = "Error reported: 403";
@Deployment(name = BadClientSalesPostSigServlet.DEPLOYMENT_NAME) @Deployment(name = BadClientSalesPostSigServlet.DEPLOYMENT_NAME)
protected static WebArchive badClientSalesPostSig() { protected static WebArchive badClientSalesPostSig() {
@ -354,7 +355,10 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
private void assertForbidden(AbstractPage page, String expectedNotContains) { private void assertForbidden(AbstractPage page, String expectedNotContains) {
page.navigateTo(); page.navigateTo();
waitUntilElement(By.xpath("//body")).text().not().contains(expectedNotContains); waitUntilElement(By.xpath("//body")).text().not().contains(expectedNotContains);
assertTrue(driver.getPageSource().contains("Forbidden") || driver.getPageSource().contains(FORBIDDEN_TEXT)); //Different 403 status page on EAP and Wildfly
assertTrue(driver.getPageSource().contains("Forbidden")
|| driver.getPageSource().contains(FORBIDDEN_TEXT)
|| driver.getPageSource().contains(WEBSPHERE_FORBIDDEN_TEXT)); // WebSphere
} }
private void assertSuccessfullyLoggedIn(AbstractPage page, String expectedText) { private void assertSuccessfullyLoggedIn(AbstractPage page, String expectedText) {
@ -368,7 +372,9 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
loginPage.form().login(username, password); loginPage.form().login(username, password);
waitUntilElement(By.xpath("//body")).text().not().contains(expectedNotContains); waitUntilElement(By.xpath("//body")).text().not().contains(expectedNotContains);
//Different 403 status page on EAP and Wildfly //Different 403 status page on EAP and Wildfly
assertTrue(driver.getPageSource().contains("Forbidden") || driver.getPageSource().contains(FORBIDDEN_TEXT)); assertTrue(driver.getPageSource().contains("Forbidden")
|| driver.getPageSource().contains(FORBIDDEN_TEXT)
|| driver.getPageSource().contains(WEBSPHERE_FORBIDDEN_TEXT)); // WebSphere
} }
private void assertSuccessfulLogin(AbstractPage page, UserRepresentation user, Login loginPage, String expectedString) { private void assertSuccessfulLogin(AbstractPage page, UserRepresentation user, Login loginPage, String expectedString) {
@ -460,7 +466,9 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
waitUntilElement(By.xpath("//body")).text().not().contains("principal="); waitUntilElement(By.xpath("//body")).text().not().contains("principal=");
//Different 403 status page on EAP and Wildfly //Different 403 status page on EAP and Wildfly
assertTrue(driver.getPageSource().contains("Forbidden") || driver.getPageSource().contains(FORBIDDEN_TEXT)); assertTrue(driver.getPageSource().contains("Forbidden")
|| driver.getPageSource().contains(FORBIDDEN_TEXT)
|| driver.getPageSource().contains(WEBSPHERE_FORBIDDEN_TEXT)); // WebSphere
} }
@Test @Test
@ -845,7 +853,10 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
samlidpInitiatedLoginPage.form().login("unauthorized", "password"); samlidpInitiatedLoginPage.form().login("unauthorized", "password");
waitUntilElement(By.xpath("//body")).text().not().contains("bburke"); waitUntilElement(By.xpath("//body")).text().not().contains("bburke");
assertTrue(driver.getPageSource().contains("Forbidden") || driver.getPageSource().contains(FORBIDDEN_TEXT)); //Different 403 status page on EAP and Wildfly
assertTrue(driver.getPageSource().contains("Forbidden")
|| driver.getPageSource().contains(FORBIDDEN_TEXT)
|| driver.getPageSource().contains(WEBSPHERE_FORBIDDEN_TEXT)); // WebSphere
assertForbidden(employee2ServletPage, "principal="); assertForbidden(employee2ServletPage, "principal=");
employee2ServletPage.logout(); employee2ServletPage.logout();
@ -1281,6 +1292,11 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
} }
private void assertOnForbiddenPage() { private void assertOnForbiddenPage() {
waitUntilElement(By.xpath("//body")).text().contains(FORBIDDEN_TEXT); waitUntilElement(By.xpath("//body")).is().present();
//Different 403 status page on EAP and Wildfly
assertTrue(driver.getPageSource().contains("Forbidden")
|| driver.getPageSource().contains(FORBIDDEN_TEXT)
|| driver.getPageSource().contains(WEBSPHERE_FORBIDDEN_TEXT)); // WebSphere
} }
} }

View file

@ -23,6 +23,11 @@
<module-name>%CONTEXT_PATH%</module-name> <module-name>%CONTEXT_PATH%</module-name>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name> <servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/*</url-pattern> <url-pattern>/*</url-pattern>

View file

@ -23,6 +23,10 @@
<module-name>%CONTEXT_PATH%</module-name> <module-name>%CONTEXT_PATH%</module-name>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name> <servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/*</url-pattern> <url-pattern>/*</url-pattern>

View file

@ -70,6 +70,8 @@
<settings.path></settings.path> <settings.path></settings.path>
<maven.repo.local></maven.repo.local> <maven.repo.local></maven.repo.local>
<repo.url></repo.url> <repo.url></repo.url>
<wl.password></wl.password>
<wl.home></wl.home>
<adapter.test.props> <adapter.test.props>
-Dapp.server.base.url=http://localhost:${app.server.http.port} -Dapp.server.base.url=http://localhost:${app.server.http.port}
@ -83,6 +85,8 @@
-Dkie.maven.settings.custom=${settings.path} -Dkie.maven.settings.custom=${settings.path}
-Dkie.maven.repo.local=${maven.repo.local} -Dkie.maven.repo.local=${maven.repo.local}
-Drepo.url=${repo.url} -Drepo.url=${repo.url}
-Dwl.password=${wl.password}
-Dwl.home=${wl.home}
</adapter.test.props> </adapter.test.props>
<app.server.home>${containers.home}/app-server-${app.server}</app.server.home> <app.server.home>${containers.home}/app-server-${app.server}</app.server.home>

View file

@ -34,7 +34,7 @@
<property name="remoteServerAddress">localhost</property> <property name="remoteServerAddress">localhost</property>
<property name="remoteServerSoapPort">8880</property> <property name="remoteServerSoapPort">8880</property>
<property name="securityEnabled">false</property> <property name="securityEnabled">false</property>
<property name="username">admin</property> <property name="username">wsadmin</property>
<property name="adapterImplClass">org.jboss.arquillian.container.was.remote_8_5.WebSphereRemoteContainer</property> <property name="adapterImplClass">org.jboss.arquillian.container.was.remote_8_5.WebSphereRemoteContainer</property>
</configuration> </configuration>
</container> </container>
@ -50,4 +50,4 @@
</xsl:template> </xsl:template>
</xsl:stylesheet> </xsl:stylesheet>

View file

@ -1,9 +1,39 @@
package org.keycloak.testsuite.adapter; package org.keycloak.testsuite.adapter;
import org.junit.Ignore;
import org.junit.Test;
import org.keycloak.testsuite.adapter.servlet.AbstractSAMLFilterServletAdapterTest; import org.keycloak.testsuite.adapter.servlet.AbstractSAMLFilterServletAdapterTest;
import org.keycloak.testsuite.arquillian.annotation.AppServerContainer; import org.keycloak.testsuite.arquillian.annotation.AppServerContainer;
@AppServerContainer("app-server-was") @AppServerContainer("app-server-was")
public class WASSAMLFilterAdapterTest extends AbstractSAMLFilterServletAdapterTest { public class WASSAMLFilterAdapterTest extends AbstractSAMLFilterServletAdapterTest {
@Override
@Ignore // KEYCLOAK-6152
@Test
public void testPostBadAssertionSignature() {}
@Override
@Ignore // KEYCLOAK-6152
@Test
public void salesPostEncRejectConsent() {}
@Override
@Ignore // KEYCLOAK-6152
@Test
public void salesPostRejectConsent() {}
@Override
@Ignore // KEYCLOAK-6152
@Test
public void testDifferentCookieName() {}
@Override
@Ignore
@Test
public void testMissingAssertionSignature() {}
@Override
@Ignore // KEYCLOAK-6152
@Test
public void testRelayStateEncoding() {}
} }

View file

@ -34,9 +34,9 @@
<property name="adapterImplClass">org.jboss.arquillian.container.wls.remote_12_1_2.WebLogicContainer</property> <property name="adapterImplClass">org.jboss.arquillian.container.wls.remote_12_1_2.WebLogicContainer</property>
<property name="adminUrl">t3://localhost:8280/</property> <property name="adminUrl">t3://localhost:8280/</property>
<property name="adminUserName">weblogic</property> <property name="adminUserName">weblogic</property>
<property name="adminPassword">weblogic1</property> <property name="adminPassword">${wl.password}</property>
<property name="target">AdminServer</property> <property name="target">AdminServer</property>
<property name="wlHome">/home/jenkins/Oracle/Middleware/Oracle_Home/wlserver</property> <property name="wlHome">${wl.home}</property>
</configuration> </configuration>
</container> </container>

View file

@ -0,0 +1,50 @@
For running WebLogic tests you need to have WLS running on port 8280 on your local machine.
## Running WLS server
Run WebLogic server on port **8280**
For example for docker image it is necessary to run it with these arguments
```bash
docker run -d \
--name="wls-server" \
--net="host" \
-v /tmp:/tmp \
your_docker_image
```
- We need to use --net="host" so that weblogic can access Keycloak server
- Also we need to map /tmp directory to /tmp directory in docker. This way arquillian will move archives used in testsuite to docker filesystem so that they are deployed to WLS
```
- And also our image always create new admin password when starting weblogic so you need to find out what password it generated
```bash
docker logs wls-server | grep password
```
## Running tests
1. At first we need to add our custom arquillian remote adapter to local repository. Only custom change is to always store tmp files in /tmp
```bash
git clone https://github.com/mhajas/arquillian-container-wls.git
cd arquillian-container-wls/wls-common
mvn clean install -DskipTests [-Dmaven.repo.local=/custom/repo/path]
cd ../wls-remote-12.1.x
mvn clean install -DskipTests [-Dmaven.repo.local=/custom/repo/path]
```
2. Build testsuite-arquillian
```bash
mvn clean install -f testsuite/integration-arquillian/pom.xml -DskipTests=true
```
3. Run tests
```bash
mvn clean install -f testsuite/integration-arquillian/tests/other/pom.xml -Papp-server-wls -Dwl.username=${admin-username} -Dwl.password=${admin-password} -Dwl.home=${wl-home-path}
```
In case of docker image one can replace wl-home-path with some preprepared directory which contains these files (example of downloading files):
```bash
docker cp wls-server:/u01/oracle/wlserver/server/lib/weblogic.jar ${wl-home-path}/server/lib/
docker cp wls-server:/u01/oracle/wlserver/server/lib/wlclient.jar ${wl-home-path}/server/lib/
docker cp wls-server:/u01/oracle/wlserver/server/lib/wljmxclient.jar ${wl-home-path}/server/lib/
```

View file

@ -41,7 +41,8 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.jboss.arquillian.container</groupId> <groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-wls-remote-12.1.x</artifactId> <artifactId>arquillian-wls-custom-remote-12.1.x</artifactId>
<version>1.0.2.Final-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -1,9 +1,15 @@
package org.keycloak.testsuite.adapter; package org.keycloak.testsuite.adapter;
import org.junit.Ignore;
import org.junit.Test;
import org.keycloak.testsuite.adapter.servlet.AbstractSAMLFilterServletAdapterTest; import org.keycloak.testsuite.adapter.servlet.AbstractSAMLFilterServletAdapterTest;
import org.keycloak.testsuite.arquillian.annotation.AppServerContainer; import org.keycloak.testsuite.arquillian.annotation.AppServerContainer;
@AppServerContainer("app-server-wls") @AppServerContainer("app-server-wls")
public class WLSSAMLFilterAdapterTest extends AbstractSAMLFilterServletAdapterTest { public class WLSSAMLFilterAdapterTest extends AbstractSAMLFilterServletAdapterTest {
@Ignore // KEYCLOAK-6152
@Override
@Test
public void testDifferentCookieName() {}
} }