diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 79b80540..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/build.gradle.kts b/build.gradle.kts index 9eae75b0..b3da05c4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,11 +10,11 @@ buildscript { plugins { java - kotlin("jvm") version "1.3.21" + kotlin("jvm") version "1.4.10" `maven-publish` jacoco - id("com.github.kt3k.coveralls") version "2.10.1" - id("org.jmailen.kotlinter") version "1.22.0" + id("com.github.kt3k.coveralls") version "2.10.2" + id("org.jmailen.kotlinter") version "3.2.0" } group = "com.github.moia-dev" diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 87b738cb..f3d88b1c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5f1b1201..12d38de6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index af6708ff..2fe81a7d 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m"' +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -109,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` @@ -138,19 +154,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -159,14 +175,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 0f8d5937..24467a14 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/router-openapi-request-validator/build.gradle.kts b/router-openapi-request-validator/build.gradle.kts index 67782c70..beea84dd 100644 --- a/router-openapi-request-validator/build.gradle.kts +++ b/router-openapi-request-validator/build.gradle.kts @@ -6,11 +6,11 @@ dependencies { compile(kotlin("stdlib-jdk8")) compile(kotlin("reflect")) - compile("com.atlassian.oai:swagger-request-validator-core:2.2.2") + compile("com.atlassian.oai:swagger-request-validator-core:2.11.0") compile(project(":router")) - testImplementation("org.junit.jupiter:junit-jupiter-engine:5.4.0") - testImplementation("org.assertj:assertj-core:3.11.1") - testImplementation("io.mockk:mockk:1.8.13.kotlin13") - testImplementation("org.slf4j:slf4j-simple:1.7.26") + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.0") + testImplementation("org.assertj:assertj-core:3.17.2") + testImplementation("io.mockk:mockk:1.10.0") + testImplementation("org.slf4j:slf4j-simple:1.7.30") } \ No newline at end of file diff --git a/router-openapi-request-validator/src/main/kotlin/io/moia/router/openapi/OpenApiValidator.kt b/router-openapi-request-validator/src/main/kotlin/io/moia/router/openapi/OpenApiValidator.kt index cb586efb..e7a07e41 100644 --- a/router-openapi-request-validator/src/main/kotlin/io/moia/router/openapi/OpenApiValidator.kt +++ b/router-openapi-request-validator/src/main/kotlin/io/moia/router/openapi/OpenApiValidator.kt @@ -19,21 +19,23 @@ class OpenApiValidator(val specUrlOrPayload: String) { } fun assertValid(request: APIGatewayProxyRequestEvent, response: APIGatewayProxyResponseEvent) { - return validate(request, response).let { if (it.hasErrors()) throw ApiInteractionInvalid( - specUrlOrPayload, - request, - response, - it - ) + return validate(request, response).let { + if (it.hasErrors()) throw ApiInteractionInvalid( + specUrlOrPayload, + request, + response, + it + ) } } fun assertValidRequest(request: APIGatewayProxyRequestEvent) = - validator.validateRequest(request.toRequest()).let { if (it.hasErrors()) throw ApiInteractionInvalid( - spec = specUrlOrPayload, - request = request, - validationReport = it - ) + validator.validateRequest(request.toRequest()).let { + if (it.hasErrors()) throw ApiInteractionInvalid( + spec = specUrlOrPayload, + request = request, + validationReport = it + ) } fun assertValidResponse(request: APIGatewayProxyRequestEvent, response: APIGatewayProxyResponseEvent) = @@ -78,4 +80,4 @@ class OpenApiValidator(val specUrlOrPayload: String) { companion object { val log = LoggerFactory.getLogger(OpenApiValidator::class.java) } -} \ No newline at end of file +} diff --git a/router-openapi-request-validator/src/main/kotlin/io/moia/router/openapi/ValidatingRequestRouterWrapper.kt b/router-openapi-request-validator/src/main/kotlin/io/moia/router/openapi/ValidatingRequestRouterWrapper.kt index 9923a7ea..4de26525 100644 --- a/router-openapi-request-validator/src/main/kotlin/io/moia/router/openapi/ValidatingRequestRouterWrapper.kt +++ b/router-openapi-request-validator/src/main/kotlin/io/moia/router/openapi/ValidatingRequestRouterWrapper.kt @@ -66,4 +66,4 @@ class ValidatingRequestRouterWrapper( companion object { private val log = LoggerFactory.getLogger(ValidatingRequestRouterWrapper::class.java) } -} \ No newline at end of file +} diff --git a/router-openapi-request-validator/src/test/kotlin/io/moia/router/openapi/OpenApiValidatorTest.kt b/router-openapi-request-validator/src/test/kotlin/io/moia/router/openapi/OpenApiValidatorTest.kt index a250208a..928b6379 100644 --- a/router-openapi-request-validator/src/test/kotlin/io/moia/router/openapi/OpenApiValidatorTest.kt +++ b/router-openapi-request-validator/src/test/kotlin/io/moia/router/openapi/OpenApiValidatorTest.kt @@ -1,11 +1,11 @@ package io.moia.router.openapi +import io.mockk.mockk import io.moia.router.GET import io.moia.router.Request import io.moia.router.RequestHandler import io.moia.router.ResponseEntity import io.moia.router.Router -import io.mockk.mockk import org.assertj.core.api.BDDAssertions.thenThrownBy import org.junit.jupiter.api.Test @@ -73,4 +73,4 @@ class OpenApiValidatorTest { } } } -} \ No newline at end of file +} diff --git a/router-openapi-request-validator/src/test/kotlin/io/moia/router/openapi/ValidatingRequestRouterWrapperTest.kt b/router-openapi-request-validator/src/test/kotlin/io/moia/router/openapi/ValidatingRequestRouterWrapperTest.kt index 4ddbc257..09ea08f1 100644 --- a/router-openapi-request-validator/src/test/kotlin/io/moia/router/openapi/ValidatingRequestRouterWrapperTest.kt +++ b/router-openapi-request-validator/src/test/kotlin/io/moia/router/openapi/ValidatingRequestRouterWrapperTest.kt @@ -44,28 +44,32 @@ class ValidatingRequestRouterWrapperTest { @Test fun `should skip validation`() { val response = ValidatingRequestRouterWrapper(InvalidTestRequestHandler(), "openapi.yml") - .handleRequestSkippingRequestAndResponseValidation(GET("/path-not-documented").withAcceptHeader("application/json"), mockk()) + .handleRequestSkippingRequestAndResponseValidation(GET("/path-not-documented").withAcceptHeader("application/json"), mockk()) then(response.statusCode).isEqualTo(404) } @Test fun `should apply additional request validation`() { - thenThrownBy { ValidatingRequestRouterWrapper( - delegate = OpenApiValidatorTest.TestRequestHandler(), - specUrlOrPayload = "openapi.yml", - additionalRequestValidationFunctions = listOf({ _ -> throw RequestValidationFailedException() })) - .handleRequest(GET("/tests").withAcceptHeader("application/json"), mockk()) + thenThrownBy { + ValidatingRequestRouterWrapper( + delegate = OpenApiValidatorTest.TestRequestHandler(), + specUrlOrPayload = "openapi.yml", + additionalRequestValidationFunctions = listOf({ _ -> throw RequestValidationFailedException() }) + ) + .handleRequest(GET("/tests").withAcceptHeader("application/json"), mockk()) } .isInstanceOf(RequestValidationFailedException::class.java) } @Test fun `should apply additional response validation`() { - thenThrownBy { ValidatingRequestRouterWrapper( - delegate = OpenApiValidatorTest.TestRequestHandler(), - specUrlOrPayload = "openapi.yml", - additionalResponseValidationFunctions = listOf({ _, _ -> throw ResponseValidationFailedException() })) - .handleRequest(GET("/tests").withAcceptHeader("application/json"), mockk()) + thenThrownBy { + ValidatingRequestRouterWrapper( + delegate = OpenApiValidatorTest.TestRequestHandler(), + specUrlOrPayload = "openapi.yml", + additionalResponseValidationFunctions = listOf({ _, _ -> throw ResponseValidationFailedException() }) + ) + .handleRequest(GET("/tests").withAcceptHeader("application/json"), mockk()) } .isInstanceOf(ResponseValidationFailedException::class.java) } @@ -88,4 +92,4 @@ class ValidatingRequestRouterWrapperTest { } } } -} \ No newline at end of file +} diff --git a/router-protobuf/build.gradle.kts b/router-protobuf/build.gradle.kts index 061dffbe..83dbba2e 100644 --- a/router-protobuf/build.gradle.kts +++ b/router-protobuf/build.gradle.kts @@ -2,7 +2,7 @@ import com.google.protobuf.gradle.protobuf import com.google.protobuf.gradle.protoc plugins { - id("com.google.protobuf") version "0.8.7" + id("com.google.protobuf") version "0.8.13" } repositories { @@ -13,17 +13,17 @@ dependencies { compile(kotlin("stdlib-jdk8")) compile(kotlin("reflect")) - compile("org.slf4j:slf4j-api:1.7.26") - compile("com.google.protobuf:protobuf-java:3.11.1") - compile("com.google.protobuf:protobuf-java-util:3.11.1") - compile("com.google.guava:guava:23.0") + compile("org.slf4j:slf4j-api:1.7.30") + compile("com.google.protobuf:protobuf-java:3.13.0") + compile("com.google.protobuf:protobuf-java-util:3.13.0") + compile("com.google.guava:guava:29.0-jre") compile(project(":router")) - testImplementation("org.junit.jupiter:junit-jupiter-engine:5.4.0") + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.0") testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.12") testImplementation("org.assertj:assertj-core:3.11.1") - testImplementation("io.mockk:mockk:1.8.13.kotlin13") - testImplementation("org.slf4j:slf4j-simple:1.7.26") + testImplementation("io.mockk:mockk:1.10.0") + testImplementation("org.slf4j:slf4j-simple:1.7.30") testImplementation("com.jayway.jsonpath:json-path:2.4.0") } @@ -31,6 +31,6 @@ dependencies { protobuf { protoc { // The artifact spec for the Protobuf Compiler - artifact = "com.google.protobuf:protoc:3.6.1" + artifact = "com.google.protobuf:protoc:3.13.0" } } \ No newline at end of file diff --git a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoBufUtils.kt b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoBufUtils.kt index cfae02ec..b74090c9 100644 --- a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoBufUtils.kt +++ b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoBufUtils.kt @@ -8,50 +8,51 @@ import com.google.protobuf.GeneratedMessageV3 import com.google.protobuf.util.JsonFormat object ProtoBufUtils { - fun toJsonWithoutWrappers(proto: GeneratedMessageV3): String { - val message = JsonFormat.printer().omittingInsignificantWhitespace().includingDefaultValueFields().print(proto) - return removeWrapperObjects(message) - } + fun toJsonWithoutWrappers(proto: GeneratedMessageV3): String { + val message = JsonFormat.printer().omittingInsignificantWhitespace().includingDefaultValueFields().print(proto) + return removeWrapperObjects(message) + } - fun removeWrapperObjects(json: String): String { - return removeWrapperObjects( - jacksonObjectMapper().readTree(json) - ).toString() - } + fun removeWrapperObjects(json: String): String { + return removeWrapperObjects( + jacksonObjectMapper().readTree(json) + ).toString() + } - fun removeWrapperObjects(json: JsonNode): JsonNode { - if (json.isArray) { - return removeWrapperObjects(json as ArrayNode) - } else if (json.isObject) { - if (json.has("value") && json.size() == 1) { - return json.get("value") - } - return removeWrapperObjects(json as ObjectNode) + fun removeWrapperObjects(json: JsonNode): JsonNode { + if (json.isArray) { + return removeWrapperObjects(json as ArrayNode) + } else if (json.isObject) { + if (json.has("value") && json.size() == 1) { + return json.get("value") } - return json + return removeWrapperObjects(json as ObjectNode) } + return json + } - private fun removeWrapperObjects(json: ObjectNode): ObjectNode { - val result = jacksonObjectMapper().createObjectNode() - for (entry in json.fields()) { - if (entry.value.isContainerNode && entry.value.size() > 0) { - if (entry.value.size() > 0) { - result.set(entry.key, - removeWrapperObjects(entry.value) - ) - } - } else { - result.set(entry.key, entry.value) + private fun removeWrapperObjects(json: ObjectNode): ObjectNode { + val result = jacksonObjectMapper().createObjectNode() + for (entry in json.fields()) { + if (entry.value.isContainerNode && entry.value.size() > 0) { + if (entry.value.size() > 0) { + result.set( + entry.key, + removeWrapperObjects(entry.value) + ) } + } else { + result.set(entry.key, entry.value) } - return result } + return result + } - private fun removeWrapperObjects(json: ArrayNode): ArrayNode { - val result = jacksonObjectMapper().createArrayNode() - for (entry in json) { - result.add(removeWrapperObjects(entry)) - } - return result + private fun removeWrapperObjects(json: ArrayNode): ArrayNode { + val result = jacksonObjectMapper().createArrayNode() + for (entry in json) { + result.add(removeWrapperObjects(entry)) } -} \ No newline at end of file + return result + } +} 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 5150662f..092cfd33 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 @@ -27,4 +27,4 @@ class ProtoDeserializationHandler : DeserializationHandler { val parser = (target?.classifier as KClass<*>).staticFunctions.first { it.name == "parser" }.call() as Parser<*> return parser.parseFrom(bytes) } -} \ No newline at end of file +} diff --git a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoEnabledRequestHandler.kt b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoEnabledRequestHandler.kt index 3cbd5d3f..c6d3e01a 100644 --- a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoEnabledRequestHandler.kt +++ b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoEnabledRequestHandler.kt @@ -19,4 +19,4 @@ abstract class ProtoEnabledRequestHandler : RequestHandler() { ): APIGatewayProxyResponseEvent { return super.createResponse(contentType, response).withIsBase64Encoded(true) } -} \ No newline at end of file +} diff --git a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoSerializationHandler.kt b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoSerializationHandler.kt index bfd9c366..e4b150a6 100644 --- a/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoSerializationHandler.kt +++ b/router-protobuf/src/main/kotlin/io/moia/router/proto/ProtoSerializationHandler.kt @@ -22,4 +22,4 @@ class ProtoSerializationHandler : SerializationHandler { Base64.getEncoder().encodeToString(message.toByteArray()) } } -} \ No newline at end of file +} diff --git a/router-protobuf/src/test/kotlin/io/moia/router/proto/ProtoBufUtilsTest.kt b/router-protobuf/src/test/kotlin/io/moia/router/proto/ProtoBufUtilsTest.kt index 846bec49..21906d34 100644 --- a/router-protobuf/src/test/kotlin/io/moia/router/proto/ProtoBufUtilsTest.kt +++ b/router-protobuf/src/test/kotlin/io/moia/router/proto/ProtoBufUtilsTest.kt @@ -41,4 +41,4 @@ class ProtoBufUtilsTest { then(JsonPath.read(json, "enumAttribute")).isEqualTo("ONE") } -} \ No newline at end of file +} 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 index af32e68b..10ea53de 100644 --- a/router-protobuf/src/test/kotlin/io/moia/router/proto/ProtoDeserializationHandlerTest.kt +++ b/router-protobuf/src/test/kotlin/io/moia/router/proto/ProtoDeserializationHandlerTest.kt @@ -23,4 +23,4 @@ internal class ProtoDeserializationHandlerTest { assertTrue(ProtoDeserializationHandler().supports(APIGatewayProxyRequestEvent().withHeader("content-type", "application/x-protobuf"))) assertTrue(ProtoDeserializationHandler().supports(APIGatewayProxyRequestEvent().withHeader("content-type", "application/vnd.moia.v1+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 f5802890..c35948d5 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 @@ -4,16 +4,16 @@ import assertk.assert import assertk.assertions.isEqualTo import assertk.assertions.isTrue import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent -import io.moia.router.Request -import io.moia.router.ResponseEntity -import io.moia.router.Router.Companion.router -import io.moia.router.bodyAsBytes -import io.moia.router.proto.sample.SampleOuterClass.Sample import io.mockk.mockk import io.moia.router.ApiError import io.moia.router.ApiException import io.moia.router.GET +import io.moia.router.Request +import io.moia.router.ResponseEntity +import io.moia.router.Router.Companion.router import io.moia.router.UnprocessableEntityError +import io.moia.router.bodyAsBytes +import io.moia.router.proto.sample.SampleOuterClass.Sample import org.junit.jupiter.api.Test import java.util.Base64 @@ -28,7 +28,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some-proto") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/json")), mockk() + .withHeaders(mapOf("Accept" to "application/json")), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -42,7 +43,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some-proto") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/vnd.moia.v1+json")), mockk() + .withHeaders(mapOf("Accept" to "application/vnd.moia.v1+json")), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -56,7 +58,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some-proto") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/x-protobuf")), mockk() + .withHeaders(mapOf("Accept" to "application/x-protobuf")), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -73,10 +76,13 @@ class RequestHandlerTest { .withPath("/some-proto") .withHttpMethod("POST") .withBody(Base64.getEncoder().encodeToString(request.toByteArray())) - .withHeaders(mapOf( - "Accept" to "application/x-protobuf", - "Content-Type" to "application/x-protobuf" - )), mockk() + .withHeaders( + mapOf( + "Accept" to "application/x-protobuf", + "Content-Type" to "application/x-protobuf" + ) + ), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -89,9 +95,12 @@ class RequestHandlerTest { val response = testRequestHandler.handleRequest( GET("/some-proto") - .withHeaders(mapOf( - "Accept" to "text/plain" - )), mockk() + .withHeaders( + mapOf( + "Accept" to "text/plain" + ) + ), + mockk() ) assert(response.statusCode).isEqualTo(406) @@ -103,9 +112,12 @@ class RequestHandlerTest { val response = testRequestHandler.handleRequest( GET("/some-error") - .withHeaders(mapOf( - "Accept" to "application/x-protobuf" - )), mockk() + .withHeaders( + mapOf( + "Accept" to "application/x-protobuf" + ) + ), + mockk() ) assert(response.statusCode).isEqualTo(400) @@ -147,4 +159,4 @@ class RequestHandlerTest { .build() } } -} \ No newline at end of file +} diff --git a/router/build.gradle.kts b/router/build.gradle.kts index ed6e77c6..a2251dde 100644 --- a/router/build.gradle.kts +++ b/router/build.gradle.kts @@ -3,18 +3,18 @@ dependencies { compile(kotlin("stdlib-jdk8")) compile(kotlin("reflect")) - compile("com.amazonaws:aws-lambda-java-core:1.2.0") - compile("com.amazonaws:aws-lambda-java-events:2.2.6") + compile("com.amazonaws:aws-lambda-java-core:1.2.1") + compile("com.amazonaws:aws-lambda-java-events:3.3.0") - compile("org.slf4j:slf4j-api:1.7.26") + compile("org.slf4j:slf4j-api:1.7.30") compile("com.fasterxml.jackson.core:jackson-databind:2.9.8") compile("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.8") - compile("com.google.guava:guava:23.0") + compile("com.google.guava:guava:29.0-jre") - testImplementation("org.junit.jupiter:junit-jupiter-engine:5.4.0") - testImplementation("org.junit.jupiter:junit-jupiter-params:5.4.0") + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.0") + testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.0") testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.12") testImplementation("org.assertj:assertj-core:3.11.1") - testImplementation("io.mockk:mockk:1.8.13.kotlin13") + testImplementation("io.mockk:mockk:1.10.0") testImplementation("ch.qos.logback:logback-classic:1.2.3") } \ No newline at end of file diff --git a/router/src/main/kotlin/io/moia/router/ApiException.kt b/router/src/main/kotlin/io/moia/router/ApiException.kt index 5b1e92eb..8f825d9b 100644 --- a/router/src/main/kotlin/io/moia/router/ApiException.kt +++ b/router/src/main/kotlin/io/moia/router/ApiException.kt @@ -46,4 +46,4 @@ data class UnprocessableEntityError( val code: String, val path: String, val details: Map = emptyMap() -) \ No newline at end of file +) diff --git a/router/src/main/kotlin/io/moia/router/DeserializationHandler.kt b/router/src/main/kotlin/io/moia/router/DeserializationHandler.kt index 07d25ed9..c7a4b6a8 100644 --- a/router/src/main/kotlin/io/moia/router/DeserializationHandler.kt +++ b/router/src/main/kotlin/io/moia/router/DeserializationHandler.kt @@ -36,10 +36,10 @@ class DeserializationHandlerChain(private val handlers: List -> (it as List).toSet() + is List<*> -> it.filterIsInstance(String::class.java).toSet() is String -> it.split(permissionSeparator).map { s -> s.trim() }.toSet() else -> null } diff --git a/router/src/main/kotlin/io/moia/router/RequestHandler.kt b/router/src/main/kotlin/io/moia/router/RequestHandler.kt index 1a3420bb..0a6d729c 100644 --- a/router/src/main/kotlin/io/moia/router/RequestHandler.kt +++ b/router/src/main/kotlin/io/moia/router/RequestHandler.kt @@ -81,10 +81,12 @@ abstract class RequestHandler : RequestHandler e.toResponseEntity(this::createErrorBody) - .also { logApiException(e, input) } - else -> exceptionToResponseEntity(e) - .also { logUnknownException(e, input) } + is ApiException -> + e.toResponseEntity(this::createErrorBody) + .also { logApiException(e, input) } + else -> + exceptionToResponseEntity(e) + .also { logUnknownException(e, input) } } private fun missingPermissions(input: APIGatewayProxyRequestEvent, routerFunction: RouterFunction) = @@ -241,9 +243,11 @@ abstract class RequestHandler : RequestHandler( fun unprocessableEntity(body: T? = null, headers: Map = emptyMap()) = ResponseEntity(422, body, headers) } -} \ No newline at end of file +} diff --git a/router/src/main/kotlin/io/moia/router/SerializationHandler.kt b/router/src/main/kotlin/io/moia/router/SerializationHandler.kt index fd441ca2..66e849f8 100644 --- a/router/src/main/kotlin/io/moia/router/SerializationHandler.kt +++ b/router/src/main/kotlin/io/moia/router/SerializationHandler.kt @@ -55,4 +55,4 @@ class PlainTextSerializationHandler(val supportedAcceptTypes: List = override fun serialize(acceptHeader: MediaType, body: Any): String = body.toString() -} \ No newline at end of file +} diff --git a/router/src/main/kotlin/io/moia/router/UriTemplate.kt b/router/src/main/kotlin/io/moia/router/UriTemplate.kt index 32c6a652..9882b90a 100644 --- a/router/src/main/kotlin/io/moia/router/UriTemplate.kt +++ b/router/src/main/kotlin/io/moia/router/UriTemplate.kt @@ -76,4 +76,4 @@ class UriTemplate private constructor(private val template: String) { } override fun toString(): String = template -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/APIGatewayProxyEventExtensionsTest.kt b/router/src/test/kotlin/io/moia/router/APIGatewayProxyEventExtensionsTest.kt index 9d7d99d0..0feba4a8 100644 --- a/router/src/test/kotlin/io/moia/router/APIGatewayProxyEventExtensionsTest.kt +++ b/router/src/test/kotlin/io/moia/router/APIGatewayProxyEventExtensionsTest.kt @@ -89,4 +89,4 @@ class APIGatewayProxyEventExtensionsTest { then(request.headers["foo"]).isEqualTo("bar") } -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/ApiRequestTest.kt b/router/src/test/kotlin/io/moia/router/ApiRequestTest.kt index f1bf57d2..911cc3f1 100644 --- a/router/src/test/kotlin/io/moia/router/ApiRequestTest.kt +++ b/router/src/test/kotlin/io/moia/router/ApiRequestTest.kt @@ -43,4 +43,4 @@ class ApiRequestTest { assert(request.acceptHeader()).isEqualTo("application/json") } -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/JsonDeserializationHandlerTest.kt b/router/src/test/kotlin/io/moia/router/JsonDeserializationHandlerTest.kt index e586e99d..66f2e342 100644 --- a/router/src/test/kotlin/io/moia/router/JsonDeserializationHandlerTest.kt +++ b/router/src/test/kotlin/io/moia/router/JsonDeserializationHandlerTest.kt @@ -28,17 +28,33 @@ class JsonDeserializationHandlerTest { @Test fun `should support json`() { - assertTrue(deserializationHandler.supports(APIGatewayProxyRequestEvent() - .withHeader("content-type", "application/json"))) - assertTrue(deserializationHandler.supports(APIGatewayProxyRequestEvent() - .withHeader("content-type", "application/vnd.moia.v1+json"))) + assertTrue( + deserializationHandler.supports( + APIGatewayProxyRequestEvent() + .withHeader("content-type", "application/json") + ) + ) + assertTrue( + deserializationHandler.supports( + APIGatewayProxyRequestEvent() + .withHeader("content-type", "application/vnd.moia.v1+json") + ) + ) } @Test fun `should not support anything else than json`() { - assertFalse(deserializationHandler.supports(APIGatewayProxyRequestEvent() - .withHeader("content-type", "image/png"))) - assertFalse(deserializationHandler.supports(APIGatewayProxyRequestEvent() - .withHeader("content-type", "text/plain"))) + assertFalse( + deserializationHandler.supports( + APIGatewayProxyRequestEvent() + .withHeader("content-type", "image/png") + ) + ) + assertFalse( + deserializationHandler.supports( + APIGatewayProxyRequestEvent() + .withHeader("content-type", "text/plain") + ) + ) } -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/JwtPermissionHandlerTest.kt b/router/src/test/kotlin/io/moia/router/JwtPermissionHandlerTest.kt index 88c395e0..e48b6f88 100644 --- a/router/src/test/kotlin/io/moia/router/JwtPermissionHandlerTest.kt +++ b/router/src/test/kotlin/io/moia/router/JwtPermissionHandlerTest.kt @@ -58,8 +58,10 @@ class JwtPermissionHandlerTest { @Test fun `should extract permissions from custom permissions claim`() { val handler = JwtPermissionHandler( - accessor = JwtAccessor(APIGatewayProxyRequestEvent() - .withHeader("Authorization", jwtWithCustomClaimAndSeparator)), + accessor = JwtAccessor( + APIGatewayProxyRequestEvent() + .withHeader("Authorization", jwtWithCustomClaimAndSeparator) + ), permissionsClaim = "userRights", permissionSeparator = "," ) @@ -97,6 +99,10 @@ class JwtPermissionHandlerTest { } private fun permissionHandler(authHeader: String) = - JwtPermissionHandler(JwtAccessor(APIGatewayProxyRequestEvent() - .withHeader("Authorization", authHeader))) -} \ No newline at end of file + JwtPermissionHandler( + JwtAccessor( + APIGatewayProxyRequestEvent() + .withHeader("Authorization", authHeader) + ) + ) +} diff --git a/router/src/test/kotlin/io/moia/router/MediaTypeTest.kt b/router/src/test/kotlin/io/moia/router/MediaTypeTest.kt index 006569bf..3b0d0d43 100644 --- a/router/src/test/kotlin/io/moia/router/MediaTypeTest.kt +++ b/router/src/test/kotlin/io/moia/router/MediaTypeTest.kt @@ -58,4 +58,4 @@ class MediaTypeTest { fun `should not match wildcard structured syntax suffix on differnt suffix`() { then(MediaType.parse("application/*+json").isCompatibleWith(MediaType.parse("application/*+x-protobuf"))).isFalse() } -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/NoOpPermissionHandlerTest.kt b/router/src/test/kotlin/io/moia/router/NoOpPermissionHandlerTest.kt index 8f76c344..bebc569f 100644 --- a/router/src/test/kotlin/io/moia/router/NoOpPermissionHandlerTest.kt +++ b/router/src/test/kotlin/io/moia/router/NoOpPermissionHandlerTest.kt @@ -27,4 +27,4 @@ class NoOpPermissionHandlerTest { then(handler.hasAnyRequiredPermission(setOf("any"))).isTrue() } -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/PlainTextDeserializationHandlerTest.kt b/router/src/test/kotlin/io/moia/router/PlainTextDeserializationHandlerTest.kt index 71225d60..8d504d91 100644 --- a/router/src/test/kotlin/io/moia/router/PlainTextDeserializationHandlerTest.kt +++ b/router/src/test/kotlin/io/moia/router/PlainTextDeserializationHandlerTest.kt @@ -26,18 +26,34 @@ class PlainTextDeserializationHandlerTest { @Test fun `should support text`() { - assertTrue(PlainTextDeserializationHandler.supports(APIGatewayProxyRequestEvent() - .withHeader("content-type", "text/plain"))) - assertTrue(PlainTextDeserializationHandler.supports(APIGatewayProxyRequestEvent() - .withHeader("content-type", "text/csv"))) + assertTrue( + PlainTextDeserializationHandler.supports( + APIGatewayProxyRequestEvent() + .withHeader("content-type", "text/plain") + ) + ) + assertTrue( + PlainTextDeserializationHandler.supports( + APIGatewayProxyRequestEvent() + .withHeader("content-type", "text/csv") + ) + ) } @Test fun `should not support anything else than text`() { - assertFalse(PlainTextDeserializationHandler.supports(APIGatewayProxyRequestEvent() - .withHeader("content-type", "image/png"))) - assertFalse(PlainTextDeserializationHandler.supports(APIGatewayProxyRequestEvent() - .withHeader("content-type", "application/json"))) + assertFalse( + PlainTextDeserializationHandler.supports( + APIGatewayProxyRequestEvent() + .withHeader("content-type", "image/png") + ) + ) + assertFalse( + PlainTextDeserializationHandler.supports( + APIGatewayProxyRequestEvent() + .withHeader("content-type", "application/json") + ) + ) } @Test fun `should not support anything when content type is null`() { @@ -51,4 +67,4 @@ class PlainTextDeserializationHandlerTest { assertEquals(request.body, result) } -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/PlainTextSerializationHandlerTest.kt b/router/src/test/kotlin/io/moia/router/PlainTextSerializationHandlerTest.kt index 600849a7..82039624 100644 --- a/router/src/test/kotlin/io/moia/router/PlainTextSerializationHandlerTest.kt +++ b/router/src/test/kotlin/io/moia/router/PlainTextSerializationHandlerTest.kt @@ -24,4 +24,4 @@ class PlainTextSerializationHandlerTest { fun `should serialize string`() { assertEquals("some", PlainTextSerializationHandler().serialize(MediaType.parse("text/plain"), "some")) } -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/RequestHandlerTest.kt b/router/src/test/kotlin/io/moia/router/RequestHandlerTest.kt index ebbb0d8f..fd94689e 100644 --- a/router/src/test/kotlin/io/moia/router/RequestHandlerTest.kt +++ b/router/src/test/kotlin/io/moia/router/RequestHandlerTest.kt @@ -42,7 +42,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/json")), mockk() + .withHeaders(mapOf("Accept" to "application/json")), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -56,7 +57,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some/me") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/json")), mockk() + .withHeaders(mapOf("Accept" to "application/json")), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -70,7 +72,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "image/jpg")), mockk() + .withHeaders(mapOf("Accept" to "image/jpg")), + mockk() ) assert(response.statusCode).isEqualTo(406) @@ -83,10 +86,13 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some") .withHttpMethod("POST") - .withHeaders(mapOf( - "Accept" to "application/json", - "Content-Type" to "image/jpg" - )), mockk() + .withHeaders( + mapOf( + "Accept" to "application/json", + "Content-Type" to "image/jpg" + ) + ), + mockk() ) assert(response.statusCode).isEqualTo(415) @@ -97,11 +103,14 @@ class RequestHandlerTest { val response = testRequestHandler.handleRequest( POST("/some") - .withHeaders(mapOf( - "Accept" to "application/json", - "Content-Type" to "application/json" - )) - .withBody("""{ "greeting": "some" }"""), mockk() + .withHeaders( + mapOf( + "Accept" to "application/json", + "Content-Type" to "application/json" + ) + ) + .withBody("""{ "greeting": "some" }"""), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -112,12 +121,15 @@ class RequestHandlerTest { fun `should handle request with body as a List`() { val response = testRequestHandler.handleRequest( - POST("/somes") - .withHeaders(mapOf( - "Accept" to "application/json", - "Content-Type" to "application/json" - )) - .withBody("""[{ "greeting": "some" },{ "greeting": "some1" }]""".trimMargin()), mockk() + POST("/somes") + .withHeaders( + mapOf( + "Accept" to "application/json", + "Content-Type" to "application/json" + ) + ) + .withBody("""[{ "greeting": "some" },{ "greeting": "some1" }]""".trimMargin()), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -131,10 +143,13 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some") .withHttpMethod("PUT") - .withHeaders(mapOf( - "Accept" to "application/json", - "Content-Type" to "image/jpg" - )), mockk() + .withHeaders( + mapOf( + "Accept" to "application/json", + "Content-Type" to "image/jpg" + ) + ), + mockk() ) assert(response.statusCode).isEqualTo(405) @@ -147,7 +162,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some-other") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/json")), mockk() + .withHeaders(mapOf("Accept" to "application/json")), + mockk() ) assert(response.statusCode).isEqualTo(404) @@ -161,7 +177,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/json")), mockk() + .withHeaders(mapOf("Accept" to "application/json")), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -176,7 +193,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some-internal-server-error") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/json")), mockk() + .withHeaders(mapOf("Accept" to "application/json")), + mockk() ) assert(response.statusCode).isEqualTo(500) @@ -192,10 +210,13 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some") .withHttpMethod("GET") - .withHeaders(mapOf( - "Accept" to "application/json", - "content-type" to "application/json" - )), mockk() + .withHeaders( + mapOf( + "Accept" to "application/json", + "content-type" to "application/json" + ) + ), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -212,7 +233,8 @@ class RequestHandlerTest { "Content-Type" to "application/json" ) ) - .withBody("{}"), mockk() + .withBody("{}"), + mockk() ) assert(response.statusCode).isEqualTo(422) } @@ -228,7 +250,8 @@ class RequestHandlerTest { "Content-Type" to "application/json" ) ) - .withBody("""{"greeting": "hello","age": "a"}"""), mockk() + .withBody("""{"greeting": "hello","age": "a"}"""), + mockk() ) assert(response.statusCode).isEqualTo(422) val body = mapper.readValue>(response.body) @@ -252,7 +275,8 @@ class RequestHandlerTest { "Content-Type" to "application/json" ) ) - .withBody("""{"greeting": "hello","age": 1, "bday": "2000-01-AA"}"""), mockk() + .withBody("""{"greeting": "hello","age": 1, "bday": "2000-01-AA"}"""), + mockk() ) assert(response.statusCode).isEqualTo(422) val body = mapper.readValue>(response.body) @@ -276,7 +300,8 @@ class RequestHandlerTest { "Content-Type" to "application/json" ) ) - .withBody("""{"greeting": "hello", bday: "2000-01-01"}"""), mockk() + .withBody("""{"greeting": "hello", bday: "2000-01-01"}"""), + mockk() ) assert(response.statusCode).isEqualTo(422) val body = mapper.readValue>(response.body) @@ -300,7 +325,8 @@ class RequestHandlerTest { "Content-Type" to "application/json" ) ) - .withBody(null), mockk() + .withBody(null), + mockk() ) assert(response.statusCode).isEqualTo(400) assert(mapper.readValue(response.body).code).isEqualTo("REQUEST_BODY_MISSING") @@ -317,7 +343,8 @@ class RequestHandlerTest { "Content-Type" to "application/json" ) ) - .withBody(null), mockk() + .withBody(null), + mockk() ) assert(response.statusCode).isEqualTo(200) assert(response.body).isEqualTo("""{"greeting":""}""") @@ -330,7 +357,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some-api-exception") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/json")), mockk() + .withHeaders(mapOf("Accept" to "application/json")), + mockk() ) assert(response.statusCode).isEqualTo(400) @@ -343,7 +371,8 @@ class RequestHandlerTest { APIGatewayProxyRequestEvent() .withPath("/some-internal-server-error") .withHttpMethod("GET") - .withHeaders(mapOf("Accept" to "application/json")), mockk() + .withHeaders(mapOf("Accept" to "application/json")), + mockk() ) assert(response.statusCode).isEqualTo(500) @@ -354,11 +383,14 @@ class RequestHandlerTest { val response = testRequestHandler.handleRequest( POST("/some") - .withHeaders(mapOf( - "Accept" to "application/xhtml+xml, application/json, application/xml;q=0.9, image/webp, */*;q=0.8", - "Content-Type" to "application/json" - )) - .withBody("""{ "greeting": "some" }"""), mockk() + .withHeaders( + mapOf( + "Accept" to "application/xhtml+xml, application/json, application/xml;q=0.9, image/webp, */*;q=0.8", + "Content-Type" to "application/json" + ) + ) + .withBody("""{ "greeting": "some" }"""), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -372,11 +404,14 @@ class RequestHandlerTest { val response = testRequestHandler.handleRequest( POST("/some") - .withHeaders(mapOf( - "Accept" to "*/*", - "Content-Type" to "application/json" - )) - .withBody("""{ "greeting": "some" }"""), mockk() + .withHeaders( + mapOf( + "Accept" to "*/*", + "Content-Type" to "application/json" + ) + ) + .withBody("""{ "greeting": "some" }"""), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -390,11 +425,14 @@ class RequestHandlerTest { val response = testRequestHandler.handleRequest( POST("/some") - .withHeaders(mapOf( - "Accept" to "application/vnd.moia.v1+json", - "Content-Type" to "application/json" - )) - .withBody("""{ "greeting": "some" }"""), mockk() + .withHeaders( + mapOf( + "Accept" to "application/vnd.moia.v1+json", + "Content-Type" to "application/json" + ) + ) + .withBody("""{ "greeting": "some" }"""), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -406,11 +444,14 @@ class RequestHandlerTest { val response = testRequestHandler.handleRequest( POST("/some") - .withHeaders(mapOf( - "Accept" to "application/vnd.moia.v2+json", - "Content-Type" to "application/json" - )) - .withBody("""{ "greeting": "v2" }"""), mockk() + .withHeaders( + mapOf( + "Accept" to "application/vnd.moia.v2+json", + "Content-Type" to "application/json" + ) + ) + .withBody("""{ "greeting": "v2" }"""), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -423,11 +464,14 @@ class RequestHandlerTest { val response = testRequestHandler.handleRequest( POST("/some") - .withHeaders(mapOf( - "Accept" to "*", - "Content-Type" to "application/json" - )) - .withBody("""{ "greeting": "some" }"""), mockk() + .withHeaders( + mapOf( + "Accept" to "*", + "Content-Type" to "application/json" + ) + ) + .withBody("""{ "greeting": "some" }"""), + mockk() ) assert(response.statusCode).isEqualTo(406) @@ -438,10 +482,13 @@ class RequestHandlerTest { val response = TestRequestHandlerAuthorization().handleRequest( GET("/some") - .withHeaders(mapOf( - "Accept" to "application/json", - "Authorization" to "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJwZXJtaXNzaW9ucyI6InBlcm1pc3Npb24xIn0.E3PxWx68uP2s9yyAV7UVs8egyrGTIuWXjtkcqAA840I" - )), mockk() + .withHeaders( + mapOf( + "Accept" to "application/json", + "Authorization" to "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJwZXJtaXNzaW9ucyI6InBlcm1pc3Npb24xIn0.E3PxWx68uP2s9yyAV7UVs8egyrGTIuWXjtkcqAA840I" + ) + ), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -452,10 +499,13 @@ class RequestHandlerTest { val response = TestRequestHandlerCustomAuthorizationHeader().handleRequest( GET("/some") - .withHeaders(mapOf( - "Accept" to "application/json", - "Custom-Auth" to "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJwZXJtaXNzaW9ucyI6InBlcm1pc3Npb24xIn0.E3PxWx68uP2s9yyAV7UVs8egyrGTIuWXjtkcqAA840I" - )), mockk() + .withHeaders( + mapOf( + "Accept" to "application/json", + "Custom-Auth" to "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJwZXJtaXNzaW9ucyI6InBlcm1pc3Npb24xIn0.E3PxWx68uP2s9yyAV7UVs8egyrGTIuWXjtkcqAA840I" + ) + ), + mockk() ) assert(response.statusCode).isEqualTo(200) @@ -466,10 +516,13 @@ class RequestHandlerTest { val response = TestRequestHandlerAuthorization().handleRequest( GET("/some") - .withHeaders(mapOf( - "Accept" to "application/json", - "Authorization" to "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJwZXJtaXNzaW9ucyI6InBlcm1pc3Npb24yIn0.RA8ERppuFmastqFN-6C98WqMEE7L6h88WylMeq6jh1w" - )), mockk() + .withHeaders( + mapOf( + "Accept" to "application/json", + "Authorization" to "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJwZXJtaXNzaW9ucyI6InBlcm1pc3Npb24yIn0.RA8ERppuFmastqFN-6C98WqMEE7L6h88WylMeq6jh1w" + ) + ), + mockk() ) assert(response.statusCode).isEqualTo(403) @@ -549,12 +602,16 @@ class RequestHandlerTest { fun `Should handle query parameters successfully`() { TestQueryParamParsingHandler().handleRequest( GET("/search") - .withQueryStringParameters(mapOf( - "testQueryParam" to "foo" - )) - .withMultiValueQueryStringParameters(mapOf( - "testMultiValueQueryStringParam" to listOf("foo", "bar") - )), + .withQueryStringParameters( + mapOf( + "testQueryParam" to "foo" + ) + ) + .withMultiValueQueryStringParameters( + mapOf( + "testMultiValueQueryStringParam" to listOf("foo", "bar") + ) + ), mockk() ) TestQueryParamParsingHandler().handleRequest( @@ -644,11 +701,13 @@ class RequestHandlerTest { } override fun permissionHandlerSupplier(): (r: APIGatewayProxyRequestEvent) -> PermissionHandler = - { JwtPermissionHandler( - request = it, - permissionsClaim = "permissions", - permissionSeparator = "," - ) } + { + JwtPermissionHandler( + request = it, + permissionsClaim = "permissions", + permissionSeparator = "," + ) + } } class TestRequestHandlerCustomAuthorizationHeader : RequestHandler() { @@ -659,13 +718,16 @@ class RequestHandlerTest { } override fun permissionHandlerSupplier(): (r: APIGatewayProxyRequestEvent) -> PermissionHandler = - { JwtPermissionHandler( - accessor = JwtAccessor( - request = it, - authorizationHeaderName = "custom-auth"), - permissionsClaim = "permissions", - permissionSeparator = "," - ) } + { + JwtPermissionHandler( + accessor = JwtAccessor( + request = it, + authorizationHeaderName = "custom-auth" + ), + permissionsClaim = "permissions", + permissionSeparator = "," + ) + } } class TestRequestHandlerWithFilter : RequestHandler() { @@ -743,11 +805,13 @@ class RequestHandlerTest { }.producing("application/json") POST("/somes") { r: Request> -> - ResponseEntity.ok(r.body.map { - TestResponse( - it.greeting - ) - }.toList()) + ResponseEntity.ok( + r.body.map { + TestResponse( + it.greeting + ) + }.toList() + ) } POST("/no-content") { _: Request -> ResponseEntity.noContent() diff --git a/router/src/test/kotlin/io/moia/router/ResponseEntityTest.kt b/router/src/test/kotlin/io/moia/router/ResponseEntityTest.kt index 99b4ecfd..f69f1335 100644 --- a/router/src/test/kotlin/io/moia/router/ResponseEntityTest.kt +++ b/router/src/test/kotlin/io/moia/router/ResponseEntityTest.kt @@ -89,4 +89,4 @@ class ResponseEntityTest { assert(response.headers).isNotEmpty() assert(response.body).isNotNull() } -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/RouterTest.kt b/router/src/test/kotlin/io/moia/router/RouterTest.kt index 6c155691..2b332557 100644 --- a/router/src/test/kotlin/io/moia/router/RouterTest.kt +++ b/router/src/test/kotlin/io/moia/router/RouterTest.kt @@ -141,4 +141,4 @@ class RouterTest { ) assert(request.requestContext.authorizer!!["claims"]).isEqualTo(claims) } -} \ No newline at end of file +} diff --git a/router/src/test/kotlin/io/moia/router/UriTemplateTest.kt b/router/src/test/kotlin/io/moia/router/UriTemplateTest.kt index 7df9aef3..742c24d5 100644 --- a/router/src/test/kotlin/io/moia/router/UriTemplateTest.kt +++ b/router/src/test/kotlin/io/moia/router/UriTemplateTest.kt @@ -106,4 +106,4 @@ class UriTemplateTest { "/{proxy+}/whatever" ) } -} \ No newline at end of file +}