| | |
| | | Map<String, Object> setParams = new HashMap<String, Object>(); |
| | | Map<String, String> whereParams = new HashMap<String, String>(); |
| | | List<String> optionslist = new ArrayList<String>(); |
| | | optionslist.add("nogreylisting"); |
| | | optionslist.add("greylisting"); |
| | | setParams.put("domainoptions", optionslist); |
| | | whereParams.put("name", "example01.org"); |
| | | Object[] params = new Object[] { user, |
| | |
| | | Map<String, Object> setParams = new HashMap<String, Object>(); |
| | | Map<String, String> whereParams = new HashMap<String, String>(); |
| | | List<String> optionslist = new ArrayList<String>(); |
| | | optionslist.add("nohtdocsfallback"); |
| | | optionslist.add("nogreylisting"); |
| | | optionslist.add("htdocsfallback"); |
| | | optionslist.add("greylisting"); |
| | | setParams.put("domainoptions", optionslist); |
| | | whereParams.put("name", "example01.org"); |
| | | Object[] params = new Object[] { user, |
| | |
| | | } |
| | | |
| | | @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<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("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) { |
| | | } |
| | | public void testGreylisting() throws UnknownHostException, IOException { |
| | | testGreylistingOnOff(true, "zuerst an"); |
| | | testGreylistingOnOff(false, "als zweites aus"); |
| | | testGreylistingOnOff(true, "zuletzt wieder an"); |
| | | } |
| | | |
| | | @Test |
| | | public void testNohtdocsfallback() throws UnknownHostException, IOException { |
| | | testNohtdocsfallbackOnOff(false, "Nothdocsfallback zuerst aus"); |
| | | testNohtdocsfallbackOnOff(true, "Nothdocsfallback als zweites an"); |
| | | testNohtdocsfallbackOnOff(false, "Nothdocsfallback zuletzt wieder aus"); |
| | | 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"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Test |
| | | public void testNohtdocsfallbackOnOff( boolean onoff, String message) throws UnknownHostException, IOException { |
| | | private void testDomainptionOnOf( boolean onoff, String message, DomainOptionTester tester) throws UnknownHostException, IOException { |
| | | String user = "aaa00"; |
| | | String domain = "example01.org"; |
| | | String grantingTicketURL = cas.getGrantingTicketURL(user); |
| | |
| | | Map<String, String> whereParams = new HashMap<String, String>(); |
| | | List<String> optionslist = new ArrayList<String>(); |
| | | if(onoff) { |
| | | optionslist.add("nohtdocsfallback"); |
| | | optionslist.add(tester.getOptionName()); |
| | | } |
| | | setParams.put("domainoptions", optionslist); |
| | | whereParams.put("name", domain); |
| | |
| | | try { |
| | | Object execute = client.execute(MODULE + ".update", params); |
| | | assertNotNull(execute); |
| | | assertEquals(message, onoff, getNohtdocsfallback(domain)); |
| | | assertEquals(tester.getOptionName()+": "+message, onoff, tester.isOptionConfigured(domain)); |
| | | } catch (XmlRpcException e) { |
| | | } |
| | | } |
| | | |
| | | |
| | | private int getDomsCount() { |
| | | int count = 0; |
| | |
| | | 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 ); |