16
16
17
17
package org .springframework .security .config .annotation .web .reactive ;
18
18
19
+ import java .util .Collections ;
20
+
21
+ import org .jetbrains .annotations .NotNull ;
19
22
import org .junit .jupiter .api .Test ;
20
23
import org .junit .jupiter .api .extension .ExtendWith ;
24
+ import reactor .core .publisher .Mono ;
21
25
26
+ import org .springframework .context .annotation .Bean ;
22
27
import 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 ;
23
31
import org .springframework .security .config .test .SpringTestContext ;
24
32
import org .springframework .security .config .test .SpringTestContextExtension ;
25
33
import org .springframework .security .config .users .ReactiveAuthenticationTestConfiguration ;
26
34
import org .springframework .security .web .server .WebFilterChainProxy ;
35
+ import org .springframework .security .web .server .firewall .ServerWebExchangeFirewall ;
36
+ import org .springframework .web .server .handler .DefaultWebFilterChain ;
27
37
28
38
import static org .assertj .core .api .Assertions .assertThat ;
29
39
@@ -47,6 +57,28 @@ public void loadConfigWhenReactiveUserDetailsServiceConfiguredThenWebFilterChain
47
57
assertThat (webFilterChainProxy ).isNotNull ();
48
58
}
49
59
60
+ @ Test
61
+ void loadConfigWhenDefaultThenFirewalled () throws Exception {
62
+ this .spring .register (ServerHttpSecurityConfiguration .class , ReactiveAuthenticationTestConfiguration .class ,
63
+ WebFluxSecurityConfiguration .class ).autowire ();
64
+ WebFilterChainProxy webFilterChainProxy = this .spring .getContext ().getBean (WebFilterChainProxy .class );
65
+ MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/;/" ).build ());
66
+ DefaultWebFilterChain chain = emptyChain ();
67
+ webFilterChainProxy .filter (exchange , chain ).block ();
68
+ assertThat (exchange .getResponse ().getStatusCode ()).isEqualTo (HttpStatus .BAD_REQUEST );
69
+ }
70
+
71
+ @ Test
72
+ void loadConfigWhenFirewallBeanThenCustomized () throws Exception {
73
+ this .spring .register (ServerHttpSecurityConfiguration .class , ReactiveAuthenticationTestConfiguration .class ,
74
+ WebFluxSecurityConfiguration .class , NoOpFirewallConfig .class ).autowire ();
75
+ WebFilterChainProxy webFilterChainProxy = this .spring .getContext ().getBean (WebFilterChainProxy .class );
76
+ MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/;/" ).build ());
77
+ DefaultWebFilterChain chain = emptyChain ();
78
+ webFilterChainProxy .filter (exchange , chain ).block ();
79
+ assertThat (exchange .getResponse ().getStatusCode ()).isNotEqualTo (HttpStatus .BAD_REQUEST );
80
+ }
81
+
50
82
@ Test
51
83
public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyExists () {
52
84
this .spring
@@ -57,6 +89,20 @@ public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyE
57
89
assertThat (webFilterChainProxy ).isNotNull ();
58
90
}
59
91
92
+ private static @ NotNull DefaultWebFilterChain emptyChain () {
93
+ return new DefaultWebFilterChain ((webExchange ) -> Mono .empty (), Collections .emptyList ());
94
+ }
95
+
96
+ @ Configuration
97
+ static class NoOpFirewallConfig {
98
+
99
+ @ Bean
100
+ ServerWebExchangeFirewall noOpFirewall () {
101
+ return ServerWebExchangeFirewall .INSECURE_NOOP ;
102
+ }
103
+
104
+ }
105
+
60
106
@ Configuration
61
107
static class SubclassConfig extends WebFluxSecurityConfiguration {
62
108
0 commit comments