Skip to content

Spring MVC Test framework never stores more than one cookie [SPR-13166] #17757

@spring-projects-issues

Description

@spring-projects-issues

Chris Beams opened SPR-13166 and commented

Scenario

An HTTP response contains multiple Set-Cookie headers, e.g.:

$ http head localhost:8080
HTTP/1.1 200 OK
[...]
Set-Cookie: JSESSIONID=58FA8366CB58657E4AD0AE50809D63CB; Path=/; HttpOnly
Set-Cookie: XSRF-TOKEN=27d3cc6d-6d9f-4b50-9d3c-adb67e41639e; Path=/

Problem

Spring MVC Test only stores the last cookie seen:

http.perform(get("/"))
    .andDo(print())
    .andExpect(status().isOk())
    .andExpect(cookie().exists("XSRF-TOKEN")) // PASS
    .andExpect(cookie().exists("JSESSIONID")) // FAIL
;

The output from the print() above tells the tale:

MockHttpServletResponse:
              Status = 200
       Error message = null
             Headers = {...}
        Content type = null
                Body = 
       Forwarded URL = index.html
      Redirected URL = null
             Cookies = [javax.servlet.http.Cookie@3ccd3277]

Note that the Cookies array contains only a single entry, where it should have two. (and it would be nice by the way, if the cookie entries themselves were rendered in a friendlier way).


Affects: 4.2 RC1

Issue Links:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions