mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-08 03:32:39 +00:00
Fix test warnings
This commit is contained in:
parent
fa11ae3c33
commit
6f5947cab7
@ -20,20 +20,26 @@ import org.junit.Rule
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.mockito.ArgumentMatchers.any
|
import org.mockito.ArgumentMatchers.any
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
import org.mockito.Mockito.mock
|
import org.mockito.Mockito.mock
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.context.ApplicationContext
|
import org.springframework.context.ApplicationContext
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
|
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
|
||||||
import org.springframework.security.config.test.SpringTestRule
|
import org.springframework.security.config.test.SpringTestRule
|
||||||
import org.springframework.security.web.server.SecurityWebFilterChain
|
import org.springframework.security.web.server.SecurityWebFilterChain
|
||||||
import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler
|
import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler
|
||||||
|
import org.springframework.security.web.server.csrf.CsrfToken
|
||||||
|
import org.springframework.security.web.server.csrf.DefaultCsrfToken
|
||||||
import org.springframework.security.web.server.csrf.ServerCsrfTokenRepository
|
import org.springframework.security.web.server.csrf.ServerCsrfTokenRepository
|
||||||
import org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher
|
import org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient
|
import org.springframework.test.web.reactive.server.WebTestClient
|
||||||
import org.springframework.web.bind.annotation.PostMapping
|
import org.springframework.web.bind.annotation.PostMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import org.springframework.web.reactive.config.EnableWebFlux
|
import org.springframework.web.reactive.config.EnableWebFlux
|
||||||
|
import org.springframework.web.reactive.function.BodyInserters.fromMultipartData
|
||||||
|
import reactor.core.publisher.Mono
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for [ServerCsrfDsl]
|
* Tests for [ServerCsrfDsl]
|
||||||
@ -45,6 +51,8 @@ class ServerCsrfDslTests {
|
|||||||
@JvmField
|
@JvmField
|
||||||
val spring = SpringTestRule()
|
val spring = SpringTestRule()
|
||||||
|
|
||||||
|
private val token: CsrfToken = DefaultCsrfToken("csrf", "CSRF", "a")
|
||||||
|
|
||||||
private lateinit var client: WebTestClient
|
private lateinit var client: WebTestClient
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -158,7 +166,7 @@ class ServerCsrfDslTests {
|
|||||||
.uri("/")
|
.uri("/")
|
||||||
.exchange()
|
.exchange()
|
||||||
|
|
||||||
Mockito.verify<ServerAccessDeniedHandler>(CustomAccessDeniedHandlerConfig.ACCESS_DENIED_HANDLER)
|
Mockito.verify(CustomAccessDeniedHandlerConfig.ACCESS_DENIED_HANDLER)
|
||||||
.handle(any(), any())
|
.handle(any(), any())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,13 +189,15 @@ class ServerCsrfDslTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `csrf when custom token repository then repository used`() {
|
fun `csrf when custom token repository then repository used`() {
|
||||||
|
`when`(CustomCsrfTokenRepositoryConfig.TOKEN_REPOSITORY.loadToken(any()))
|
||||||
|
.thenReturn(Mono.just(this.token))
|
||||||
this.spring.register(CustomCsrfTokenRepositoryConfig::class.java).autowire()
|
this.spring.register(CustomCsrfTokenRepositoryConfig::class.java).autowire()
|
||||||
|
|
||||||
this.client.post()
|
this.client.post()
|
||||||
.uri("/")
|
.uri("/")
|
||||||
.exchange()
|
.exchange()
|
||||||
|
|
||||||
Mockito.verify<ServerCsrfTokenRepository>(CustomCsrfTokenRepositoryConfig.TOKEN_REPOSITORY)
|
Mockito.verify(CustomCsrfTokenRepositoryConfig.TOKEN_REPOSITORY)
|
||||||
.loadToken(any())
|
.loadToken(any())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user