Correctinos and enhancements for domain options testing via sockets.

This commit is contained in:
Purodha Blissenbach 2012-10-02 16:44:36 +02:00
parent d3c62505b3
commit 984d169e2c

View File

@ -296,11 +296,15 @@ public class DomainTest {
public boolean isOptionConfigured(String domain) public boolean isOptionConfigured(String domain)
throws UnknownHostException, IOException { throws UnknownHostException, IOException {
String host = "test-h99.hostsharing.net"; String host = "test-h99.hostsharing.net";
String answer = socketQuery(host, 25, "HELO " + domain + "\n" String[] query = {
+ "MAIL FROM: hsadmin-testing@" + domain + "\n" "HELO " + domain + "\n" ,
+ "RCPT TO: postmaster@" + domain + "\n" + "DATA\n" "MAIL FROM: hsadmin-testing@" + domain + "\n" ,
+ ".\n"); "RCPT TO: postmaster@" + domain + "\n" ,
return answer.contains("450") && answer.contains("reylisting"); "DATA\n" ,
".\n" ,
"QUIT\n" } ;
String[] answer = socketQuery(host, 25, query ) ;
return answer[3].contains("450") && answer[3].contains("reylisting");
} }
}); });
} }
@ -318,12 +322,12 @@ public class DomainTest {
public boolean isOptionConfigured(String domain) public boolean isOptionConfigured(String domain)
throws UnknownHostException, IOException { throws UnknownHostException, IOException {
String host = "test-h99.hostsharing.net"; String host = "test-h99.hostsharing.net";
String answer = socketQuery(host, 80, "GET / HTTP/1.1\n" String[] answer = socketQuery(host, 80, "GET / HTTP/1.1\n"
+ "Host: x.y.z." + domain + "Host: x.y.z." + domain
+ "User-Agent: hsAdmin Test\n" + "User-Agent: hsAdmin Test\n"
+ "Connection: close\n"); + "Connection: close\n");
answer = answer.substring(0, answer.indexOf("\n")); // answer = answer.substring(0, answer.indexOf("\n"));
return answer.contains("404"); return answer[1].contains("404");
} }
}); });
} }
@ -342,12 +346,12 @@ public class DomainTest {
throws UnknownHostException, IOException { throws UnknownHostException, IOException {
String host = "test-h99.hostsharing.net"; String host = "test-h99.hostsharing.net";
// TODO dieser Test ist Humbug // TODO dieser Test ist Humbug
String answer = socketQuery(host, 80, "GET / HTTP/1.1\n" String[] answer = socketQuery(host, 80, "GET / HTTP/1.1\n"
+ "Host: " + domain + "Host: " + domain
+ "User-Agent: hsAdmin Test\n" + "User-Agent: hsAdmin Test\n"
+ "Connection: close\n"); + "Connection: close\n");
answer = answer.substring(0, answer.indexOf("\n")); // answer = answer.substring(0, answer.indexOf("\n"));
return answer.contains("404"); return answer[1].contains("404");
} }
}); });
} }
@ -366,12 +370,12 @@ public class DomainTest {
throws UnknownHostException, IOException { throws UnknownHostException, IOException {
String host = "test-h99.hostsharing.net"; String host = "test-h99.hostsharing.net";
// TODO dieser Test ist Humbug // TODO dieser Test ist Humbug
String answer = socketQuery(host, 80, "GET / HTTP/1.1\n" String[] answer = socketQuery(host, 80, "GET / HTTP/1.1\n"
+ "Host: " + domain + "Host: " + domain
+ "User-Agent: hsAdmin Test\n" + "User-Agent: hsAdmin Test\n"
+ "Connection: close\n"); + "Connection: close\n");
answer = answer.substring(0, answer.indexOf("\n")); // answer = answer.substring(0, answer.indexOf("\n"));
return answer.contains("404"); return answer[1].contains("404");
} }
}); });
} }
@ -390,12 +394,12 @@ public class DomainTest {
throws UnknownHostException, IOException { throws UnknownHostException, IOException {
String host = "test-h99.hostsharing.net"; String host = "test-h99.hostsharing.net";
// TODO dieser Test ist Humbug // TODO dieser Test ist Humbug
String answer = socketQuery(host, 80, "GET / HTTP/1.1\n" String[] answer = socketQuery(host, 80, "GET / HTTP/1.1\n"
+ "Host: " + domain + "Host: " + domain
+ "User-Agent: hsAdmin Test\n" + "User-Agent: hsAdmin Test\n"
+ "Connection: close\n"); + "Connection: close\n");
answer = answer.substring(0, answer.indexOf("\n")); // answer = answer.substring(0, answer.indexOf("\n"));
return answer.contains("404"); return answer[1].contains("404");
} }
}); });
} }
@ -469,13 +473,35 @@ public class DomainTest {
return count; return count;
} }
private String socketQuery( String host, int port, String query) throws UnknownHostException, IOException{ 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{
Socket socket = new Socket( host, port ); Socket socket = new Socket( host, port );
socketQueryWriter( socket, query ); String[] retval = socketQuery( socket, query );
return socketQueryReader(socket); 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;
} }
private void socketQueryWriter( Socket socket, String buffer) throws IOException{ private static void socketQueryWriter( Socket socket, String buffer) throws IOException{
PrintWriter printWriter = PrintWriter printWriter =
new PrintWriter( new PrintWriter(
new OutputStreamWriter( new OutputStreamWriter(
@ -484,7 +510,7 @@ public class DomainTest {
printWriter.flush(); printWriter.flush();
} }
private String socketQueryReader( Socket socket ) throws IOException{ private static String socketQueryReader( Socket socket ) throws IOException{
int maxbufferbytecount = 4099; int maxbufferbytecount = 4099;
BufferedReader bufferedReader = BufferedReader bufferedReader =
new BufferedReader( new BufferedReader(