2010-10-05 21:42:07 +02:00
|
|
|
package de.hsadmin.remote;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
2012-09-20 17:09:51 +02:00
|
|
|
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;
|
2012-07-18 13:53:41 +02:00
|
|
|
import java.util.ArrayList;
|
2010-10-05 21:42:07 +02:00
|
|
|
import java.util.HashMap;
|
2012-07-18 13:53:41 +02:00
|
|
|
import java.util.List;
|
2010-10-05 21:42:07 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
public class DomainTest {
|
|
|
|
|
|
|
|
private static final String MODULE = "domain";
|
|
|
|
|
|
|
|
private XmlRpcClient client;
|
|
|
|
private RemoteCASHelper cas;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
client = RemoteTestHelper.getClient();
|
|
|
|
cas = new RemoteCASHelper();
|
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
client = null;
|
|
|
|
cas = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSearchAllAsPacAdmin() {
|
2011-05-06 18:28:11 +02:00
|
|
|
String user = "aaa00";
|
2010-10-05 21:42:07 +02:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".search", params);
|
|
|
|
Object[] result = (Object[]) execute;
|
2012-01-02 15:41:11 +01:00
|
|
|
assertEquals(2, result.length);
|
2010-10-05 21:42:07 +02:00
|
|
|
for (Object o : result) {
|
|
|
|
if (o instanceof Map<?, ?>) {
|
|
|
|
Map<?, ?> row = (Map<?, ?>) o;
|
2012-01-02 16:07:48 +01:00
|
|
|
assertTrue("aaa00".equals(row.get("user")) || "aaa00-admin".equals(row.get("user")));
|
2010-10-05 21:42:07 +02:00
|
|
|
} else {
|
|
|
|
fail("map expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testUpdate() {
|
2012-01-02 15:13:43 +01:00
|
|
|
String user = "aaa00";
|
2010-10-05 21:42:07 +02:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> setParams = new HashMap<String, String>();
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2012-01-02 15:13:43 +01:00
|
|
|
setParams.put("user", "aaa00");
|
|
|
|
whereParams.put("name", "example01.org");
|
2010-10-05 21:42:07 +02:00
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
|
|
|
fail("exception expected");
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2012-09-21 14:30:03 +02:00
|
|
|
public void testCreate() throws UnknownHostException, IOException {
|
2010-10-05 21:42:07 +02:00
|
|
|
int count = getDomsCount();
|
2012-01-02 15:13:43 +01:00
|
|
|
String user = "aaa00";
|
2010-10-05 21:42:07 +02:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> setParams = new HashMap<String, String>();
|
|
|
|
setParams.put("name", "f6n.de");
|
2012-01-02 15:19:56 +01:00
|
|
|
setParams.put("user", "aaa00-admin");
|
2010-10-05 21:42:07 +02:00
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".add", params);
|
|
|
|
assertTrue(execute instanceof Map<?, ?>);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count + 1, getDomsCount());
|
2012-09-21 14:30:03 +02:00
|
|
|
// TODO die beiden folgenden Tests sind etwas spezifisch für Version 2.2
|
2012-11-28 16:46:44 +01:00
|
|
|
assertEquals("neue Domain ist nicht kompatibel zum Bisher",5,getDomOptionsCount());
|
2012-09-21 14:30:03 +02:00
|
|
|
testGreylistingOnOff(true, "sollte bei neuer Domain eingeschaltet sein");
|
2012-11-28 16:46:44 +01:00
|
|
|
testHtdocsfallbackOnOff(true, "sollte bei neuer Domain eingeschaltet sein");
|
|
|
|
testIncludesOnOff(true, "sollte bei neuer Domain eingeschaltet sein");
|
|
|
|
testIndexesOnOff(true, "sollte bei neuer Domain eingeschaltet sein");
|
|
|
|
testMultiviewsOnOff(true, "sollte bei neuer Domain eingeschaltet sein");
|
|
|
|
testBackupMxForExternamlMxOnOff(false, "sollte bei neuer Domain ausgeschaltet sein");
|
2010-10-05 21:42:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDelete() {
|
|
|
|
int count = getDomsCount();
|
2012-01-02 15:13:43 +01:00
|
|
|
String user = "aaa00";
|
2010-10-05 21:42:07 +02:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("name", "f6n.de");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".delete", params);
|
|
|
|
assertNull(execute);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count - 1, getDomsCount());
|
|
|
|
}
|
|
|
|
|
2012-07-18 19:12:42 +02:00
|
|
|
@Test
|
|
|
|
public void testDomainOption() {
|
|
|
|
// these tests build upon each other
|
2012-09-20 17:09:51 +02:00
|
|
|
testZeroOptions();
|
2012-07-18 19:12:42 +02:00
|
|
|
testOneValidOption();
|
|
|
|
testTwoValidOptions();
|
|
|
|
testZeroOptions();
|
|
|
|
}
|
|
|
|
|
2012-07-18 21:28:02 +02:00
|
|
|
@Test
|
2012-07-18 13:53:41 +02:00
|
|
|
public void testInvalidOption() {
|
2012-07-18 13:24:46 +02:00
|
|
|
String user = "aaa00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
2012-07-18 13:53:41 +02:00
|
|
|
Map<String, Object> setParams = new HashMap<String, Object>();
|
2012-07-18 13:24:46 +02:00
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2012-07-18 13:53:41 +02:00
|
|
|
List<String> optionslist = new ArrayList<String>();
|
|
|
|
optionslist.add("invalide");
|
|
|
|
setParams.put("domainoptions", optionslist);
|
2012-07-18 13:24:46 +02:00
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
|
|
|
fail("exception expected");
|
|
|
|
} catch (XmlRpcException e) {
|
2012-07-18 14:11:08 +02:00
|
|
|
assertEquals(getDomOptionsCount(),0);
|
2012-07-18 13:24:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 13:53:41 +02:00
|
|
|
public void testOneValidOption() {
|
|
|
|
String user = "aaa00";
|
|
|
|
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>();
|
2012-09-20 20:24:55 +02:00
|
|
|
optionslist.add("greylisting");
|
2012-07-18 13:53:41 +02:00
|
|
|
setParams.put("domainoptions", optionslist);
|
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
2012-07-18 20:28:20 +02:00
|
|
|
assertEquals(1, getDomOptionsCount());
|
2012-07-18 13:53:41 +02:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testTwoValidOptions() {
|
|
|
|
String user = "aaa00";
|
|
|
|
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>();
|
2012-09-20 20:24:55 +02:00
|
|
|
optionslist.add("htdocsfallback");
|
|
|
|
optionslist.add("greylisting");
|
2012-07-18 13:53:41 +02:00
|
|
|
setParams.put("domainoptions", optionslist);
|
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
2012-07-18 20:28:20 +02:00
|
|
|
assertEquals(2, getDomOptionsCount());
|
2012-07-18 13:53:41 +02:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 15:31:58 +02:00
|
|
|
public void testZeroOptions() {
|
|
|
|
String user = "aaa00";
|
|
|
|
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>();
|
|
|
|
setParams.put("domainoptions", optionslist);
|
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
2012-07-18 20:28:20 +02:00
|
|
|
assertEquals(0, getDomOptionsCount());
|
2012-07-18 15:31:58 +02:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-21 11:29:18 +02:00
|
|
|
// @Test
|
|
|
|
public void testBackupMxForExternamlMx() throws UnknownHostException, IOException {
|
|
|
|
testBackupMxForExternamlMxOnOff(true, "zuerst an");
|
|
|
|
testBackupMxForExternamlMxOnOff(false, "als zweites aus");
|
|
|
|
testBackupMxForExternamlMxOnOff(true, "zuletzt wieder an");
|
|
|
|
}
|
|
|
|
|
2012-09-20 17:09:51 +02:00
|
|
|
@Test
|
2012-09-20 20:24:55 +02:00
|
|
|
public void testGreylisting() throws UnknownHostException, IOException {
|
|
|
|
testGreylistingOnOff(true, "zuerst an");
|
|
|
|
testGreylistingOnOff(false, "als zweites aus");
|
|
|
|
testGreylistingOnOff(true, "zuletzt wieder an");
|
2012-09-20 17:09:51 +02:00
|
|
|
}
|
|
|
|
|
2012-09-20 20:24:55 +02:00
|
|
|
@Test
|
|
|
|
public void testHtdocsfallback() throws UnknownHostException, IOException {
|
|
|
|
testHtdocsfallbackOnOff(false, "zuerst aus");
|
|
|
|
testHtdocsfallbackOnOff(true, "als zweites an");
|
|
|
|
testHtdocsfallbackOnOff(false, "zuletzt wieder aus");
|
2012-09-20 17:09:51 +02:00
|
|
|
}
|
2012-09-21 11:29:18 +02:00
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void testIncludes() throws UnknownHostException, IOException {
|
|
|
|
testIncludesOnOff(false, "zuerst aus");
|
|
|
|
testIncludesOnOff(true, "als zweites an");
|
|
|
|
testIncludesOnOff(false, "zuletzt wieder aus");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void testIndexes() throws UnknownHostException, IOException {
|
|
|
|
testIndexesOnOff(false, "zuerst aus");
|
|
|
|
testIndexesOnOff(true, "als zweites an");
|
|
|
|
testIndexesOnOff(false, "zuletzt wieder aus");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void testMultiviews() throws UnknownHostException, IOException {
|
|
|
|
testMultiviewsOnOff(true, "zuerst an");
|
|
|
|
testMultiviewsOnOff(false, "als zweites aus");
|
|
|
|
testMultiviewsOnOff(true, "zuletzt wieder an");
|
|
|
|
}
|
2012-09-20 20:24:55 +02:00
|
|
|
|
2012-09-21 11:29:18 +02:00
|
|
|
private void testBackupMxForExternamlMxOnOff(boolean onoff, String message)
|
2012-09-20 20:24:55 +02:00
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
testDomainptionOnOf(onoff, message, new DomainOptionTester() {
|
2012-09-20 17:09:51 +02:00
|
|
|
|
2012-09-20 20:24:55 +02:00
|
|
|
@Override
|
|
|
|
public String getOptionName() {
|
2012-09-21 11:29:18 +02:00
|
|
|
return "backupmxforexternalmx";
|
2012-09-20 20:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOptionConfigured(String domain)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
String host = "test-h99.hostsharing.net";
|
2012-09-21 11:29:18 +02:00
|
|
|
return host == ""; // noch kein sinnvoller test
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-09-21 17:31:58 +02:00
|
|
|
private void testGreylistingOnOff(boolean onoff, String message)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
testDomainptionOnOf(onoff, message, new DomainOptionTester() {
|
2012-09-21 11:29:18 +02:00
|
|
|
|
2012-09-21 17:31:58 +02:00
|
|
|
@Override
|
|
|
|
public String getOptionName() {
|
|
|
|
return "greylisting";
|
|
|
|
}
|
2012-09-21 11:29:18 +02:00
|
|
|
|
2012-09-21 17:31:58 +02:00
|
|
|
@Override
|
|
|
|
public boolean isOptionConfigured(String domain)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
String host = "test-h99.hostsharing.net";
|
2012-10-02 16:44:36 +02:00
|
|
|
String[] query = {
|
|
|
|
"HELO " + domain + "\n" ,
|
|
|
|
"MAIL FROM: hsadmin-testing@" + domain + "\n" ,
|
|
|
|
"RCPT TO: postmaster@" + domain + "\n" ,
|
|
|
|
"DATA\n" ,
|
|
|
|
".\n" ,
|
|
|
|
"QUIT\n" } ;
|
|
|
|
String[] answer = socketQuery(host, 25, query ) ;
|
|
|
|
return answer[3].contains("450") && answer[3].contains("reylisting");
|
2012-09-20 20:24:55 +02:00
|
|
|
}
|
|
|
|
});
|
2012-09-20 17:09:51 +02:00
|
|
|
}
|
2012-09-21 11:29:18 +02:00
|
|
|
|
2012-09-20 20:24:55 +02:00
|
|
|
private void testHtdocsfallbackOnOff(boolean onoff, String message)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
testDomainptionOnOf(onoff, message, new DomainOptionTester() {
|
2012-09-20 17:09:51 +02:00
|
|
|
|
2012-09-20 20:24:55 +02:00
|
|
|
@Override
|
|
|
|
public String getOptionName() {
|
|
|
|
return "htdocsfallback";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOptionConfigured(String domain)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
String host = "test-h99.hostsharing.net";
|
2012-10-02 16:44:36 +02:00
|
|
|
String[] answer = socketQuery(host, 80, "GET / HTTP/1.1\n"
|
2012-09-21 11:29:18 +02:00
|
|
|
+ "Host: x.y.z." + domain
|
|
|
|
+ "User-Agent: hsAdmin Test\n"
|
|
|
|
+ "Connection: close\n");
|
2012-10-02 16:44:36 +02:00
|
|
|
// answer = answer.substring(0, answer.indexOf("\n"));
|
|
|
|
return answer[1].contains("404");
|
2012-09-21 11:29:18 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void testIncludesOnOff(boolean onoff, String message)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
testDomainptionOnOf(onoff, message, new DomainOptionTester() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOptionName() {
|
|
|
|
return "includes";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOptionConfigured(String domain)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
String host = "test-h99.hostsharing.net";
|
|
|
|
// TODO dieser Test ist Humbug
|
2012-10-02 16:44:36 +02:00
|
|
|
String[] answer = socketQuery(host, 80, "GET / HTTP/1.1\n"
|
2012-09-21 11:29:18 +02:00
|
|
|
+ "Host: " + domain
|
|
|
|
+ "User-Agent: hsAdmin Test\n"
|
|
|
|
+ "Connection: close\n");
|
2012-10-02 16:44:36 +02:00
|
|
|
// answer = answer.substring(0, answer.indexOf("\n"));
|
|
|
|
return answer[1].contains("404");
|
2012-09-21 11:29:18 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void testIndexesOnOff(boolean onoff, String message)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
testDomainptionOnOf(onoff, message, new DomainOptionTester() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOptionName() {
|
|
|
|
return "indexes";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOptionConfigured(String domain)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
String host = "test-h99.hostsharing.net";
|
|
|
|
// TODO dieser Test ist Humbug
|
2012-10-02 16:44:36 +02:00
|
|
|
String[] answer = socketQuery(host, 80, "GET / HTTP/1.1\n"
|
2012-09-21 11:29:18 +02:00
|
|
|
+ "Host: " + domain
|
|
|
|
+ "User-Agent: hsAdmin Test\n"
|
|
|
|
+ "Connection: close\n");
|
2012-10-02 16:44:36 +02:00
|
|
|
// answer = answer.substring(0, answer.indexOf("\n"));
|
|
|
|
return answer[1].contains("404");
|
2012-09-21 11:29:18 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void testMultiviewsOnOff(boolean onoff, String message)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
testDomainptionOnOf(onoff, message, new DomainOptionTester() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOptionName() {
|
|
|
|
return "multiviews";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOptionConfigured(String domain)
|
|
|
|
throws UnknownHostException, IOException {
|
|
|
|
String host = "test-h99.hostsharing.net";
|
|
|
|
// TODO dieser Test ist Humbug
|
2012-10-02 16:44:36 +02:00
|
|
|
String[] answer = socketQuery(host, 80, "GET / HTTP/1.1\n"
|
2012-09-21 11:29:18 +02:00
|
|
|
+ "Host: " + domain
|
|
|
|
+ "User-Agent: hsAdmin Test\n"
|
|
|
|
+ "Connection: close\n");
|
2012-10-02 16:44:36 +02:00
|
|
|
// answer = answer.substring(0, answer.indexOf("\n"));
|
|
|
|
return answer[1].contains("404");
|
2012-09-20 20:24:55 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void testDomainptionOnOf( boolean onoff, String message, DomainOptionTester tester) throws UnknownHostException, IOException {
|
2012-09-20 17:09:51 +02:00
|
|
|
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) {
|
2012-09-20 20:24:55 +02:00
|
|
|
optionslist.add(tester.getOptionName());
|
2012-09-20 17:09:51 +02:00
|
|
|
}
|
|
|
|
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);
|
2012-09-20 20:24:55 +02:00
|
|
|
assertEquals(tester.getOptionName()+": "+message, onoff, tester.isOptionConfigured(domain));
|
2012-09-20 17:09:51 +02:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-05 21:42:07 +02:00
|
|
|
private int getDomsCount() {
|
|
|
|
int count = 0;
|
2012-01-02 15:13:43 +01:00
|
|
|
String user = "aaa00";
|
2010-10-05 21:42:07 +02:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".search", params);
|
|
|
|
Object[] result = (Object[]) execute;
|
|
|
|
count = result.length;
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-07-18 14:11:08 +02:00
|
|
|
private int getDomOptionsCount() {
|
|
|
|
int count = 0;
|
|
|
|
String user = "aaa00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".search", params);
|
|
|
|
Object[] result = (Object[]) execute;
|
2012-07-19 16:27:58 +02:00
|
|
|
assertEquals(result.length, 1);
|
2012-07-18 16:49:31 +02:00
|
|
|
assertTrue(result[0] instanceof Map<?, ?>);
|
2012-07-25 18:24:12 +02:00
|
|
|
Map<?, ?> domainMap = (Map<?, ?>) result[0];
|
2012-07-18 14:51:07 +02:00
|
|
|
assertNotNull(domainMap);
|
2012-07-18 20:41:25 +02:00
|
|
|
Object[] optsList = (Object[])domainMap.get("domainoptions");
|
2012-07-19 16:27:58 +02:00
|
|
|
if (optsList == null) {
|
|
|
|
count = 0;
|
|
|
|
} else {
|
2012-07-18 20:41:25 +02:00
|
|
|
count = optsList.length;
|
2012-07-19 16:27:58 +02:00
|
|
|
}
|
2012-07-18 14:11:08 +02:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-10-02 16:44:36 +02:00
|
|
|
private static String[] socketQuery( String host, int port, String command) throws UnknownHostException, IOException{
|
|
|
|
String[] query = { command } ;
|
|
|
|
return socketQuery( host , port , query );
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String[] socketQuery( String host, int port, String[] query) throws UnknownHostException, IOException{
|
2012-09-20 17:09:51 +02:00
|
|
|
Socket socket = new Socket( host, port );
|
2012-10-02 16:44:36 +02:00
|
|
|
String[] retval = socketQuery( socket, query );
|
|
|
|
socket.close();
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String[] socketQuery( Socket socket, String command) throws UnknownHostException, IOException{
|
|
|
|
String[] query = { command } ;
|
|
|
|
return socketQuery( socket , query );
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String[] socketQuery( Socket socket, String[] query) throws UnknownHostException, IOException{
|
|
|
|
int l = query.length;
|
|
|
|
String[] retval = new String[l];
|
|
|
|
retval[0] = socketQueryReader(socket);
|
|
|
|
for(int i=0; i<l; ){
|
|
|
|
socketQueryWriter( socket, query[i] );
|
|
|
|
retval[i++] = socketQueryReader(socket);
|
|
|
|
}
|
|
|
|
return retval;
|
2012-09-20 17:09:51 +02:00
|
|
|
}
|
|
|
|
|
2012-10-02 16:44:36 +02:00
|
|
|
private static void socketQueryWriter( Socket socket, String buffer) throws IOException{
|
2012-09-20 17:09:51 +02:00
|
|
|
PrintWriter printWriter =
|
|
|
|
new PrintWriter(
|
|
|
|
new OutputStreamWriter(
|
|
|
|
socket.getOutputStream()));
|
|
|
|
printWriter.print(buffer);
|
|
|
|
printWriter.flush();
|
|
|
|
}
|
|
|
|
|
2012-10-02 16:44:36 +02:00
|
|
|
private static String socketQueryReader( Socket socket ) throws IOException{
|
2012-09-20 17:09:51 +02:00
|
|
|
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);
|
|
|
|
}
|
2010-10-05 21:42:07 +02:00
|
|
|
}
|