diff --git a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoDeserializationHandler.kt b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoDeserializationHandler.kt index 73af0469..83f05eb0 100644 --- a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoDeserializationHandler.kt +++ b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoDeserializationHandler.kt @@ -14,7 +14,7 @@ class ProtoDeserializationHandler : DeserializationHandler { private val proto = MediaType.parse("application/x-protobuf") override fun supports(input: APIGatewayProxyRequestEvent): Boolean = - MediaType.parse(input.contentType()).`is`(proto) + input.contentType() != null && MediaType.parse(input.contentType()).`is`(proto) override fun deserialize(input: APIGatewayProxyRequestEvent, target: KType?): Any { val bytes = Base64.getDecoder().decode(input.body) diff --git a/router-protobuf/src/test/kotlin/io/moia/router/proto/ProtoDeserializationHandlerTest.kt b/router-protobuf/src/test/kotlin/io/moia/router/proto/ProtoDeserializationHandlerTest.kt new file mode 100644 index 00000000..d90bc7fa --- /dev/null +++ b/router-protobuf/src/test/kotlin/io/moia/router/proto/ProtoDeserializationHandlerTest.kt @@ -0,0 +1,25 @@ +package io.moia.router.proto + +import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent +import io.moia.router.withHeader +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test + +internal class ProtoDeserializationHandlerTest { + + @Test + fun `Deserializer should not support if the content type of the input is null`() { + assertFalse(ProtoDeserializationHandler().supports(APIGatewayProxyRequestEvent())) + } + + @Test + fun `Deserializer should not support if the content type of the input is json`() { + assertFalse(ProtoDeserializationHandler().supports(APIGatewayProxyRequestEvent().withHeader("content-type", "application/json"))) + } + + @Test + fun `Deserializer should support if the content type of the input is protobuf`() { + assertTrue(ProtoDeserializationHandler().supports(APIGatewayProxyRequestEvent().withHeader("content-type", "application/x-protobuf"))) + } +} \ No newline at end of file diff --git a/router-protobuf/src/test/kotlin/io/moia/router/proto/RequestHandlerTest.kt b/router-protobuf/src/test/kotlin/io/moia/router/proto/RequestHandlerTest.kt index ea8713f5..45cf7d80 100644 --- a/router-protobuf/src/test/kotlin/io/moia/router/proto/RequestHandlerTest.kt +++ b/router-protobuf/src/test/kotlin/io/moia/router/proto/RequestHandlerTest.kt @@ -14,7 +14,7 @@ import java.util.Base64 class RequestHandlerTest { - val testRequestHandler = TestRequestHandler() + private val testRequestHandler = TestRequestHandler() @Test fun `should match request to proto handler and return json`() {