]> 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 20318a7f03eb35a46fcba5abad8bb7d714644ed0..d7a5fcac9dba458d5ce7b09a966b2f1c47e88dfe 100644 (file)
@@ -1,7 +1,6 @@
 package org.cacert.gigi.testUtils;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 import java.io.BufferedReader;
 import java.io.DataOutputStream;
@@ -389,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;
+       }
+
 }