- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Closed
Labels
in: testIssues in the test moduleIssues in the test moduletype: enhancementA general enhancementA general enhancement
Milestone
Description
Rob Winch opened SPR-12945 and commented
If a RequestPostProcessor is used with the default request, it is placed after additional RequestPostProcessors. For example, the following test fails:
@Before
public void setup() {
	MockHttpServletRequestBuilder defaultRequest = get("/")
			.with(requestAttr("ATTR").value("default"));
	mvc = MockMvcBuilders.webAppContextSetup(context)
		.defaultRequest(defaultRequest)
		.build();
}
@Test
public void defaultRequestPostProcessorsShouldExecuteBeforeAdditionalRequestPostProcessors() throws Exception {
	MockHttpServletRequestBuilder request = get("/abc")
			.with(requestAttr("ATTR").value("override"));
	mvc.perform(request)
		.andExpect(request().attribute("ATTR", "override"));
}
private static RequestAttributePostProcessor requestAttr(String name) {
	return new RequestAttributePostProcessor().attr(name);
}
public class RequestAttributePostProcessor implements RequestPostProcessor {
	String attr;
	String value;
	public RequestAttributePostProcessor attr(String attr) {
		this.attr = attr;
		return this;
	}
	public RequestAttributePostProcessor value(String value) {
		this.value = value;
		return this;
	}
	public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
		request.setAttribute(attr, value);
		return request;
	}
}A default RequestPostProcessor should happen first so that additional RequestPostProcessors override additional RequestPostProcessors.
The problem appears to be in MockHttpServletRequestBuilder.merge which adds the parent to the end instead of the front of the postProcessors.
Affects: 4.1.6
Issue Links:
- SEC-2941 Default RequestPostProcessor overrides additional DefaultRequestPostProcessor ("is depended on by")
Referenced from: pull request #782, and commits spring-projects/spring-security@dd09243, spring-projects/spring-security@269127c
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test moduletype: enhancementA general enhancementA general enhancement