]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/testUtils/ManagedTest.java
UPD: Make some test methods static
[gigi.git] / tests / org / cacert / gigi / testUtils / ManagedTest.java
index 724126ab4eb39180eee8bd4d9486f72f85f0e542..5d4db1299df473caf6a8e3849f76bcc711ad0b0b 100644 (file)
@@ -36,6 +36,10 @@ import javax.net.ssl.SSLContext;
 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;
@@ -282,7 +286,7 @@ public class ManagedTest {
 
        static int count = 0;
 
-       public String createUniqueName() {
+       public static String createUniqueName() {
                return "test" + System.currentTimeMillis() + "a" + (count++);
        }
 
@@ -371,11 +375,17 @@ public class ManagedTest {
        }
 
        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);
        }
@@ -394,11 +404,16 @@ public class ManagedTest {
                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);
@@ -412,4 +427,15 @@ public class ManagedTest {
                return error;
        }
 
+       public static 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;
+       }
+
 }