Przeglądaj źródła

Use mock class instead of interface on mock's return

Issue gh-11860
Marcus Da Coregio 2 lat temu
rodzic
commit
bd18c05a27

+ 10 - 3
config/src/test/kotlin/org/springframework/security/config/annotation/web/OAuth2ResourceServerDslTests.kt

@@ -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
@@ -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")
@@ -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)