Update MockCookie#parse(String) validation - #37134
Conversation
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
sbrannen
left a comment
There was a problem hiding this comment.
Good catch! 👍
I've requested a minor change to the test.
Also, please update the duplicate variant of this class: spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockCookie.java
Thanks
| @Test | ||
| void parseEmptyHeader() { | ||
| assertThatIllegalArgumentException() | ||
| .isThrownBy(() -> MockCookie.parse("")) | ||
| .withMessageContaining("Set-Cookie header must not be null or empty"); | ||
| assertThatIllegalArgumentException() | ||
| .isThrownBy(() -> MockCookie.parse(" ")) | ||
| .withMessageContaining("Set-Cookie header must not be null or empty"); |
There was a problem hiding this comment.
| @Test | |
| void parseEmptyHeader() { | |
| assertThatIllegalArgumentException() | |
| .isThrownBy(() -> MockCookie.parse("")) | |
| .withMessageContaining("Set-Cookie header must not be null or empty"); | |
| assertThatIllegalArgumentException() | |
| .isThrownBy(() -> MockCookie.parse(" ")) | |
| .withMessageContaining("Set-Cookie header must not be null or empty"); | |
| @ParameterizedTest | |
| @ValueSource(strings = {"", " "}) | |
| void parseEmptyHeader(String header) { | |
| assertThatIllegalArgumentException() | |
| .isThrownBy(() -> MockCookie.parse(header)) | |
| .withMessageContaining("Set-Cookie header must not be null or empty"); | |
| } |
A @ParameterizedTest would be better here.
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
sbrannen
left a comment
There was a problem hiding this comment.
Thanks for making the requested changes.
Looks good now.
|
Due to a code freeze on After the 7.1 M1 release, I will cherry pick those two commits back on top of In light of that, can you please create a new issue (not a PR) with the title and body of this PR, referencing the two original commits (8b89493 and 27a85be) to be applied? Or if you'd prefer that I do that, just let me know. I apologize for the inconvenience. Regards, Sam |
That looks perfect. Thanks, @ngocnhan-tran1996. 👍 I've now labeled this PR as:
And I've already assigned that issue to the 7.1 M2 milestone. Cheers, Sam |
spring-framework/spring-test/src/main/java/org/springframework/mock/web/MockCookie.java
Lines 130 to 132 in 68e6acd
Based on the Javadoc, I think it should throw
Set-Cookie header must not be null or emptyinstead ofInvalid Set-Cookie header ''when setCookieHeader is empty.