Aligned exception message for httpOnly

Issue: SPR-15488
This commit is contained in:
Juergen Hoeller 2017-04-27 21:32:11 +02:00
parent baa7b1c6c8
commit 04f0f137e6
2 changed files with 9 additions and 3 deletions

View File

@ -199,12 +199,13 @@ public class CookieResultMatchers {
}
/**
* Assert whether the cookie must be httpOnly.
* Assert whether the cookie must be HTTP only.
* @since 4.3.9
*/
public ResultMatcher httpOnly(final String name, final boolean httpOnly) {
return result -> {
Cookie cookie = result.getResponse().getCookie(name);
assertEquals("Response cookie httpOnly", httpOnly, cookie.isHttpOnly());
assertEquals("Response cookie '" + name + "' httpOnly", httpOnly, cookie.isHttpOnly());
};
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
* Examples of expectations on response cookies values.
*
* @author Rossen Stoyanchev
* @author Nikola Yovchev
*/
public class CookieAssertionTests {
@ -47,6 +48,7 @@ public class CookieAssertionTests {
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
localeResolver.setCookieDomain("domain");
localeResolver.setCookieHttpOnly(true);
this.mockMvc = standaloneSetup(new SimpleController())
.addInterceptors(new LocaleChangeInterceptor())
.setLocaleResolver(localeResolver)
@ -55,6 +57,7 @@ public class CookieAssertionTests {
.build();
}
@Test
public void testExists() throws Exception {
this.mockMvc.perform(get("/")).andExpect(cookie().exists(COOKIE_NAME));
@ -106,6 +109,7 @@ public class CookieAssertionTests {
this.mockMvc.perform(get("/")).andExpect(cookie().httpOnly(COOKIE_NAME, true));
}
@Controller
private static class SimpleController {
@ -114,4 +118,5 @@ public class CookieAssertionTests {
return "home";
}
}
}