From 12fbcf4579d9024f5ce4c3d288d27a84245739e0 Mon Sep 17 00:00:00 2001 From: Wadeck Follonier Date: Thu, 26 Mar 2020 09:26:58 +0100 Subject: [PATCH 1/4] Adapt the test for recent core --- .../plugins/git/GitStatusCrumbExclusionTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java b/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java index 2b8c1f1cb2..d6123fc071 100644 --- a/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java +++ b/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java @@ -2,7 +2,9 @@ import hudson.security.csrf.CrumbFilter; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -32,6 +34,16 @@ public class GitStatusCrumbExclusionTest { private HttpServletResponse resp; private FilterChain chain; + @BeforeClass + public static void setProps() { + System.setProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO", "true"); + } + + @AfterClass + public static void unsetProps() { + System.setProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO", ""); + } + @Before public void before() { filter = new CrumbFilter(); From 62ba4cd7f7bf0d84ebc3ef9f2fcf091325ba7f0c Mon Sep 17 00:00:00 2001 From: Wadeck Follonier Date: Thu, 26 Mar 2020 09:50:45 +0100 Subject: [PATCH 2/4] Use previous value --- .../java/hudson/plugins/git/GitStatusCrumbExclusionTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java b/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java index d6123fc071..735baf6a89 100644 --- a/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java +++ b/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java @@ -34,14 +34,17 @@ public class GitStatusCrumbExclusionTest { private HttpServletResponse resp; private FilterChain chain; + private static String systemPropertyPreviousValue; + @BeforeClass public static void setProps() { + systemPropertyPreviousValue = System.getProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO"); System.setProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO", "true"); } @AfterClass public static void unsetProps() { - System.setProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO", ""); + System.setProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO", systemPropertyPreviousValue); } @Before From a772ab4bb14aca7131e649726681e93995ad583a Mon Sep 17 00:00:00 2001 From: Wadeck Follonier Date: Thu, 26 Mar 2020 14:19:17 +0100 Subject: [PATCH 3/4] Correct Mark's finding --- .../java/hudson/plugins/git/GitStatusCrumbExclusionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java b/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java index 735baf6a89..cd5c3e0455 100644 --- a/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java +++ b/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java @@ -44,7 +44,7 @@ public static void setProps() { @AfterClass public static void unsetProps() { - System.setProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO", systemPropertyPreviousValue); + System.setProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO", systemPropertyPreviousValue != null ? systemPropertyPreviousValue : ""); } @Before From 965e00f200656058bc01878f8332798d4d1c68d9 Mon Sep 17 00:00:00 2001 From: Wadeck Follonier Date: Thu, 26 Mar 2020 18:10:43 +0100 Subject: [PATCH 4/4] Use Daniel's proposal --- .../hudson/plugins/git/GitStatusCrumbExclusionTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java b/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java index cd5c3e0455..84f065dde6 100644 --- a/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java +++ b/src/test/java/hudson/plugins/git/GitStatusCrumbExclusionTest.java @@ -44,7 +44,11 @@ public static void setProps() { @AfterClass public static void unsetProps() { - System.setProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO", systemPropertyPreviousValue != null ? systemPropertyPreviousValue : ""); + if (systemPropertyPreviousValue == null) { + System.clearProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO"); + } else { + System.setProperty("hudson.security.csrf.CrumbFilter.UNPROCESSED_PATHINFO", systemPropertyPreviousValue); + } } @Before