-
Notifications
You must be signed in to change notification settings - Fork 6k
formLogin() does not work with REST Docs #7572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Out of curiosity and the following comment
I decided to give this a try. I updated the
I then
Curious why the |
Looks like there are two additional components to this change, one in spring-framework and another in spring-security. Firstly, we need to read the post processors from the parent during the merge() call and save them in the instance of the Secondly, we need to implement the Thus it looks like there are prerequisites that must be applied in the spring-framework repository first https://github.com/spring-projects/spring-framework/blob/master/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java before proceeding with this issue (both the new interface and implementation of this interface in the |
Hi! Is there any update about this issue? Is there a corresponding issue in the spring-framework repository as well? Is this issue still considered ideal for contribution, because if yes I would like to take it :) |
@dadikovi The issue is yours. NOTE: I'm not aware of any corresponding issues logged in Spring Framework. |
@rwinch but the solution defined in #7572 (comment) seems legit? |
@dadikovi I haven't looked into the proposed solution. What might be a good place to start is producing a unit test that reproduces the issue so I can easily look at it in isolation. You could do this with a draft PR. What do you think? |
@rwinch Thank you for your answer, I will do that! :) |
This commit adds a new test which fails right now, and also suggest a change. Fixes spring-projectsgh-7572
@rwinch I could manage to understand the problem here, @sandmannn 's comment #7572 (comment) seems 100% accurate for me, but since the solution would need contribution in another spring project (which I would do happily) and I'm new here, I would appreciate your double-check. |
@dadikovi I don't think anything needs to be done outside of Spring Security. I believe if these changes are made to Spring Security's private Mergeable mergeable;
@Override
public MockHttpServletRequest buildRequest(ServletContext servletContext) {
RequestBuilder builder = post(this.loginProcessingUrl)
.accept(this.acceptMediaType).param(this.usernameParam, this.username)
.param(this.passwordParam, this.password);
if (this.mergeable != null) {
builder = (RequestBuilder) this.mergeable.merge(builder);
}
MockHttpServletRequest request = builder
.buildRequest(servletContext);
return this.postProcessor.postProcessRequest(request);
}
@Override
public Object merge(Object o) {
this.mergeable = (Mergeable) o;
return this.mergeable;
} Similar changes would need to be applied to |
@rwinch wow, it works! Thanks! |
Right now formLogin() does not work with REST Docs. This commit adds a new test which fails right now, and also suggest a change. Fixes spring-projectsgh-7572
This is necessary so that default requests like Spring REST Docs work. Closes gh-7572
This is necessary so that default requests like Spring REST Docs work. Closes gh-7572
Summary
I was asked to open this issue here after Spring REST Docs team investigated my issue why REST Docs did not get configured with formLogin().
The original issue can be found here: spring-projects/spring-restdocs#655
The following code causes
java.lang.IllegalStateException: REST Docs configuration not found. Did you forget to apply a MockMvcRestDocumentationConfigurer when building the MockMvc instance?
Actual Behavior
On
mvn test
the code causesjava.lang.IllegalStateException: REST Docs configuration not found. Did you forget to apply a MockMvcRestDocumentationConfigurer when building the MockMvc instance?
on the line withdocument("login")
.Expected Behavior
No errors. The REST Docs should be correctly configured.
Version
All versions
Sample
restdocs-formlogin.zip
This sample causes the same error on
mvn test
.The text was updated successfully, but these errors were encountered: