mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-24 04:52:16 +00:00
Add tests for invalid/missing token
Issue gh-14634
This commit is contained in:
parent
79801134b6
commit
ba575e8564
@ -1221,6 +1221,24 @@ public class CsrfTests {
|
|||||||
.andExpect(header().string(HttpHeaders.LOCATION, "/"));
|
.andExpect(header().string(HttpHeaders.LOCATION, "/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void loginWhenInvalidCsrfTokenThenForbidden() throws Exception {
|
||||||
|
this.mockMvc.perform(post("/login").with(csrf().useInvalidToken())
|
||||||
|
.accept(MediaType.TEXT_HTML)
|
||||||
|
.param("username", "user")
|
||||||
|
.param("password", "password"))
|
||||||
|
.andExpect(status().isForbidden());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void loginWhenMissingCsrfTokenThenForbidden() throws Exception {
|
||||||
|
this.mockMvc.perform(post("/login")
|
||||||
|
.accept(MediaType.TEXT_HTML)
|
||||||
|
.param("username", "user")
|
||||||
|
.param("password", "password"))
|
||||||
|
.andExpect(status().isForbidden());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser
|
@WithMockUser
|
||||||
public void logoutWhenValidCsrfTokenThenSuccess() throws Exception {
|
public void logoutWhenValidCsrfTokenThenSuccess() throws Exception {
|
||||||
@ -1264,6 +1282,24 @@ class CsrfTests {
|
|||||||
.andExpect(header().string(HttpHeaders.LOCATION, "/"))
|
.andExpect(header().string(HttpHeaders.LOCATION, "/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun loginWhenInvalidCsrfTokenThenForbidden() {
|
||||||
|
mockMvc.perform(post("/login").with(csrf().useInvalidToken())
|
||||||
|
.accept(MediaType.TEXT_HTML)
|
||||||
|
.param("username", "user")
|
||||||
|
.param("password", "password"))
|
||||||
|
.andExpect(status().isForbidden)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun loginWhenMissingCsrfTokenThenForbidden() {
|
||||||
|
mockMvc.perform(post("/login")
|
||||||
|
.accept(MediaType.TEXT_HTML)
|
||||||
|
.param("username", "user")
|
||||||
|
.param("password", "password"))
|
||||||
|
.andExpect(status().isForbidden)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser
|
@WithMockUser
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user