MockCookie compares attributes in case-insensitive manner

Closes gh-22786
This commit is contained in:
Juergen Hoeller
2019-04-12 11:10:02 +02:00
parent 49557471a9
commit b07d46da99
3 changed files with 40 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 @@ public class MockCookieTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void constructCookie() {
MockCookie cookie = new MockCookie("SESSION", "123");
@@ -57,9 +58,7 @@ public class MockCookieTests {
@Test
public void parseHeaderWithoutAttributes() {
MockCookie cookie;
cookie = MockCookie.parse("SESSION=123");
MockCookie cookie = MockCookie.parse("SESSION=123");
assertCookie(cookie, "SESSION", "123");
cookie = MockCookie.parse("SESSION=123;");
@@ -80,6 +79,11 @@ public class MockCookieTests {
assertEquals("Lax", cookie.getSameSite());
}
private void assertCookie(MockCookie cookie, String name, String value) {
assertEquals(name, cookie.getName());
assertEquals(value, cookie.getValue());
}
@Test
public void parseNullHeader() {
exception.expect(IllegalArgumentException.class);
@@ -103,9 +107,18 @@ public class MockCookieTests {
MockCookie.parse(header);
}
private void assertCookie(MockCookie cookie, String name, String value) {
assertEquals(name, cookie.getName());
assertEquals(value, cookie.getValue());
@Test
public void parseHeaderWithAttributesCaseSensitivity() {
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());
}
}