Testing Logout
虽然使用标准 Spring MVC Test 相当简单,但可以使用 Spring Security 的测试支持来简化测试注销。例如,以下 logout
RequestPostProcessor
将使用有效的 CSRF 令牌向“/logout”提交一个 POST:
While fairly trivial using standard Spring MVC Test, you can use Spring Security’s testing support to make testing log out easier.
For example, the following logout
RequestPostProcessor
will submit a POST to "/logout" with a valid CSRF token:
-
Java
-
Kotlin
mvc
.perform(logout())
mvc
.perform(logout())
您还可以自定义要发布到的 URL。例如,以下代码段会向“/signout”提交一个 POST 请求,其中包含一个有效 CSRF 令牌:
You can also customize the URL to post to. For example, the snippet below will submit a POST to "/signout" with a valid CSRF token:
-
Java
-
Kotlin
mvc
.perform(logout("/signout"))
mvc
.perform(logout("/signout"))