diff --git a/build.gradle.kts b/build.gradle.kts index 39b3aa15..a1ecf443 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ val caffeineVersion = "3.1.8" val coroutinesVersion = "1.9.0" val jacksonVersion = "2.18.0" val kluentVersion = "1.73" -val ktorVersion = "2.3.12" +val ktorVersion = "3.0.1" val logbackVersion = "1.5.8" val logstashEncoderVersion = "8.0" val prometheusVersion = "0.16.0" @@ -26,7 +26,7 @@ plugins { id("application") kotlin("jvm") version "2.0.20" id("com.diffplug.spotless") version "6.25.0" - id("com.github.johnrengelman.shadow") version "8.1.1" + id("com.gradleup.shadow") version "8.3.3" } application { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135c..e6441136 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 a4413138..df97d72b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 0adc8e1a..b740cf13 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -202,11 +202,11 @@ fi # 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" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 6689b85b..7101f8e4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/src/main/kotlin/no/nav/syfo/Application.kt b/src/main/kotlin/no/nav/syfo/Application.kt index dbcd41e9..d393c0ea 100644 --- a/src/main/kotlin/no/nav/syfo/Application.kt +++ b/src/main/kotlin/no/nav/syfo/Application.kt @@ -264,7 +264,7 @@ fun harTilgang(credentials: JWTCredential, clientId: String): Boolean { return credentials.payload.audience.contains(clientId) } -fun unauthorized(credentials: JWTCredential): Principal? { +fun unauthorized(credentials: JWTCredential): Unit? { logger.warn( "Auth: Unexpected audience for jwt {}, {}", StructuredArguments.keyValue("issuer", credentials.payload.issuer), diff --git a/src/main/kotlin/no/nav/syfo/metrics/MonitorHttpRequests.kt b/src/main/kotlin/no/nav/syfo/metrics/MonitorHttpRequests.kt index 583c9639..4061ce74 100644 --- a/src/main/kotlin/no/nav/syfo/metrics/MonitorHttpRequests.kt +++ b/src/main/kotlin/no/nav/syfo/metrics/MonitorHttpRequests.kt @@ -1,10 +1,10 @@ package no.nav.syfo.metrics -import io.ktor.server.application.ApplicationCall +import io.ktor.server.application.* import io.ktor.server.request.path -import io.ktor.util.pipeline.PipelineContext +import io.ktor.util.pipeline.* -fun monitorHttpRequests(): suspend PipelineContext.(Unit) -> Unit { +fun monitorHttpRequests(): PipelineInterceptor { return { val label = context.request.path() val timer = HTTP_HISTOGRAM.labels(label).startTimer() diff --git a/src/test/kotlin/no/nav/syfo/application/api/SelftestSpek.kt b/src/test/kotlin/no/nav/syfo/application/api/SelftestSpek.kt index bf294d20..e8560f6f 100644 --- a/src/test/kotlin/no/nav/syfo/application/api/SelftestSpek.kt +++ b/src/test/kotlin/no/nav/syfo/application/api/SelftestSpek.kt @@ -1,67 +1,79 @@ -package no.nav.syfo.application.api +package no.nav.syfo import io.kotest.core.spec.style.FunSpec -import io.ktor.http.HttpMethod +import io.ktor.client.request.* +import io.ktor.client.statement.* import io.ktor.http.HttpStatusCode import io.ktor.server.routing.routing -import io.ktor.server.testing.TestApplicationEngine -import io.ktor.server.testing.handleRequest -import no.nav.syfo.ApplicationState +import io.ktor.server.testing.* import no.nav.syfo.nais.isalive.naisIsAliveRoute import no.nav.syfo.nais.isready.naisIsReadyRoute import org.amshove.kluent.shouldBeEqualTo -object SelftestSpek : - FunSpec({ - context("Successfull liveness and readyness tests") { - with(TestApplicationEngine()) { - start() - val applicationState = ApplicationState() - applicationState.ready = true - applicationState.alive = true - application.routing { - naisIsAliveRoute(applicationState) - naisIsReadyRoute(applicationState) - } - +class SelftestSpek : + FunSpec( + { + context("Successfull liveness and readyness tests") { test("Returns ok on is_alive") { - with(handleRequest(HttpMethod.Get, "/internal/is_alive")) { - response.status() shouldBeEqualTo HttpStatusCode.OK - response.content shouldBeEqualTo "I'm alive! :)" + testApplication { + application { + val applicationState = ApplicationState() + applicationState.ready = true + applicationState.alive = true + routing { naisIsAliveRoute(applicationState) } + } + + val response = client.get("/internal/is_alive") + + response.status shouldBeEqualTo HttpStatusCode.OK + response.bodyAsText() shouldBeEqualTo "I'm alive! :)" } } test("Returns ok in is_ready") { - with(handleRequest(HttpMethod.Get, "/internal/is_ready")) { - response.status() shouldBeEqualTo HttpStatusCode.OK - response.content shouldBeEqualTo "I'm ready! :)" + testApplication { + application { + val applicationState = ApplicationState() + applicationState.ready = true + applicationState.alive = true + routing { naisIsReadyRoute(applicationState) } + } + + val response = client.get("/internal/is_ready") + response.status shouldBeEqualTo HttpStatusCode.OK + response.bodyAsText() shouldBeEqualTo "I'm ready! :)" } } } - } - context("Unsuccessful liveness and readyness") { - with(TestApplicationEngine()) { - start() - val applicationState = ApplicationState() - applicationState.ready = false - applicationState.alive = false - application.routing { - naisIsAliveRoute(applicationState) - naisIsReadyRoute(applicationState) - } - + context("Unsuccessful liveness and readyness") { test("Returns internal server error when liveness check fails") { - with(handleRequest(HttpMethod.Get, "/internal/is_alive")) { - response.status() shouldBeEqualTo HttpStatusCode.InternalServerError - response.content shouldBeEqualTo "I'm dead x_x" + testApplication { + application { + val applicationState = ApplicationState() + applicationState.ready = false + applicationState.alive = false + routing { naisIsAliveRoute(applicationState) } + } + val response = client.get("/internal/is_alive") + + response.status shouldBeEqualTo HttpStatusCode.InternalServerError + response.bodyAsText() shouldBeEqualTo "I'm dead x_x" } } test("Returns internal server error when readyness check fails") { - with(handleRequest(HttpMethod.Get, "/internal/is_ready")) { - response.status() shouldBeEqualTo HttpStatusCode.InternalServerError - response.content shouldBeEqualTo "Please wait! I'm not ready :(" + testApplication { + application { + val applicationState = ApplicationState() + applicationState.ready = false + applicationState.alive = false + routing { naisIsReadyRoute(applicationState) } + } + val response = client.get("/internal/is_ready") + + response.status shouldBeEqualTo HttpStatusCode.InternalServerError + response.bodyAsText() shouldBeEqualTo "Please wait! I'm not ready :(" } } } - } - }) + }, + )