csrf.adoc 639 B

12345678910111213141516171819202122232425262728293031323334
  1. = Testing with CSRF
  2. Spring Security also provides support for CSRF testing with `WebTestClient` -- for example:
  3. [tabs]
  4. ======
  5. Java::
  6. +
  7. [source,java,role="primary"]
  8. ----
  9. import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf;
  10. this.rest
  11. // provide a valid CSRF token
  12. .mutateWith(csrf())
  13. .post()
  14. .uri("/login")
  15. ...
  16. ----
  17. Kotlin::
  18. +
  19. [source,kotlin,role="secondary"]
  20. ----
  21. import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf
  22. this.rest
  23. // provide a valid CSRF token
  24. .mutateWith(csrf())
  25. .post()
  26. .uri("/login")
  27. ...
  28. ----
  29. ======