use of org.springframework.test.web.reactive.server.WebTestClient in project spring-security by spring-projects.
the class EnableWebFluxSecurityTests method formLoginWorks.
@Test
public void formLoginWorks() {
this.spring.register(Config.class).autowire();
// @formatter:off
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.springSecurityFilterChain, writePrincipalWebFilter()).build();
// @formatter:on
MultiValueMap<String, String> data = new LinkedMultiValueMap<>();
data.add("username", "user");
data.add("password", "password");
// @formatter:off
client.mutateWith(csrf()).post().uri("/login").body(BodyInserters.fromFormData(data)).exchange().expectStatus().is3xxRedirection().expectHeader().valueMatches("Location", "/");
// @formatter:on
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-security by spring-projects.
the class EnableWebFluxSecurityTests method passwordEncoderBeanIsUsed.
@Test
public void passwordEncoderBeanIsUsed() {
this.spring.register(CustomPasswordEncoderConfig.class).autowire();
// @formatter:off
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.springSecurityFilterChain, writePrincipalWebFilter()).build();
client.get().uri("/").headers((headers) -> headers.setBasicAuth("user", "password")).exchange().expectStatus().isOk().expectBody(String.class).consumeWith((result) -> assertThat(result.getResponseBody()).isEqualTo("user"));
// @formatter:on
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-security by spring-projects.
the class EnableWebFluxSecurityTests method authenticationPrincipalArgumentResolverWhenSpelThenWorks.
@Test
@WithMockUser
public void authenticationPrincipalArgumentResolverWhenSpelThenWorks() {
this.spring.register(AuthenticationPrincipalConfig.class).autowire();
// @formatter:off
WebTestClient client = WebTestClient.bindToApplicationContext(this.spring.getContext()).build();
client.get().uri("/spel").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("user");
// @formatter:on
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-security by spring-projects.
the class EnableWebFluxSecurityTests method passwordUpdateManagerUsed.
@Test
public void passwordUpdateManagerUsed() {
this.spring.register(MapReactiveUserDetailsServiceConfig.class).autowire();
// @formatter:off
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.springSecurityFilterChain).build();
client.get().uri("/").headers((h) -> h.setBasicAuth("user", "password")).exchange().expectStatus().isOk();
// @formatter:on
ReactiveUserDetailsService users = this.spring.getContext().getBean(ReactiveUserDetailsService.class);
assertThat(users.findByUsername("user").block().getPassword()).startsWith("{bcrypt}");
}
use of org.springframework.test.web.reactive.server.WebTestClient in project pact-jvm by DiUS.
the class WebTestClientPactTest method setup.
@BeforeEach
void setup(PactVerificationContext context) {
Handler handler = new Handler();
WebTestClient webTestClient = WebTestClient.bindToRouterFunction(new Router().route(handler)).build();
context.setTarget(new WebTestClientTarget(webTestClient));
}
Aggregations