Skip to content

Commit

Permalink
Tester ktor 3/
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-santa committed Dec 3, 2024
1 parent 29a9099 commit 0b0f34e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 40 deletions.
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/default/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ interface KotliQueryDefaults: DependencyGroup {
}

object KtorDefaults {
val version get() = "2.3.12"
val version get() = "3.0.1"
val groupId get() = "io.ktor"

interface ServerDefaults: DependencyGroup {
Expand Down Expand Up @@ -210,7 +210,7 @@ interface TestContainersDefaults: DependencyGroup {

interface TmsCommonLibDefaults: DependencyGroup {
override val groupId get() = "no.nav.tms.common"
override val version get() = "4.0.2"
override val version get() = "5.0.0"

val metrics get() = dependency("metrics")
val observability get() = dependency("observability")
Expand All @@ -228,7 +228,7 @@ interface TmsKafkaToolsDefaults: DependencyGroup {

interface TmsKtorTokenSupportDefaults: DependencyGroup {
override val groupId get() = "no.nav.tms.token.support"
override val version get() = "4.1.2"
override val version get() = "5.0.0"

val azureExchange get() = dependency("azure-exchange")
val azureValidation get() = dependency("azure-validation")
Expand Down
32 changes: 15 additions & 17 deletions src/main/kotlin/no/nav/tms/varsel/api/Application.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package no.nav.tms.varsel.api

import io.ktor.server.engine.applicationEngineEnvironment
import io.ktor.server.engine.connector
import io.ktor.server.engine.embeddedServer
import io.ktor.server.engine.*
import io.ktor.server.netty.Netty
import no.nav.tms.token.support.tokendings.exchange.TokendingsServiceBuilder
import no.nav.tms.varsel.api.varsel.VarselConsumer
Expand All @@ -14,23 +12,23 @@ fun main() {

embeddedServer(
factory = Netty,
environment = applicationEngineEnvironment {
rootPath = "tms-varsel-api"
module {
varselApi(
corsAllowedOrigins = environment.corsAllowedOrigins,
httpClient = httpClient,
varselConsumer = VarselConsumer(
client = httpClient,
varselAuthorityUrl = "http://tms-varsel-authority",
varselAuthorityClientId = environment.eventhandlerClientId,
tokendingsService = TokendingsServiceBuilder.buildTokendingsService(),
)
)
}
configure = {
connector {
port = 8080
}
},
module = {
rootPath = "tms-varsel-api"
varselApi(
corsAllowedOrigins = environment.corsAllowedOrigins,
httpClient = httpClient,
varselConsumer = VarselConsumer(
client = httpClient,
varselAuthorityUrl = "http://tms-varsel-authority",
varselAuthorityClientId = environment.eventhandlerClientId,
tokendingsService = TokendingsServiceBuilder.buildTokendingsService(),
)
)
}
).start(wait = true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.call
import io.ktor.server.request.*
import io.ktor.server.response.respond
import io.ktor.server.routing.Route
import io.ktor.server.routing.get
import io.ktor.server.routing.route
import io.ktor.server.routing.*
import io.ktor.util.pipeline.PipelineContext
import no.nav.tms.token.support.idporten.sidecar.user.IdportenUser
import no.nav.tms.token.support.idporten.sidecar.user.IdportenUserFactory
Expand Down Expand Up @@ -40,8 +38,8 @@ fun Route.bjellevarsler(varselConsumer: VarselConsumer) {

private val ApplicationRequest.preferertSpraak get() = queryParameters["preferert_spraak"]?.lowercase()

private val PipelineContext<Unit, ApplicationCall>.idportenUser: IdportenUser
private val RoutingContext.idportenUser: IdportenUser
get() = IdportenUserFactory.createIdportenUser(this.call)

private val PipelineContext<Unit, ApplicationCall>.tokenxUser: TokenXUser
private val RoutingContext.tokenxUser: TokenXUser
get() = TokenXUserFactory.createTokenXUser(this.call)
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/tms/varsel/api/varselApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fun Application.varselApi(
typealias TokenXLoa = no.nav.tms.token.support.tokenx.validation.LevelOfAssurance

private fun Application.configureShutdownHook(httpClient: HttpClient) {
environment.monitor.subscribe(ApplicationStopping) {
monitor.subscribe(ApplicationStopping) {
httpClient.close()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class VarselbjelleRoutesTest {
setupVarselAuthority(aktiveVarslerFromEventHandler = varsler)
mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)

client.get("/varselbjelle/varsler").apply {
Expand Down Expand Up @@ -67,7 +67,7 @@ class VarselbjelleRoutesTest {
setupVarselAuthority(aktiveVarslerFromEventHandler = varsler)
mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)

client.get("/bjellevarsler").apply {
Expand Down Expand Up @@ -96,7 +96,7 @@ class VarselbjelleRoutesTest {
setupVarselAuthority(expectedSpraakkodeParam = "en")
mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)

client.get("/bjellevarsler?preferert_spraak=en").apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class VarselRoutesTest {

mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)

val response = client.get("/alle")
Expand All @@ -83,7 +83,7 @@ class VarselRoutesTest {
setupVarselAuthority(inaktiveVarslerFromEventHandler = varsler)
mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)

val response = client.get("/inaktive")
Expand Down Expand Up @@ -127,7 +127,7 @@ class VarselRoutesTest {
setupVarselAuthority(aktiveVarslerFromEventHandler = varsler)
mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)

val response = client.get("/aktive")
Expand Down Expand Up @@ -160,7 +160,7 @@ class VarselRoutesTest {
)
mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_3)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.SUBSTANTIAL)
)

val response = client.get("/aktive")
Expand Down Expand Up @@ -195,7 +195,7 @@ class VarselRoutesTest {
setupVarselAuthority(aktiveVarslerFromEventHandler = varsler)
mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)

val response = client.get("/antall/aktive")
Expand Down Expand Up @@ -230,7 +230,7 @@ class VarselRoutesTest {

mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)
client.post("/beskjed/inaktiver") {
header(HttpHeaders.ContentType, ContentType.Application.Json)
Expand All @@ -249,7 +249,7 @@ class VarselRoutesTest {
setupVarselAuthority(aktiveVarslerFromEventHandler = listOf(beskjed), inaktiveVarslerFromEventHandler = listOf(oppgave))
mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)

val aktiveVarsler: AktiveVarsler = client.get("/aktive").bodyFromJson()
Expand Down Expand Up @@ -302,9 +302,11 @@ class VarselRoutesTest {
}
}



mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)
client.post("/beskjed/inaktiver") {
header(HttpHeaders.ContentType, ContentType.Application.Json)
Expand All @@ -320,7 +322,7 @@ class VarselRoutesTest {
setupVarselAuthority(expectedSpraakkodeParam = "en")
mockVarselApi(
varselConsumer = setupVarselConsumer(),
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.LEVEL_4)
authMockInstaller = installAuthenticatedMock(LevelOfAssurance.HIGH)
)

client.get("/aktive?preferert_spraak=en").apply {
Expand Down
2 changes: 0 additions & 2 deletions src/test/kotlin/no/nav/tms/varsel/api/varselTestData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,5 @@ fun installAuthenticatedMock(

private fun LevelOfAssurance.toTokenxLoa() = when(this) {
LevelOfAssurance.SUBSTANTIAL -> no.nav.tms.token.support.tokenx.validation.mock.LevelOfAssurance.SUBSTANTIAL
LevelOfAssurance.LEVEL_3 -> no.nav.tms.token.support.tokenx.validation.mock.LevelOfAssurance.SUBSTANTIAL
LevelOfAssurance.HIGH -> no.nav.tms.token.support.tokenx.validation.mock.LevelOfAssurance.HIGH
LevelOfAssurance.LEVEL_4 -> no.nav.tms.token.support.tokenx.validation.mock.LevelOfAssurance.HIGH
}

0 comments on commit 0b0f34e

Please sign in to comment.