More domainoptions preemptively preset in data base, existing options

renmend ( no no-), tests universalized.
This commit is contained in:
Purodha Blissenbach 2012-09-20 20:24:55 +02:00
parent 796799bc63
commit ea42d6fedb
3 changed files with 70 additions and 106 deletions

View File

@ -155,6 +155,14 @@ INSERT INTO unixuser (name, comment, shell, homedir, locked, packet_id, userid)
-- table: domain_option -- table: domain_option
-- --
INSERT INTO domain_option (domain_option_name) INSERT INTO domain_option (domain_option_name)
VALUES ('nogreylisting'); VALUES ('backupmxforexternalmx');
INSERT INTO domain_option (domain_option_name) INSERT INTO domain_option (domain_option_name)
VALUES ('nohtdocsfallback'); VALUES ('greylisting');
INSERT INTO domain_option (domain_option_name)
VALUES ('htdocsfallback');
INSERT INTO domain_option (domain_option_name)
VALUES ('includes');
INSERT INTO domain_option (domain_option_name)
VALUES ('indexes');
INSERT INTO domain_option (domain_option_name)
VALUES ('multiviews');

View File

@ -1,43 +0,0 @@
CREATE SEQUENCE domain_option_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
CREATE TABLE domain_option (
domain_option_id integer DEFAULT nextval(('"domain_option_id_seq"'::text)::regclass) NOT NULL,
domain_option_name character varying(50) NOT NULL
);
ALTER TABLE ONLY domain_option
ADD CONSTRAINT domain_option_uniq UNIQUE (domain_option_id);
CREATE UNIQUE INDEX ON domain_option ( 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 domain_option_id_fkey FOREIGN KEY (domain_option_id)
REFERENCES domain_option(domain_option_id) DEFERRABLE;
ALTER TABLE ONLY domain__domain_option
ADD CONSTRAINT domain_id_fkey FOREIGN KEY (domain_id)
REFERENCES domain(domain_id) DEFERRABLE;
update domain set domain_since=domain_filed;
alter table domain drop column domain_free;
alter table domain drop column domain_until;
alter table domain drop column domain_filed;
alter table domain drop column domain_reminder;
alter table domain drop column domain_template;
alter table domain drop column domain_status;
alter table domain drop column domain_status_changed;

View File

@ -163,7 +163,7 @@ public class DomainTest {
Map<String, Object> setParams = new HashMap<String, Object>(); Map<String, Object> setParams = new HashMap<String, Object>();
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
List<String> optionslist = new ArrayList<String>(); List<String> optionslist = new ArrayList<String>();
optionslist.add("nogreylisting"); optionslist.add("greylisting");
setParams.put("domainoptions", optionslist); setParams.put("domainoptions", optionslist);
whereParams.put("name", "example01.org"); whereParams.put("name", "example01.org");
Object[] params = new Object[] { user, Object[] params = new Object[] { user,
@ -184,8 +184,8 @@ public class DomainTest {
Map<String, Object> setParams = new HashMap<String, Object>(); Map<String, Object> setParams = new HashMap<String, Object>();
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
List<String> optionslist = new ArrayList<String>(); List<String> optionslist = new ArrayList<String>();
optionslist.add("nohtdocsfallback"); optionslist.add("htdocsfallback");
optionslist.add("nogreylisting"); optionslist.add("greylisting");
setParams.put("domainoptions", optionslist); setParams.put("domainoptions", optionslist);
whereParams.put("name", "example01.org"); whereParams.put("name", "example01.org");
Object[] params = new Object[] { user, Object[] params = new Object[] { user,
@ -221,13 +221,66 @@ public class DomainTest {
} }
@Test @Test
public void testNogreylisting() throws UnknownHostException, IOException { public void testGreylisting() throws UnknownHostException, IOException {
testNogreylistingOnOff(true, "Nogreylisting zuerst an"); testGreylistingOnOff(true, "zuerst an");
testNogreylistingOnOff(false, "Nogreylisting als zweites aus"); testGreylistingOnOff(false, "als zweites aus");
testNogreylistingOnOff(true, "Nogreylisting zuletzt wieder an"); testGreylistingOnOff(true, "zuletzt wieder an");
} }
public void testNogreylistingOnOff(boolean onoff, String message) throws UnknownHostException, IOException { @Test
public void testHtdocsfallback() throws UnknownHostException, IOException {
testHtdocsfallbackOnOff(false, "zuerst aus");
testHtdocsfallbackOnOff(true, "als zweites an");
testHtdocsfallbackOnOff(false, "zuletzt wieder aus");
}
private void testGreylistingOnOff(boolean onoff, String message)
throws UnknownHostException, IOException {
testDomainptionOnOf(onoff, message, new DomainOptionTester() {
@Override
public String getOptionName() {
return "greylisting";
}
@Override
public boolean isOptionConfigured(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 void testHtdocsfallbackOnOff(boolean onoff, String message)
throws UnknownHostException, IOException {
testDomainptionOnOf(onoff, message, new DomainOptionTester() {
@Override
public String getOptionName() {
return "htdocsfallback";
}
@Override
public boolean isOptionConfigured(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 void testDomainptionOnOf( boolean onoff, String message, DomainOptionTester tester) throws UnknownHostException, IOException {
String user = "aaa00"; String user = "aaa00";
String domain = "example01.org"; String domain = "example01.org";
String grantingTicketURL = cas.getGrantingTicketURL(user); String grantingTicketURL = cas.getGrantingTicketURL(user);
@ -235,7 +288,7 @@ public class DomainTest {
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
List<String> optionslist = new ArrayList<String>(); List<String> optionslist = new ArrayList<String>();
if(onoff) { if(onoff) {
optionslist.add("nogreylisting"); optionslist.add(tester.getOptionName());
} }
setParams.put("domainoptions", optionslist); setParams.put("domainoptions", optionslist);
whereParams.put("name", domain); whereParams.put("name", domain);
@ -245,43 +298,11 @@ public class DomainTest {
try { try {
Object execute = client.execute(MODULE + ".update", params); Object execute = client.execute(MODULE + ".update", params);
assertNotNull(execute); assertNotNull(execute);
assertEquals(message, onoff, getNogreylisting(domain)); assertEquals(tester.getOptionName()+": "+message, onoff, tester.isOptionConfigured(domain));
} catch (XmlRpcException e) { } 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<String, Object> setParams = new HashMap<String, Object>();
Map<String, String> whereParams = new HashMap<String, String>();
List<String> optionslist = new ArrayList<String>();
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() { private int getDomsCount() {
int count = 0; int count = 0;
String user = "aaa00"; String user = "aaa00";
@ -328,28 +349,6 @@ public class DomainTest {
return count; 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{ private String socketQuery( String host, int port, String query) throws UnknownHostException, IOException{
Socket socket = new Socket( host, port ); Socket socket = new Socket( host, port );
socketQueryWriter( socket, query ); socketQueryWriter( socket, query );