From 83af470c44c6fe3b37d4ba50499e32530c48ed60 Mon Sep 17 00:00:00 2001 From: Janis Streib Date: Fri, 25 Jul 2014 01:08:23 +0200 Subject: [PATCH] UPD: Added formIndex for CSRF token parsing --- .../cacert/gigi/testUtils/ManagedTest.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/org/cacert/gigi/testUtils/ManagedTest.java b/tests/org/cacert/gigi/testUtils/ManagedTest.java index 724126ab..1cca75aa 100644 --- a/tests/org/cacert/gigi/testUtils/ManagedTest.java +++ b/tests/org/cacert/gigi/testUtils/ManagedTest.java @@ -371,11 +371,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(""); 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 +400,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); -- 2.39.2