Skip to content

Commit

Permalink
T - Retting av test etter oppdateting av httpclient5
Browse files Browse the repository at this point in the history
  • Loading branch information
dskarpas committed Jan 6, 2025
1 parent 4dd832d commit 15a66fa
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import no.nav.eessi.pensjon.utils.toJson
import org.apache.hc.client5.http.impl.classic.HttpClients
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder
import org.apache.hc.client5.http.io.HttpClientConnectionManager
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder
import org.apache.hc.client5.http.ssl.*
import org.apache.hc.core5.ssl.SSLContextBuilder
import org.apache.hc.core5.ssl.SSLContexts
import org.apache.hc.core5.ssl.TrustStrategy
import org.junit.jupiter.api.AfterEach
Expand Down Expand Up @@ -210,24 +209,24 @@ class ListenerIntegrasjonsTest {
class TestConfig {
@Bean
fun penAzureTokenRestTemplate(templateBuilder: RestTemplateBuilder): RestTemplate {
val acceptingTrustStrategy = TrustStrategy { _: Array<X509Certificate?>?, _: String? -> true }

val sslcontext: SSLContext = SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build()
val sslSocketFactory: SSLConnectionSocketFactory = SSLConnectionSocketFactoryBuilder.create()
.setSslContext(sslcontext)
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build()
val connectionManager: HttpClientConnectionManager = PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(sslSocketFactory)
val sslContext = SSLContextBuilder.create()
.loadTrustMaterial(null) { _, _ -> true } // Trust all certificates
.build()

val connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
.setTlsSocketStrategy(
DefaultClientTlsStrategy(
sslContext,
HostnameVerificationPolicy.CLIENT,
NoopHostnameVerifier.INSTANCE
)
).build()

val httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.build()

val customRequestFactory = HttpComponentsClientHttpRequestFactory()
customRequestFactory.httpClient = httpClient
val customRequestFactory = HttpComponentsClientHttpRequestFactory(httpClient)

return RestTemplateBuilder()
.rootUri("https://localhost:${System.getProperty("mockServerport")}")
Expand Down

0 comments on commit 15a66fa

Please sign in to comment.