|
@@ -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)
|