@Test public void writeCookieCookiePathDefaultContextPathUsed() { this.request.setContextPath("/context"); this.serializer.writeCookieValue(cookieValue(this.sessionId)); assertThat(getCookie().getPath()).isEqualTo("/context/"); }
@Test public void writeCookieCookiePathDefaultEmptyContextPathUsed() { this.request.setContextPath(""); this.serializer.writeCookieValue(cookieValue(this.sessionId)); assertThat(getCookie().getPath()).isEqualTo("/"); }
@Test public void writeCookieCookiePathExplicitNullCookiePathContextPathUsed() { this.request.setContextPath("/context"); this.serializer.setCookiePath(null); this.serializer.writeCookieValue(cookieValue(this.sessionId)); assertThat(getCookie().getPath()).isEqualTo("/context/"); }
@Test public void writeCookieCookiePathExplicitCookiePath() { this.request.setContextPath("/context"); this.serializer.setCookiePath("/"); this.serializer.writeCookieValue(cookieValue(this.sessionId)); assertThat(getCookie().getPath()).isEqualTo("/"); }
@Test public void constructCookie() { MockCookie cookie = new MockCookie("SESSION", "123"); assertCookie(cookie, "SESSION", "123"); assertNull(cookie.getDomain()); assertEquals(-1, cookie.getMaxAge()); assertNull(cookie.getPath()); assertFalse(cookie.isHttpOnly()); assertFalse(cookie.getSecure()); assertNull(cookie.getSameSite()); }
@Test public void parseHeaderWithAttributes() { MockCookie cookie = MockCookie.parse( "SESSION=123; Domain=example.com; Max-Age=60; Path=/; Secure; HttpOnly; SameSite=Lax"); assertCookie(cookie, "SESSION", "123"); assertEquals("example.com", cookie.getDomain()); assertEquals(60, cookie.getMaxAge()); assertEquals("/", cookie.getPath()); assertTrue(cookie.getSecure()); assertTrue(cookie.isHttpOnly()); assertEquals("Lax", cookie.getSameSite()); }