Allow for HttpOnly cookie result matcher

Issue: SPR-15488
(cherry picked from commit 04f0f13)
This commit is contained in:
Juergen Hoeller
2017-04-27 21:32:11 +02:00
parent 38089d8e66
commit 9b647021f7
2 changed files with 61 additions and 35 deletions

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 {
@@ -46,6 +47,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())
@@ -55,6 +57,7 @@ public class CookieAssertionTests {
.build();
}
@Test
public void testExists() throws Exception {
this.mockMvc.perform(get("/")).andExpect(cookie().exists(COOKIE_NAME));
@@ -62,7 +65,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 +104,11 @@ 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 {
@@ -110,4 +118,5 @@ public class CookieAssertionTests {
return "home";
}
}
}