Skip to content

Commit

Permalink
Skal prøve å utstede token på nytt hvis servern feiler å svare
Browse files Browse the repository at this point in the history
  • Loading branch information
blommish committed Dec 11, 2024
1 parent 6f6ddad commit d370f00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package no.nav.tilleggsstonader.libs.http.client
import no.nav.security.token.support.client.core.http.OAuth2HttpRequest
import no.nav.security.token.support.client.core.oauth2.OAuth2AccessTokenResponse
import no.nav.security.token.support.client.spring.oauth2.DefaultOAuth2HttpClient
import org.apache.hc.core5.http.NoHttpResponseException
import org.slf4j.LoggerFactory
import org.springframework.core.NestedExceptionUtils
import org.springframework.web.client.HttpServerErrorException
Expand All @@ -23,6 +24,7 @@ class RetryOAuth2HttpClient(
SocketException::class,
SocketTimeoutException::class,
HttpServerErrorException.GatewayTimeout::class,
NoHttpResponseException::class,
)

override fun post(req: OAuth2HttpRequest): OAuth2AccessTokenResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ internal class RetryOAuth2HttpClientTest {
wireMockServer.verify(3, RequestPatternBuilder.allRequests())
}

@Test
internal fun `fault - skal prøve på nytt hvis servern feiler med å svare`() {
stub(WireMock.aResponse().withBody("{}").withFault(Fault.EMPTY_RESPONSE))
post()
wireMockServer.verify(3, RequestPatternBuilder.allRequests())
}

private fun stub(responseDefinitionBuilder: ResponseDefinitionBuilder?) {
wireMockServer.stubFor(
WireMock.post(WireMock.anyUrl())
Expand Down

0 comments on commit d370f00

Please sign in to comment.