Skip to content

Commit 04f0f13

Browse files
committed
Aligned exception message for httpOnly
Issue: SPR-15488
1 parent baa7b1c commit 04f0f13

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,13 @@ public ResultMatcher secure(final String name, final boolean secure) {
199199
}
200200

201201
/**
202-
* Assert whether the cookie must be httpOnly.
202+
* Assert whether the cookie must be HTTP only.
203+
* @since 4.3.9
203204
*/
204205
public ResultMatcher httpOnly(final String name, final boolean httpOnly) {
205206
return result -> {
206207
Cookie cookie = result.getResponse().getCookie(name);
207-
assertEquals("Response cookie httpOnly", httpOnly, cookie.isHttpOnly());
208+
assertEquals("Response cookie '" + name + "' httpOnly", httpOnly, cookie.isHttpOnly());
208209
};
209210
}
210211

spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/CookieAssertionTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
* Examples of expectations on response cookies values.
3535
*
3636
* @author Rossen Stoyanchev
37+
* @author Nikola Yovchev
3738
*/
3839
public class CookieAssertionTests {
3940

@@ -47,6 +48,7 @@ public void setup() {
4748
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
4849
localeResolver.setCookieDomain("domain");
4950
localeResolver.setCookieHttpOnly(true);
51+
5052
this.mockMvc = standaloneSetup(new SimpleController())
5153
.addInterceptors(new LocaleChangeInterceptor())
5254
.setLocaleResolver(localeResolver)
@@ -55,6 +57,7 @@ public void setup() {
5557
.build();
5658
}
5759

60+
5861
@Test
5962
public void testExists() throws Exception {
6063
this.mockMvc.perform(get("/")).andExpect(cookie().exists(COOKIE_NAME));
@@ -106,6 +109,7 @@ public void testHttpOnly() throws Exception {
106109
this.mockMvc.perform(get("/")).andExpect(cookie().httpOnly(COOKIE_NAME, true));
107110
}
108111

112+
109113
@Controller
110114
private static class SimpleController {
111115

@@ -114,4 +118,5 @@ public String home() {
114118
return "home";
115119
}
116120
}
121+
117122
}

0 commit comments

Comments
 (0)