Skip to content

Replace matcher explicitly in replace-CSP test for reactive stack - #19924

Merged
jzheaux merged 1 commit into
spring-projects:mainfrom
ziqin:fix-csp-replace-test
Nov 24, 2026
Merged

jzheaux merged 1 commit into
spring-projects:mainfrom
ziqin:fix-csp-replace-test

Conversation

@ziqin

@ziqin ziqin commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

The current HeaderSpecTests#headersWhenContentSecurityPolicyConfiguredTwiceThenSecondCallReplacesFirst test relies on the fact that the exchangeMatcher is implicitly reset to ServerWebExchangeMatchers.anyExchange() when headers.contentSecurityPolicy(...) is called the second time, which makes it incompatible with gh-19842.

This PR addresses the aforementioned problem by aligning the reactive test with
HeadersConfigurerTests#ContentSecurityPolicyConfiguredTwiceConfig in the servlet stack:

@Configuration
@EnableWebSecurity
static class ContentSecurityPolicyConfiguredTwiceConfig {
@Bean
SecurityFilterChain filterChain(HttpSecurity http) {
// @formatter:off
http
.headers((headers) -> headers
.defaultsDisabled()
.contentSecurityPolicy((csp) -> csp
.policyDirectives("script-src 'self'")
.requestMatchers("/foo/**"))
.contentSecurityPolicy((csp) -> csp
.policyDirectives("default-src 'self'")
.requestMatchers("/bar/**")));
// @formatter:on
return http.build();
}
}

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 17, 2026
@jzheaux jzheaux added in: config An issue in spring-security-config type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 24, 2026
@jzheaux jzheaux self-assigned this Nov 24, 2026
@jzheaux jzheaux added this to the 7.2.1 milestone Nov 24, 2026
@jzheaux
jzheaux force-pushed the fix-csp-replace-test branch from 7af6dd9 to 5fb3f98 Compare November 24, 2026 15:56
The current headersWhenContentSecurityPolicyConfiguredTwiceThenSecondCallReplacesFirst
test relies on the fact that the exchangeMatcher is reset to
ServerWebExchangeMatchers.anyExchange() when
headers.contentSecurityPolicy(...) is called the second time, which
makes it incompatible with spring-projectsgh-19842.

This commit aligns the reactive test with
HeadersConfigurerTests.ContentSecurityPolicyConfiguredTwiceConfig
in the servlet stack to address the aforementioned problem.

Signed-off-by: Ziqin Wang <ziqin@wangziqin.net>
@jzheaux
jzheaux force-pushed the fix-csp-replace-test branch from 5fb3f98 to 53c6747 Compare November 24, 2026 16:46
@jzheaux
jzheaux merged commit 53c6747 into spring-projects:main Nov 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: config An issue in spring-security-config type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants