cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestCookie.java TestWebappCookie.java

2003-10-20 Thread olegk
olegk   2003/10/20 15:17:12

  Modified:httpclient/src/examples CookieDemoApp.java
FormLoginDemo.java
   httpclient/src/java/org/apache/commons/httpclient
Cookie.java HttpMethodBase.java HttpState.java
   httpclient/src/java/org/apache/commons/httpclient/cookie
CookiePolicy.java
   httpclient/src/java/org/apache/commons/httpclient/params
DefaultHttpParamsFactory.java HttpMethodParams.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java TestWebappCookie.java
  Log:
  PR# 21151 (Customizable Cookie Policy)
  
  The patch extends CookiePolicy class with a custom cookie specification plug-in
  mechanism.
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  ChangesPath
  1.12  +12 -10jakarta-commons/httpclient/src/examples/CookieDemoApp.java
  
  Index: CookieDemoApp.java
  ===
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/CookieDemoApp.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CookieDemoApp.java3 Oct 2003 20:57:35 -   1.11
  +++ CookieDemoApp.java20 Oct 2003 22:17:11 -  1.12
  @@ -108,24 +108,26 @@
   Cookie mycookie = new Cookie(".foobar.com", "mycookie", "stuff", "/", null, 
false);
   // and then added to your HTTP state instance
   initialState.addCookie(mycookie);
  +
  +// Get HTTP client instance
  +HttpClient httpclient = new HttpClient();
  +httpclient.getParams().setConnectionTimeout(3);
  +httpclient.setState(initialState);
  +
   // RFC 2101 cookie management spec is used per default
   // to parse, validate, format & match cookies
  -initialState.setCookiePolicy(CookiePolicy.RFC2109);
  +httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
   // A different cookie management spec can be selected
   // when desired
   
  -//  initialState.setCookiePolicy(CookiePolicy.NETSCAPE_DRAFT);
  +//httpclient.getParams().setCookiePolicy(CookiePolicy.NETSCAPE);
   // Netscape Cookie Draft spec is provided for completeness
   // You would hardly want to use this spec in real life situations
  -//  initialState.setCookiePolicy(CookiePolicy.COMPATIBILITY);
  +
//httppclient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
   // Compatibility policy is provided in order to mimic cookie
   // management of popular web browsers that is in some areas 
   // not 100% standards compliant
   
  -// Get HTTP client instance
  -HttpClient httpclient = new HttpClient();
  -httpclient.getParams().setConnectionTimeout(3);
  -httpclient.setState(initialState);
   // Get HTTP GET method
   GetMethod httpget = new GetMethod(strURL);
   // Execute HTTP GET
  
  
  
  1.3   +1 -1  jakarta-commons/httpclient/src/examples/FormLoginDemo.java
  
  Index: FormLoginDemo.java
  ===
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/FormLoginDemo.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FormLoginDemo.java17 Jul 2003 21:57:42 -  1.2
  +++ FormLoginDemo.java20 Oct 2003 22:17:11 -  1.3
  @@ -84,7 +84,7 @@
   
   HttpClient client = new HttpClient();
   client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
  -client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY);
  +client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
// 'developer.java.sun.com' has cookie compliance problems
   // Their session cookie's domain attribute is in violation of the RFC2109
   // We have to resort to using compatibility cookie policy
  
  
  
  1.40  +11 -6 
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java
  
  Index: Cookie.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- Cookie.java   5 Jul 2003 22:31:20 -   1.39
  +++ Cookie.java   20 Oct 2003 22:17:11 -  1.40
  @@ -468,8 +468,13 @@
* @return a string suitable for sending in a Cookie header.
*/
   public String toExternalForm() {
  -return CookiePolicy.getSpecByVersion(
  -getVersion()).formatCookie(this);
  +CookieSpec spec = null;
  +if (getVersion() > 0) {
  +spec 

cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestCookie.java TestWebappCookie.java

2002-03-15 Thread marcsaeg

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