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,32 @@ public void loadConfigWhenReactiveUserDetailsServiceConfiguredThenWebFilterChain
47
57
assertThat (webFilterChainProxy ).isNotNull ();
48
58
}
49
59
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
+
50
86
@ Test
51
87
public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyExists () {
52
88
this .spring
@@ -57,6 +93,20 @@ public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyE
57
93
assertThat (webFilterChainProxy ).isNotNull ();
58
94
}
59
95
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
+
60
110
@ Configuration
61
111
static class SubclassConfig extends WebFluxSecurityConfiguration {
62
112
0 commit comments