2021-10-29 12:09:04 -04:00
|
|
|
= WebTestClient Security Setup
|
|
|
|
|
|
|
|
The basic setup looks like this:
|
|
|
|
|
2022-07-21 13:29:00 -04:00
|
|
|
====
|
|
|
|
.Java
|
|
|
|
[source,java,role="primary"]
|
2021-10-29 12:09:04 -04:00
|
|
|
----
|
2022-03-22 15:30:10 -04:00
|
|
|
@ExtendWith(SpringExtension.class)
|
2021-10-29 12:09:04 -04:00
|
|
|
@ContextConfiguration(classes = HelloWebfluxMethodApplication.class)
|
|
|
|
public class HelloWebfluxMethodApplicationTests {
|
|
|
|
@Autowired
|
|
|
|
ApplicationContext context;
|
|
|
|
|
|
|
|
WebTestClient rest;
|
|
|
|
|
2022-03-22 15:30:10 -04:00
|
|
|
@BeforeEach
|
2021-10-29 12:09:04 -04:00
|
|
|
public void setup() {
|
|
|
|
this.rest = WebTestClient
|
|
|
|
.bindToApplicationContext(this.context)
|
|
|
|
// add Spring Security test Support
|
|
|
|
.apply(springSecurity())
|
|
|
|
.configureClient()
|
2022-07-21 13:29:00 -04:00
|
|
|
.filter(basicAuthentication("user", "password"))
|
2021-10-29 12:09:04 -04:00
|
|
|
.build();
|
|
|
|
}
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
----
|
2022-07-21 13:29:00 -04:00
|
|
|
|
|
|
|
.Kotlin
|
|
|
|
[source,kotlin,role="secondary"]
|
|
|
|
----
|
|
|
|
@ExtendWith(SpringExtension::class)
|
|
|
|
@ContextConfiguration(classes = [HelloWebfluxMethodApplication::class])
|
|
|
|
class HelloWebfluxMethodApplicationTests {
|
|
|
|
@Autowired
|
|
|
|
lateinit var context: ApplicationContext
|
|
|
|
|
|
|
|
lateinit var rest: WebTestClient
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
fun setup() {
|
|
|
|
this.rest = WebTestClient
|
|
|
|
.bindToApplicationContext(this.context)
|
|
|
|
// add Spring Security test Support
|
|
|
|
.apply(springSecurity())
|
|
|
|
.configureClient()
|
|
|
|
.filter(basicAuthentication("user", "password"))
|
|
|
|
.build()
|
|
|
|
}
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
----
|
|
|
|
====
|