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

2004-01-06 Thread olegk
olegk   2004/01/06 14:09:04

  Modified:httpclient/src/java/org/apache/commons/httpclient/cookie
Tag: HTTPCLIENT_2_0_BRANCH CookieSpecBase.java
   httpclient/src/test/org/apache/commons/httpclient Tag:
HTTPCLIENT_2_0_BRANCH TestCookie.java
  Log:
  PR #25264 (Cookie rejected)
  
  Fixes the problem that causes rejection of cookies with a domain attribute 
'.domain.com' issued by host 'domain.com' in the browser compatibility mode. Even 
though the cookie violates the RFC 2109 it still gets accepted by mainstream browsers 
(tested with Mozilla Firebird and IE)
  
  Contributed by Oleg Kalnichevski
  
  Revision  ChangesPath
  No   revision
  No   revision
  1.16.2.2  +12 -6 
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.16.2.1
  retrieving revision 1.16.2.2
  diff -u -r1.16.2.1 -r1.16.2.2
  --- CookieSpecBase.java   20 Oct 2003 22:27:37 -  1.16.2.1
  +++ CookieSpecBase.java   6 Jan 2004 22:09:04 -   1.16.2.2
  @@ -419,9 +419,15 @@
   
   // domain must match host
   if (!host.endsWith(cookie.getDomain())) {
  -throw new MalformedCookieException(
  -Illegal domain attribute \ + cookie.getDomain() 
  -+ \. Domain of origin: \ + host + \);
  +String s = cookie.getDomain();
  +if (s.startsWith(.)) {
  +s = s.substring(1, s.length());
  +}
  +if (!host.equals(s)) { 
  +throw new MalformedCookieException(
  +Illegal domain attribute \ + cookie.getDomain() 
  ++ \. Domain of origin: \ + host + \);
  +}
   }
   } else {
   if (!host.equals(cookie.getDomain())) {
  
  
  
  No   revision
  No   revision
  1.22.2.2  +26 -4 
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.22.2.1
  retrieving revision 1.22.2.2
  diff -u -r1.22.2.1 -r1.22.2.2
  --- TestCookie.java   20 Oct 2003 22:27:37 -  1.22.2.1
  +++ TestCookie.java   6 Jan 2004 22:09:04 -   1.22.2.2
  @@ -1001,6 +1001,28 @@
   assertEquals($Version=0; name=; $Domain=.whatever.com; $Path=/, s);
   }
   
  +/**
  + * Tests if that invalid second domain level cookie gets 
  + * rejected in the strict mode, but gets accepted in the
  + * browser compatibility mode.
  + */
  +public void testSecondDomainLevelCookie() throws Exception {
  +Cookie cookie = new Cookie(.sourceforge.net, name, null, /, null, 
false); 
  +cookie.setDomainAttributeSpecified(true);
  +cookie.setPathAttributeSpecified(true);
   
  +CookieSpec parser = null;
  +
  +parser = CookiePolicy.getSpecByPolicy(CookiePolicy.COMPATIBILITY);
  +parser.validate(sourceforge.net, 80, /, false, cookie);
  +
  +parser = CookiePolicy.getSpecByPolicy(CookiePolicy.RFC2109);
  +try {
  +parser.validate(sourceforge.net, 80, /, false, cookie);
  +fail(MalformedCookieException should have been thrown);
  +} catch (MalformedCookieException e) {
  +// Expected
  +}
  +}
   }
   
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2004-01-06 Thread olegk
olegk   2004/01/06 14:10:44

  Modified:httpclient/src/java/org/apache/commons/httpclient/cookie
CookieSpecBase.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  PR #25264 (Cookie rejected)
  
  Fixes the problem that causes rejection of cookies with a domain attribute 
'.domain.com' issued by host 'domain.com' in the browser compatibility mode. Even 
though the cookie violates the RFC 2109 it still gets accepted by mainstream browsers 
(tested with Mozilla Firebird and IE)
  
  Contributed by Oleg Kalnichevski
  
  Revision  ChangesPath
  1.21  +12 -6 
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- CookieSpecBase.java   2 Nov 2003 18:18:30 -   1.20
  +++ CookieSpecBase.java   6 Jan 2004 22:10:44 -   1.21
  @@ -428,9 +428,15 @@
   
   // domain must match host
   if (!host.endsWith(cookie.getDomain())) {
  -throw new MalformedCookieException(
  -Illegal domain attribute \ + cookie.getDomain() 
  -+ \. Domain of origin: \ + host + \);
  +String s = cookie.getDomain();
  +if (s.startsWith(.)) {
  +s = s.substring(1, s.length());
  +}
  +if (!host.equals(s)) { 
  +throw new MalformedCookieException(
  +Illegal domain attribute \ + cookie.getDomain() 
  ++ \. Domain of origin: \ + host + \);
  +}
   }
   } else {
   if (!host.equals(cookie.getDomain())) {
  
  
  
  1.27  +28 -4 
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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- TestCookie.java   2 Nov 2003 18:18:30 -   1.26
  +++ TestCookie.java   6 Jan 2004 22:10:44 -   1.27
  @@ -1048,5 +1048,29 @@
   assertEquals(b,c, cookies[0].getValue());
   }
   
  +
  +/**
  + * Tests if that invalid second domain level cookie gets 
  + * rejected in the strict mode, but gets accepted in the
  + * browser compatibility mode.
  + */
  +public void testSecondDomainLevelCookie() throws Exception {
  +Cookie cookie = new Cookie(.sourceforge.net, name, null, /, null, 
false); 
  +cookie.setDomainAttributeSpecified(true);
  +cookie.setPathAttributeSpecified(true);
  +
  +CookieSpec parser = null;
  +
  +parser = CookiePolicy.getCookieSpec(CookiePolicy.BROWSER_COMPATIBILITY);
  +parser.validate(sourceforge.net, 80, /, false, cookie);
  +
  +parser = CookiePolicy.getCookieSpec(CookiePolicy.RFC_2109);
  +try {
  +parser.validate(sourceforge.net, 80, /, false, cookie);
  +fail(MalformedCookieException should have been thrown);
  +} catch (MalformedCookieException e) {
  +// Expected
  +}
  +}
   }
   
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2003-10-20 Thread olegk
olegk   2003/10/20 15:26:28

  Modified:httpclient/src/java/org/apache/commons/httpclient/cookie
CookieSpecBase.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  PR# 23866 (Invalid cookie causing IllegalArgumentException)
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  ChangesPath
  1.19  +14 -10
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- CookieSpecBase.java   13 Jul 2003 21:29:05 -  1.18
  +++ CookieSpecBase.java   20 Oct 2003 22:26:28 -  1.19
  @@ -206,13 +206,17 @@
   for (int i = 0; i  headerElements.length; i++) {
   
   HeaderElement headerelement = headerElements[i];
  -Cookie cookie = new Cookie(host,
  -   headerelement.getName(),
  -   headerelement.getValue(),
  -   defaultPath, 
  -   null,
  -   false);
  -
  +Cookie cookie = null;
  +try {
  +cookie = new Cookie(host,
  +headerelement.getName(),
  +headerelement.getValue(),
  +defaultPath, 
  +null,
  +false);
  +} catch (IllegalArgumentException e) {
  +throw new MalformedCookieException(e.getMessage()); 
  +}
   // cycle through the parameters
   NameValuePair[] parameters = headerelement.getParameters();
   // could be null. In case only a header element and no parameters.
  
  
  
  1.25  +12 -10
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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- TestCookie.java   20 Oct 2003 22:17:12 -  1.24
  +++ TestCookie.java   20 Oct 2003 22:26:28 -  1.25
  @@ -787,10 +787,11 @@
   public void testInvalidCookieName() {
   try
   {
  -Cookie dummy = new Cookie(localhost, invalid name, cooke name may 
not have blanks);
  -fail(IllegalArgumentException must have been thrown);
  +CookieSpec parser = new CookieSpecBase();
  +parser.parse(localhost, 80, /, false, invalid name=); 
  +fail(MalformedCookieException must have been thrown);
   }
  -catch(IllegalArgumentException e)
  +catch(MalformedCookieException e)
   {
   // Expected
   }
  @@ -803,10 +804,11 @@
   public void testInvalidCookieName2() {
   try
   {
  -Cookie dummy = new Cookie(localhost, $invalid_name, cooke name may 
not start with $);
  -fail(IllegalArgumentException must have been thrown);
  +CookieSpec parser = new CookieSpecBase();
  +parser.parse(localhost, 80, /, false, $invalid_name=); 
  +fail(MalformedCookieException must have been thrown);
   }
  -catch(IllegalArgumentException e)
  +catch(MalformedCookieException e)
   {
   // Expected
   }
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2003-10-20 Thread olegk
olegk   2003/10/20 15:27:37

  Modified:httpclient/src/java/org/apache/commons/httpclient/cookie
Tag: HTTPCLIENT_2_0_BRANCH CookieSpecBase.java
   httpclient/src/test/org/apache/commons/httpclient Tag:
HTTPCLIENT_2_0_BRANCH TestCookie.java
  Log:
  PR# 23866 (Invalid cookie causing IllegalArgumentException)
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  ChangesPath
  No   revision
  No   revision
  1.16.2.1  +14 -10
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.16
  retrieving revision 1.16.2.1
  diff -u -r1.16 -r1.16.2.1
  --- CookieSpecBase.java   12 Jun 2003 19:12:16 -  1.16
  +++ CookieSpecBase.java   20 Oct 2003 22:27:37 -  1.16.2.1
  @@ -189,13 +189,17 @@
   for (int i = 0; i  headerElements.length; i++) {
   
   HeaderElement headerelement = headerElements[i];
  -Cookie cookie = new Cookie(host,
  -   headerelement.getName(),
  -   headerelement.getValue(),
  -   defaultPath, 
  -   null,
  -   false);
  -
  +Cookie cookie = null;
  +try {
  +cookie = new Cookie(host,
  +headerelement.getName(),
  +headerelement.getValue(),
  +defaultPath, 
  +null,
  +false);
  +} catch (IllegalArgumentException e) {
  +throw new MalformedCookieException(e.getMessage()); 
  +}
   // cycle through the parameters
   NameValuePair[] parameters = headerelement.getParameters();
   // could be null. In case only a header element and no parameters.
  
  
  
  No   revision
  No   revision
  1.22.2.1  +12 -10
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.22
  retrieving revision 1.22.2.1
  diff -u -r1.22 -r1.22.2.1
  --- TestCookie.java   12 Jun 2003 19:12:16 -  1.22
  +++ TestCookie.java   20 Oct 2003 22:27:37 -  1.22.2.1
  @@ -786,10 +786,11 @@
   public void testInvalidCookieName() {
   try
   {
  -Cookie dummy = new Cookie(localhost, invalid name, cooke name may 
not have blanks);
  -fail(IllegalArgumentException must have been thrown);
  +CookieSpec parser = new CookieSpecBase();
  +parser.parse(localhost, 80, /, false, invalid name=); 
  +fail(MalformedCookieException must have been thrown);
   }
  -catch(IllegalArgumentException e)
  +catch(MalformedCookieException e)
   {
   // Expected
   }
  @@ -802,10 +803,11 @@
   public void testInvalidCookieName2() {
   try
   {
  -Cookie dummy = new Cookie(localhost, $invalid_name, cooke name may 
not start with $);
  -fail(IllegalArgumentException must have been thrown);
  +CookieSpec parser = new CookieSpecBase();
  +parser.parse(localhost, 80, /, false, $invalid_name=); 
  +fail(MalformedCookieException must have been thrown);
   }
  -catch(IllegalArgumentException e)
  +catch(MalformedCookieException e)
   {
   // Expected
   }
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2003-07-19 Thread olegk
olegk   2003/07/19 01:46:59

  Modified:httpclient/src/java/org/apache/commons/httpclient/cookie
NetscapeDraftSpec.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  Bug fix #11240 (Cookies with ',' in the value string is not parsed correctly in some 
cases)
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke  Laura Werner
  
  Revision  ChangesPath
  1.8   +92 -3 
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java
  
  Index: NetscapeDraftSpec.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NetscapeDraftSpec.java28 Jan 2003 04:40:23 -  1.7
  +++ NetscapeDraftSpec.java19 Jul 2003 08:46:59 -  1.8
  @@ -69,6 +69,8 @@
   import java.text.DateFormat; 
   import java.text.SimpleDateFormat;  
   import java.text.ParseException; 
  +
  +import org.apache.commons.httpclient.HeaderElement;
   import org.apache.commons.httpclient.NameValuePair;
   import org.apache.commons.httpclient.Cookie;
   
  @@ -94,6 +96,93 @@
   /** Default constructor */
   public NetscapeDraftSpec() {
   super();
  +}
  +
  +/**
  +  * Parses the Set-Cookie value into an array of ttCookie/tts.
  +  *
  +  * pSyntax of the Set-Cookie HTTP Response Header:/p
  +  * 
  +  * pThis is the format a CGI script would use to add to 
  +  * the HTTP headers a new piece of data which is to be stored by 
  +  * the client for later retrieval./p
  +  *  
  +  * PRE
  +  *  Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure
  +  * /PRE
  +  *
  +  * pPlease note that Netscape draft specification does not fully 
  +  * conform to the HTTP header format. Netscape draft does not specify 
  +  * whether multiple cookies may be sent in one header. Hence, comma 
  +  * character may be present in unquoted cookie value or unquoted 
  +  * parameter value./p
  +  * 
  +  * @link http://wp.netscape.com/newsref/std/cookie_spec.html
  +  * 
  +  * @param host the host from which the ttSet-Cookie/tt value was
  +  * received
  +  * @param port the port from which the ttSet-Cookie/tt value was
  +  * received
  +  * @param path the path from which the ttSet-Cookie/tt value was
  +  * received
  +  * @param secure tttrue/tt when the ttSet-Cookie/tt value was
  +  * received over secure conection
  +  * @param header the ttSet-Cookie/tt received from the server
  +  * @return an array of ttCookie/tts parsed from the Set-Cookie value
  +  * @throws MalformedCookieException if an exception occurs during parsing
  +  */
  +public Cookie[] parse(String host, int port, String path, 
  +boolean secure, final String header) 
  +throws MalformedCookieException {
  +
  +LOG.trace(enter NetscapeDraftSpec.parse(String, port, path, boolean, 
Header));
  +
  +if (host == null) {
  +throw new IllegalArgumentException(Host of origin may not be null);
  +}
  +if (host.trim().equals()) {
  +throw new IllegalArgumentException(Host of origin may not be blank);
  +}
  +if (port  0) {
  +throw new IllegalArgumentException(Invalid port:  + port);
  +}
  +if (path == null) {
  +throw new IllegalArgumentException(Path of origin may not be null.);
  +}
  +if (header == null) {
  +throw new IllegalArgumentException(Header may not be null.);
  +}
  +
  +if (path.trim().equals()) {
  +path = PATH_DELIM;
  +}
  +host = host.toLowerCase();
  +
  +String defaultPath = path;
  +int lastSlashIndex = defaultPath.lastIndexOf(PATH_DELIM);
  +if (lastSlashIndex = 0) {
  +if (lastSlashIndex == 0) {
  +//Do not remove the very first slash
  +lastSlashIndex = 1;
  +}
  +defaultPath = defaultPath.substring(0, lastSlashIndex);
  +}
  +HeaderElement headerelement = new HeaderElement(header.toCharArray());
  +Cookie cookie = new Cookie(host,
  +   headerelement.getName(),
  +   headerelement.getValue(),
  +   defaultPath, 
  +   null,
  +   false);
  +// cycle through the parameters
  +NameValuePair[] parameters = headerelement.getParameters();
  +// could be null. In case only a header element and no parameters.
  +if (parameters != null) {
  +for 

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

2003-06-12 Thread olegk
olegk   2003/06/12 12:12:17

  Modified:httpclient/src/java/org/apache/commons/httpclient/cookie
CookieSpecBase.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  RFC2109 cookie spec implementation does not properly handle default cookie path with 
a single leading back-slash ('/whatever.php'). Default cookie path with multiple 
back-slashes is processed correctly ('/path/whatever.php')
  
  Reported by Dan Ã…berg [EMAIL PROTECTED]
  Contributed by Oleg Kalnichevski
  
  Revision  ChangesPath
  1.16  +8 -4  
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- CookieSpecBase.java   26 May 2003 17:58:03 -  1.15
  +++ CookieSpecBase.java   12 Jun 2003 19:12:16 -  1.16
  @@ -176,7 +176,11 @@
   
   String defaultPath = path;
   int lastSlashIndex = defaultPath.lastIndexOf(PATH_DELIM);
  -if (lastSlashIndex  0) {
  +if (lastSlashIndex = 0) {
  +if (lastSlashIndex == 0) {
  +//Do not remove the very first slash
  +lastSlashIndex = 1;
  +}
   defaultPath = defaultPath.substring(0, lastSlashIndex);
   }
   
  
  
  
  1.22  +21 -4 
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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- TestCookie.java   7 Mar 2003 18:23:46 -   1.21
  +++ TestCookie.java   12 Jun 2003 19:12:16 -  1.22
  @@ -298,6 +298,23 @@
   }


  +public void testParseSimple2() throws Exception {
  +Header setCookie = new Header(Set-Cookie,cookie-name=cookie-value);
  +Cookie[] parsed = cookieParse(127.0.0.1,/path,setCookie);
  +assertEquals(Found 1 cookie.,1,parsed.length);
  +assertEquals(Name,cookie-name,parsed[0].getName());
  +assertEquals(Value,cookie-value,parsed[0].getValue());
  +assertTrue(Comment,null == parsed[0].getComment());
  +assertTrue(ExpiryDate,null == parsed[0].getExpiryDate());
  +//assertTrue(isToBeDiscarded,parsed[0].isToBeDiscarded());
  +assertTrue(isPersistent,!parsed[0].isPersistent());
  +assertEquals(Domain,127.0.0.1,parsed[0].getDomain());
  +assertEquals(Path,/,parsed[0].getPath());
  +assertTrue(Secure,!parsed[0].getSecure());
  +assertEquals(Version,0,parsed[0].getVersion());
  +}
  + 
  + 
   public void testParseNoValue() throws Exception {
   Header setCookie = new Header(Set-Cookie,cookie-name=);
   Cookie[] parsed = cookieParse(127.0.0.1,/,setCookie);
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2003-03-07 Thread olegk
olegk   2003/03/07 10:23:47

  Modified:httpclient/src/java/org/apache/commons/httpclient/cookie
CookieSpecBase.java RFC2109Spec.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  Fixes the null-value cookie formatting bug reported by Tom Samplonius [EMAIL 
PROTECTED]
  
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17768
  
  Contributed by Oleg Kalnichevski
  
  Revision  ChangesPath
  1.13  +9 -4  
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CookieSpecBase.java   18 Feb 2003 15:54:30 -  1.12
  +++ CookieSpecBase.java   7 Mar 2003 18:23:45 -   1.13
  @@ -646,7 +646,12 @@
   throw new IllegalArgumentException(Cookie may not be null);
   }
   StringBuffer buf = new StringBuffer();
  -buf.append(cookie.getName()).append(=).append(cookie.getValue());
  +buf.append(cookie.getName());
  +buf.append(=);
  +String s = cookie.getValue();
  +if (s != null) {
  +buf.append(s);
  +};
   return buf.toString();
   }
   
  
  
  
  1.13  +14 -5 
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java
  
  Index: RFC2109Spec.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RFC2109Spec.java  31 Jan 2003 00:33:36 -  1.12
  +++ RFC2109Spec.java  7 Mar 2003 18:23:46 -   1.13
  @@ -203,9 +203,18 @@
   
   final StringBuffer buffer = new StringBuffer();
   if (version  1) {
  -buffer.append(name).append(=).append(value);   
  +buffer.append(name);
  +buffer.append(=);
  +if (value != null) {
  +buffer.append(value);   
  +}
   } else {
  -buffer.append(name).append(=\).append(value).append(\);
  +buffer.append(name);
  +buffer.append(=\);
  +if (value != null) {
  +buffer.append(value);
  +}
  +buffer.append(\);
   }
   return buffer.toString(); 
   }
  
  
  
  1.21  +28 -7 
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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TestCookie.java   28 Jan 2003 22:09:51 -  1.20
  +++ TestCookie.java   7 Mar 2003 18:23:46 -   1.21
  @@ -744,7 +744,7 @@
*/
   public void testDefaultConsttuctor() {
   Cookie dummy = new Cookie();
  -assertEquals( noname=null, dummy.toExternalForm() );
  +assertEquals( noname=, dummy.toExternalForm() );
   }
   
   /**
  @@ -752,9 +752,9 @@
*/
   public void testDomainCaseInsensitivity() {
   Header setCookie = new Header(
  -  Set-Cookie, name=value; path=/; domain=.sybase.com);
  +  Set-Cookie, name=value; path=/; domain=.whatever.com);
   try {
  -Cookie[] parsed = cookieParse(www.Sybase.com, /, false, setCookie );
  +Cookie[] parsed = cookieParse(www.WhatEver.com, /, false, setCookie 
);
   }
   catch(HttpException e) {
   e.printStackTrace();
  @@ -762,6 +762,7 @@
   }
   }
   
  +
   /**
* Tests if cookie constructor rejects cookie name containing blanks.
*/
  @@ -961,6 +962,26 @@
   }
   
   
  +/**
  + * Tests if null cookie values are handled correctly.
  + */
  +public void testNullCookieValueFormatting() {
  +Cookie cookie = new Cookie(.whatever.com, name, null, /, null, 
false); 
  +cookie.setDomainAttributeSpecified(true);
  +cookie.setPathAttributeSpecified(true);
  +
  +CookieSpec parser = null;
  +String s = null;
  +
  +parser = CookiePolicy.getSpecByPolicy(CookiePolicy.COMPATIBILITY);
  +s = parser.formatCookie(cookie);
  +assertEquals(name=, s);
  +
  +parser = CookiePolicy.getSpecByPolicy(CookiePolicy.RFC2109);
  +s = parser.formatCookie(cookie);
  +assertEquals($Version=0; name=; 

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

2003-01-28 Thread olegk
olegk   2003/01/28 14:09:52

  Modified:httpclient/src/java/org/apache/commons/httpclient/cookie
CookieSpecBase.java RFC2109Spec.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  PR: 16497, 16505
  Submitted by: Oleg Kalnichevski
  
  Fixes the following bugs:
  
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16497
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16505
  
  Revision  ChangesPath
  1.10  +10 -3 
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CookieSpecBase.java   28 Jan 2003 04:40:23 -  1.9
  +++ CookieSpecBase.java   28 Jan 2003 22:09:48 -  1.10
  @@ -446,6 +446,13 @@
   + \. Domain of origin: \ + host + \);
   }
   }
  +else {
  +if (!host.equals(cookie.getDomain())) {
  +throw new MalformedCookieException(
  +Illegal domain attribute \ + cookie.getDomain() 
  ++ \. Domain of origin: \ + host + \);
  +}
  +}
   
   // another security check... we musn't allow the server to give us a
   // cookie that doesn't match this path
  
  
  
  1.9   +26 -20
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java
  
  Index: RFC2109Spec.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- RFC2109Spec.java  28 Jan 2003 04:40:23 -  1.8
  +++ RFC2109Spec.java  28 Jan 2003 22:09:48 -  1.9
  @@ -167,17 +167,22 @@
   if (dotIndex  0 || dotIndex == cookie.getDomain().length() - 1) {
   throw new MalformedCookieException(Domain attribute \ 
   + cookie.getDomain() 
  -+ \ violates RFC 2109: domain must contain an 
  -+ embedded dot);
  ++ \ violates RFC 2109: domain must contain an embedded dot);
   }
  -// host minus domain may not contain any dots
  -if (host.substring(0,
  -host.length()
  -- cookie.getDomain().length()).indexOf('.') != -1) {
  -throw new MalformedCookieException(Domain attribute \ 
  -+ cookie.getDomain() 
  -+ \ violates RFC 2109: host minus domain may not 
  -+ contain any dots);
  +host = host.toLowerCase();
  +if (host.indexOf('.') = 0) {
  +if (!host.endsWith(cookie.getDomain())) {
  +throw new MalformedCookieException(
  +Illegal domain attribute \ + cookie.getDomain() 
  ++ \. Domain of origin: \ + host + \);
  +}
  +// host minus domain may not contain any dots
  +String hostWithoutDomain = host.substring(0, host.length() - 
cookie.getDomain().length());
  +if (hostWithoutDomain.indexOf('.') != -1) {
  +throw new MalformedCookieException(Domain attribute \ 
  ++ cookie.getDomain() 
  ++ \ violates RFC 2109: host minus domain may not contain 
any dots);
  +}
   }
   }
   }
  @@ -246,7 +251,13 @@
   if (cookie == null) {
   throw new IllegalArgumentException(Cookie may not be null);
   }
  -return formatCookieAsVer(cookie, cookie.getVersion());
  +int ver = cookie.getVersion();
  +StringBuffer buffer = new StringBuffer();
  +buffer.append(formatNameValuePair($Version, 
  +  Integer.toString(ver), ver));
  +buffer.append(; );
  +buffer.append(formatCookieAsVer(cookie, ver));
  +return buffer.toString();
   }
   
   /**
  @@ -286,11 +297,6 @@
*/
   public Header formatCookieHeader(Cookie cookie) {
   LOG.trace(enter RFC2109Spec.formatCookieHeader(Cookie));
  -StringBuffer buffer = new StringBuffer();
  -buffer.append(formatNameValuePair($Version, 
  -Integer.toString(cookie.getVersion()), cookie.getVersion()));
  -buffer.append(; );
  -buffer.append(formatCookie(cookie));
  -return new Header(Cookie, buffer.toString());
  +return new Header(Cookie, formatCookie(cookie));
  

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

2002-12-11 Thread oglueck
oglueck 2002/12/11 05:16:09

  Modified:httpclient/src/java/org/apache/commons/httpclient/cookie
CookieSpecBase.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  Fixed StringIndexOutOfBoundsException and added test case.
  
  Reported by: Christopher Lenz
  Patch contributed by: Michael Becke
  
  Revision  ChangesPath
  1.3   +4 -2  
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CookieSpecBase.java   9 Dec 2002 12:48:40 -   1.2
  +++ CookieSpecBase.java   11 Dec 2002 13:16:09 -  1.3
  @@ -501,14 +501,16 @@
   private static boolean pathMatch(final String path, final String topmostPath)
   {
   boolean match = path.startsWith( topmostPath );
  -if (match) {
  +
  +// if there is a match and these values are not exactly the same we have
  +// to make sure we're not matcing /foobar and /foo
  +if ( match  path.length() != topmostPath.length() ) {
   if (!topmostPath.endsWith(PATH_DELIM)) {
   match = (path.charAt(topmostPath.length()) == PATH_DELIM_CHAR);
   }
   }
   return match;
   }
  -
   
   /**
* Return an array of {@link Cookie}s that should be submitted with a request 
with
  
  
  
  1.16  +28 -5 
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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TestCookie.java   8 Dec 2002 06:09:46 -   1.15
  +++ TestCookie.java   11 Dec 2002 13:16:09 -  1.16
  @@ -721,7 +721,30 @@
   // Expected
   }
   }
  -
  +
  +/**
  + * Makes sure that a cookie matches with a path of the same value.
  + */
  +public void testMatchWithEqualPaths() {
  +
  +Cookie cookie = new Cookie(.test.com, test, 1, /test, null, false);
  +
  +try {
  +boolean match = cookie.matches(
  +test.test.com, 
  +80, 
  +/test, 
  +false, 
  +new Date()
  +);
  +
  +assertTrue(Cookie paths did not match, match);
  +} catch ( Exception e ) {
  +e.printStackTrace();
  +fail(Unexpected exception:  + e);
  +}
  +   
  +}
   
   /**
* Tests Netscape specific cookie formatting.
  
  
  

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




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

2002-11-29 Thread jsdever
jsdever 2002/11/29 11:03:02

  Modified:httpclient/src/java/org/apache/commons/httpclient
Cookie.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  Make version 2 cookies the default.
  
  Changes:
  1) This patch fixes the problem of Cookie class assuming Netscape cookie format per 
default. With this fix RFC 2109 compliant validation applies unless the cookie version 
is explicitly set to 0 (Netscape cookie draft)
  
  2) I have also taken liberty in heavily refactoring the Cookie.parse() method
  - I have tried to restructure the code by separating parsing and validation 
processes. The code is a bit more modular now
  - I have improved (or so I'd like to hope) exception handling and logging, which was 
next to awful, at least in my humble opinion. Stuff should be more consistent now
  - The code should have gotten somewhat cleaner. (Code clarity is a subjective 
matter, though, so critique is always welcome)
  
  Contributed by: Oleg Kalnichevski
  
  Revision  ChangesPath
  1.27  +235 -221  
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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- Cookie.java   28 Nov 2002 00:21:14 -  1.26
  +++ Cookie.java   29 Nov 2002 19:03:02 -  1.27
  @@ -791,257 +791,271 @@
   /* Build the default path.  Per RFC 2109/4.3.1 this is the 
* request path up to, but not including, the right-most / charater.
*/
  -if(path.length() == 0){
  -log.debug(Cookie.parse():  Fixing up empty request path.);
  +if (path.length() == 0) {
  +log.debug(Fixing up empty request path.);
   path = PATH_DELIM;
   }
   String defaultPath = null;
   int lastSlashIndex = path.lastIndexOf(PATH_DELIM);
   if(lastSlashIndex == 0){
   defaultPath = PATH_DELIM;
  -}else if(lastSlashIndex  0){
  +}
  +else if(lastSlashIndex  0) {
   defaultPath = path.substring(0, lastSlashIndex);
  -}else{
  +}
  +else {
   defaultPath = path;
   }
  -HeaderElement[] headerElements =
  -HeaderElement.parse(setCookie.getValue());
  -
  -Cookie[] cookies = new Cookie[headerElements.length];
  -int index = 0;
  -for (int i = 0; i  headerElements.length; i++) {
  -
  -Cookie cookie = new Cookie(domain,
  -   headerElements[i].getName(),
  -   headerElements[i].getValue(),
  -   defaultPath, 
  -   null,
  -   false);
  -
  -// cycle through the parameters
  -NameValuePair[] parameters = headerElements[i].getParameters();
  -// could be null. In case only a header element and no parameters.
  -if (parameters != null) {
  -boolean discard_set = false, secure_set = false;
  -for (int j = 0; j  parameters.length; j++) {
  -String name = parameters[j].getName().toLowerCase();
  -
  -// check for required value parts
  -if ( (name.equals(version) || name.equals(max-age) ||
  -  name.equals(domain) || name.equals(path) ||
  -  name.equals(comment) || name.equals(expires)) 
  -  parameters[j].getValue() == null) {
  -if(log.isDebugEnabled()) {
  -log.debug(Cookie.parse(): Unable to parse set-cookie 
header \ + setCookie.getValue() + \ because \ + parameters[j].getName() + \ 
requires a value in cookie \ + headerElements[i].getName() + \.);
  -}
  -throw new HttpException(
  -Bad Set-Cookie header:  + setCookie.getValue() +
  -\nMissing value for  +
  -parameters[j].getName() +
  - attribute in cookie ' +
  -headerElements[i].getName() + ');
  -}
  -
  -if (name.equals(version)) {
  -try {
  -   cookie.setVersion(
  -   Integer.parseInt(parameters[j].getValue()));
  -} catch (NumberFormatException nfe) {
  -if(log.isDebugEnabled()) {
  -log.debug(Cookie.parse(): Exception 

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

2002-11-27 Thread jsdever
jsdever 2002/11/27 16:21:14

  Modified:httpclient/src/java/org/apache/commons/httpclient
Cookie.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  Fixes cookie domain matching being case sesnitive.
  
  Contributed by: Oleg Kalnichevski
  
  Revision  ChangesPath
  1.26  +7 -4  
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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- Cookie.java   27 Nov 2002 01:32:34 -  1.25
  +++ Cookie.java   28 Nov 2002 00:21:14 -  1.26
  @@ -785,6 +785,9 @@
   throw new IllegalArgumentException(set-cookie header may not be 
null.);
   }
   
  +// Normalize domain name
  +domain = domain.toLowerCase();
  +
   /* Build the default path.  Per RFC 2109/4.3.1 this is the 
* request path up to, but not including, the right-most / charater.
*/
  
  
  
  1.13  +23 -4 
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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestCookie.java   27 Nov 2002 01:32:34 -  1.12
  +++ TestCookie.java   28 Nov 2002 00:21:14 -  1.13
  @@ -80,6 +80,7 @@
* @author dIon Gillard
* @author a href=mailto:[EMAIL PROTECTED];John Evans/a
* @author Marc A. Saegesser
  + * @author a href=mailto:[EMAIL PROTECTED];Oleg Kalnichevski/a
* @version $Revision$
*/
   public class TestCookie extends TestCase {
  @@ -681,9 +682,27 @@
   }
   
   
  +/**
  + * Tests default constructor.
  + */
   public void testDefaultConsttuctor() throws Exception {
   Cookie dummy = new Cookie();
   assertEquals( dummy.toExternalForm(), noname=null );
  +}
  +
  +/**
  + * Tests whether domain attribute check is case-insensitive.
  + */
  +public void testDomainCaseInsensitivity() {
  +Header setCookie = new Header(
  +  Set-Cookie, name=value; domain=.sybase.com; path=/);
  +try {
  +Cookie[] parsed = Cookie.parse(www.Sybase.com, /, false, setCookie 
);
  +}
  +catch(HttpException e) {
  +e.printStackTrace();
  +fail(Unexpected exception:  + e.toString());
  +}
   }
   }
   
  
  
  

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




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

2002-11-26 Thread jsdever
jsdever 2002/11/26 17:32:34

  Modified:httpclient/src/java/org/apache/commons/httpclient
Cookie.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  Fixes for Cookie.java
  
  Fixes bugs:
  http://issues.apache.org/bugzilla/show_bug.cgi?id=6513
  http://issues.apache.org/bugzilla/show_bug.cgi?id=11223
  
  Whats Changed:
  1) Constructors throw IllegalArguementException if name parameter is
  null or blank. Current implementation of the cookie class accepts blank
  cookie name, which is disallowed if I interpret RFC-2109 right. Actually
  as far as I can see blank cookie values also violate the RFC-2109.
  Please let me know if you agree or disagree
  
  2) Default (parameterless) constructor added. The constructor assigns
  'noname' per default for a lack of a better idea on my part. Please let
  me know if you see a problem with this kind of naming convention
  
  3) Method Cookie.match() logs a warning message if a cookie has invalid state
  (domain and/or path not specified) and returns false.  IllegalArguementException
  is thrown if any of the input parameters is null.
  
  4) Path matching logic is somewhat improved as the current
  implementation is a bit flaky. Currently /foo and /foobar paths would
  match which is not supposed to be the case, unless I have missed something
  in the RFC
  
  5) All methods should react appropriately to null parameter input
  throwing an exception if null parameter is disallowed
  
  Contributed by: Oleg Kalnichevski
  
  Revision  ChangesPath
  1.25  +74 -22
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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Cookie.java   21 Oct 2002 14:39:22 -  1.24
  +++ Cookie.java   27 Nov 2002 01:32:34 -  1.25
  @@ -91,6 +91,7 @@
* @author Sean C. Sullivan
* @author a href=mailto:[EMAIL PROTECTED];John Evans/a
* @author Marc A. Saegesser
  + * @author a href=mailto:[EMAIL PROTECTED];Oleg Kalnichevski/a
* @version $Revision$ $Date$
*/
   
  @@ -99,6 +100,16 @@
   // --- Constructors
   
   /**
  + * Create a cookie. Default constructor 
  + * 
  + * The new cookie is assigned 
  + */
  +
  +public Cookie() {
  +this(null, noname, null, null, null, false);
  +}
  +
  +/**
* Create a cookie.
*
* @param namethe cookie name
  @@ -124,6 +135,12 @@
   public Cookie(String domain, String name, String value, String path, Date 
expires, boolean secure) {
   super(name, value);
   log.trace(enter Cookie(String, String, String, String, Date, boolean));
  +if (name == null) {
  +throw new IllegalArgumentException(Cookie name may not be null);
  +}
  +if (name.equals()) {
  +throw new IllegalArgumentException(Cookie name may not be blank);
  +}
   this.setPath(path);
   this.setDomain(domain);
   this.setExpiryDate(expires);
  @@ -448,7 +465,7 @@
* @param secure tttrue/tt if the request is using the HTTPS protocol
* @param date the time at which the request is submitted
*/
  -public boolean matches(String domain, int port, String path, boolean secure, 
Date now) {
  +public boolean matches(String domain, int port, String path, boolean secure, 
Date date) {
   log.trace(enter Cookie.matches(Strinng, int, String, boolean, Date);
   // FIXME: RFC2109 doesn't consider ports when filtering/matching
   //cookies. Quoting from Section 2 - Terminology:
  @@ -464,18 +481,32 @@
   //
   //The current implementation doesn't support RFC2965,
   //and ignores ports when matching cookies.
  +if (domain == null) {
  +throw new IllegalArgumentException(domain parameter may not be null);
  +}
  +if (path == null) {
  +throw new IllegalArgumentException(path parameter may not be null);
  +}
  +if (date == null) {
  +throw new IllegalArgumentException(date parameter may not be null);
  +}
  +if (getDomain() == null) {
  +log.warn(Invalid cookie state: domain not specified);
  +return false;
  +}
  +if (getPath() == null) {
  +log.warn(Invalid cookie state: path not specified);
  +return false;
  +}
  +
   domain = domain.toLowerCase();
   
  -// FIXME: Is path.startsWith(cookie.getPath()) enough?
  -//Or do we need to check 

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

2002-10-21 Thread oglueck
oglueck 2002/10/21 07:39:23

  Modified:httpclient/src/java/org/apache/commons/httpclient
Cookie.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  added more date format
  added date tests
  
  Revision  ChangesPath
  1.24  +7 -5  
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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Cookie.java   11 Oct 2002 07:37:46 -  1.23
  +++ Cookie.java   21 Oct 2002 14:39:22 -  1.24
   -1099,7 +1099,9 
  new SimpleDateFormat(EEE dd MMM yy HH:mm:ss z, Locale.US),
  new SimpleDateFormat(EEE dd MMM  HH:mm:ss z, Locale.US),
  new SimpleDateFormat(EEE, dd MMM yy HH:mm:ss z, Locale.US),
  -   new SimpleDateFormat(EEE, dd MMM  HH:mm:ss z, Locale.US)
  +   new SimpleDateFormat(EEE, dd MMM  HH:mm:ss z, Locale.US),
  +   new SimpleDateFormat(EEE, dd-MMM- HH-mm-ss z, Locale.US),
  +   new SimpleDateFormat(EEE dd-MMM- HH-mm-ss z, Locale.US)
  };
   
  /** Collator for Cookie comparisons.  Could be replaced with references to 
specific Locales. */
  
  
  
  1.11  +37 -4 
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestCookie.java   1 May 2002 07:07:50 -   1.10
  +++ TestCookie.java   21 Oct 2002 14:39:22 -  1.11
   -633,5 +633,38 
   fail(Threw wrong type of exception.  Expected 
IllegalArgumentException.);
   }
   }
  +
  +/**
  + * Tests several date formats.
  + */
  +public void testDateFormats() throws Exception {
  +//comma, dashes
  +checkDate(Thu, 01-Jan-70 00:00:10 GMT);
  +checkDate(Thu, 01-Jan-2070 00:00:10 GMT);
  +//no comma, dashes
  +checkDate(Thu 01-Jan-70 00:00:10 GMT);
  +checkDate(Thu 01-Jan-2070 00:00:10 GMT);
  +//comma, spaces
  +checkDate(Thu, 01 Jan 70 00:00:10 GMT);
  +checkDate(Thu, 01 Jan 2070 00:00:10 GMT);
  +//no comma, spaces
  +checkDate(Thu 01 Jan 70 00:00:10 GMT);
  +checkDate(Thu 01 Jan 2070 00:00:10 GMT);
  +//weird stuff
  +checkDate(Wed, 20-Nov-2002 09-38-33 GMT);
  +
  +
  +try {
  +checkDate(this aint a date);
  +fail(Date check is bogous);
  +} catch(Exception e) {
  +/* must fail */
  +}
  +}
  +
  +private void checkDate(String date) throws Exception {
  +Header setCookie = new Header(Set-Cookie, 
custno=12345;Expires='+date+');
  +Cookie.parse(localhost,/,setCookie);
  +}
   }
   
  
  
  

--
To unsubscribe, e-mail:   mailto:commons-dev-unsubscribe;jakarta.apache.org
For additional commands, e-mail: mailto:commons-dev-help;jakarta.apache.org




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

2002-05-01 Thread rwaldhoff

rwaldhoff02/05/01 00:07:50

  Modified:httpclient/src/java/org/apache/commons/httpclient
Cookie.java
   httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  fix bugzilla bug 5279: single quotes around cookie's expires attribute
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5279
  
  Revision  ChangesPath
  1.18  +13 -4 
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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Cookie.java   23 Apr 2002 18:59:47 -  1.17
  +++ Cookie.java   1 May 2002 07:07:50 -   1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v
 1.17 2002/04/23 18:59:47 marcsaeg Exp $
  - * $Revision: 1.17 $
  - * $Date: 2002/04/23 18:59:47 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v
 1.18 2002/05/01 07:07:50 rwaldhoff Exp $
  + * $Revision: 1.18 $
  + * $Date: 2002/05/01 07:07:50 $
* 
*
* The Apache Software License, Version 1.1
  @@ -90,7 +90,7 @@
* @author Sean C. Sullivan
* @author a href=mailto:[EMAIL PROTECTED];John Evans/a
* @author Marc A. Saegesser
  - * @version $Revision: 1.17 $ $Date: 2002/04/23 18:59:47 $
  + * @version $Revision: 1.18 $ $Date: 2002/05/01 07:07:50 $
*/
   
   public class Cookie extends NameValuePair implements Serializable, Comparator {
  @@ -836,6 +836,15 @@
   } else if (name.equals(expires)) {
   boolean set = false;
   String expiryDate = parameters[j].getValue();
  +// trim single quotes around expiry if present
  +// see 
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5279
  +if(null != expiryDate) {
  +if(expiryDate.length()  1 
  +expiryDate.startsWith(') 
  +expiryDate.endsWith(')) {
  +expiryDate = 
expiryDate.substring(1,expiryDate.length()-1);
  +}
  +}
   for(int k=0;kexpiryFormats.length;k++) {
   try {
   Date date = expiryFormats[k].parse(expiryDate);
  
  
  
  1.10  +14 -4 
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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestCookie.java   23 Apr 2002 19:01:03 -  1.9
  +++ TestCookie.java   1 May 2002 07:07:50 -   1.10
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
 1.9 2002/04/23 19:01:03 marcsaeg Exp $
  - * $Revision: 1.9 $
  - * $Date: 2002/04/23 19:01:03 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
 1.10 2002/05/01 07:07:50 rwaldhoff Exp $
  + * $Revision: 1.10 $
  + * $Date: 2002/05/01 07:07:50 $
* 
*
* The Apache Software License, Version 1.1
  @@ -80,7 +80,7 @@
* @author dIon Gillard
* @author a href=mailto:[EMAIL PROTECTED];John Evans/a
* @author Marc A. Saegesser
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
*/
   public class TestCookie extends TestCase {
   
  @@ -184,6 +184,16 @@
   }
   
   // - More Tests
  +
  +// see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5279
  +public void testQuotedExpiresAttribute() throws Exception {
  +String headerValue = custno=12345;Expires='Thu, 01-Jan-2070 00:00:10 GMT';
  +Cookie[] cookies = Cookie.parse(DOMAIN_NAME,/,true,new Header(
  +set-cookie, headerValue));
  +assertNotNull(Expected some cookies,cookies);
  +assertEquals(Expected 1 cookie,1,cookies.length);
  +assertNotNull(Expected cookie to have 
getExpiryDate,cookies[0].getExpiryDate());
  +}
   
   public void testSecurityError() throws Exception {
   String headerValue = custno=12345;comment=test; version=1, +
  
  
  

--
To unsubscribe, e-mail:   mailto:[EMAIL 

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

2002-03-03 Thread marcsaeg

marcsaeg02/03/03 19:22:18

  Modified:httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
  Log:
  Changed expected version from 1 to 0 for 'Netscape' style cookies.  Changed
  testParseWithAll() to explicitly set Version=1 and verify that version
  is properly set.
  
  Revision  ChangesPath
  1.7   +9 -8  
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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestCookie.java   18 Feb 2002 23:42:07 -  1.6
  +++ TestCookie.java   4 Mar 2002 03:22:18 -   1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
 1.6 2002/02/18 23:42:07 dion Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/02/18 23:42:07 $
  + * $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 $
* 
*
* The Apache Software License, Version 1.1
  @@ -79,7 +79,7 @@
* @author Rod Waldhoff
* @author dIon Gillard
* @author a href=mailto:[EMAIL PROTECTED];John Evans/a
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
*/
   public class TestCookie extends TestCase {
   
  @@ -209,7 +209,7 @@
   assertEquals(Domain,127.0.0.1,parsed[0].getDomain());
   assertEquals(Path,/,parsed[0].getPath());
   assertTrue(Secure,!parsed[0].getSecure());
  -assertEquals(Version,1,parsed[0].getVersion());
  +assertEquals(Version,0,parsed[0].getVersion());
   }
   
   public void testParseNoName() throws Exception {
  @@ -225,7 +225,7 @@
   assertEquals(Domain,127.0.0.1,parsed[0].getDomain());
   assertEquals(Path,/,parsed[0].getPath());
   assertTrue(Secure,!parsed[0].getSecure());
  -assertEquals(Version,1,parsed[0].getVersion());
  +assertEquals(Version,0,parsed[0].getVersion());
   }
   
   public void testParseNoValue() throws Exception {
  @@ -241,7 +241,7 @@
   assertEquals(Domain,127.0.0.1,parsed[0].getDomain());
   assertEquals(Path,/,parsed[0].getPath());
   assertTrue(Secure,!parsed[0].getSecure());
  -assertEquals(Version,1,parsed[0].getVersion());
  +assertEquals(Version,0,parsed[0].getVersion());
   }
   
   public void testParseWithWhiteSpace() throws Exception {
  @@ -336,7 +336,7 @@
   }
   
   public void testParseWithAll() throws Exception {
  -Header setCookie = new 
Header(Set-Cookie,cookie-name=cookie-value;Path=/commons;Domain=.apache.org;Comment=This
 is a comment.;secure;Expires=Thu, 01-Jan-1970 00:00:10 GMT);
  +Header setCookie = new 
Header(Set-Cookie,cookie-name=cookie-value;Version=1;Path=/commons;Domain=.apache.org;Comment=This
 is a comment.;secure;Expires=Thu, 01-Jan-1970 00:00:10 GMT);
   Cookie[] parsed = 
Cookie.parse(.apache.org,/commons/httpclient,true,setCookie);
   assertEquals(Found 1 cookie.,1,parsed.length);
   assertEquals(Name,cookie-name,parsed[0].getName());
  @@ -346,6 +346,7 @@
   assertTrue(Secure,parsed[0].getSecure());
   assertEquals(new Date(1L),parsed[0].getExpiryDate());
   assertEquals(Comment,This is a comment.,parsed[0].getComment());
  +assertEquals(Version,1,parsed[0].getVersion());
   }
   
   public void testParseWithWrongDomain() throws Exception {
  
  
  

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]