From ac2d4eee46431f570dda0140e0c3172554c24819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20Tr=C3=B8en?= Date: Tue, 24 Mar 2020 18:30:54 +0100 Subject: [PATCH] move start of fixedport server in test to beforeeach --- .../no/nav/security/mock/oauth2/MockOAuth2ServerTest.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/kotlin/no/nav/security/mock/oauth2/MockOAuth2ServerTest.kt b/src/test/kotlin/no/nav/security/mock/oauth2/MockOAuth2ServerTest.kt index 985e167f..488ba9b3 100644 --- a/src/test/kotlin/no/nav/security/mock/oauth2/MockOAuth2ServerTest.kt +++ b/src/test/kotlin/no/nav/security/mock/oauth2/MockOAuth2ServerTest.kt @@ -37,6 +37,7 @@ class MockOAuth2ServerTest { private lateinit var server: MockOAuth2Server private lateinit var interactiveLoginServer: MockOAuth2Server + private lateinit var serverWithFixedPort: MockOAuth2Server @BeforeEach fun before() { @@ -49,18 +50,20 @@ class MockOAuth2ServerTest { tokenProvider = OAuth2TokenProvider() ) ) + serverWithFixedPort = MockOAuth2Server() + serverWithFixedPort.start(1234) } @AfterEach fun shutdown() { server.shutdown() interactiveLoginServer.shutdown() + serverWithFixedPort.shutdown() } @Test fun startServerWithFixedPort() { - val serverWithFixedPort = MockOAuth2Server() - serverWithFixedPort.start(1234) + val wellKnown: WellKnown = assertWellKnownResponseForIssuer(serverWithFixedPort, "default") val tokenIssuedDirectlyFromServer: SignedJWT = serverWithFixedPort.issueToken("default", "yo", DefaultOAuth2TokenCallback()) @@ -79,7 +82,6 @@ class MockOAuth2ServerTest { val tokenResponse: OAuth2TokenResponse = jacksonObjectMapper().readValue(authCodeTokenResponse.body!!.string()) val tokenFromAuthCode: SignedJWT = tokenResponse.idToken!!.let { SignedJWT.parse(it) } assertThat(tokenFromAuthCode.verifySignatureAndIssuer(Issuer(wellKnown.issuer), retrieveJwks(wellKnown.jwksUri))).isNotNull - serverWithFixedPort.shutdown() } @Test