You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2020/11/05 11:53:55 UTC
[cxf-fediz] 01/03: systests: throw exception on server starup
failure
This is an automated email from the ASF dual-hosted git repository.
buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git
commit 213b0b78c4958c634ab0e88ebb261caeb1ec6ba0
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Thu Nov 5 14:52:11 2020 +0300
systests: throw exception on server starup failure
---
.../cxf/fediz/systests/cxf/FederationTest.java | 159 ++++++++++-----------
.../cxf/fediz/systests/cxf/TokenExpiryTest.java | 158 ++++++++++----------
.../fediz/systests/federation/wsfed/WSFedTest.java | 5 +-
.../org/apache/cxf/fediz/systests/idp/IdpTest.java | 50 +++----
4 files changed, 171 insertions(+), 201 deletions(-)
diff --git a/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/FederationTest.java b/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/FederationTest.java
index 84cc44e..53817e7 100644
--- a/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/FederationTest.java
+++ b/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/FederationTest.java
@@ -19,7 +19,8 @@
package org.apache.cxf.fediz.systests.cxf;
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import com.gargoylesoftware.htmlunit.CookieManager;
import com.gargoylesoftware.htmlunit.WebClient;
@@ -29,6 +30,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;
@@ -52,7 +54,7 @@ public class FederationTest extends AbstractTests {
private static Tomcat rpServer;
@BeforeClass
- public static void init() {
+ public static void init() throws Exception {
idpHttpsPort = System.getProperty("idp.https.port");
// idpHttpsPort = "12345";
Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
@@ -63,95 +65,86 @@ public class FederationTest extends AbstractTests {
initRp();
}
- private static void initIdp() {
- try {
- idpServer = new Tomcat();
- idpServer.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- idpServer.setBaseDir(currentDir + File.separator + "target");
-
- idpServer.getHost().setAppBase("tomcat/idp/webapps");
- idpServer.getHost().setAutoDeploy(true);
- idpServer.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setProperty("keyAlias", "mytomidpkey");
- httpsConnector.setProperty("keystorePass", "tompass");
- httpsConnector.setProperty("keystoreFile", "test-classes/server.jks");
- httpsConnector.setProperty("truststorePass", "tompass");
- httpsConnector.setProperty("truststoreFile", "test-classes/server.jks");
- httpsConnector.setProperty("clientAuth", "want");
- // httpsConnector.setProperty("clientAuth", "false");
- httpsConnector.setProperty("sslProtocol", "TLS");
- httpsConnector.setProperty("SSLEnabled", "true");
-
- idpServer.getService().addConnector(httpsConnector);
-
- idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts");
- idpServer.addWebapp("/fediz-idp", "fediz-idp");
-
- idpServer.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ private static void initIdp() throws LifecycleException {
+ idpServer = new Tomcat();
+ idpServer.setPort(0);
+ final Path targetDir = Paths.get("target").toAbsolutePath();
+ idpServer.setBaseDir(targetDir.toString());
+
+ idpServer.getHost().setAppBase("tomcat/idp/webapps");
+ idpServer.getHost().setAutoDeploy(true);
+ idpServer.getHost().setDeployOnStartup(true);
+
+ Connector httpsConnector = new Connector();
+ httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
+ httpsConnector.setSecure(true);
+ httpsConnector.setScheme("https");
+ httpsConnector.setProperty("keyAlias", "mytomidpkey");
+ httpsConnector.setProperty("keystorePass", "tompass");
+ httpsConnector.setProperty("keystoreFile", "test-classes/server.jks");
+ httpsConnector.setProperty("truststorePass", "tompass");
+ httpsConnector.setProperty("truststoreFile", "test-classes/server.jks");
+ httpsConnector.setProperty("clientAuth", "want");
+ // httpsConnector.setProperty("clientAuth", "false");
+ httpsConnector.setProperty("sslProtocol", "TLS");
+ httpsConnector.setProperty("SSLEnabled", "true");
+
+ idpServer.getService().addConnector(httpsConnector);
+
+ idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts");
+ idpServer.addWebapp("/fediz-idp", "fediz-idp");
+
+ idpServer.start();
}
- private static void initRp() {
- try {
- rpServer = new Tomcat();
- rpServer.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- rpServer.setBaseDir(currentDir + File.separator + "target");
-
- rpServer.getHost().setAppBase("tomcat/rp/webapps");
- rpServer.getHost().setAutoDeploy(true);
- rpServer.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(rpHttpsPort));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setProperty("keyAlias", "mytomidpkey");
- httpsConnector.setProperty("keystorePass", "tompass");
- httpsConnector.setProperty("keystoreFile", "test-classes/server.jks");
- httpsConnector.setProperty("truststorePass", "tompass");
- httpsConnector.setProperty("truststoreFile", "test-classes/server.jks");
- // httpsConnector.setProperty("clientAuth", "false");
- httpsConnector.setProperty("clientAuth", "want");
- httpsConnector.setProperty("sslProtocol", "TLS");
- httpsConnector.setProperty("SSLEnabled", "true");
-
- rpServer.getService().addConnector(httpsConnector);
-
- rpServer.addWebapp("/fedizhelloworld", "cxfWebapp");
- rpServer.addWebapp("/fedizhelloworldnoreqvalidation", "cxfWebapp");
-
- rpServer.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ private static void initRp() throws LifecycleException {
+ rpServer = new Tomcat();
+ rpServer.setPort(0);
+ final Path targetDir = Paths.get("target").toAbsolutePath();
+ rpServer.setBaseDir(targetDir.toString());
+
+ rpServer.getHost().setAppBase("tomcat/rp/webapps");
+ rpServer.getHost().setAutoDeploy(true);
+ rpServer.getHost().setDeployOnStartup(true);
+
+ Connector httpsConnector = new Connector();
+ httpsConnector.setPort(Integer.parseInt(rpHttpsPort));
+ httpsConnector.setSecure(true);
+ httpsConnector.setScheme("https");
+ httpsConnector.setProperty("keyAlias", "mytomidpkey");
+ httpsConnector.setProperty("keystorePass", "tompass");
+ httpsConnector.setProperty("keystoreFile", "test-classes/server.jks");
+ httpsConnector.setProperty("truststorePass", "tompass");
+ httpsConnector.setProperty("truststoreFile", "test-classes/server.jks");
+ // httpsConnector.setProperty("clientAuth", "false");
+ httpsConnector.setProperty("clientAuth", "want");
+ httpsConnector.setProperty("sslProtocol", "TLS");
+ httpsConnector.setProperty("SSLEnabled", "true");
+
+ rpServer.getService().addConnector(httpsConnector);
+
+ rpServer.addWebapp("/fedizhelloworld", "cxfWebapp");
+ rpServer.addWebapp("/fedizhelloworldnoreqvalidation", "cxfWebapp");
+
+ rpServer.start();
}
@AfterClass
- public static void cleanup() {
- shutdownServer(idpServer);
- shutdownServer(rpServer);
+ public static void cleanup() throws Exception {
+ try {
+ shutdownServer(idpServer);
+ } finally {
+ shutdownServer(rpServer);
+ }
}
- private static void shutdownServer(Tomcat server) {
- try {
- if (server != null && server.getServer() != null
- && server.getServer().getState() != LifecycleState.DESTROYED) {
- if (server.getServer().getState() != LifecycleState.STOPPED) {
- server.stop();
- }
- server.destroy();
+ private static void shutdownServer(Tomcat server) throws LifecycleException {
+ if (server != null && server.getServer() != null
+ && server.getServer().getState() != LifecycleState.DESTROYED) {
+ if (server.getServer().getState() != LifecycleState.STOPPED) {
+ server.stop();
}
- } catch (Exception e) {
- e.printStackTrace();
+ server.destroy();
}
}
diff --git a/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/TokenExpiryTest.java b/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/TokenExpiryTest.java
index 5e2218e..7d89331 100644
--- a/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/TokenExpiryTest.java
+++ b/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/TokenExpiryTest.java
@@ -19,8 +19,10 @@
package org.apache.cxf.fediz.systests.cxf;
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;
@@ -42,9 +44,8 @@ public class TokenExpiryTest extends AbstractExpiryTests {
private static Tomcat rpServer;
@BeforeClass
- public static void init() {
+ public static void init() throws Exception {
idpHttpsPort = System.getProperty("idp.https.port");
- // idpHttpsPort = "12345";
Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
rpHttpsPort = System.getProperty("rp.https.port");
Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
@@ -53,94 +54,85 @@ public class TokenExpiryTest extends AbstractExpiryTests {
initRp();
}
- private static void initIdp() {
- try {
- idpServer = new Tomcat();
- idpServer.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- idpServer.setBaseDir(currentDir + File.separator + "target");
-
- idpServer.getHost().setAppBase("tomcat/idp/webapps");
- idpServer.getHost().setAutoDeploy(true);
- idpServer.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setProperty("keyAlias", "mytomidpkey");
- httpsConnector.setProperty("keystorePass", "tompass");
- httpsConnector.setProperty("keystoreFile", "test-classes/server.jks");
- httpsConnector.setProperty("truststorePass", "tompass");
- httpsConnector.setProperty("truststoreFile", "test-classes/server.jks");
- httpsConnector.setProperty("clientAuth", "want");
- // httpsConnector.setProperty("clientAuth", "false");
- httpsConnector.setProperty("sslProtocol", "TLS");
- httpsConnector.setProperty("SSLEnabled", "true");
-
- idpServer.getService().addConnector(httpsConnector);
-
- idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts");
- idpServer.addWebapp("/fediz-idp", "fediz-idp");
-
- idpServer.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ private static void initIdp() throws LifecycleException {
+ idpServer = new Tomcat();
+ idpServer.setPort(0);
+ final Path targetDir = Paths.get("target").toAbsolutePath();
+ idpServer.setBaseDir(targetDir.toString());
+
+ idpServer.getHost().setAppBase("tomcat/idp/webapps");
+ idpServer.getHost().setAutoDeploy(true);
+ idpServer.getHost().setDeployOnStartup(true);
+
+ Connector httpsConnector = new Connector();
+ httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
+ httpsConnector.setSecure(true);
+ httpsConnector.setScheme("https");
+ httpsConnector.setProperty("keyAlias", "mytomidpkey");
+ httpsConnector.setProperty("keystorePass", "tompass");
+ httpsConnector.setProperty("keystoreFile", "test-classes/server.jks");
+ httpsConnector.setProperty("truststorePass", "tompass");
+ httpsConnector.setProperty("truststoreFile", "test-classes/server.jks");
+ httpsConnector.setProperty("clientAuth", "want");
+ // httpsConnector.setProperty("clientAuth", "false");
+ httpsConnector.setProperty("sslProtocol", "TLS");
+ httpsConnector.setProperty("SSLEnabled", "true");
+
+ idpServer.getService().addConnector(httpsConnector);
+
+ idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts");
+ idpServer.addWebapp("/fediz-idp", "fediz-idp");
+
+ idpServer.start();
}
- private static void initRp() {
- try {
- rpServer = new Tomcat();
- rpServer.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- rpServer.setBaseDir(currentDir + File.separator + "target");
-
- rpServer.getHost().setAppBase("tomcat/rp/webapps");
- rpServer.getHost().setAutoDeploy(true);
- rpServer.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(rpHttpsPort));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setProperty("keyAlias", "mytomidpkey");
- httpsConnector.setProperty("keystorePass", "tompass");
- httpsConnector.setProperty("keystoreFile", "test-classes/server.jks");
- httpsConnector.setProperty("truststorePass", "tompass");
- httpsConnector.setProperty("truststoreFile", "test-classes/server.jks");
- // httpsConnector.setProperty("clientAuth", "false");
- httpsConnector.setProperty("clientAuth", "want");
- httpsConnector.setProperty("sslProtocol", "TLS");
- httpsConnector.setProperty("SSLEnabled", "true");
-
- rpServer.getService().addConnector(httpsConnector);
-
- rpServer.addWebapp("/fedizhelloworld", "cxfWebappExpiry");
-
- rpServer.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ private static void initRp() throws LifecycleException {
+ rpServer = new Tomcat();
+ rpServer.setPort(0);
+ final Path targetDir = Paths.get("target").toAbsolutePath();
+ rpServer.setBaseDir(targetDir.toString());
+
+ rpServer.getHost().setAppBase("tomcat/rp/webapps");
+ rpServer.getHost().setAutoDeploy(true);
+ rpServer.getHost().setDeployOnStartup(true);
+
+ Connector httpsConnector = new Connector();
+ httpsConnector.setPort(Integer.parseInt(rpHttpsPort));
+ httpsConnector.setSecure(true);
+ httpsConnector.setScheme("https");
+ httpsConnector.setProperty("keyAlias", "mytomidpkey");
+ httpsConnector.setProperty("keystorePass", "tompass");
+ httpsConnector.setProperty("keystoreFile", "test-classes/server.jks");
+ httpsConnector.setProperty("truststorePass", "tompass");
+ httpsConnector.setProperty("truststoreFile", "test-classes/server.jks");
+ // httpsConnector.setProperty("clientAuth", "false");
+ httpsConnector.setProperty("clientAuth", "want");
+ httpsConnector.setProperty("sslProtocol", "TLS");
+ httpsConnector.setProperty("SSLEnabled", "true");
+
+ rpServer.getService().addConnector(httpsConnector);
+
+ rpServer.addWebapp("/fedizhelloworld", "cxfWebappExpiry");
+
+ rpServer.start();
}
@AfterClass
- public static void cleanup() {
- shutdownServer(idpServer);
- shutdownServer(rpServer);
+ public static void cleanup() throws Exception {
+ try {
+ shutdownServer(idpServer);
+ } finally {
+ shutdownServer(rpServer);
+ }
}
- private static void shutdownServer(Tomcat server) {
- try {
- if (server != null && server.getServer() != null
- && server.getServer().getState() != LifecycleState.DESTROYED) {
- if (server.getServer().getState() != LifecycleState.STOPPED) {
- server.stop();
- }
- server.destroy();
+ private static void shutdownServer(Tomcat server) throws LifecycleException {
+ if (server != null && server.getServer() != null
+ && server.getServer().getState() != LifecycleState.DESTROYED) {
+ if (server.getServer().getState() != LifecycleState.STOPPED) {
+ server.stop();
}
- } catch (Exception e) {
- e.printStackTrace();
+ server.destroy();
}
}
diff --git a/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/systests/federation/wsfed/WSFedTest.java b/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/systests/federation/wsfed/WSFedTest.java
index 81ade30..77e1985 100644
--- a/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/systests/federation/wsfed/WSFedTest.java
+++ b/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/systests/federation/wsfed/WSFedTest.java
@@ -27,8 +27,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
-import javax.servlet.ServletException;
-
import com.gargoylesoftware.htmlunit.CookieManager;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.WebClient;
@@ -98,8 +96,7 @@ public class WSFedTest {
rpServer = startServer(ServerType.RP, RP_HTTPS_PORT);
}
- private static Tomcat startServer(ServerType serverType, String port)
- throws ServletException, LifecycleException, IOException {
+ private static Tomcat startServer(ServerType serverType, String port) throws LifecycleException {
Tomcat server = new Tomcat();
server.setPort(0);
diff --git a/systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java b/systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java
index 59dcf81..81f8750 100644
--- a/systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java
+++ b/systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java
@@ -19,14 +19,11 @@
package org.apache.cxf.fediz.systests.idp;
-import java.io.File;
-import java.io.IOException;
import java.net.URLEncoder;
-import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Base64;
-import javax.servlet.ServletException;
-
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -49,6 +46,7 @@ import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;
import org.apache.cxf.fediz.core.FederationConstants;
import org.apache.cxf.fediz.core.util.DOMUtils;
+import org.apache.cxf.helpers.IOUtils;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.wss4j.dom.engine.WSSConfig;
@@ -83,13 +81,11 @@ public class IdpTest {
WSSConfig.init();
}
- private static Tomcat startServer(boolean idp, String port)
- throws ServletException, LifecycleException, IOException {
+ private static Tomcat startServer(boolean idp, String port) throws LifecycleException {
Tomcat server = new Tomcat();
server.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- String baseDir = currentDir + File.separator + "target";
- server.setBaseDir(baseDir);
+ final Path targetDir = Paths.get("target").toAbsolutePath();
+ server.setBaseDir(targetDir.toString());
server.getHost().setAppBase("tomcat/idp/webapps");
server.getHost().setAutoDeploy(true);
@@ -111,11 +107,11 @@ public class IdpTest {
server.getService().addConnector(httpsConnector);
- File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts");
- server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
+ Path stsWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp-sts");
+ server.addWebapp("/fediz-idp-sts", stsWebapp.toString());
- File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp");
- server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
+ Path idpWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp");
+ server.addWebapp("/fediz-idp", idpWebapp.toString());
server.start();
@@ -123,21 +119,17 @@ public class IdpTest {
}
@AfterClass
- public static void cleanup() {
+ public static void cleanup() throws Exception {
shutdownServer(idpServer);
}
- private static void shutdownServer(Tomcat server) {
- try {
- if (server != null && server.getServer() != null
- && server.getServer().getState() != LifecycleState.DESTROYED) {
- if (server.getServer().getState() != LifecycleState.STOPPED) {
- server.stop();
- }
- server.destroy();
+ private static void shutdownServer(Tomcat server) throws LifecycleException {
+ if (server != null && server.getServer() != null
+ && server.getServer().getState() != LifecycleState.DESTROYED) {
+ if (server.getServer().getState() != LifecycleState.STOPPED) {
+ server.stop();
}
- } catch (Exception e) {
- e.printStackTrace();
+ server.destroy();
}
}
@@ -405,9 +397,7 @@ public class IdpTest {
String wreply = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet";
url += "&wreply=" + wreply;
- String currentDir = new File(".").getCanonicalPath();
- File f = new File(currentDir + "/src/test/resources/entity_wreq.xml");
- String entity = new String(Files.readAllBytes(f.toPath()), "UTF-8");
+ String entity = IOUtils.toString(getClass().getResourceAsStream("/entity_wreq.xml"));
String validWreq =
"<RequestSecurityToken xmlns=\"http://docs.oasis-open.org/ws-sx/ws-trust/200512\">"
+ "<TokenType>&m;http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</TokenType>"
@@ -445,9 +435,7 @@ public class IdpTest {
String wreply = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet";
url += "&wreply=" + wreply;
- String currentDir = new File(".").getCanonicalPath();
- File f = new File(currentDir + "/src/test/resources/entity_wreq2.xml");
- String entity = new String(Files.readAllBytes(f.toPath()), "UTF-8");
+ String entity = IOUtils.toString(getClass().getResourceAsStream("/entity_wreq2.xml"));
String validWreq =
"<RequestSecurityToken xmlns=\"http://docs.oasis-open.org/ws-sx/ws-trust/200512\">"
+ "<TokenType>&m;http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</TokenType>"