File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
api-model/src/commonMain/kotlin
backend/src/test/kotlin/routes/organization Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -52,9 +52,9 @@ data class PostSecret(
5252 val description : String?
5353) {
5454 companion object {
55- val NAME_PATTERN_REGEX = """ ^(?!\s)[A-Za-z0-9- ]* (?<!\s)$""" .toRegex()
56- const val NAME_PATTERN_MESSAGE = " The entity name may only contain letters, numbers, hyphen marks and " +
57- " spaces. Leading and trailing whitespaces are not allowed."
55+ val NAME_PATTERN_REGEX = """ ^(?!\s)[A-Za-z0-9- ]+ (?<!\s)$""" .toRegex()
56+ const val NAME_PATTERN_MESSAGE = " The entity name must not be empty and may only contain letters, " +
57+ " numbers, hyphen marks and spaces. Leading and trailing whitespaces are not allowed."
5858 }
5959
6060 fun validate () =
Original file line number Diff line number Diff line change @@ -126,5 +126,35 @@ class PostOrganizationSecretIntegrationTest : SecretsIntegrationTest({
126126 provider.readSecret(Path ("organization_${orgId}_ ${secret.name}"))?.value.shouldBeNull()
127127 }
128128 }
129+
130+ " respond with 'Bad Request' if the secret's name is empty" {
131+ secretsTestApplication { client ->
132+ install(StatusPages ) {
133+ // TODO: This should use the same config as in core.
134+ exception<RequestValidationException > { call, e ->
135+ call.respondError(
136+ HttpStatusCode .BadRequest ,
137+ message = "Request validation has failed.",
138+ cause = e.message
139+ )
140+ }
141+ }
142+
143+ val secret = PostSecret ("", "value", "description")
144+
145+ val response = client.post("/organizations/$orgId/secrets") {
146+ setBody(secret)
147+ }
148+
149+ response shouldHaveStatus HttpStatusCode .BadRequest
150+
151+ val body = response.body<ErrorResponse >()
152+ body.message shouldBe " Request validation has failed."
153+ body.cause shouldContain " Validation failed for PostSecret"
154+
155+ val provider = SecretsProviderFactoryForTesting .instance()
156+ provider.readSecret(Path ("organization_${orgId}_ ${secret.name}"))?.value.shouldBeNull()
157+ }
158+ }
129159 }
130160})
You can’t perform that action at this time.
0 commit comments