ComplianceTester.java (4149B)
1 package eu.siacs; 2 3 import eu.siacs.compliance.suites.*; 4 import eu.siacs.compliance.TestSuiteFactory; 5 import eu.siacs.utils.ExceptionUtils; 6 import rocks.xmpp.addr.Jid; 7 import rocks.xmpp.core.XmppException; 8 import rocks.xmpp.core.sasl.AuthenticationException; 9 import rocks.xmpp.core.stream.StreamErrorException; 10 import rocks.xmpp.core.stream.model.errors.Condition; 11 12 import java.security.InvalidAlgorithmParameterException; 13 import java.util.Arrays; 14 import java.util.List; 15 16 public class ComplianceTester { 17 18 19 public static void main(String[] args) { 20 String password; 21 if (args.length < 1 || args.length > 2) { 22 System.err.println("java -jar ComplianceTester.jar username@domain.tld [password]"); 23 System.exit(1); 24 return; 25 } 26 Jid jid = Jid.of(args[0]); 27 28 if (args.length == 2) { 29 password = args[1]; 30 AccountStore.storePassword(jid, password); 31 } else { 32 String storedPassword = AccountStore.getPassword(jid); 33 if (storedPassword != null) { 34 password = storedPassword; 35 } else { 36 System.err.println("password for "+jid+ " was not stored. trying to register"); 37 try { 38 password = RegistrationHelper.register(jid); 39 AccountStore.storePassword(jid, password); 40 } catch (RegistrationHelper.RegistrationNotSupported e) { 41 System.err.println("server "+jid.getDomain()+" does not support registration"); 42 System.exit(1); 43 return; 44 } catch (RegistrationHelper.RegistrationFailed e) { 45 System.out.println("registration failed on server "+jid.getDomain()+" "+e.getMessage()); 46 System.exit(1); 47 return; 48 } 49 50 } 51 } 52 List<Class <? extends AbstractTestSuite>> testSuites = Arrays.asList( 53 AdvancedServerCore.class, 54 AdvancedServerIM.class, 55 AdvancedServerMobile.class, 56 Conversations.class 57 ); 58 for(Class<?extends AbstractTestSuite> testSuite : testSuites) { 59 runTestSuite(testSuite, jid, password); 60 System.out.println("\n"); 61 } 62 } 63 64 private static void runTestSuite(Class <? extends AbstractTestSuite> clazz, Jid jid, String password) { 65 runTestSuite(clazz, jid, password, false); 66 } 67 68 private static void runTestSuite(Class <? extends AbstractTestSuite> clazz, Jid jid, String password, boolean rerun) { 69 try { 70 try { 71 AbstractTestSuite testSuite = TestSuiteFactory.create(clazz, jid, password); 72 System.out.println("Use compliance suite '"+testSuite.getName()+"' to test "+jid.getDomain()+"\n"); 73 testSuite.run(); 74 System.out.println("\n"+testSuite.getName() + ": " + testSuite.result()); 75 } catch (AbstractTestSuite.TestSuiteCreationException e) { 76 e.printStackTrace(); 77 System.out.println("Test suite creation failed"); 78 } 79 } catch(AuthenticationException e) { 80 System.err.println("username or password wrong"); 81 System.exit(1); 82 } catch (StreamErrorException e) { 83 if (e.getCondition() == Condition.POLICY_VIOLATION && !rerun) { 84 System.err.println("Policy violation. Waiting 61s"); 85 runTestSuite(clazz, jid, password, true); 86 try { 87 Thread.sleep(61000); 88 } catch (InterruptedException ie) { 89 System.err.println("interrupted"); 90 } 91 } 92 } catch (XmppException e) { 93 if (ExceptionUtils.getRootCause(e) instanceof InvalidAlgorithmParameterException) { 94 System.err.println("The ComplianceTester can not handle DH key sizes above 2048 bit. Modify your Prosody to use the default TLS configuration."); 95 } else { 96 System.err.println(e.getMessage()); 97 } 98 } 99 } 100 }