mirror of https://github.com/usbharu/Hideout.git
fix: POST: /api/v1/accountsに対するリクエストにCSRFトークンが必須に
This commit is contained in:
parent
50415688d5
commit
6727a1c8da
|
@ -129,12 +129,36 @@ class AccountApiTest {
|
||||||
mockMvc
|
mockMvc
|
||||||
.post("/api/v1/accounts") {
|
.post("/api/v1/accounts") {
|
||||||
contentType = MediaType.APPLICATION_FORM_URLENCODED
|
contentType = MediaType.APPLICATION_FORM_URLENCODED
|
||||||
param("username", "api-test-user-3")
|
param("username", "api-test-user-4")
|
||||||
with(SecurityMockMvcRequestPostProcessors.csrf())
|
with(SecurityMockMvcRequestPostProcessors.csrf())
|
||||||
}
|
}
|
||||||
.andExpect { status { isBadRequest() } }
|
.andExpect { status { isBadRequest() } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithAnonymousUser
|
||||||
|
fun apiV1AccountsPostでJSONで作ろうとしても400() {
|
||||||
|
mockMvc
|
||||||
|
.post("/api/v1/accounts") {
|
||||||
|
contentType = MediaType.APPLICATION_JSON
|
||||||
|
content = """{"username":"api-test-user-5","password":"very-very-secure-password"}"""
|
||||||
|
with(SecurityMockMvcRequestPostProcessors.csrf())
|
||||||
|
}
|
||||||
|
.andExpect { status { isUnsupportedMediaType() } }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithAnonymousUser
|
||||||
|
fun apiV1AccountsPostにCSRFトークンは必要() {
|
||||||
|
mockMvc
|
||||||
|
.post("/api/v1/accounts") {
|
||||||
|
contentType = MediaType.APPLICATION_FORM_URLENCODED
|
||||||
|
param("username", "api-test-user-2")
|
||||||
|
param("password", "very-secure-password")
|
||||||
|
}
|
||||||
|
.andExpect { status { isForbidden() } }
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
|
|
@ -190,7 +190,7 @@ class SecurityConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
csrf {
|
csrf {
|
||||||
ignoringRequestMatchers("/users/*/inbox", "/inbox", "/api/v1/apps", "/api/v1/accounts")
|
ignoringRequestMatchers("/users/*/inbox", "/inbox", "/api/v1/apps")
|
||||||
}
|
}
|
||||||
|
|
||||||
headers {
|
headers {
|
||||||
|
|
Loading…
Reference in New Issue