import org.cacert.gigi.database.GigiPreparedStatement;
import org.cacert.gigi.database.GigiResultSet;
import org.cacert.gigi.dbObjects.EmailAddress;
+import org.cacert.gigi.dbObjects.Group;
import org.cacert.gigi.dbObjects.ObjectCache;
import org.cacert.gigi.dbObjects.User;
import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.pages.Manager;
import org.cacert.gigi.pages.account.MyDetails;
import org.cacert.gigi.pages.main.RegisterPage;
import org.cacert.gigi.testUtils.TestEmailReciever.TestMail;
e.printStackTrace();
}
System.out.println(" in " + (System.currentTimeMillis() - ms) + " ms");
- String type = testProps.getProperty("type");
+ clearCaches();
+ }
+
+ public static void clearCaches() throws IOException {
ObjectCache.clearAllCaches();
- if (type.equals("local")) {
- URL u = new URL("https://" + getServerName() + "/manage");
- u.openConnection().getHeaderField("Location");
- }
+ String type = testProps.getProperty("type");
+ URL u = new URL("https://" + getServerName() + "/manage");
+ u.openConnection().getHeaderField("Location");
}
private static Properties generateMainProps() {
Properties mainProps = new Properties();
+ mainProps.setProperty("testrunner", "true");
mainProps.setProperty("host", "127.0.0.1");
mainProps.setProperty("name.secure", testProps.getProperty("name.secure"));
mainProps.setProperty("name.www", testProps.getProperty("name.www"));
mainProps.setProperty("sql.url", testProps.getProperty("sql.url"));
mainProps.setProperty("sql.user", testProps.getProperty("sql.user"));
mainProps.setProperty("sql.password", testProps.getProperty("sql.password"));
+ mainProps.setProperty("testing", "true");
return mainProps;
}
}
}
+ public static void grant(String email, Group g) throws IOException {
+ HttpURLConnection huc = (HttpURLConnection) new URL("https://" + getServerName() + Manager.PATH).openConnection();
+ huc.setDoOutput(true);
+ huc.getOutputStream().write(("addpriv=y&priv=" + URLEncoder.encode(g.getDatabaseName(), "UTF-8") + "&email=" + URLEncoder.encode(email, "UTF-8")).getBytes());
+ assertEquals(200, huc.getResponseCode());
+ }
+
/**
* Creates a new user with 100 Assurance points given by an (invalid)
* assurance.
public static String login(String email, String pw) throws IOException {
URL u = new URL("https://" + getServerName() + "/login");
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
+
+ String csrf = getCSRF(huc);
+ String headerField = stripCookie(huc.getHeaderField("Set-Cookie"));
+
+ huc = (HttpURLConnection) u.openConnection();
+ cookie(huc, headerField);
huc.setDoOutput(true);
OutputStream os = huc.getOutputStream();
- String data = "username=" + URLEncoder.encode(email, "UTF-8") + "&password=" + URLEncoder.encode(pw, "UTF-8");
+ String data = "username=" + URLEncoder.encode(email, "UTF-8") + "&password=" + URLEncoder.encode(pw, "UTF-8") + "&csrf=" + URLEncoder.encode(csrf, "UTF-8");
os.write(data.getBytes());
os.flush();
- String headerField = huc.getHeaderField("Set-Cookie");
+ headerField = huc.getHeaderField("Set-Cookie");
+ if (headerField == null) {
+ return "";
+ }
return stripCookie(headerField);
}