21
21
import org .junit .jupiter .api .extension .ExtendWith ;
22
22
23
23
import org .springframework .beans .factory .annotation .Autowired ;
24
+ import org .springframework .http .HttpStatus ;
24
25
import org .springframework .mock .web .MockFilterChain ;
25
26
import org .springframework .mock .web .MockHttpServletRequest ;
26
27
import org .springframework .mock .web .MockHttpServletResponse ;
29
30
import org .springframework .security .core .context .SecurityContextHolder ;
30
31
import org .springframework .security .web .FilterChainProxy ;
31
32
import org .springframework .security .web .context .HttpSessionSecurityContextRepository ;
32
- import org .springframework .security .web .firewall .RequestRejectedException ;
33
33
import org .springframework .test .context .ContextConfiguration ;
34
34
import org .springframework .test .context .junit .jupiter .SpringExtension ;
35
35
36
- import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
36
+ import static org .assertj .core .api .Assertions .assertThat ;
37
37
38
38
@ ContextConfiguration (locations = { "/http-path-param-stripping-app-context.xml" })
39
39
@ ExtendWith (SpringExtension .class )
@@ -48,8 +48,8 @@ public void securedFilterChainCannotBeBypassedByAddingPathParameters() throws Ex
48
48
request .setPathInfo ("/secured;x=y/admin.html" );
49
49
request .setSession (createAuthenticatedSession ("ROLE_USER" ));
50
50
MockHttpServletResponse response = new MockHttpServletResponse ();
51
- assertThatExceptionOfType ( RequestRejectedException . class )
52
- . isThrownBy (() -> this . fcp . doFilter ( request , response , new MockFilterChain () ));
51
+ this . fcp . doFilter ( request , response , new MockFilterChain ());
52
+ assertThat ( response . getStatus ()). isEqualTo ( HttpStatus . BAD_REQUEST . value ( ));
53
53
}
54
54
55
55
@ Test
@@ -58,8 +58,8 @@ public void adminFilePatternCannotBeBypassedByAddingPathParameters() throws Exce
58
58
request .setServletPath ("/secured/admin.html;x=user.html" );
59
59
request .setSession (createAuthenticatedSession ("ROLE_USER" ));
60
60
MockHttpServletResponse response = new MockHttpServletResponse ();
61
- assertThatExceptionOfType ( RequestRejectedException . class )
62
- . isThrownBy (() -> this . fcp . doFilter ( request , response , new MockFilterChain () ));
61
+ this . fcp . doFilter ( request , response , new MockFilterChain ());
62
+ assertThat ( response . getStatus ()). isEqualTo ( HttpStatus . BAD_REQUEST . value ( ));
63
63
}
64
64
65
65
@ Test
@@ -69,8 +69,8 @@ public void adminFilePatternCannotBeBypassedByAddingPathParametersWithPathInfo()
69
69
request .setPathInfo ("/admin.html;x=user.html" );
70
70
request .setSession (createAuthenticatedSession ("ROLE_USER" ));
71
71
MockHttpServletResponse response = new MockHttpServletResponse ();
72
- assertThatExceptionOfType ( RequestRejectedException . class )
73
- . isThrownBy (() -> this . fcp . doFilter ( request , response , new MockFilterChain () ));
72
+ this . fcp . doFilter ( request , response , new MockFilterChain ());
73
+ assertThat ( response . getStatus ()). isEqualTo ( HttpStatus . BAD_REQUEST . value ( ));
74
74
}
75
75
76
76
public HttpSession createAuthenticatedSession (String ... roles ) {
0 commit comments