Skip to content

Commit

Permalink
Use mock class instead of interface on mock's return
Browse files Browse the repository at this point in the history
Issue gh-11860
  • Loading branch information
marcusdacoregio committed Sep 16, 2022
1 parent fee1ffa commit bd18c05
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.test.SpringTestContext
import org.springframework.security.config.test.SpringTestContextExtension
import org.springframework.security.core.Authentication
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames.SUB
import org.springframework.security.oauth2.jwt.Jwt
import org.springframework.security.oauth2.jwt.JwtDecoder
Expand Down Expand Up @@ -207,9 +208,7 @@ class OAuth2ResourceServerDslTests {
mockkObject(AuthenticationManagerResolverConfig.RESOLVER)
every {
AuthenticationManagerResolverConfig.RESOLVER.resolve(any())
} returns AuthenticationManager {
JwtAuthenticationToken(JWT)
}
} returns MockAuthenticationManager(JwtAuthenticationToken(JWT))

this.mockMvc.get("/") {
header("Authorization", "Bearer token")
Expand Down Expand Up @@ -241,6 +240,14 @@ class OAuth2ResourceServerDslTests {
}
}

class MockAuthenticationManager(var authentication: Authentication) : AuthenticationManager {

override fun authenticate(authentication: Authentication?): Authentication {
return this.authentication
}

}

@Test
fun `oauth2Resource server when custom authentication manager resolver and opaque then exception`() {
Assertions.assertThatExceptionOfType(BeanCreationException::class.java)
Expand Down

0 comments on commit bd18c05

Please sign in to comment.