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
@@ -45,6 +55,28 @@ public void loadConfigWhenReactiveUserDetailsServiceConfiguredThenWebFilterChain
45
55
assertThat (webFilterChainProxy ).isNotNull ();
46
56
}
47
57
58
+ @ Test
59
+ void loadConfigWhenDefaultThenFirewalled () throws Exception {
60
+ this .spring .register (ServerHttpSecurityConfiguration .class , ReactiveAuthenticationTestConfiguration .class ,
61
+ WebFluxSecurityConfiguration .class ).autowire ();
62
+ WebFilterChainProxy webFilterChainProxy = this .spring .getContext ().getBean (WebFilterChainProxy .class );
63
+ MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/;/" ).build ());
64
+ DefaultWebFilterChain chain = emptyChain ();
65
+ webFilterChainProxy .filter (exchange , chain ).block ();
66
+ assertThat (exchange .getResponse ().getStatusCode ()).isEqualTo (HttpStatus .BAD_REQUEST );
67
+ }
68
+
69
+ @ Test
70
+ void loadConfigWhenFirewallBeanThenCustomized () throws Exception {
71
+ this .spring .register (ServerHttpSecurityConfiguration .class , ReactiveAuthenticationTestConfiguration .class ,
72
+ WebFluxSecurityConfiguration .class , NoOpFirewallConfig .class ).autowire ();
73
+ WebFilterChainProxy webFilterChainProxy = this .spring .getContext ().getBean (WebFilterChainProxy .class );
74
+ MockServerWebExchange exchange = MockServerWebExchange .from (MockServerHttpRequest .get ("/;/" ).build ());
75
+ DefaultWebFilterChain chain = emptyChain ();
76
+ webFilterChainProxy .filter (exchange , chain ).block ();
77
+ assertThat (exchange .getResponse ().getStatusCode ()).isNotEqualTo (HttpStatus .BAD_REQUEST );
78
+ }
79
+
48
80
@ Test
49
81
public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyExists () {
50
82
this .spring .register (ServerHttpSecurityConfiguration .class , ReactiveAuthenticationTestConfiguration .class ,
@@ -53,6 +85,20 @@ public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyE
53
85
assertThat (webFilterChainProxy ).isNotNull ();
54
86
}
55
87
88
+ private static @ NotNull DefaultWebFilterChain emptyChain () {
89
+ return new DefaultWebFilterChain ((webExchange ) -> Mono .empty (), Collections .emptyList ());
90
+ }
91
+
92
+ @ Configuration
93
+ static class NoOpFirewallConfig {
94
+
95
+ @ Bean
96
+ ServerWebExchangeFirewall noOpFirewall () {
97
+ return ServerWebExchangeFirewall .INSECURE_NOOP ;
98
+ }
99
+
100
+ }
101
+
56
102
@ Configuration
57
103
static class SubclassConfig extends WebFluxSecurityConfiguration {
58
104
0 commit comments