]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/testUtils/ManagedTest.java
UPD: Abstracted web interactions
[gigi.git] / tests / org / cacert / gigi / testUtils / ManagedTest.java
index 36ae2ca1802beec9cd821a1b0569e4f14b0941a8..d7a5fcac9dba458d5ce7b09a966b2f1c47e88dfe 100644 (file)
@@ -1,8 +1,6 @@
 package org.cacert.gigi.testUtils;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 import java.io.BufferedReader;
 import java.io.DataOutputStream;
@@ -196,7 +194,9 @@ public class ManagedTest {
        public String fetchStartErrorMessage(String d) throws IOException {
                String formFail = "<div class='formError'>";
                int idx = d.indexOf(formFail);
-               assertNotEquals(-1, idx);
+               if (idx == -1) {
+                       return null;
+               }
                String startError = d.substring(idx + formFail.length(), idx + 100).trim();
                return startError;
        }
@@ -388,4 +388,22 @@ public class ManagedTest {
                return parts;
        }
 
+       public String executeBasicWebInteraction(String cookie, String path, String query) throws IOException,
+               MalformedURLException, UnsupportedEncodingException {
+               URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
+               uc.addRequestProperty("Cookie", cookie);
+               String csrf = getCSRF(uc);
+
+               uc = new URL("https://" + getServerName() + path).openConnection();
+               uc.addRequestProperty("Cookie", cookie);
+               uc.setDoOutput(true);
+               OutputStream os = uc.getOutputStream();
+               os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
+               + query//
+               ).getBytes());
+               os.flush();
+               String error = fetchStartErrorMessage(IOUtils.readURL(uc));
+               return error;
+       }
+
 }