From 159d29892ab99a666e379d08cd5974c33e8491f9 Mon Sep 17 00:00:00 2001 From: markt Date: Sun, 16 Nov 2008 00:30:19 +0000 Subject: [PATCH] Add jfclere's cookie test fixes to trunk. Merge of r633793. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@717950 13f79535-47bb-0310-9956-ffa450edef68 --- test/build.xml | 3 ++- .../catalina/tomcat/util/http/TestCookies.java | 26 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/test/build.xml b/test/build.xml index 54a017282..a27150849 100644 --- a/test/build.xml +++ b/test/build.xml @@ -28,6 +28,7 @@ + @@ -61,7 +62,7 @@ - + diff --git a/test/org/apache/catalina/tomcat/util/http/TestCookies.java b/test/org/apache/catalina/tomcat/util/http/TestCookies.java index 22858646b..e67e2a619 100644 --- a/test/org/apache/catalina/tomcat/util/http/TestCookies.java +++ b/test/org/apache/catalina/tomcat/util/http/TestCookies.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.catalina.tomcat.util.http; +package org.apache.catalina.tomcat.util.http; import org.apache.tomcat.util.http.Cookies; import org.apache.tomcat.util.http.ServerCookie; @@ -71,8 +71,8 @@ public class TestCookies extends TestCase { test("$Version=1;foo=\"bar\";$Domain=apache.org;$Port=8080;a=b", "foo", "bar", "a", "b"); // make sure these never split into two cookies - JVK - test("$Version=1;foo=\"b\"ar\";$Domain=apache.org;$Port=8080;a=b", "foo", "b", "a", "b"); - test("$Version=1;foo=\"b\\\"ar\";$Domain=apache.org;$Port=8080;a=b", "foo", "b\\\"ar", "a", "b"); + test("$Version=1;foo=\"b\"ar\";$Domain=apache.org;$Port=8080;a=b", "foo", "b", "a", "b"); // Incorrectly escaped. + test("$Version=1;foo=\"b\\\"ar\";$Domain=apache.org;$Port=8080;a=b", "foo", "b\"ar", "a", "b"); // correctly escaped. test("$Version=1;foo=\"b'ar\";$Domain=apache.org;$Port=8080;a=b", "foo", "b'ar", "a", "b"); // JFC: sure it is "b" and not b'ar ? test("$Version=1;foo=b'ar;$Domain=apache.org;$Port=8080;a=b", "foo", "b", "a", "b"); @@ -115,8 +115,28 @@ public class TestCookies extends TestCase { test("foo;a=b;;\\;bar=rab", "foo", "", "a", "b", "bar", "rab"); + + // Try all the separators of version1 in version0 cookie. + // Won't work we only parse version1 cookie result 1 cookie. + test("a=()<>@:\\\"/[]?={}\t; foo=bar", "foo", "bar"); + + // Test the version. + test("$Version=1;foo=bar", 1); + test("$Version=0;foo=bar", 0); } + public static void test( String s, int val ) throws Exception { + System.out.println("Processing [" + s + "]"); + Cookies cs=new Cookies(null); + cs.processCookieHeader( s.getBytes(), 0, s.length()); + int num = cs.getCookieCount(); + if (num != 1) + throw new Exception("wrong number of cookies " + num); + ServerCookie co = cs.getCookie(0); + System.out.println("One Cookie: " + co); + if (co.getVersion() != val) + throw new Exception("wrong version " + co.getVersion() + " != " + val); + } public static void test( String s ) throws Exception { System.out.println("Processing [" + s + "]"); Cookies cs=new Cookies(null); -- 2.11.0