Skip to content

Commit ba575e8

Browse files
committed
Add tests for invalid/missing token
Issue gh-14634
1 parent 7980113 commit ba575e8

File tree

1 file changed

+36
-0
lines changed
  • docs/modules/ROOT/pages/servlet/exploits

1 file changed

+36
-0
lines changed

docs/modules/ROOT/pages/servlet/exploits/csrf.adoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,24 @@ public class CsrfTests {
12211221
.andExpect(header().string(HttpHeaders.LOCATION, "/"));
12221222
}
12231223
1224+
@Test
1225+
public void loginWhenInvalidCsrfTokenThenForbidden() throws Exception {
1226+
this.mockMvc.perform(post("/login").with(csrf().useInvalidToken())
1227+
.accept(MediaType.TEXT_HTML)
1228+
.param("username", "user")
1229+
.param("password", "password"))
1230+
.andExpect(status().isForbidden());
1231+
}
1232+
1233+
@Test
1234+
public void loginWhenMissingCsrfTokenThenForbidden() throws Exception {
1235+
this.mockMvc.perform(post("/login")
1236+
.accept(MediaType.TEXT_HTML)
1237+
.param("username", "user")
1238+
.param("password", "password"))
1239+
.andExpect(status().isForbidden());
1240+
}
1241+
12241242
@Test
12251243
@WithMockUser
12261244
public void logoutWhenValidCsrfTokenThenSuccess() throws Exception {
@@ -1264,6 +1282,24 @@ class CsrfTests {
12641282
.andExpect(header().string(HttpHeaders.LOCATION, "/"))
12651283
}
12661284
1285+
@Test
1286+
fun loginWhenInvalidCsrfTokenThenForbidden() {
1287+
mockMvc.perform(post("/login").with(csrf().useInvalidToken())
1288+
.accept(MediaType.TEXT_HTML)
1289+
.param("username", "user")
1290+
.param("password", "password"))
1291+
.andExpect(status().isForbidden)
1292+
}
1293+
1294+
@Test
1295+
fun loginWhenMissingCsrfTokenThenForbidden() {
1296+
mockMvc.perform(post("/login")
1297+
.accept(MediaType.TEXT_HTML)
1298+
.param("username", "user")
1299+
.param("password", "password"))
1300+
.andExpect(status().isForbidden)
1301+
}
1302+
12671303
@Test
12681304
@WithMockUser
12691305
@Throws(Exception::class)

0 commit comments

Comments
 (0)