marcsaeg02/03/15 14:52:07
Modified:httpclient/src/test/org/apache/commons/httpclient
TestCookie.java TestWebappCookie.java
Log:
Updated existing tests to conform to RFC 2109 and Netscape cookie
behaviour. Added several new test cases to better test cookie behaviour.
Revision ChangesPath
1.8 +175 -88
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java
Index: TestCookie.java
===
RCS file:
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TestCookie.java 4 Mar 2002 03:22:18 - 1.7
+++ TestCookie.java 15 Mar 2002 22:52:07 - 1.8
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
1.7 2002/03/04 03:22:18 marcsaeg Exp $
- * $Revision: 1.7 $
- * $Date: 2002/03/04 03:22:18 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
1.8 2002/03/15 22:52:07 marcsaeg Exp $
+ * $Revision: 1.8 $
+ * $Date: 2002/03/15 22:52:07 $
*
*
* The Apache Software License, Version 1.1
@@ -79,7 +79,8 @@
* @author Rod Waldhoff
* @author dIon Gillard
* @author mailto:[EMAIL PROTECTED]";>John Evans
- * @version $Revision: 1.7 $
+ * @author Marc A. Saegesser
+ * @version $Revision: 1.8 $
*/
public class TestCookie extends TestCase {
@@ -198,7 +199,7 @@
public void testParseSimple() throws Exception {
Header setCookie = new Header("Set-Cookie","cookie-name=cookie-value");
-Cookie[] parsed = Cookie.parse("127.0.0.1","/",setCookie);
+Cookie[] parsed = Cookie.parse("127.0.0.1","/path/path",setCookie);
assertEquals("Found 1 cookie.",1,parsed.length);
assertEquals("Name","cookie-name",parsed[0].getName());
assertEquals("Value","cookie-value",parsed[0].getValue());
@@ -207,7 +208,7 @@
//assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
assertTrue("isPersistent",!parsed[0].isPersistent());
assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-assertEquals("Path","/",parsed[0].getPath());
+assertEquals("Path","/path",parsed[0].getPath());
assertTrue("Secure",!parsed[0].getSecure());
assertEquals("Version",0,parsed[0].getVersion());
}
@@ -272,7 +273,7 @@
public void testParseWithPath() throws Exception {
Header setCookie = new Header("Set-Cookie","cookie-name=cookie-value;
Path=/path/");
-Cookie[] parsed = Cookie.parse("127.0.0.1","/path/",setCookie);
+Cookie[] parsed = Cookie.parse("127.0.0.1","/path/path",setCookie);
assertEquals("Found 1 cookie.",1,parsed.length);
assertEquals("Name","cookie-name",parsed[0].getName());
assertEquals("Value","cookie-value",parsed[0].getValue());
@@ -349,8 +350,32 @@
assertEquals("Version",1,parsed[0].getVersion());
}
+public void testParseMultipleDifferentPaths() throws Exception {
+Header setCookie = new
Header("Set-Cookie","name1=value1;Version=1;Path=/commons,name1=value2;Version=1;Path=/commons/httpclient;Version=1");
+Cookie[] parsed =
Cookie.parse(".apache.org","/commons/httpclient",true,setCookie);
+HttpState state = new HttpState();
+state.addCookies(parsed);
+Cookie[] cookies = state.getCookies();
+assertEquals("Wrong number of cookies.",2,cookies.length);
+assertEquals("Name","name1",cookies[0].getName());
+assertEquals("Value","value1",cookies[0].getValue());
+assertEquals("Name","name1",cookies[1].getName());
+assertEquals("Value","value2",cookies[1].getValue());
+}
+
+public void testParseMultipleSamePaths() throws Exception {
+Header setCookie = new
Header("Set-Cookie","name1=value1;Version=1;Path=/commons,name1=value2;Version=1;Path=/commons");
+Cookie[] parsed =
Cookie.parse(".apache.org","/commons/httpclient",true,setCookie);
+HttpState state = new HttpState();
+state.addCookies(parsed);
+Cookie[] cookies = state.getCookies();
+assertEquals("Found 1 cookies.",1,cookies.length);
+assertEquals("Name","name1",cookies[0].getName());
+assertEquals("Value","value2",cookies[0].getValue());
+}
+
public void testParseWithWrongDomain() throws Exception {
-Header setCookie = new Header("Set-Cookie","cookie-name=cookie-value;
domain=127.0.0.1");
+Header setCookie = new Header("Set-Cookie","cookie-name=cookie-value;
domain=127.0.0.1; vers