Skip to content
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

MockHttpServletResponse addHeader does not allow Comment part with Set-Cookie header #28730

Closed
charlesk40 opened this issue Jun 29, 2022 · 3 comments
Assignees
Labels
in: test Issues in the test module type: bug A general bug
Milestone

Comments

@charlesk40
Copy link

charlesk40 commented Jun 29, 2022

I'm using the following dependency for using MockHttpServletResponse for unit tests.

<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-test</artifactId>
	<version>6.0.0-M4</version>
	<scope>test</scope>
</dependency>

Please see below test case where it shows that addHeader/getHeader methods from MockHttpServletResponse object do not return the same value; particularly the Comment part is stripped out.

I tried adding the same in Jetty container, and Jetty does not seem to strip the comment part. Also note that other header names like Set-CookieTest preserve the Comment part which seems to indicate that it only strips when encountering the Set-Cookie header name.

    @Test
    void addHeader() throws Exception {
        MockHttpServletResponse servletResponse = new MockHttpServletResponse();
        servletResponse.addHeader("Set-Cookie", "NOT_SAFE=;Domain=mydomain.com;Comment=COOKIECLEANER;Path=/;Expires=Thu, 01 Jan 1970 00:00:00 GMT");
        System.out.println("MockHttpServletResponse: " + servletResponse.getHeader("Set-Cookie"));
    }

Output:

MockHttpServletResponse: NOT_SAFE=; Path=/; Domain=mydomain.com; Expires=Thu, 1 Jan 1970 00:00:00 GMT

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 29, 2022
@sbrannen sbrannen changed the title MockHttpServletResponse addHeader does not allow Comment part with Set-Cookie headername MockHttpServletResponse addHeader does not allow Comment part with Set-Cookie header Jun 30, 2022
@sbrannen sbrannen added in: test Issues in the test module type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 30, 2022
@sbrannen sbrannen added this to the 5.3.22 milestone Jun 30, 2022
@sbrannen sbrannen self-assigned this Jun 30, 2022
@sbrannen
Copy link
Member

That's correct.

Currently, MockHttpServletResponse.getCookieHeader(Cookie) does not include the value from jakarta.servlet.http.Cookie.getComment().

The counterpart to this issue is that MockCookie.parse(String) does not parse the Comment attribute.

So we have to fix it on both sides.

@sbrannen
Copy link
Member

This has been addressed for 5.3.22 and 6.0 M5 in 9ea4569.

@charlesk40
Copy link
Author

Great. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants