}
static Properties testProps = new Properties();
+
+ public static Properties getTestProps() {
+ return testProps;
+ }
+
static {
InitTruststore.run();
HttpURLConnection.setFollowRedirects(false);
if ( !DatabaseConnection.isInited()) {
DatabaseConnection.init(testProps);
}
- System.out.println("... purging Database");
- DatabaseManager.run(new String[] {
- testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password")
- });
+ purgeDatabase();
String type = testProps.getProperty("type");
Properties mainProps = generateMainProps();
ServerConstants.init(mainProps);
if (type.equals("local")) {
- url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort");
+ url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
String[] parts = testProps.getProperty("mail").split(":", 2);
ter = new TestEmailReciever(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])));
return;
}
- url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort");
+ url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
gigi = Runtime.getRuntime().exec(testProps.getProperty("java"));
DataOutputStream toGigi = new DataOutputStream(gigi.getOutputStream());
System.out.println("... starting server");
SimpleSigner.runSigner();
} catch (IOException e) {
throw new Error(e);
- } catch (ClassNotFoundException e1) {
- e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
}
+ public static void purgeDatabase() throws SQLException, IOException {
+ System.out.print("... resetting Database");
+ long ms = System.currentTimeMillis();
+ try {
+ DatabaseManager.run(new String[] {
+ testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password")
+ }, true);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ System.out.println(" in " + (System.currentTimeMillis() - ms) + " ms");
+ }
+
private static Properties generateMainProps() {
Properties mainProps = new Properties();
mainProps.setProperty("host", "127.0.0.1");
mainProps.setProperty("name.www", testProps.getProperty("name.www"));
mainProps.setProperty("name.static", testProps.getProperty("name.static"));
- mainProps.setProperty("port", testProps.getProperty("serverPort"));
+ mainProps.setProperty("https.port", testProps.getProperty("serverPort.https"));
+ mainProps.setProperty("http.port", testProps.getProperty("serverPort.http"));
mainProps.setProperty("emailProvider", "org.cacert.gigi.email.TestEmailProvider");
mainProps.setProperty("emailProvider.port", "8473");
mainProps.setProperty("sql.driver", testProps.getProperty("sql.driver"));
public static String getCSRF(URLConnection u, int formIndex) throws IOException {
String content = IOUtils.readURL(u);
+ return getCSRF(formIndex, content);
+ }
+
+ public static String getCSRF(int formIndex, String content) throws Error {
Pattern p = Pattern.compile("<input type='hidden' name='csrf' value='([^']+)'>");
Matcher m = p.matcher(content);
for (int i = 0; i < formIndex + 1; i++) {
return adrr;
}
+ public static URLConnection cookie(URLConnection openConnection, String cookie) {
+ openConnection.setRequestProperty("Cookie", cookie);
+ return openConnection;
+ }
+
}