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(
38
38
matchContentType = contentTypeMatches(request.contentType(), consumes)
39
39
)
40
40
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
44
43
private fun methodMatches (request : APIGatewayProxyRequestEvent ) = method.equals(request.httpMethod, true )
45
44
private fun contentTypeMatches (contentType : String? , accepted : Set <String >) =
46
45
if (accepted.isEmpty() && contentType == null ) true
Original file line number Diff line number Diff line change @@ -244,6 +244,24 @@ class RequestHandlerTest {
244
244
assert (response.statusCode).isEqualTo(401 )
245
245
}
246
246
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
+
247
265
class TestRequestHandlerAuthorization : RequestHandler () {
248
266
override val router = router {
249
267
GET (" /some" ) { _: Request <Unit > ->
You can’t perform that action at this time.
0 commit comments