X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=inline;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FManagedTest.java;h=437031e4bf8a3b6fef077cfff37c0b52ed64b0a2;hb=4f532bd35f41121838756b67dfc0ca330940079e;hp=a65d3f243f655acb20d3abddbc18fd780a2bc54d;hpb=e87392fd58e9152531a8d1cb34cb46e370062108;p=gigi.git diff --git a/tests/org/cacert/gigi/testUtils/ManagedTest.java b/tests/org/cacert/gigi/testUtils/ManagedTest.java index a65d3f24..437031e4 100644 --- a/tests/org/cacert/gigi/testUtils/ManagedTest.java +++ b/tests/org/cacert/gigi/testUtils/ManagedTest.java @@ -155,16 +155,19 @@ public class ManagedTest extends ConfiguredTest { 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")); @@ -328,12 +331,21 @@ public class ManagedTest extends ConfiguredTest { 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); }