Skip to content

MockMvcWebConnection should share CookieManager with HtmlUnit driver [SPR-14066] #18638

Closed
@spring-projects-issues

Description

@spring-projects-issues

Christopher Smith opened SPR-14066 and commented

While working on the other side of #18623 (trying to explicitly set a cookie as a given and then loading a page, expecting the controller to see the cookie's value), I discovered that the MockMvcWebConnection used by the HtmlUnit driver maintains a completely separate copy of WebClient with its own state. This is presumably because the DelegatingWebConnection operates as a sort of decorator.

However, this means that any cookies set in the driver.manage().addCookie() (or equivalent) are simply missing from the context used to issue local MockMvc requests.

The connection object should, when creating the delegate WebClient, use the same CookieManager as the parent WebClient.

This code, inserted in setup(), appears to induce the expected behavior:

WebClient topLevelWebClient = driver.@webClient
CookieManager topLevelCookieManager = topLevelWebClient.cookieManager

(topLevelWebClient.webConnection as DelegatingWebConnection).@connections
    .findAll { DelegatingWebConnection.DelegateWebConnection connection ->
        connection.delegate instanceof MockMvcWebConnection
    }.each { (it.@delegate as MockMvcWebConnection).@webClient.cookieManager = topLevelCookieManager }

Affects: 4.2.5

Issue Links:

Referenced from: commits 411ff84, 4a6c2db, 7d96ad1

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions