csrf.adoc 637 B

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