From f90b56308c78d958f117c32df1758fef557932d7 Mon Sep 17 00:00:00 2001 From: Trong Huu Nguyen Date: Mon, 6 Nov 2023 14:51:02 +0100 Subject: [PATCH] fix: use hostname instead of canonicalHostname (#586) Fixes https://github.com/navikt/mock-oauth2-server/issues/582. Co-authored-by: Youssef Bel Mekki <38552193+ybelMekk@users.noreply.github.com> --- .../nav/security/mock/oauth2/http/OAuth2HttpServer.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/no/nav/security/mock/oauth2/http/OAuth2HttpServer.kt b/src/main/kotlin/no/nav/security/mock/oauth2/http/OAuth2HttpServer.kt index 9be7e34e..c23a0355 100644 --- a/src/main/kotlin/no/nav/security/mock/oauth2/http/OAuth2HttpServer.kt +++ b/src/main/kotlin/no/nav/security/mock/oauth2/http/OAuth2HttpServer.kt @@ -78,6 +78,7 @@ MockWebServerWrapper val ssl: Ssl? = null, ) : OAuth2HttpServer { val mockWebServer: MockWebServer = MockWebServer() + private var address: InetAddress? = null override fun start( inetAddress: InetAddress, @@ -90,6 +91,7 @@ MockWebServerWrapper if (ssl != null) { mockWebServer.useHttps(ssl.sslContext().socketFactory, false) } + this.address = inetAddress log.debug("started server on address=$inetAddress and port=${mockWebServer.port}, httpsEnabled=${ssl != null}") } @@ -100,7 +102,11 @@ MockWebServerWrapper override fun port(): Int = mockWebServer.port - override fun url(path: String): HttpUrl = mockWebServer.url(path) + override fun url(path: String): HttpUrl = mockWebServer + .url(path) + .newBuilder() + .host(address?.hostName ?: mockWebServer.hostName) + .build() override fun sslConfig(): Ssl? = ssl @@ -189,7 +195,7 @@ class NettyWrapper } return HttpUrl.Builder() .scheme(scheme) - .host(address.address.canonicalHostName) + .host(address.address.hostName) .port(port()) .build() .resolve(path)!!