1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import org .junit .runner .RunWith ;
21
21
import org .mockito .Mock ;
22
22
import org .mockito .junit .MockitoJUnitRunner ;
23
-
24
- import org .springframework .http .HttpMethod ;
25
23
import org .springframework .http .HttpStatus ;
26
24
import org .springframework .http .MediaType ;
27
25
import org .springframework .mock .http .server .reactive .MockServerHttpRequest ;
28
26
import org .springframework .mock .web .server .MockServerWebExchange ;
29
- import org .springframework .security .web .server .util .matcher .ServerWebExchangeMatcher ;
30
- import org .springframework .security .web .server .util .matcher .ServerWebExchangeMatcher .MatchResult ;
31
27
import org .springframework .web .server .WebFilterChain ;
32
28
import org .springframework .web .server .WebSession ;
33
29
import reactor .core .publisher .Mono ;
37
33
import static org .assertj .core .api .AssertionsForInterfaceTypes .assertThat ;
38
34
import static org .mockito .ArgumentMatchers .any ;
39
35
import static org .mockito .Mockito .when ;
40
- import static org .springframework .mock .web .server .MockServerWebExchange .from ;
41
36
42
37
/**
43
38
* @author Rob Winch
44
- * @author Parikshit Dutta
45
39
* @since 5.0
46
40
*/
47
41
@ RunWith (MockitoJUnitRunner .class )
@@ -55,10 +49,10 @@ public class CsrfWebFilterTests {
55
49
56
50
private CsrfWebFilter csrfFilter = new CsrfWebFilter ();
57
51
58
- private MockServerWebExchange get = from (
52
+ private MockServerWebExchange get = MockServerWebExchange . from (
59
53
MockServerHttpRequest .get ("/" ));
60
54
61
- private MockServerWebExchange post = from (
55
+ private MockServerWebExchange post = MockServerWebExchange . from (
62
56
MockServerHttpRequest .post ("/" ));
63
57
64
58
@ Test
@@ -110,7 +104,7 @@ public void filterWhenPostAndEstablishedCsrfTokenAndRequestParamInvalidTokenThen
110
104
this .csrfFilter .setCsrfTokenRepository (this .repository );
111
105
when (this .repository .loadToken (any ()))
112
106
.thenReturn (Mono .just (this .token ));
113
- this .post = from (MockServerHttpRequest .post ("/" )
107
+ this .post = MockServerWebExchange . from (MockServerHttpRequest .post ("/" )
114
108
.body (this .token .getParameterName () + "=" +this .token .getToken ()+"INVALID" ));
115
109
116
110
Mono <Void > result = this .csrfFilter .filter (this .post , this .chain );
@@ -131,7 +125,7 @@ public void filterWhenPostAndEstablishedCsrfTokenAndRequestParamValidTokenThenCo
131
125
.thenReturn (Mono .just (this .token ));
132
126
when (this .repository .generateToken (any ()))
133
127
.thenReturn (Mono .just (this .token ));
134
- this .post = from (MockServerHttpRequest .post ("/" )
128
+ this .post = MockServerWebExchange . from (MockServerHttpRequest .post ("/" )
135
129
.contentType (MediaType .APPLICATION_FORM_URLENCODED )
136
130
.body (this .token .getParameterName () + "=" +this .token .getToken ()));
137
131
@@ -148,7 +142,7 @@ public void filterWhenPostAndEstablishedCsrfTokenAndHeaderInvalidTokenThenCsrfEx
148
142
this .csrfFilter .setCsrfTokenRepository (this .repository );
149
143
when (this .repository .loadToken (any ()))
150
144
.thenReturn (Mono .just (this .token ));
151
- this .post = from (MockServerHttpRequest .post ("/" )
145
+ this .post = MockServerWebExchange . from (MockServerHttpRequest .post ("/" )
152
146
.header (this .token .getHeaderName (), this .token .getToken ()+"INVALID" ));
153
147
154
148
Mono <Void > result = this .csrfFilter .filter (this .post , this .chain );
@@ -169,7 +163,7 @@ public void filterWhenPostAndEstablishedCsrfTokenAndHeaderValidTokenThenContinue
169
163
.thenReturn (Mono .just (this .token ));
170
164
when (this .repository .generateToken (any ()))
171
165
.thenReturn (Mono .just (this .token ));
172
- this .post = from (MockServerHttpRequest .post ("/" )
166
+ this .post = MockServerWebExchange . from (MockServerHttpRequest .post ("/" )
173
167
.header (this .token .getHeaderName (), this .token .getToken ()));
174
168
175
169
Mono <Void > result = this .csrfFilter .filter (this .post , this .chain );
@@ -179,14 +173,4 @@ public void filterWhenPostAndEstablishedCsrfTokenAndHeaderValidTokenThenContinue
179
173
180
174
chainResult .assertWasSubscribed ();
181
175
}
182
-
183
- @ Test
184
- // gh-8452
185
- public void matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed () {
186
- HttpMethod customHttpMethod = HttpMethod .resolve ("non-standard-http-method" );
187
- MockServerWebExchange nonStandardHttpRequest = from (MockServerHttpRequest .method (customHttpMethod , "/" ));
188
-
189
- ServerWebExchangeMatcher serverWebExchangeMatcher = CsrfWebFilter .DEFAULT_CSRF_MATCHER ;
190
- assertThat (serverWebExchangeMatcher .matches (nonStandardHttpRequest ).map (MatchResult ::isMatch ).block ()).isTrue ();
191
- }
192
176
}
0 commit comments