import javax.net.ssl.X509KeyManager;
import org.cacert.gigi.DevelLauncher;
+import org.cacert.gigi.EmailAddress;
+import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.Language;
+import org.cacert.gigi.User;
import org.cacert.gigi.database.DatabaseConnection;
import org.cacert.gigi.testUtils.TestEmailReciever.TestMail;
import org.cacert.gigi.util.DatabaseManager;
}
public String getCSRF(URLConnection u) throws IOException {
+ return getCSRF(u, 0);
+ }
+
+ public String getCSRF(URLConnection u, int formIndex) throws IOException {
String content = IOUtils.readURL(u);
Pattern p = Pattern.compile("<input type='hidden' name='csrf' value='([^']+)'>");
Matcher m = p.matcher(content);
- if (!m.find()) {
- throw new Error("No CSRF Token");
+ for (int i = 0; i < formIndex + 1; i++) {
+ if (!m.find()) {
+ throw new Error("No CSRF Token");
+ }
}
return m.group(1);
}
return parts;
}
- public String executeBasicWebInteraction(String cookie, String path, String query) throws IOException,
- MalformedURLException, UnsupportedEncodingException {
+ public String executeBasicWebInteraction(String cookie, String path, String query) throws MalformedURLException,
+ UnsupportedEncodingException, IOException {
+ return executeBasicWebInteraction(cookie, path, query, 0);
+ }
+
+ public String executeBasicWebInteraction(String cookie, String path, String query, int formIndex)
+ throws IOException, MalformedURLException, UnsupportedEncodingException {
URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
uc.addRequestProperty("Cookie", cookie);
- String csrf = getCSRF(uc);
+ String csrf = getCSRF(uc, formIndex);
uc = new URL("https://" + getServerName() + path).openConnection();
uc.addRequestProperty("Cookie", cookie);
return error;
}
+ public EmailAddress createVerifiedEmail(User u) throws InterruptedException, GigiApiException {
+ EmailAddress adrr = new EmailAddress(createUniqueName() + "test@test.tld", u);
+ adrr.insert(Language.getInstance("en"));
+ TestMail testMail = getMailReciever().recieve();
+ assertTrue(adrr.getAddress().equals(testMail.getTo()));
+ String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1);
+ adrr.verify(hash);
+ getMailReciever().clearMails();
+ return adrr;
+ }
+
}