Skip to content

Commit bd18c05

Browse files
Use mock class instead of interface on mock's return
Issue gh-11860
1 parent fee1ffa commit bd18c05

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: config/src/test/kotlin/org/springframework/security/config/annotation/web/OAuth2ResourceServerDslTests.kt

+10-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity
3535
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
3636
import org.springframework.security.config.test.SpringTestContext
3737
import org.springframework.security.config.test.SpringTestContextExtension
38+
import org.springframework.security.core.Authentication
3839
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames.SUB
3940
import org.springframework.security.oauth2.jwt.Jwt
4041
import org.springframework.security.oauth2.jwt.JwtDecoder
@@ -207,9 +208,7 @@ class OAuth2ResourceServerDslTests {
207208
mockkObject(AuthenticationManagerResolverConfig.RESOLVER)
208209
every {
209210
AuthenticationManagerResolverConfig.RESOLVER.resolve(any())
210-
} returns AuthenticationManager {
211-
JwtAuthenticationToken(JWT)
212-
}
211+
} returns MockAuthenticationManager(JwtAuthenticationToken(JWT))
213212

214213
this.mockMvc.get("/") {
215214
header("Authorization", "Bearer token")
@@ -241,6 +240,14 @@ class OAuth2ResourceServerDslTests {
241240
}
242241
}
243242

243+
class MockAuthenticationManager(var authentication: Authentication) : AuthenticationManager {
244+
245+
override fun authenticate(authentication: Authentication?): Authentication {
246+
return this.authentication
247+
}
248+
249+
}
250+
244251
@Test
245252
fun `oauth2Resource server when custom authentication manager resolver and opaque then exception`() {
246253
Assertions.assertThatExceptionOfType(BeanCreationException::class.java)

0 commit comments

Comments
 (0)