From 31889d3f9b447fab98d3136155ae89a4cd003eff Mon Sep 17 00:00:00 2001 From: HSAdmin Test Services Date: Thu, 20 Sep 2012 12:39:14 +0200 Subject: [PATCH 1/7] corrected sql for domain_options --- hsarback/database/schema.sql | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hsarback/database/schema.sql b/hsarback/database/schema.sql index 98645d7..0424bd4 100644 --- a/hsarback/database/schema.sql +++ b/hsarback/database/schema.sql @@ -912,16 +912,17 @@ CREATE TABLE domain_option ( ); ALTER TABLE ONLY domain_option - ADD CONSTRAINT domain_option_uniq UNIQUE (domain_option_id); + ADD CONSTRAINT pk_domain_option PRIMARY KEY (domain_option_id); -CREATE UNIQUE INDEX ON domain_option ( domain_option_name ); +CREATE UNIQUE INDEX domain_option_name_idx ON domain_option USING btree ( domain_option_name ); CREATE TABLE domain__domain_option ( domain_option_id integer NOT NULL, domain_id integer NOT NULL ); -CREATE UNIQUE INDEX unique_domain__domain_option ON domain__domain_option USING btree (domain_option_id, domain_id); +ALTER TABLE ONLY domain__domain_option + ADD CONSTRAINT pk_domain__domain_option PRIMARY KEY (domain_option_id, domain_id); ALTER TABLE ONLY domain__domain_option ADD CONSTRAINT domain_option_id_fkey FOREIGN KEY (domain_option_id) From c0e94a6e65f4c7f76bbe9ea1aad0898548804cc6 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 20 Sep 2012 15:39:45 +0200 Subject: [PATCH 2/7] mkdir -p because directories exist on domain update --- hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 5214daa..8447866 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -249,13 +249,13 @@ public class DomainProcessorFactory implements EntityProcessorFactory { "chmod g+rx " + homeDir + " && " + "mkdir --mode=1550 --parents " + domsDir + " && " + "chown httpd:" + pacName + " " + domsDir + " && " + - "mkdir --mode=750 " + domainDir + " && " + + "mkdir --mode=750 --parents " + domainDir + " && " + "chown " + userName + ":httpd " + domainDir ); CompoundProcessor domDirsProcessor = new CompoundProcessor(mkDomainDirProzessor); for (String subDir : subDirs) { domDirsProcessor.appendProcessor(new ShellProcessor( - "mkdir --mode=755 " + domainDir + "/" + subDir + " && " + + "mkdir --mode=755 --parents " + domainDir + "/" + subDir + " && " + "chown " + userName + ":" + pacName + " " + domainDir + "/" + subDir )); } From 56d3425ad86b03d8a10963bf4afb688c903487d6 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 20 Sep 2012 15:40:42 +0200 Subject: [PATCH 3/7] mkdir -p because directories exist on domain update --- hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 5214daa..8447866 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -249,13 +249,13 @@ public class DomainProcessorFactory implements EntityProcessorFactory { "chmod g+rx " + homeDir + " && " + "mkdir --mode=1550 --parents " + domsDir + " && " + "chown httpd:" + pacName + " " + domsDir + " && " + - "mkdir --mode=750 " + domainDir + " && " + + "mkdir --mode=750 --parents " + domainDir + " && " + "chown " + userName + ":httpd " + domainDir ); CompoundProcessor domDirsProcessor = new CompoundProcessor(mkDomainDirProzessor); for (String subDir : subDirs) { domDirsProcessor.appendProcessor(new ShellProcessor( - "mkdir --mode=755 " + domainDir + "/" + subDir + " && " + + "mkdir --mode=755 --parents " + domainDir + "/" + subDir + " && " + "chown " + userName + ":" + pacName + " " + domainDir + "/" + subDir )); } From 8855708fd08148d54a5c2ce1e3ae154e55bd95c9 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 20 Sep 2012 16:20:01 +0200 Subject: [PATCH 4/7] overwrite existing link on domain update --- hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 8447866..832172a 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -288,7 +288,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { ); } domDirsProcessor.appendProcessor( - new ShellProcessor("ln -s " + domainDir + " /home/doms/ && " + + new ShellProcessor("ln -s -f " + domainDir + " /home/doms/ && " + "chown --no-dereference " + userName + ":httpd /home/doms/" + domName + " && " + "chown " + userName + ":httpd /home/doms/" + domName + "/") ); From 324f4900df09d6e277056c5336f488c8eb5b926c Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 20 Sep 2012 16:31:39 +0200 Subject: [PATCH 5/7] overwrite existing link an domain update --- hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 832172a..ead2757 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -288,7 +288,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { ); } domDirsProcessor.appendProcessor( - new ShellProcessor("ln -s -f " + domainDir + " /home/doms/ && " + + new ShellProcessor("ln -sf " + domainDir + " /home/doms/ && " + "chown --no-dereference " + userName + ":httpd /home/doms/" + domName + " && " + "chown " + userName + ":httpd /home/doms/" + domName + "/") ); From f3485454869e3802c0c4833749dd6e8ac8878adc Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 20 Sep 2012 16:32:07 +0200 Subject: [PATCH 6/7] overwrite existing link an domain update --- hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 832172a..ead2757 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -288,7 +288,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { ); } domDirsProcessor.appendProcessor( - new ShellProcessor("ln -s -f " + domainDir + " /home/doms/ && " + + new ShellProcessor("ln -sf " + domainDir + " /home/doms/ && " + "chown --no-dereference " + userName + ":httpd /home/doms/" + domName + " && " + "chown " + userName + ":httpd /home/doms/" + domName + "/") ); From fba68a65ee50a76493f49c95826c5a373b4ced7f Mon Sep 17 00:00:00 2001 From: Purodha Blissenbach Date: Thu, 20 Sep 2012 17:09:51 +0200 Subject: [PATCH 7/7] Tests added for domain options: Nogreylisting, Nohtdocsfallback --- .../test/de/hsadmin/remote/DomainTest.java | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) 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); + } }