File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
main/kotlin/io/moia/router
test/kotlin/io/moia/router Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,8 @@ data class RequestPredicate(
3838 matchContentType = contentTypeMatches(request.contentType(), consumes)
3939 )
4040
41- private fun pathMatches (request : APIGatewayProxyRequestEvent ) = UriTemplate .from(
42- pathPattern
43- ).matches(request.path)
41+ private fun pathMatches (request : APIGatewayProxyRequestEvent ) =
42+ request.path?.let { UriTemplate .from(pathPattern).matches(it) } ? : false
4443 private fun methodMatches (request : APIGatewayProxyRequestEvent ) = method.equals(request.httpMethod, true )
4544 private fun contentTypeMatches (contentType : String? , accepted : Set <String >) =
4645 if (accepted.isEmpty() && contentType == null ) true
Original file line number Diff line number Diff line change @@ -244,6 +244,24 @@ class RequestHandlerTest {
244244 assert (response.statusCode).isEqualTo(401 )
245245 }
246246
247+ @Test
248+ fun `Request without headers should return status code 406` () {
249+ val response = testRequestHandler.handleRequest(
250+ GET (" /some" ),
251+ mockk()
252+ )
253+ assert (response.statusCode).isEqualTo(406 )
254+ }
255+
256+ @Test
257+ fun `Request without request path should return status code 404` () {
258+ val response = testRequestHandler.handleRequest(
259+ GET (),
260+ mockk()
261+ )
262+ assert (response.statusCode).isEqualTo(404 )
263+ }
264+
247265 class TestRequestHandlerAuthorization : RequestHandler () {
248266 override val router = router {
249267 GET (" /some" ) { _: Request <Unit > ->
You can’t perform that action at this time.
0 commit comments