Skip to content

Commit 630597c

Browse files
committed
ikke godta channelid som ikke er på forventet format
1 parent a7ecc59 commit 630597c

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

core/src/main/kotlin/no/javazone/feedback/setupRouting.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ fun Application.setupRouting() {
5656
get("/{channelId}") {
5757
val channelId = call.parameters["channelId"]
5858
?: return@get call.respond(HttpStatusCode.NotFound)
59+
if (channelId.length != 4) {
60+
return@get call.respond(HttpStatusCode.BadRequest)
61+
}
5962
val channel = feedbackAdapter.findChannel(channelId)
6063
?: return@get call.respond(HttpStatusCode.NotFound, "Channel not found")
6164
call.respondHtml { feedbackPage(channel) }

core/src/test/kotlin/no/javazone/feedback/FeedbackEndpointsTest.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,33 @@ class FeedbackEndpointsTest {
279279
module(TestDatabase.config())
280280
}
281281

282-
val response = client.get("/non-existent-channel")
282+
val response = client.get("/session/ZZZZ")
283283

284284
assertEquals(HttpStatusCode.NotFound, response.status)
285285
}
286286

287+
@Test
288+
fun `test session endpoint returns bad request for channel id longer than four characters`() = testApplication {
289+
application {
290+
module(TestDatabase.config())
291+
}
292+
293+
val response = client.get("/session/ABCDE")
294+
295+
assertEquals(HttpStatusCode.BadRequest, response.status)
296+
}
297+
298+
@Test
299+
fun `test session endpoint returns bad request for channel id shorter than four characters`() = testApplication {
300+
application {
301+
module(TestDatabase.config())
302+
}
303+
304+
val response = client.get("/session/ABC")
305+
306+
assertEquals(HttpStatusCode.BadRequest, response.status)
307+
}
308+
287309
@Test
288310
fun `test thank you page returns HTML fragment`() = testApplication {
289311
application {

0 commit comments

Comments
 (0)