1818 */
1919package org .apache .ofbiz .webapp .control ;
2020
21+ import static org .mockito .ArgumentMatchers .anyString ;
2122import static org .mockito .Mockito .mock ;
22- import static org .mockito .Mockito .when ;
23- import static org .mockito .Mockito .verify ;
24- import static org .mockito .Mockito .anyString ;
2523import static org .mockito .Mockito .times ;
24+ import static org .mockito .Mockito .verify ;
25+ import static org .mockito .Mockito .when ;
26+
27+ import org .junit .Before ;
28+ import org .junit .Test ;
2629
2730import javax .servlet .FilterChain ;
2831import javax .servlet .FilterConfig ;
2932import javax .servlet .http .HttpServletRequest ;
3033import javax .servlet .http .HttpServletResponse ;
3134import javax .servlet .http .HttpSession ;
3235
33- import org .junit .Before ;
34- import org .junit .Test ;
35-
3636public class ControlFilterTests {
3737
3838 private FilterConfig config ;
@@ -58,6 +58,7 @@ public void setUp() {
5858
5959 @ Test
6060 public void filterWithExactAllowedPath () throws Exception {
61+ System .setProperty ("ControlFilterTests" , "runsAfterControlFilter" );
6162 when (config .getInitParameter ("redirectPath" )).thenReturn ("/foo" );
6263 when (config .getInitParameter ("allowedPaths" )).thenReturn ("/foo:/bar" );
6364 when (req .getRequestURI ()).thenReturn ("/servlet/bar" );
@@ -66,10 +67,12 @@ public void filterWithExactAllowedPath() throws Exception {
6667 filter .init (config );
6768 filter .doFilter (req , resp , next );
6869 verify (next ).doFilter (req , resp );
70+ System .clearProperty ("ControlFilterTests" );
6971 }
7072
7173 @ Test
7274 public void filterWithAllowedSubPath () throws Exception {
75+ System .setProperty ("ControlFilterTests" , "runsAfterControlFilter" );
7376 when (config .getInitParameter ("redirectPath" )).thenReturn ("/foo" );
7477 when (config .getInitParameter ("allowedPaths" )).thenReturn ("/foo:/bar" );
7578 when (req .getRequestURI ()).thenReturn ("/servlet/bar/baz" );
@@ -78,32 +81,38 @@ public void filterWithAllowedSubPath() throws Exception {
7881 filter .init (config );
7982 filter .doFilter (req , resp , next );
8083 verify (next ).doFilter (req , resp );
84+ System .clearProperty ("ControlFilterTests" );
8185 }
8286
8387 @ Test
8488 public void filterWithRedirection () throws Exception {
89+ System .setProperty ("ControlFilterTests" , "runsAfterControlFilter" );
8590 when (config .getInitParameter ("redirectPath" )).thenReturn ("/foo" );
8691 when (config .getInitParameter ("allowedPaths" )).thenReturn ("/bar:/baz" );
8792 when (req .getRequestURI ()).thenReturn ("/missing/path" );
8893
8994 filter .init (config );
9095 filter .doFilter (req , resp , next );
9196 verify (resp ).sendRedirect ("/foo" );
97+ System .clearProperty ("ControlFilterTests" );
9298 }
9399
94100 @ Test
95101 public void filterWithURIredirection () throws Exception {
102+ System .setProperty ("ControlFilterTests" , "runsAfterControlFilter" );
96103 when (config .getInitParameter ("redirectPath" )).thenReturn ("http://example.org/foo" );
97104 when (config .getInitParameter ("allowedPaths" )).thenReturn ("/foo:/bar" );
98105 when (req .getRequestURI ()).thenReturn ("/baz" );
99106
100107 filter .init (config );
101108 filter .doFilter (req , resp , next );
102109 verify (resp ).sendRedirect ("http://example.org/foo" );
110+ System .clearProperty ("ControlFilterTests" );
103111 }
104112
105113 @ Test
106114 public void bailsOutWithVariousErrorCodes () throws Exception {
115+ System .setProperty ("ControlFilterTests" , "runsAfterControlFilter" );
107116 when (config .getInitParameter ("allowedPaths" )).thenReturn ("/foo" );
108117 when (req .getRequestURI ()).thenReturn ("/baz" );
109118
@@ -129,10 +138,12 @@ public void bailsOutWithVariousErrorCodes() throws Exception {
129138 filter .init (config );
130139 filter .doFilter (req , resp , next );
131140 verify (resp ).sendError (404 , "/baz" );
141+ System .clearProperty ("ControlFilterTests" );
132142 }
133143
134144 @ Test
135145 public void redirectAllAllowed () throws Exception {
146+ System .setProperty ("ControlFilterTests" , "runsAfterControlFilter" );
136147 when (config .getInitParameter ("redirectPath" )).thenReturn ("/bar" );
137148 when (config .getInitParameter ("forceRedirectAll" )).thenReturn ("Y" );
138149 when (config .getInitParameter ("allowedPaths" )).thenReturn ("/foo" );
@@ -141,10 +152,12 @@ public void redirectAllAllowed() throws Exception {
141152 filter .init (config );
142153 filter .doFilter (req , resp , next );
143154 verify (resp ).sendRedirect ("/bar" );
155+ System .clearProperty ("ControlFilterTests" );
144156 }
145157
146158 @ Test
147159 public void redirectAllNotAllowed () throws Exception {
160+ System .setProperty ("ControlFilterTests" , "runsAfterControlFilter" );
148161 when (config .getInitParameter ("redirectPath" )).thenReturn ("/bar" );
149162 when (config .getInitParameter ("forceRedirectAll" )).thenReturn ("Y" );
150163 when (config .getInitParameter ("allowedPaths" )).thenReturn ("/foo" );
@@ -153,10 +166,12 @@ public void redirectAllNotAllowed() throws Exception {
153166 filter .init (config );
154167 filter .doFilter (req , resp , next );
155168 verify (resp ).sendRedirect ("/bar" );
169+ System .clearProperty ("ControlFilterTests" );
156170 }
157171
158172 @ Test
159173 public void redirectAllRecursive () throws Exception {
174+ System .setProperty ("ControlFilterTests" , "runsAfterControlFilter" );
160175 when (config .getInitParameter ("redirectPath" )).thenReturn ("/foo" );
161176 when (config .getInitParameter ("forceRedirectAll" )).thenReturn ("Y" );
162177 when (config .getInitParameter ("allowedPaths" )).thenReturn ("/foo" );
@@ -174,5 +189,6 @@ public void redirectAllRecursive() throws Exception {
174189 filter .doFilter (req , resp , next );
175190 verify (next ).doFilter (req , resp );
176191 verify (session ).removeAttribute ("_FORCE_REDIRECT_" );
192+ System .clearProperty ("ControlFilterTests" );
177193 }
178194}
0 commit comments