From 98477776a8e63a9ce0960099854c4dbd3df4249c Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Wed, 4 Jan 2012 12:27:05 +0000 Subject: [PATCH] fix #79 with testcase --- hsarback/build.xml | 2 +- .../de/hsadmin/core/qserv/CommandShell.java | 174 +++++------------- .../de/hsadmin/core/qserv/ShellException.java | 19 +- .../de/hsadmin/core/qserv/ShellProcessor.java | 27 +-- .../mods/dom/DomainProcessorFactory.java | 5 + .../hsadmin/mods/dom/httpd-vhost-dynamic.jtpl | 2 + .../hsadmin/mods/dom/httpd-vhost-static.jtpl | 2 + .../remote/ContinuousIntegrationTest.java | 26 +++ .../test/de/hsadmin/remote/InitDataTest.java | 39 ---- .../de/hsadmin/remote/SSLCertDomainTest.java | 68 +++++++ 10 files changed, 160 insertions(+), 204 deletions(-) create mode 100644 hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java create mode 100644 hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java diff --git a/hsarback/build.xml b/hsarback/build.xml index 8490157..12d7622 100644 --- a/hsarback/build.xml +++ b/hsarback/build.xml @@ -154,7 +154,7 @@ - + diff --git a/hsarback/src/de/hsadmin/core/qserv/CommandShell.java b/hsarback/src/de/hsadmin/core/qserv/CommandShell.java index c57bb56..7760d22 100644 --- a/hsarback/src/de/hsadmin/core/qserv/CommandShell.java +++ b/hsarback/src/de/hsadmin/core/qserv/CommandShell.java @@ -7,151 +7,69 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; -public class CommandShell -{ - private static boolean bExecute = true; // really execute or just store command and stdin? - private static String executedCommands; // stored command and stdin - private static String[] aEnvironment; // stored environment - - /** Set mode of real execution or just storing the command and stdin. - * - * @param bExec - * specifies whether shell commands should really be executed (true) or not (false) - */ - public static void setExecute( boolean bExec ) - { - bExecute = bExec; - } +public class CommandShell { - /** Returns and clears the last command which should have been executed. - * - * @return - * Last command, plus "< 0 ) + if (stdInput != null) { logCommand += "< 0 && callOutput.charAt(nLen-1) == '\n' ) - // callOutput = callOutput.substring(0, nLen-1); + if (callOutput != null) { return callOutput.trim(); } return null; } - private static String readProcessStream(InputStream stream) throws IOException - { - BufferedReader reader = new BufferedReader( - new InputStreamReader(stream)); + private static String readProcessStream(InputStream stream) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); StringBuffer textBuff = new StringBuffer(); String textLine = reader.readLine(); - while (textLine != null) - { + while (textLine != null) { textBuff.append(textLine); textBuff.append('\n'); textLine = reader.readLine(); diff --git a/hsarback/src/de/hsadmin/core/qserv/ShellException.java b/hsarback/src/de/hsadmin/core/qserv/ShellException.java index 1970b54..eb9836f 100644 --- a/hsarback/src/de/hsadmin/core/qserv/ShellException.java +++ b/hsarback/src/de/hsadmin/core/qserv/ShellException.java @@ -1,19 +1,14 @@ package de.hsadmin.core.qserv; -public class ShellException - extends Exception -{ - private static final long serialVersionUID = 8335020360721047849L; +public class ShellException extends Exception { - int nExitCode; - - public ShellException() - { + private static final long serialVersionUID = 5499293305075489652L; + + public ShellException(String message) { + super(message); } - public ShellException( int exitCode, String message ) - { - super( message ); - nExitCode = exitCode; + public ShellException(Throwable e) { + super(e); } } diff --git a/hsarback/src/de/hsadmin/core/qserv/ShellProcessor.java b/hsarback/src/de/hsadmin/core/qserv/ShellProcessor.java index e4dca5c..8d46052 100644 --- a/hsarback/src/de/hsadmin/core/qserv/ShellProcessor.java +++ b/hsarback/src/de/hsadmin/core/qserv/ShellProcessor.java @@ -13,47 +13,26 @@ public class ShellProcessor extends AbstractProcessor { private static final long serialVersionUID = -649045174380048818L; private String aSystemCall; - private String[] aEnv; private String aInput; private String aOutput; private String aErrors; - /** - * Constructor for a queue entry which executes a system call. - * - * @param aSystemCall - * the system call to be executed - */ - public ShellProcessor(String aSystemCall) { - this(aSystemCall, null, null); - } - - /** - * Constructor for a queue entry which executes a system call with stdin - * data. - * - * @param aSystemCall - * the system call to be executed - * @param aInput - * data for stdin of the system call - */ public ShellProcessor(String aSystemCall, String aInput) { this.aSystemCall = aSystemCall; this.aInput = aInput; } - public ShellProcessor(String aSystemCall, String[] aEnv, String aInput) { + public ShellProcessor(String aSystemCall) { this.aSystemCall = aSystemCall; - this.aEnv = aEnv; - this.aInput = aInput; + this.aInput = null; } public Object process() throws ProcessorException { try { - CommandShell.setEnvironment(aEnv); aOutput = CommandShell.execute(aSystemCall, aInput); return aOutput; } catch (ShellException aExc) { + aErrors = aExc.getMessage(); aExc.printStackTrace(System.err); // Logging throw new ProcessorException(aExc); } diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index d6d17f7..40b41a0 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -249,9 +249,14 @@ public class DomainProcessorFactory implements EntityProcessorFactory { private Processor createApacheVHostSetupProcessor(Domain dom, Map templateVars) throws ProcessorException { String domName = dom.getName(); + String pac = dom.getUser().getPac().getName(); Processor domSetupProcessor = new CompoundProcessor( createDomainDirectoriesProcessor(dom, templateVars), new CreateFileProcessor(selectVHostTemplate(dom), templateVars, "/etc/apache2/sites-generated/" + domName, "root", "root", "644"), + new ShellProcessor("ls /etc/apache2/pem/" + pac + ".pem >/dev/null 2>&1 " + + "&& sed -i '/SSLCertificate.*default/d' " + "/etc/apache2/sites-generated/" + domName + + " && (ls /etc/apache2/pem/" + pac + ".chain.pem >/dev/null 2>&1 || sed -i '/SSLCertificateChain.*" + pac + "/d' " + "/etc/apache2/sites-generated/" + domName + ")" + + " || sed -i '/SSLCertificate.*" + pac + "/d' " + "/etc/apache2/sites-generated/" + domName), new ShellProcessor( "ln -sf /etc/apache2/sites-generated/" + domName + " /etc/apache2/sites-enabled/010-" + domName + " && invoke-rc.d apache2 reload >/dev/null 2>&1") diff --git a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl index 2430380..45ec4a0 100644 --- a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl +++ b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl @@ -62,6 +62,8 @@ NameVirtualHost {DOM_IPNUMBEREX}:443 SSLEngine On SSLCertificateFile /etc/apache2/pems/default.pem SSLCertificateChainFile /etc/apache2/pems/default.chain.pem + SSLCertificateFile /etc/apache2/pems/{PAC}.pem + SSLCertificateChainFile /etc/apache2/pems/{PAC}.chain.pem DocumentRoot /home/doms/{DOM_HOSTNAME}/htdocs-ssl diff --git a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-static.jtpl b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-static.jtpl index 854a071..bf875fd 100644 --- a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-static.jtpl +++ b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-static.jtpl @@ -52,6 +52,8 @@ NameVirtualHost {DOM_IPNUMBEREX}:443 SSLEngine On SSLCertificateFile /etc/apache2/pems/default.pem SSLCertificateChainFile /etc/apache2/pems/default.chain.pem + SSLCertificateFile /etc/apache2/pems/{PAC}.pem + SSLCertificateChainFile /etc/apache2/pems/{PAC}.chain.pem DocumentRoot /home/doms/{DOM_HOSTNAME}/htdocs-ssl diff --git a/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java b/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java new file mode 100644 index 0000000..1f1f193 --- /dev/null +++ b/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java @@ -0,0 +1,26 @@ +package de.hsadmin.remote; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + InitDataTest.class, + RoleTest.class, + MysqlUserTest.class, + MysqlDbTest.class, + PgsqlUserTest.class, + PgsqlDbTest.class, + PacTest.class, + UnixUserTest.class, + EMailAliasTest.class, + DomainTest.class, + EMailAddressTest.class, + SSLCertDomainTest.class +// CustomerTest.class, +// QueueTaskTest.class +}) + +public class ContinuousIntegrationTest { + +} diff --git a/hsarback/test/de/hsadmin/remote/InitDataTest.java b/hsarback/test/de/hsadmin/remote/InitDataTest.java index 3d8bf51..3a63a39 100644 --- a/hsarback/test/de/hsadmin/remote/InitDataTest.java +++ b/hsarback/test/de/hsadmin/remote/InitDataTest.java @@ -62,9 +62,6 @@ public class InitDataTest { setParams }; try { client.execute(CUST_MODULE + ".add", params); -// Object execute = client.execute(CUST_MODULE + ".add", params); -// Map result = (Map) execute; -// System.out.println(result); assertEquals(membersCount + 1, getMembersCount()); } catch (XmlRpcException e) { fail(e.getMessage()); @@ -167,42 +164,6 @@ public class InitDataTest { assertEquals(count + 1, getUsersCount()); } -// @Test - public void testDelPac() { - int count = getPacsCount(); - String user = "ad"; - String grantingTicketURL = cas.getGrantingTicketURL(user); - Map whereParams = new HashMap(); - whereParams.put("name", "aaa00"); - Object[] params = new Object[] { user, - cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), - whereParams }; - try { - client.execute(PAC_MODULE + ".delete", params); - } catch (XmlRpcException e) { - fail(e.getMessage()); - } - assertEquals(count - 1, getPacsCount()); - } - -// @Test - public void testDelMember() { - int count = getMembersCount(); - String user = "ad"; - String grantingTicketURL = cas.getGrantingTicketURL(user); - Map whereParams = new HashMap(); - whereParams.put("membercode", "hsh00-aaa"); - Object[] params = new Object[] { user, - cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), - whereParams }; - try { - client.execute(CUST_MODULE + ".delete", params); - } catch (XmlRpcException e) { - fail(e.getMessage()); - } - assertEquals(count - 1, getMembersCount()); - } - private int getMembersCount() { int count = 0; String user = "ad"; diff --git a/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java b/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java new file mode 100644 index 0000000..57c20fc --- /dev/null +++ b/hsarback/test/de/hsadmin/remote/SSLCertDomainTest.java @@ -0,0 +1,68 @@ +package de.hsadmin.remote; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import de.hsadmin.core.qserv.CommandShell; +import de.hsadmin.core.qserv.ShellException; +import de.hsadmin.core.util.Config; + +public class SSLCertDomainTest { + + private static final String MODULE = "domain"; + + private XmlRpcClient client; + private RemoteCASHelper cas; + private Config config; + + @Before + public void setUp() throws Exception { + client = RemoteTestHelper.getClient(); + cas = new RemoteCASHelper(); + config = Config.getInstance(); + } + + @After + public void tearDown() throws Exception { + client = null; + cas = null; + config = null; + } + + @Test + public void testSSLCertWithoutChain() { + String user = "ad"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map setParams = new HashMap(); + setParams.put("name", "aaa02"); + setParams.put("hive", "h81"); + setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa"); + setParams.put("basepac", "DW/B"); + setParams.put("curinetaddr", "176.9.242.75"); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + setParams }; + try { + Object execute = client.execute(MODULE + ".add", params); + assertTrue(execute instanceof Map); + Thread.sleep(5000L); + CommandShell.execute("grep 'SSLCertificateChainFile' /var/local/lxc/hive/etc/apache2/sites-generated/aaa02.hostsharing.net"); + fail("ShellException expected"); + } catch (XmlRpcException e) { + fail(e.getMessage()); + } catch (ShellException e) { + } catch (InterruptedException e) { + fail(e.getMessage()); + } + } + +}