Merge pull request #1373 from lc-nyovchev/master
HttpOnly Cookie Result Matcher
This commit is contained in:
@@ -198,4 +198,14 @@ public class CookieResultMatchers {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert whether the cookie must be httpOnly.
|
||||
*/
|
||||
public ResultMatcher httpOnly(final String name, final boolean httpOnly) {
|
||||
return result -> {
|
||||
Cookie cookie = result.getResponse().getCookie(name);
|
||||
assertEquals("Response cookie httpOnly", httpOnly, cookie.isHttpOnly());
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class CookieAssertionTests {
|
||||
public void setup() {
|
||||
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
|
||||
localeResolver.setCookieDomain("domain");
|
||||
|
||||
localeResolver.setCookieHttpOnly(true);
|
||||
this.mockMvc = standaloneSetup(new SimpleController())
|
||||
.addInterceptors(new LocaleChangeInterceptor())
|
||||
.setLocaleResolver(localeResolver)
|
||||
@@ -62,7 +62,7 @@ public class CookieAssertionTests {
|
||||
|
||||
@Test
|
||||
public void testNotExists() throws Exception {
|
||||
this.mockMvc.perform(get("/")).andExpect(cookie().doesNotExist("unknowCookie"));
|
||||
this.mockMvc.perform(get("/")).andExpect(cookie().doesNotExist("unknownCookie"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,6 +101,10 @@ public class CookieAssertionTests {
|
||||
this.mockMvc.perform(get("/")).andExpect(cookie().secure(COOKIE_NAME, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHttpOnly() throws Exception {
|
||||
this.mockMvc.perform(get("/")).andExpect(cookie().httpOnly(COOKIE_NAME, true));
|
||||
}
|
||||
|
||||
@Controller
|
||||
private static class SimpleController {
|
||||
|
||||
Reference in New Issue
Block a user