Fix CsrfWebFilter error message when expected CSRF not found
Closes gh-9337
This commit is contained in:
parent
0fc80a6a65
commit
b08075a721
|
@ -133,7 +133,7 @@ public class CsrfWebFilter implements WebFilter {
|
||||||
|
|
||||||
private Mono<Void> validateToken(ServerWebExchange exchange) {
|
private Mono<Void> validateToken(ServerWebExchange exchange) {
|
||||||
return this.csrfTokenRepository.loadToken(exchange)
|
return this.csrfTokenRepository.loadToken(exchange)
|
||||||
.switchIfEmpty(Mono.defer(() -> Mono.error(new CsrfException("CSRF Token has been associated to this client"))))
|
.switchIfEmpty(Mono.defer(() -> Mono.error(new CsrfException("An expected CSRF token cannot be found"))))
|
||||||
.filterWhen(expected -> containsValidCsrfToken(exchange, expected))
|
.filterWhen(expected -> containsValidCsrfToken(exchange, expected))
|
||||||
.switchIfEmpty(Mono.defer(() -> Mono.error(new CsrfException("Invalid CSRF Token"))))
|
.switchIfEmpty(Mono.defer(() -> Mono.error(new CsrfException("Invalid CSRF Token"))))
|
||||||
.then();
|
.then();
|
||||||
|
|
|
@ -65,8 +65,7 @@ public class CsrfWebFilterTests {
|
||||||
private MockServerWebExchange get = from(
|
private MockServerWebExchange get = from(
|
||||||
MockServerHttpRequest.get("/"));
|
MockServerHttpRequest.get("/"));
|
||||||
|
|
||||||
private ServerWebExchange post = from(
|
private MockServerWebExchange post = MockServerWebExchange.from(MockServerHttpRequest.post("/"));
|
||||||
MockServerHttpRequest.post("/"));
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filterWhenGetThenSessionNotCreatedAndChainContinues() {
|
public void filterWhenGetThenSessionNotCreatedAndChainContinues() {
|
||||||
|
@ -110,6 +109,8 @@ public class CsrfWebFilterTests {
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
assertThat(this.post.getResponse().getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
assertThat(this.post.getResponse().getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
|
StepVerifier.create(this.post.getResponse().getBodyAsString())
|
||||||
|
.assertNext(b -> assertThat(b).contains("An expected CSRF token cannot be found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue