Make TestCsrfTokenRepository delegate to the actual CsrfTokenRepository configured in CsrfFilter

This commit is contained in:
Christian Schuster 2023-04-24 18:54:12 +02:00
parent 27ebeefb14
commit b67374811f
No known key found for this signature in database
GPG Key ID: 5EF176BCDB4190E5
1 changed files with 1 additions and 2 deletions

View File

@ -98,7 +98,6 @@ import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.security.web.csrf.CsrfTokenRepository;
import org.springframework.security.web.csrf.CsrfTokenRequestHandler;
import org.springframework.security.web.csrf.DeferredCsrfToken;
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
@ -518,7 +517,7 @@ public final class SecurityMockMvcRequestPostProcessors {
CsrfTokenRepository repository = WebTestUtils.getCsrfTokenRepository(request);
CsrfTokenRequestHandler handler = WebTestUtils.getCsrfTokenRequestHandler(request);
if (!(repository instanceof TestCsrfTokenRepository)) {
repository = new TestCsrfTokenRepository(new HttpSessionCsrfTokenRepository());
repository = new TestCsrfTokenRepository(repository);
WebTestUtils.setCsrfTokenRepository(request, repository);
}
TestCsrfTokenRepository.enable(request);