File tree Expand file tree Collapse file tree
main/kotlin/no/javazone/feedback
test/kotlin/no/javazone/feedback Expand file tree Collapse file tree Original file line number Diff line number Diff 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) }
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments