diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 23dade5..7572ddd 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -317,11 +317,11 @@ public class DomainProcessorFactory implements EntityProcessorFactory { " && (ls /etc/apache2/pems/" + pac + ".chain.pem >/dev/null 2>&1 || sed -i '/SSLCertificateChain.*" + pac + "/d' " + "/etc/apache2/sites-available/" + domName + ".tmp )" + " || sed -i '/SSLCertificate.*" + pac + "/d' " + "/etc/apache2/sites-available/" + domName + ".tmp"), new ShellProcessor( - " ( diff -q /etc/apache2/sites-available/" + domName + ".tmp /etc/apache2/sites-available/" + domName + " && rm /etc/apache2/sites-available/" + domName + ".tmp ) " + - " || ( mv /etc/apache2/sites-available/" + domName + ".tmp /etc/apache2/sites-available/" + domName + + " (diff -q /etc/apache2/sites-available/" + domName + ".tmp /etc/apache2/sites-available/" + domName + " && rm /etc/apache2/sites-available/" + domName + ".tmp ) " + + " || (mv /etc/apache2/sites-available/" + domName + ".tmp /etc/apache2/sites-available/" + domName + " && rm -f /etc/apache2/sites-enabled/" + linkPrefix + "-" + domName + " && ln -sf /etc/apache2/sites-available/" + domName + " /etc/apache2/sites-enabled/" + linkPrefix + "-" + domName + - " && invoke-rc.d apache2 reload >/dev/null 2>&1 ) ") + " && invoke-rc.d apache2 reload >/dev/null 2>&1)") ); return domSetupProcessor; } diff --git a/hsarback/test/de/hsadmin/remote/DomainTest.java b/hsarback/test/de/hsadmin/remote/DomainTest.java index f72e591..c84540b 100644 --- a/hsarback/test/de/hsadmin/remote/DomainTest.java +++ b/hsarback/test/de/hsadmin/remote/DomainTest.java @@ -6,6 +6,13 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.Socket; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -122,6 +129,7 @@ public class DomainTest { @Test public void testDomainOption() { // these tests build upon each other + testZeroOptions(); testOneValidOption(); testTwoValidOptions(); testZeroOptions(); @@ -212,6 +220,68 @@ public class DomainTest { } } + @Test + public void testNogreylisting() throws UnknownHostException, IOException { + testNogreylistingOnOff(true, "Nogreylisting zuerst an"); + testNogreylistingOnOff(false, "Nogreylisting als zweites aus"); + testNogreylistingOnOff(true, "Nogreylisting zuletzt wieder an"); + } + + public void testNogreylistingOnOff(boolean onoff, String message) throws UnknownHostException, IOException { + String user = "aaa00"; + String domain = "example01.org"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map setParams = new HashMap(); + Map whereParams = new HashMap(); + List optionslist = new ArrayList(); + if(onoff) { + optionslist.add("nogreylisting"); + } + setParams.put("domainoptions", optionslist); + whereParams.put("name", domain); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + setParams, whereParams }; + try { + Object execute = client.execute(MODULE + ".update", params); + assertNotNull(execute); + assertEquals(message, onoff, getNogreylisting(domain)); + } catch (XmlRpcException e) { + } + } + + @Test + public void testNohtdocsfallback() throws UnknownHostException, IOException { + testNohtdocsfallbackOnOff(false, "Nothdocsfallback zuerst aus"); + testNohtdocsfallbackOnOff(true, "Nothdocsfallback als zweites an"); + testNohtdocsfallbackOnOff(false, "Nothdocsfallback zuletzt wieder aus"); + } + + @Test + public void testNohtdocsfallbackOnOff( boolean onoff, String message) throws UnknownHostException, IOException { + String user = "aaa00"; + String domain = "example01.org"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map setParams = new HashMap(); + Map whereParams = new HashMap(); + List optionslist = new ArrayList(); + if(onoff) { + optionslist.add("nohtdocsfallback"); + } + setParams.put("domainoptions", optionslist); + whereParams.put("name", domain); + Object[] params = new Object[] { user, + cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), + setParams, whereParams }; + try { + Object execute = client.execute(MODULE + ".update", params); + assertNotNull(execute); + assertEquals(message, onoff, getNohtdocsfallback(domain)); + } catch (XmlRpcException e) { + } + } + + private int getDomsCount() { int count = 0; String user = "aaa00"; @@ -258,4 +328,51 @@ public class DomainTest { return count; } + private boolean getNogreylisting(String domain) throws UnknownHostException, IOException { + String host = "test-h99.hostsharing.net"; + String answer = socketQuery( host, 25, + "HELO " + domain + "\n" + + "MAIl FROM: hsadmin-testing@" + domain + "\n" + + "RCPT TO: postmaster@" + domain + "\n" + + "DATA\n" + + ".\n") ; + return answer.contains("450") && answer.contains("reylisting"); + } + + private boolean getNohtdocsfallback(String domain) throws UnknownHostException, IOException { + String host = "test-h99.hostsharing.net"; + String answer = socketQuery( host, 80, + "GET / HTTP/1.1\n" + + "Host: x.y.z." + domain + + "User-Agent: hsAdmin Test\n" + + "Connection: close\n"); + answer = answer.substring(0, answer.indexOf("\n")); + return answer.contains("404"); + } + + private String socketQuery( String host, int port, String query) throws UnknownHostException, IOException{ + Socket socket = new Socket( host, port ); + socketQueryWriter( socket, query ); + return socketQueryReader(socket); + } + + private void socketQueryWriter( Socket socket, String buffer) throws IOException{ + PrintWriter printWriter = + new PrintWriter( + new OutputStreamWriter( + socket.getOutputStream())); + printWriter.print(buffer); + printWriter.flush(); + } + + private String socketQueryReader( Socket socket ) throws IOException{ + int maxbufferbytecount = 4099; + BufferedReader bufferedReader = + new BufferedReader( + new InputStreamReader( + socket.getInputStream())); + char[] buffer = new char[maxbufferbytecount]; + int bufferbytecount = bufferedReader.read(buffer, 0, maxbufferbytecount); // blocks til end of transmission + return new String(buffer, 0, bufferbytecount); + } }