This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new 5a725fb5f9 Improved: no functional change in ControlFilterTests class
5a725fb5f9 is described below
commit 5a725fb5f929fd291517acc5ee276b784c3fe431
Author: Jacques Le Roux <[email protected]>
AuthorDate: Wed Jun 3 12:33:15 2026 +0200
Improved: no functional change in ControlFilterTests class
Uses @BeforeEach and @AfterEach to set and remove
"ControlFilterTests" property
This commit completes the previous revert and the initial wanted operation
---
.../ofbiz/webapp/control/ControlFilterTests.java | 24 ++++++++--------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git
a/framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/ControlFilterTests.java
b/framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/ControlFilterTests.java
index e1e6ce2fde..baae0b4636 100644
---
a/framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/ControlFilterTests.java
+++
b/framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/ControlFilterTests.java
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -53,12 +54,18 @@ public final class ControlFilterTests {
when(req.getContextPath()).thenReturn("");
resp = mock(HttpServletResponse.class);
next = mock(FilterChain.class);
+ System.setProperty("ControlFilterTests",
"bypassPreventsStreamExploitation");
filter = new ControlFilter();
+
+ }
+
+ @AfterEach
+ public void tearDown() {
+ System.clearProperty("ControlFilterTests");
}
@Test
public void filterWithExactAllowedPath() throws Exception {
- System.setProperty("ControlFilterTests",
"bypassPreventsStreamExploitation");
when(config.getInitParameter("redirectPath")).thenReturn("/foo");
when(config.getInitParameter("allowedPaths")).thenReturn("/foo:/bar");
when(req.getRequestURI()).thenReturn("/servlet/bar");
@@ -67,12 +74,10 @@ public final class ControlFilterTests {
filter.init(config);
filter.doFilter(req, resp, next);
verify(next).doFilter(req, resp);
- System.clearProperty("ControlFilterTests");
}
@Test
public void filterWithAllowedSubPath() throws Exception {
- System.setProperty("ControlFilterTests",
"bypassPreventsStreamExploitation");
when(config.getInitParameter("redirectPath")).thenReturn("/foo");
when(config.getInitParameter("allowedPaths")).thenReturn("/foo:/bar");
when(req.getRequestURI()).thenReturn("/servlet/bar/baz");
@@ -81,12 +86,10 @@ public final class ControlFilterTests {
filter.init(config);
filter.doFilter(req, resp, next);
verify(next).doFilter(req, resp);
- System.clearProperty("ControlFilterTests");
}
@Test
public void filterWithRedirection() throws Exception {
- System.setProperty("ControlFilterTests",
"bypassPreventsStreamExploitation");
when(config.getInitParameter("redirectPath")).thenReturn("/foo");
when(config.getInitParameter("allowedPaths")).thenReturn("/bar:/baz");
when(req.getRequestURI()).thenReturn("/missing/path");
@@ -94,12 +97,10 @@ public final class ControlFilterTests {
filter.init(config);
filter.doFilter(req, resp, next);
verify(resp).sendRedirect("/foo");
- System.clearProperty("ControlFilterTests");
}
@Test
public void filterWithURIredirection() throws Exception {
- System.setProperty("ControlFilterTests",
"bypassPreventsStreamExploitation");
when(config.getInitParameter("redirectPath")).thenReturn("http://example.org/foo");
when(config.getInitParameter("allowedPaths")).thenReturn("/foo:/bar");
when(req.getRequestURI()).thenReturn("/baz");
@@ -107,12 +108,10 @@ public final class ControlFilterTests {
filter.init(config);
filter.doFilter(req, resp, next);
verify(resp).sendRedirect("http://example.org/foo");
- System.clearProperty("ControlFilterTests");
}
@Test
public void bailsOutWithVariousErrorCodes() throws Exception {
- System.setProperty("ControlFilterTests",
"bypassPreventsStreamExploitation");
when(config.getInitParameter("allowedPaths")).thenReturn("/foo");
when(req.getRequestURI()).thenReturn("/baz");
@@ -138,12 +137,10 @@ public final class ControlFilterTests {
filter.init(config);
filter.doFilter(req, resp, next);
verify(resp).sendError(404, "/baz");
- System.clearProperty("ControlFilterTests");
}
@Test
public void redirectAllAllowed() throws Exception {
- System.setProperty("ControlFilterTests",
"bypassPreventsStreamExploitation");
when(config.getInitParameter("redirectPath")).thenReturn("/bar");
when(config.getInitParameter("forceRedirectAll")).thenReturn("Y");
when(config.getInitParameter("allowedPaths")).thenReturn("/foo");
@@ -152,12 +149,10 @@ public final class ControlFilterTests {
filter.init(config);
filter.doFilter(req, resp, next);
verify(resp).sendRedirect("/bar");
- System.clearProperty("ControlFilterTests");
}
@Test
public void redirectAllNotAllowed() throws Exception {
- System.setProperty("ControlFilterTests",
"bypassPreventsStreamExploitation");
when(config.getInitParameter("redirectPath")).thenReturn("/bar");
when(config.getInitParameter("forceRedirectAll")).thenReturn("Y");
when(config.getInitParameter("allowedPaths")).thenReturn("/foo");
@@ -166,12 +161,10 @@ public final class ControlFilterTests {
filter.init(config);
filter.doFilter(req, resp, next);
verify(resp).sendRedirect("/bar");
- System.clearProperty("ControlFilterTests");
}
@Test
public void redirectAllRecursive() throws Exception {
- System.setProperty("ControlFilterTests",
"bypassPreventsStreamExploitation");
when(config.getInitParameter("redirectPath")).thenReturn("/foo");
when(config.getInitParameter("forceRedirectAll")).thenReturn("Y");
when(config.getInitParameter("allowedPaths")).thenReturn("/foo");
@@ -189,6 +182,5 @@ public final class ControlFilterTests {
filter.doFilter(req, resp, next);
verify(next).doFilter(req, resp);
verify(session).removeAttribute("_FORCE_REDIRECT_");
- System.clearProperty("ControlFilterTests");
}
}