use of org.springframework.test.web.reactive.server.WebTestClient in project spring-security by spring-projects.
the class AuthenticationWebFilterTests method filterWhenConvertEmptyThenOk.
@Test
public void filterWhenConvertEmptyThenOk() {
given(this.authenticationConverter.convert(any())).willReturn(Mono.empty());
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
client.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).consumeWith((b) -> assertThat(b.getResponseBody()).isEqualTo("ok")).returnResult();
verify(this.securityContextRepository, never()).save(any(), any());
verifyZeroInteractions(this.authenticationManager, this.successHandler, this.failureHandler);
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-security by spring-projects.
the class AuthenticationWebFilterTests method filterWhenAuthenticationManagerResolverDefaultsAndNoAuthenticationThenContinues.
@Test
public void filterWhenAuthenticationManagerResolverDefaultsAndNoAuthenticationThenContinues() {
this.filter = new AuthenticationWebFilter(this.authenticationManagerResolver);
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
EntityExchangeResult<String> result = client.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).consumeWith((b) -> assertThat(b.getResponseBody()).isEqualTo("ok")).returnResult();
verifyZeroInteractions(this.authenticationManagerResolver);
assertThat(result.getResponseCookies()).isEmpty();
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-security by spring-projects.
the class CsrfWebFilterTests method filterWhenMultipartFormDataAndEnabledThenGranted.
@Test
public void filterWhenMultipartFormDataAndEnabledThenGranted() {
this.csrfFilter.setCsrfTokenRepository(this.repository);
this.csrfFilter.setTokenFromMultipartDataEnabled(true);
given(this.repository.loadToken(any())).willReturn(Mono.just(this.token));
given(this.repository.generateToken(any())).willReturn(Mono.just(this.token));
WebTestClient client = WebTestClient.bindToController(new OkController()).webFilter(this.csrfFilter).build();
client.post().uri("/").contentType(MediaType.MULTIPART_FORM_DATA).body(BodyInserters.fromMultipartData(this.token.getParameterName(), this.token.getToken())).exchange().expectStatus().is2xxSuccessful();
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-security by spring-projects.
the class CsrfWebFilterTests method filterWhenMultipartMixedAndEnabledThenNotRead.
@Test
public void filterWhenMultipartMixedAndEnabledThenNotRead() {
this.csrfFilter.setCsrfTokenRepository(this.repository);
this.csrfFilter.setTokenFromMultipartDataEnabled(true);
given(this.repository.loadToken(any())).willReturn(Mono.just(this.token));
WebTestClient client = WebTestClient.bindToController(new OkController()).webFilter(this.csrfFilter).build();
client.post().uri("/").contentType(MediaType.MULTIPART_MIXED).bodyValue(this.token.getParameterName() + "=" + this.token.getToken()).exchange().expectStatus().isForbidden();
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-security by spring-projects.
the class CsrfWebFilterTests method filterWhenMultipartFormDataAndNotEnabledThenDenied.
@Test
public void filterWhenMultipartFormDataAndNotEnabledThenDenied() {
this.csrfFilter.setCsrfTokenRepository(this.repository);
given(this.repository.loadToken(any())).willReturn(Mono.just(this.token));
WebTestClient client = WebTestClient.bindToController(new OkController()).webFilter(this.csrfFilter).build();
client.post().uri("/").contentType(MediaType.MULTIPART_FORM_DATA).body(BodyInserters.fromMultipartData(this.token.getParameterName(), this.token.getToken())).exchange().expectStatus().isForbidden();
}
Aggregations