Skip to content

In MockMvc tests all filters end up with empty-string filterName, breaking OncePerRequestFilter #31474

@jeffbswope

Description

@jeffbswope

As discovered in spring-boot:3.2.0-RC1 (previous milestone unaffected) changes to populate init parameters and dispatch types in MockMvc auto-configuration have led to all filters (or those without explicit registration?) ending up with empty-string as their getFilterName. This ultimately breaks the OncePerRequestFilter behavior because all filters use .FILTERED as their request attribute so only the first one runs.

The stack here I believe is something like:

org.springframework.boot.test.autoconfigure.web.servlet.SpringBootMockMvcBuilderCustomizer#addFilter
org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder#addFilter(jakarta.servlet.Filter, java.util.Map<java.lang.String,java.lang.String>, java.util.EnumSet<jakarta.servlet.DispatcherType>, java.lang.String...)

So we end up with MockMvcFilterDecorator even though we aren't doing any filtering/otherwise -- this is change from last milestone.

Then in MockMvcFilterDecorator#initIfRequired we create a MockFilterConfig which always has an empty-string filterName.

@wilkinsona had suggestions over here about different approaches to harmonizing this between framework and boot:
spring-projects/spring-boot#37835 (comment)

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions