1616
1717package org .springframework .security .config .annotation .web .reactive ;
1818
19+ import java .util .Collections ;
20+
21+ import org .jetbrains .annotations .NotNull ;
1922import org .junit .jupiter .api .Test ;
2023import org .junit .jupiter .api .extension .ExtendWith ;
24+ import reactor .core .publisher .Mono ;
2125
26+ import org .springframework .context .annotation .Bean ;
2227import org .springframework .context .annotation .Configuration ;
28+ import org .springframework .http .HttpStatus ;
29+ import org .springframework .mock .http .server .reactive .MockServerHttpRequest ;
30+ import org .springframework .mock .web .server .MockServerWebExchange ;
2331import org .springframework .security .config .test .SpringTestContext ;
2432import org .springframework .security .config .test .SpringTestContextExtension ;
2533import org .springframework .security .config .users .ReactiveAuthenticationTestConfiguration ;
2634import org .springframework .security .web .server .WebFilterChainProxy ;
35+ import org .springframework .security .web .server .firewall .ServerWebExchangeFirewall ;
36+ import org .springframework .web .server .handler .DefaultWebFilterChain ;
2737
2838import static org .assertj .core .api .Assertions .assertThat ;
2939
@@ -47,6 +57,32 @@ public void loadConfigWhenReactiveUserDetailsServiceConfiguredThenWebFilterChain
4757 assertThat (webFilterChainProxy ).isNotNull ();
4858 }
4959
60+ @ Test
61+ void loadConfigWhenDefaultThenFirewalled () throws Exception {
62+ this .spring
63+ .register (ServerHttpSecurityConfiguration .class , ReactiveAuthenticationTestConfiguration .class ,
64+ WebFluxSecurityConfiguration .class )
65+ .autowire ();
66+ WebFilterChainProxy webFilterChainProxy = this .spring .getContext ().getBean (WebFilterChainProxy .class );
67+ MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/;/" ).build ());
68+ DefaultWebFilterChain chain = emptyChain ();
69+ webFilterChainProxy .filter (exchange , chain ).block ();
70+ assertThat (exchange .getResponse ().getStatusCode ()).isEqualTo (HttpStatus .BAD_REQUEST );
71+ }
72+
73+ @ Test
74+ void loadConfigWhenFirewallBeanThenCustomized () throws Exception {
75+ this .spring
76+ .register (ServerHttpSecurityConfiguration .class , ReactiveAuthenticationTestConfiguration .class ,
77+ WebFluxSecurityConfiguration .class , NoOpFirewallConfig .class )
78+ .autowire ();
79+ WebFilterChainProxy webFilterChainProxy = this .spring .getContext ().getBean (WebFilterChainProxy .class );
80+ MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/;/" ).build ());
81+ DefaultWebFilterChain chain = emptyChain ();
82+ webFilterChainProxy .filter (exchange , chain ).block ();
83+ assertThat (exchange .getResponse ().getStatusCode ()).isNotEqualTo (HttpStatus .BAD_REQUEST );
84+ }
85+
5086 @ Test
5187 public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyExists () {
5288 this .spring
@@ -57,6 +93,20 @@ public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyE
5793 assertThat (webFilterChainProxy ).isNotNull ();
5894 }
5995
96+ private static @ NotNull DefaultWebFilterChain emptyChain () {
97+ return new DefaultWebFilterChain ((webExchange ) -> Mono .empty (), Collections .emptyList ());
98+ }
99+
100+ @ Configuration
101+ static class NoOpFirewallConfig {
102+
103+ @ Bean
104+ ServerWebExchangeFirewall noOpFirewall () {
105+ return ServerWebExchangeFirewall .INSECURE_NOOP ;
106+ }
107+
108+ }
109+
60110 @ Configuration
61111 static class SubclassConfig extends WebFluxSecurityConfiguration {
62112
0 commit comments