Valider les resource entrente #91
@@ -1,5 +1,6 @@
|
|||||||
package fr.dcproject.component.article.routes
|
package fr.dcproject.component.article.routes
|
||||||
|
|
||||||
|
import fr.dcproject.application.http.respondIfNotValid
|
||||||
import fr.dcproject.common.response.toOutput
|
import fr.dcproject.common.response.toOutput
|
||||||
import fr.dcproject.common.security.assert
|
import fr.dcproject.common.security.assert
|
||||||
import fr.dcproject.common.validation.isUuid
|
import fr.dcproject.common.validation.isUuid
|
||||||
@@ -16,7 +17,6 @@ import io.konform.validation.jsonschema.enum
|
|||||||
import io.konform.validation.jsonschema.maximum
|
import io.konform.validation.jsonschema.maximum
|
||||||
import io.konform.validation.jsonschema.minimum
|
import io.konform.validation.jsonschema.minimum
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
import io.ktor.http.HttpStatusCode
|
|
||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.get
|
import io.ktor.locations.get
|
||||||
@@ -74,10 +74,7 @@ object FindArticles {
|
|||||||
|
|
||||||
fun Route.findArticles(repo: ArticleRepository, ac: ArticleAccessControl) {
|
fun Route.findArticles(repo: ArticleRepository, ac: ArticleAccessControl) {
|
||||||
get<ArticlesRequest> {
|
get<ArticlesRequest> {
|
||||||
if (it.validate().errors.size > 0) {
|
respondIfNotValid(it.validate())?.apply { return@get }
|
||||||
call.respond(HttpStatusCode.BadRequest)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
repo.findArticles(it)
|
repo.findArticles(it)
|
||||||
.apply { ac.assert { canView(result, citizenOrNull) } }
|
.apply { ac.assert { canView(result, citizenOrNull) } }
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ class `Article routes` : BaseTest() {
|
|||||||
fun `I cannot get article list`() {
|
fun `I cannot get article list`() {
|
||||||
withIntegrationApplication {
|
withIntegrationApplication {
|
||||||
`Given I have articles`(3)
|
`Given I have articles`(3)
|
||||||
`When I send a GET request`("/articles?page=1&limit=10&sort=title&createdBy=hello", Validate.ALL - Validate.REQUEST_PARAM) `Then the response should be` BadRequest
|
`When I send a GET request`("/articles?page=1&limit=10&sort=title&createdBy=hello", Validate.ALL - Validate.REQUEST_PARAM) `Then the response should be` BadRequest and {
|
||||||
|
`And the response should contain`("$.invalidParams[*].name", ".createdBy")
|
||||||
|
`And the response should contain`("$.invalidParams[*].reason", "must be UUID")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user