From 4390dc345a541ab51d06b398300e82715a3ad228 Mon Sep 17 00:00:00 2001 From: geir-waagboe Date: Fri, 5 Jan 2024 14:17:50 +0100 Subject: [PATCH] Migrate GCP and Postgres --- .../no/nav/syfo/config/ApplicationConfig.kt | 5 +++ .../consumer/azuread/NaisProxyCustomizer.kt | 32 ------------------- .../azuread/RestTemplateWithProxyConfig.kt | 16 ---------- .../azuread/v2/AzureAdV2TokenConsumer.kt | 6 ++-- .../BehandlendeEnhetConsumer.kt | 5 ++- .../narmesteleder/NarmesteLederClient.kt | 5 ++- .../migration/R__grant_to_cloudsqliamuser.sql | 21 ++++++++++++ .../MotebehovArbeidsgiverControllerV3Test.kt | 18 ++++++----- .../MotebehovArbeidstakerControllerV3Test.kt | 24 ++++++++------ .../v2/MotebehovVeilederADControllerV2Test.kt | 22 +++++++------ .../v2/MotebehovVeilederADTilgangV2Test.kt | 16 +++++----- .../no/nav/syfo/testhelper/RestHelper.kt | 13 ++++---- .../testhelper/SyfoTilgangskontrollMock.kt | 4 +-- 13 files changed, 86 insertions(+), 101 deletions(-) delete mode 100644 src/main/kotlin/no/nav/syfo/consumer/azuread/NaisProxyCustomizer.kt delete mode 100644 src/main/kotlin/no/nav/syfo/consumer/azuread/RestTemplateWithProxyConfig.kt diff --git a/src/main/kotlin/no/nav/syfo/config/ApplicationConfig.kt b/src/main/kotlin/no/nav/syfo/config/ApplicationConfig.kt index 0e3b8b25..e739dc0e 100644 --- a/src/main/kotlin/no/nav/syfo/config/ApplicationConfig.kt +++ b/src/main/kotlin/no/nav/syfo/config/ApplicationConfig.kt @@ -1,5 +1,6 @@ package no.nav.syfo.config +import org.springframework.beans.factory.annotation.Qualifier import org.springframework.context.annotation.* import org.springframework.scheduling.TaskScheduler import org.springframework.scheduling.annotation.EnableScheduling @@ -19,6 +20,10 @@ class ApplicationConfig { @Bean fun restTemplate() = RestTemplate() + @Bean + @Qualifier("AzureAD") + fun restTemplateAzureAd() = RestTemplate() + @Bean fun webClient() = WebClient .builder() diff --git a/src/main/kotlin/no/nav/syfo/consumer/azuread/NaisProxyCustomizer.kt b/src/main/kotlin/no/nav/syfo/consumer/azuread/NaisProxyCustomizer.kt deleted file mode 100644 index 6b40cb4b..00000000 --- a/src/main/kotlin/no/nav/syfo/consumer/azuread/NaisProxyCustomizer.kt +++ /dev/null @@ -1,32 +0,0 @@ -package no.nav.syfo.consumer.azuread - -import org.apache.hc.client5.http.classic.HttpClient -import org.apache.hc.client5.http.impl.classic.HttpClientBuilder -import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner -import org.apache.hc.core5.http.HttpException -import org.apache.hc.core5.http.HttpHost -import org.apache.hc.core5.http.protocol.HttpContext -import org.springframework.boot.web.client.RestTemplateCustomizer -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory -import org.springframework.web.client.RestTemplate - -class NaisProxyCustomizer : RestTemplateCustomizer { - override fun customize(restTemplate: RestTemplate) { - val proxy = HttpHost("webproxy-nais.nav.no", 8088) - val client: HttpClient = HttpClientBuilder.create() - .setRoutePlanner( - object : DefaultProxyRoutePlanner(proxy) { - @Throws(HttpException::class) - public override fun determineProxy( - target: HttpHost, - context: HttpContext - ): HttpHost? { - return if (target.hostName.contains("microsoft")) { - super.determineProxy(target, context) - } else null - } - } - ).build() - restTemplate.requestFactory = HttpComponentsClientHttpRequestFactory(client) - } -} diff --git a/src/main/kotlin/no/nav/syfo/consumer/azuread/RestTemplateWithProxyConfig.kt b/src/main/kotlin/no/nav/syfo/consumer/azuread/RestTemplateWithProxyConfig.kt deleted file mode 100644 index 47a0cd7f..00000000 --- a/src/main/kotlin/no/nav/syfo/consumer/azuread/RestTemplateWithProxyConfig.kt +++ /dev/null @@ -1,16 +0,0 @@ -package no.nav.syfo.consumer.azuread - -import org.springframework.boot.web.client.RestTemplateBuilder -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestTemplate - -@Configuration -class RestTemplateWithProxyConfig { - @Bean(name = ["restTemplateWithProxy"]) - fun restTemplateWithProxy(): RestTemplate { - return RestTemplateBuilder() - .additionalCustomizers(NaisProxyCustomizer()) - .build() - } -} diff --git a/src/main/kotlin/no/nav/syfo/consumer/azuread/v2/AzureAdV2TokenConsumer.kt b/src/main/kotlin/no/nav/syfo/consumer/azuread/v2/AzureAdV2TokenConsumer.kt index 0c26e502..78c047f6 100644 --- a/src/main/kotlin/no/nav/syfo/consumer/azuread/v2/AzureAdV2TokenConsumer.kt +++ b/src/main/kotlin/no/nav/syfo/consumer/azuread/v2/AzureAdV2TokenConsumer.kt @@ -12,7 +12,7 @@ import java.util.concurrent.ConcurrentHashMap @Component class AzureAdV2TokenConsumer @Autowired constructor( - @Qualifier("restTemplateWithProxy") private val restTemplateWithProxy: RestTemplate, + @Qualifier("AzureAD") private val restTemplate: RestTemplate, @Value("\${azure.app.client.id}") private val azureAppClientId: String, @Value("\${azure.app.client.secret}") private val azureAppClientSecret: String, @Value("\${azure.openid.config.token.endpoint}") private val azureTokenEndpoint: String @@ -22,7 +22,7 @@ class AzureAdV2TokenConsumer @Autowired constructor( token: String ): String { try { - val response = restTemplateWithProxy.exchange( + val response = restTemplate.exchange( azureTokenEndpoint, HttpMethod.POST, requestEntity(scopeClientId, token), @@ -49,7 +49,7 @@ class AzureAdV2TokenConsumer @Autowired constructor( val requestEntity = systemTokenRequestEntity( scopeClientId = scopeClientId ) - val response = restTemplateWithProxy.exchange( + val response = restTemplate.exchange( azureTokenEndpoint, HttpMethod.POST, requestEntity, diff --git a/src/main/kotlin/no/nav/syfo/consumer/behandlendeenhet/BehandlendeEnhetConsumer.kt b/src/main/kotlin/no/nav/syfo/consumer/behandlendeenhet/BehandlendeEnhetConsumer.kt index 898a6ef6..a5bef8da 100644 --- a/src/main/kotlin/no/nav/syfo/consumer/behandlendeenhet/BehandlendeEnhetConsumer.kt +++ b/src/main/kotlin/no/nav/syfo/consumer/behandlendeenhet/BehandlendeEnhetConsumer.kt @@ -5,7 +5,6 @@ import no.nav.syfo.consumer.azuread.v2.AzureAdV2TokenConsumer import no.nav.syfo.metric.Metric import no.nav.syfo.util.* import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Qualifier import org.springframework.beans.factory.annotation.Value import org.springframework.cache.annotation.Cacheable import org.springframework.http.* @@ -19,7 +18,7 @@ class BehandlendeEnhetConsumer( private val metric: Metric, @Value("\${syfobehandlendeenhet.client.id}") private val syfobehandlendeenhetClientId: String, @Value("\${syfobehandlendeenhet.url}") private val baseUrl: String, - @Qualifier("restTemplateWithProxy") private val restTemplateWithProxy: RestTemplate + private val restTemplate: RestTemplate ) { @Cacheable(cacheNames = [CacheConfig.CACHENAME_BEHANDLENDEENHET_FNR], key = "#fnr", condition = "#fnr != null") @@ -30,7 +29,7 @@ class BehandlendeEnhetConsumer( val httpEntity = entity(callId, bearer, fnr) try { - val response = restTemplateWithProxy.exchange( + val response = restTemplate.exchange( "$baseUrl$BEHANDLENDEENHET_PATH", HttpMethod.GET, httpEntity, diff --git a/src/main/kotlin/no/nav/syfo/consumer/narmesteleder/NarmesteLederClient.kt b/src/main/kotlin/no/nav/syfo/consumer/narmesteleder/NarmesteLederClient.kt index 73ebfb0f..5345d180 100644 --- a/src/main/kotlin/no/nav/syfo/consumer/narmesteleder/NarmesteLederClient.kt +++ b/src/main/kotlin/no/nav/syfo/consumer/narmesteleder/NarmesteLederClient.kt @@ -6,7 +6,6 @@ import no.nav.syfo.util.NAV_CALL_ID_HEADER import no.nav.syfo.util.NAV_CONSUMER_ID_HEADER import no.nav.syfo.util.NAV_PERSONIDENT_HEADER import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Qualifier import org.springframework.beans.factory.annotation.Value import org.springframework.core.ParameterizedTypeReference import org.springframework.http.HttpEntity @@ -24,7 +23,7 @@ class NarmesteLederClient( private val azureAdV2TokenConsumer: AzureAdV2TokenConsumer, @Value("\${isnarmesteleder.url}") private val baseUrl: String, @Value("\${isnarmesteleder.client.id}") private val targetApp: String, - @Qualifier("restTemplateWithProxy") private val restTemplateWithProxy: RestTemplate + private val restTemplate: RestTemplate ) { fun getNarmesteledere(fnr: String): List? { try { @@ -32,7 +31,7 @@ class NarmesteLederClient( scopeClientId = targetApp ) - val response: ResponseEntity?> = restTemplateWithProxy.exchange( + val response: ResponseEntity?> = restTemplate.exchange( "$baseUrl/api/system/v1/narmestelederrelasjoner", HttpMethod.GET, entity(token, fnr), diff --git a/src/main/resources/db/migration/R__grant_to_cloudsqliamuser.sql b/src/main/resources/db/migration/R__grant_to_cloudsqliamuser.sql index 380047db..aae34e75 100644 --- a/src/main/resources/db/migration/R__grant_to_cloudsqliamuser.sql +++ b/src/main/resources/db/migration/R__grant_to_cloudsqliamuser.sql @@ -1,4 +1,25 @@ REVOKE ALL ON ALL TABLES IN SCHEMA public FROM cloudsqliamuser; + -- GRANT SELECT ON ALL TABLES IN SCHEMA public TO cloudsqliamuser; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO cloudsqliamuser; GRANT USAGE ON ALL SEQUENCES IN SCHEMA public TO cloudsqliamuser; + +DO $$ +BEGIN + CREATE ROLE cloudsqlsuperuser WITH NOLOGIN; + EXCEPTION WHEN DUPLICATE_OBJECT THEN + RAISE NOTICE 'not creating role cloudsqlsuperuser -- it already exists'; +END +$$; + +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO cloudsqlsuperuser; +GRANT USAGE ON ALL SEQUENCES IN SCHEMA public TO cloudsqlsuperuser; + +DO $$ +BEGIN + CREATE USER "esyfo-analyse"; + EXCEPTION WHEN DUPLICATE_OBJECT THEN + RAISE NOTICE 'not creating role esyfo-analyse -- it already exists'; +END +$$; +GRANT SELECT ON ALL TABLES IN SCHEMA public TO "esyfo-analyse"; diff --git a/src/test/kotlin/no/nav/syfo/motebehov/api/MotebehovArbeidsgiverControllerV3Test.kt b/src/test/kotlin/no/nav/syfo/motebehov/api/MotebehovArbeidsgiverControllerV3Test.kt index 15974c48..62a8cd8d 100644 --- a/src/test/kotlin/no/nav/syfo/motebehov/api/MotebehovArbeidsgiverControllerV3Test.kt +++ b/src/test/kotlin/no/nav/syfo/motebehov/api/MotebehovArbeidsgiverControllerV3Test.kt @@ -83,9 +83,8 @@ class MotebehovArbeidsgiverControllerV3Test { private lateinit var dialogmotekandidatDAO: DialogmotekandidatDAO @Autowired - @Qualifier("restTemplateWithProxy") - private lateinit var restTemplateWithProxy: RestTemplate - private lateinit var mockRestServiceWithProxyServer: MockRestServiceServer + @Qualifier("AzureAD") + private lateinit var restTemplateAzureAD: RestTemplate @Autowired private lateinit var restTemplate: RestTemplate @@ -105,6 +104,7 @@ class MotebehovArbeidsgiverControllerV3Test { @MockkBean(relaxed = true) private lateinit var personoppgavehendelseProducer: PersonoppgavehendelseProducer + private lateinit var mockRestServiceServerAzureAD: MockRestServiceServer private lateinit var mockRestServiceServer: MockRestServiceServer private val motebehovGenerator = MotebehovGenerator() @@ -119,7 +119,7 @@ class MotebehovArbeidsgiverControllerV3Test { every { pdlConsumer.isKode6(ARBEIDSTAKER_FNR) } returns false mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build() - mockRestServiceWithProxyServer = MockRestServiceServer.bindTo(restTemplateWithProxy).build() + mockRestServiceServerAzureAD = MockRestServiceServer.bindTo(restTemplateAzureAD).build() tokenValidationUtil.logInAsDialogmoteUser(LEDER_FNR) cleanDB() } @@ -513,7 +513,8 @@ class MotebehovArbeidsgiverControllerV3Test { private fun submitMotebehovAndSendOversikthendelse(motebehovSvar: MotebehovSvar) { mockAndExpectBehandlendeEnhetRequest( azureTokenEndpoint, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, + mockRestServiceServer, behandlendeenhetUrl, ARBEIDSTAKER_FNR, ) @@ -533,7 +534,8 @@ class MotebehovArbeidsgiverControllerV3Test { private fun lagreMotebehov(innsendtMotebehov: NyttMotebehovArbeidsgiver) { mockAndExpectBehandlendeEnhetRequest( azureTokenEndpoint, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, + mockRestServiceServer, behandlendeenhetUrl, innsendtMotebehov.arbeidstakerFnr, ) @@ -575,7 +577,7 @@ class MotebehovArbeidsgiverControllerV3Test { private fun resetMockRestServers() { mockRestServiceServer.reset() - mockRestServiceWithProxyServer.reset() + mockRestServiceServerAzureAD.reset() } private fun cleanDB() { @@ -590,7 +592,7 @@ class MotebehovArbeidsgiverControllerV3Test { private fun mockBehandlendEnhetWithTilgangskontroll(fnr: String) { mockAndExpectBehandlendeEnhetRequestWithTilgangskontroll( azureTokenEndpoint, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, mockRestServiceServer, behandlendeenhetUrl, tilgangskontrollUrl, diff --git a/src/test/kotlin/no/nav/syfo/motebehov/api/MotebehovArbeidstakerControllerV3Test.kt b/src/test/kotlin/no/nav/syfo/motebehov/api/MotebehovArbeidstakerControllerV3Test.kt index f1af0db8..a9df5da2 100644 --- a/src/test/kotlin/no/nav/syfo/motebehov/api/MotebehovArbeidstakerControllerV3Test.kt +++ b/src/test/kotlin/no/nav/syfo/motebehov/api/MotebehovArbeidstakerControllerV3Test.kt @@ -84,9 +84,8 @@ class MotebehovArbeidstakerControllerV3Test { private lateinit var dialogmotekandidatDAO: DialogmotekandidatDAO @Autowired - @Qualifier("restTemplateWithProxy") - private lateinit var restTemplateWithProxy: RestTemplate - private lateinit var mockRestServiceWithProxyServer: MockRestServiceServer + @Qualifier("AzureAD") + private lateinit var restTemplateAzureAD: RestTemplate @Autowired private lateinit var restTemplate: RestTemplate @@ -103,6 +102,7 @@ class MotebehovArbeidstakerControllerV3Test { @MockkBean(relaxed = true) private lateinit var personoppgavehendelseProducer: PersonoppgavehendelseProducer + private lateinit var mockRestServiceServerAzureAD: MockRestServiceServer private lateinit var mockRestServiceServer: MockRestServiceServer private val motebehovGenerator = MotebehovGenerator() @@ -115,7 +115,7 @@ class MotebehovArbeidstakerControllerV3Test { every { pdlConsumer.isKode6(ARBEIDSTAKER_FNR) } returns false mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build() - mockRestServiceWithProxyServer = MockRestServiceServer.bindTo(restTemplateWithProxy).build() + mockRestServiceServerAzureAD = MockRestServiceServer.bindTo(restTemplateAzureAD).build() tokenValidationUtil.logInAsDialogmoteUser(ARBEIDSTAKER_FNR) cleanDB() } @@ -479,13 +479,15 @@ class MotebehovArbeidstakerControllerV3Test { mockAndExpectBehandlendeEnhetRequest( azureTokenEndpoint, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, + mockRestServiceServer, behandlendeenhetUrl, ARBEIDSTAKER_FNR, ) mockAndExpectBehandlendeEnhetRequest( azureTokenEndpoint, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, + mockRestServiceServer, behandlendeenhetUrl, ARBEIDSTAKER_FNR, ) @@ -502,7 +504,8 @@ class MotebehovArbeidstakerControllerV3Test { private fun submitMotebehovAndSendOversikthendelse(motebehovSvar: MotebehovSvar) { mockAndExpectBehandlendeEnhetRequest( azureTokenEndpoint, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, + mockRestServiceServer, behandlendeenhetUrl, ARBEIDSTAKER_FNR, ) @@ -518,7 +521,8 @@ class MotebehovArbeidstakerControllerV3Test { private fun lagreOgHentMotebehovOgSendOversikthendelse(harBehov: Boolean) { mockAndExpectBehandlendeEnhetRequest( azureTokenEndpoint, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, + mockRestServiceServer, behandlendeenhetUrl, ARBEIDSTAKER_FNR, ) @@ -554,7 +558,7 @@ class MotebehovArbeidstakerControllerV3Test { private fun mockBehandlendEnhetWithTilgangskontroll(fnr: String) { mockAndExpectBehandlendeEnhetRequestWithTilgangskontroll( azureTokenEndpoint, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, mockRestServiceServer, behandlendeenhetUrl, tilgangskontrollUrl, @@ -574,7 +578,7 @@ class MotebehovArbeidstakerControllerV3Test { private fun resetMockRestServers() { mockRestServiceServer.reset() - mockRestServiceWithProxyServer.reset() + mockRestServiceServerAzureAD.reset() } private fun cleanDB() { diff --git a/src/test/kotlin/no/nav/syfo/motebehov/api/internad/v2/MotebehovVeilederADControllerV2Test.kt b/src/test/kotlin/no/nav/syfo/motebehov/api/internad/v2/MotebehovVeilederADControllerV2Test.kt index a21cca32..d92e597a 100644 --- a/src/test/kotlin/no/nav/syfo/motebehov/api/internad/v2/MotebehovVeilederADControllerV2Test.kt +++ b/src/test/kotlin/no/nav/syfo/motebehov/api/internad/v2/MotebehovVeilederADControllerV2Test.kt @@ -41,6 +41,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Qualifier import org.springframework.beans.factory.annotation.Value import org.springframework.boot.test.context.SpringBootTest @@ -83,6 +84,10 @@ class MotebehovVeilederADControllerV2Test { @Inject private lateinit var cacheManager: CacheManager + @Autowired + @Qualifier("AzureAD") + private lateinit var restTemplateAzureAD: RestTemplate + @Inject private lateinit var restTemplate: RestTemplate @@ -98,19 +103,15 @@ class MotebehovVeilederADControllerV2Test { @MockkBean(relaxed = true) private lateinit var personoppgavehendelseProducer: PersonoppgavehendelseProducer + private lateinit var mockRestServiceServerAzureAD: MockRestServiceServer private lateinit var mockRestServiceServer: MockRestServiceServer - @Inject - @Qualifier("restTemplateWithProxy") - private lateinit var restTemplateWithProxy: RestTemplate - private lateinit var mockRestServiceWithProxyServer: MockRestServiceServer - @BeforeEach fun setUp() { cleanDB() mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build() - mockRestServiceWithProxyServer = MockRestServiceServer.bindTo(restTemplateWithProxy).build() + mockRestServiceServerAzureAD = MockRestServiceServer.bindTo(restTemplateAzureAD).build() every { personoppgavehendelseProducer.sendPersonoppgavehendelse(any(), any()) } returns Unit every { brukertilgangConsumer.hasAccessToAnsatt(ARBEIDSTAKER_FNR) } returns true @@ -129,7 +130,7 @@ class MotebehovVeilederADControllerV2Test { fun tearDown() { // Verify all expectations met mockRestServiceServer.verify() - mockRestServiceWithProxyServer.verify() + mockRestServiceServerAzureAD.verify() resetMockRestServers() cacheManager.cacheNames .forEach( @@ -339,7 +340,7 @@ class MotebehovVeilederADControllerV2Test { azureTokenEndpoint = azureTokenEndpoint, tilgangskontrollUrl = tilgangskontrollUrl, mockRestServiceServer = mockRestServiceServer, - mockRestServiceWithProxyServer = mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD = mockRestServiceServerAzureAD, status = status, fnr = fnr, ) @@ -348,7 +349,8 @@ class MotebehovVeilederADControllerV2Test { private fun mockBehandlendEnhet(fnr: String) { mockAndExpectBehandlendeEnhetRequest( azureTokenEndpoint, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, + mockRestServiceServer, behandlendeenhetUrl, fnr, ) @@ -365,7 +367,7 @@ class MotebehovVeilederADControllerV2Test { private fun resetMockRestServers() { mockRestServiceServer.reset() - mockRestServiceWithProxyServer.reset() + mockRestServiceServerAzureAD.reset() } private fun cleanDB() { diff --git a/src/test/kotlin/no/nav/syfo/motebehov/api/internad/v2/MotebehovVeilederADTilgangV2Test.kt b/src/test/kotlin/no/nav/syfo/motebehov/api/internad/v2/MotebehovVeilederADTilgangV2Test.kt index e8f7e282..567bdf9b 100644 --- a/src/test/kotlin/no/nav/syfo/motebehov/api/internad/v2/MotebehovVeilederADTilgangV2Test.kt +++ b/src/test/kotlin/no/nav/syfo/motebehov/api/internad/v2/MotebehovVeilederADTilgangV2Test.kt @@ -32,29 +32,29 @@ class MotebehovVeilederADTilgangV2Test { @Inject private lateinit var motebehovVeilederController: MotebehovVeilederADControllerV2 + @Inject + @Qualifier("AzureAD") + private lateinit var restTemplateAzureAD: RestTemplate + @Inject private lateinit var restTemplate: RestTemplate @Inject private lateinit var tokenValidationUtil: TokenValidationUtil + private lateinit var mockRestServiceServerAzureAD: MockRestServiceServer private lateinit var mockRestServiceServer: MockRestServiceServer - @Inject - @Qualifier("restTemplateWithProxy") - private lateinit var restTemplateWithProxy: RestTemplate - private lateinit var mockRestServiceWithProxyServer: MockRestServiceServer - @BeforeEach fun setUp() { + mockRestServiceServerAzureAD = MockRestServiceServer.bindTo(restTemplateAzureAD).build() mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build() - mockRestServiceWithProxyServer = MockRestServiceServer.bindTo(restTemplateWithProxy).build() } @AfterEach fun tearDown() { mockRestServiceServer.verify() - mockRestServiceWithProxyServer.verify() + mockRestServiceServerAzureAD.verify() } @Test @@ -83,7 +83,7 @@ class MotebehovVeilederADTilgangV2Test { azureTokenEndpoint = azureTokenEndpoint, tilgangskontrollUrl = tilgangskontrollUrl, mockRestServiceServer = mockRestServiceServer, - mockRestServiceWithProxyServer = mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD = mockRestServiceServerAzureAD, status = status, fnr = fnr, ) diff --git a/src/test/kotlin/no/nav/syfo/testhelper/RestHelper.kt b/src/test/kotlin/no/nav/syfo/testhelper/RestHelper.kt index 1ed916a4..0c951db7 100644 --- a/src/test/kotlin/no/nav/syfo/testhelper/RestHelper.kt +++ b/src/test/kotlin/no/nav/syfo/testhelper/RestHelper.kt @@ -18,7 +18,8 @@ import org.springframework.web.util.UriComponentsBuilder fun mockAndExpectBehandlendeEnhetRequest( azureTokenEndpoint: String, - mockRestServiceWithProxyServer: MockRestServiceServer, + mockRestServiceServerAzureAD: MockRestServiceServer, + mockRestServiceServer: MockRestServiceServer, behandlendeenhetUrl: String, fnr: String, ) { @@ -32,12 +33,12 @@ fun mockAndExpectBehandlendeEnhetRequest( val systemToken = generateAzureAdV2TokenResponse() - mockAndExpectAzureADV2(mockRestServiceWithProxyServer, azureTokenEndpoint, systemToken) + mockAndExpectAzureADV2(mockRestServiceServerAzureAD, azureTokenEndpoint, systemToken) try { val json = ObjectMapper().writeValueAsString(behandlendeEnhet) - mockRestServiceWithProxyServer.expect(ExpectedCount.once(), MockRestRequestMatchers.requestTo(uriString)) + mockRestServiceServer.expect(ExpectedCount.once(), MockRestRequestMatchers.requestTo(uriString)) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) .andExpect(MockRestRequestMatchers.header(HttpHeaders.AUTHORIZATION, bearerCredentials(systemToken.access_token))) .andExpect(MockRestRequestMatchers.header(NAV_PERSONIDENT_HEADER, fnr)) @@ -49,7 +50,7 @@ fun mockAndExpectBehandlendeEnhetRequest( fun mockAndExpectBehandlendeEnhetRequestWithTilgangskontroll( azureTokenEndpoint: String, - mockRestServiceWithProxyServer: MockRestServiceServer, + mockRestServiceServerAzureAD: MockRestServiceServer, mockRestServiceServer: MockRestServiceServer, behandlendeenhetUrl: String, tilgangskontrollUrl: String, @@ -65,11 +66,11 @@ fun mockAndExpectBehandlendeEnhetRequestWithTilgangskontroll( val systemToken = generateAzureAdV2TokenResponse() - mockAndExpectAzureADV2(mockRestServiceWithProxyServer, azureTokenEndpoint, systemToken) + mockAndExpectAzureADV2(mockRestServiceServerAzureAD, azureTokenEndpoint, systemToken) mockSvarFraIstilgangskontrollTilgangTilBruker( azureTokenEndpoint, tilgangskontrollUrl, - mockRestServiceWithProxyServer, + mockRestServiceServerAzureAD, mockRestServiceServer, fnr, HttpStatus.OK, diff --git a/src/test/kotlin/no/nav/syfo/testhelper/SyfoTilgangskontrollMock.kt b/src/test/kotlin/no/nav/syfo/testhelper/SyfoTilgangskontrollMock.kt index eae2d0ab..1a84ea7c 100644 --- a/src/test/kotlin/no/nav/syfo/testhelper/SyfoTilgangskontrollMock.kt +++ b/src/test/kotlin/no/nav/syfo/testhelper/SyfoTilgangskontrollMock.kt @@ -16,12 +16,12 @@ import org.springframework.web.util.UriComponentsBuilder fun mockSvarFraIstilgangskontrollTilgangTilBruker( azureTokenEndpoint: String, tilgangskontrollUrl: String, - mockRestServiceWithProxyServer: MockRestServiceServer, + mockRestServiceServerAzureAD: MockRestServiceServer, mockRestServiceServer: MockRestServiceServer, fnr: String, status: HttpStatus, ) { - mockAndExpectAzureADV2(mockRestServiceWithProxyServer, azureTokenEndpoint, generateAzureAdV2TokenResponse()) + mockAndExpectAzureADV2(mockRestServiceServerAzureAD, azureTokenEndpoint, generateAzureAdV2TokenResponse()) val oboToken = generateAzureAdV2TokenResponse().access_token