hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r415068 - in /jakarta/httpcomponents/httpclient/trunk/src: java/org/apache/http/cookie/impl/ test/org/apache/http/cookie/impl/
Date Sat, 17 Jun 2006 21:51:44 GMT
Author: olegk
Date: Sat Jun 17 14:51:43 2006
New Revision: 415068

URL: http://svn.apache.org/viewvc?rev=415068&view=rev
Log:
Refactoring of the Netscape cookie draft spec

Added:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BasicDomainHandler.java
      - copied, changed from r409994, jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatDomainHandler.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDomainHandler.java   (with props)
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpec.java
      - copied, changed from r410049, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieNetscapeDraft.java
      - copied, changed from r413725, jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/cookie/TestCookieNetscapeDraft.java
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestNetscapeCookieAttribHandlers.java   (with props)
Removed:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatDomainHandler.java
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBrowserCompatCookieAttribHandlers.java
Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpec.java
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestAllCookieImpl.java
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBasicCookieAttribHandlers.java

Copied: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BasicDomainHandler.java (from r409994, jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatDomainHandler.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BasicDomainHandler.java?p2=jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BasicDomainHandler.java&p1=jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatDomainHandler.java&r1=409994&r2=415068&rev=415068&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatDomainHandler.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BasicDomainHandler.java Sat Jun 17 14:51:43 2006
@@ -33,9 +33,9 @@
 import org.apache.http.cookie.CookieOrigin;
 import org.apache.http.cookie.MalformedCookieException;
 
-public class BrowserCompatDomainHandler implements CookieAttributeHandler {
+public class BasicDomainHandler implements CookieAttributeHandler {
 
-    public BrowserCompatDomainHandler() {
+    public BasicDomainHandler() {
         super();
     }
     

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpec.java?rev=415068&r1=415067&r2=415068&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatSpec.java Sat Jun 17 14:51:43 2006
@@ -71,7 +71,7 @@
     public BrowserCompatSpec() {
         super();
         registerAttribHandler("path", new BasicPathHandler());
-        registerAttribHandler("domain", new BrowserCompatDomainHandler());
+        registerAttribHandler("domain", new BasicDomainHandler());
         registerAttribHandler("max-age", new BasicMaxAgeHandler());
         registerAttribHandler("secure", new BasicSecureHandler());
         registerAttribHandler("comment", new BasicCommentHandler());

Added: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDomainHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDomainHandler.java?rev=415068&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDomainHandler.java (added)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDomainHandler.java Sat Jun 17 14:51:43 2006
@@ -0,0 +1,104 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 2002-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */ 
+package org.apache.http.cookie.impl;
+
+import java.util.StringTokenizer;
+
+import org.apache.http.cookie.Cookie;
+import org.apache.http.cookie.CookieOrigin;
+import org.apache.http.cookie.MalformedCookieException;
+
+public class NetscapeDomainHandler extends BasicDomainHandler {
+
+    public NetscapeDomainHandler() {
+        super();
+    }
+
+    public void validate(final Cookie cookie, final CookieOrigin origin) 
+            throws MalformedCookieException {
+        super.validate(cookie, origin);
+        // Perform Netscape Cookie draft specific validation
+        String host = origin.getHost();
+        String domain = cookie.getDomain();
+        if (host.indexOf(".") >= 0) {
+            int domainParts = new StringTokenizer(domain, ".").countTokens();
+
+            if (isSpecialDomain(domain)) {
+                if (domainParts < 2) {
+                    throw new MalformedCookieException("Domain attribute \""
+                        + domain 
+                        + "\" violates the Netscape cookie specification for "
+                        + "special domains");
+                }
+            } else {
+                if (domainParts < 3) {
+                    throw new MalformedCookieException("Domain attribute \""
+                        + domain 
+                        + "\" violates the Netscape cookie specification");
+                }            
+            }
+        }
+    }
+
+   /**
+    * Checks if the given domain is in one of the seven special
+    * top level domains defined by the Netscape cookie specification.
+    * @param domain The domain.
+    * @return True if the specified domain is "special"
+    */
+   private static boolean isSpecialDomain(final String domain) {
+       final String ucDomain = domain.toUpperCase();
+       if (ucDomain.endsWith(".COM") 
+          || ucDomain.endsWith(".EDU")
+          || ucDomain.endsWith(".NET")
+          || ucDomain.endsWith(".GOV")
+          || ucDomain.endsWith(".MIL")
+          || ucDomain.endsWith(".ORG")
+          || ucDomain.endsWith(".INT")) {
+           return true;
+       }
+       return false;
+   }
+
+   public boolean match(Cookie cookie, CookieOrigin origin) {
+       if (cookie == null) {
+           throw new IllegalArgumentException("Cookie may not be null");
+       }
+       if (origin == null) {
+           throw new IllegalArgumentException("Cookie origin may not be null");
+       }
+       String host = origin.getHost();
+       String domain = cookie.getDomain();
+       if (domain == null) {
+           return false;
+       }
+       return host.endsWith(domain);
+   }
+
+}
\ No newline at end of file

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDomainHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDomainHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDomainHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpec.java (from r410049, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpec.java?p2=jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpec.java&p1=jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java&r1=410049&r2=415068&rev=415068&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/NetscapeDraftSpec.java Sat Jun 17 14:51:43 2006
@@ -1,5 +1,5 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java,v 1.11 2004/05/13 04:02:00 mbecke Exp $
+ * $HeadURL$
  * $Revision$
  * $Date$
  *
@@ -27,21 +27,17 @@
  *
  */
 
-package org.apache.commons.httpclient.cookie;
+package org.apache.http.cookie.impl;
 
-import java.util.StringTokenizer;
-import java.util.Date;
-import java.util.Locale;   
-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;
+import org.apache.http.Header;
+import org.apache.http.HeaderElement;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.cookie.CookieOrigin;
+import org.apache.http.cookie.MalformedCookieException;
+import org.apache.http.io.CharArrayBuffer;
 
 /**
- * <P>Netscape cookie draft specific cookie management functions
+ * Netscape cookie draft specific cookie management functions
  *
  * @author  B.C. Holmes
  * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
@@ -56,12 +52,18 @@
  * 
  * @since 2.0 
  */
-
 public class NetscapeDraftSpec extends CookieSpecBase {
 
     /** Default constructor */
     public NetscapeDraftSpec() {
         super();
+        registerAttribHandler("path", new BasicPathHandler());
+        registerAttribHandler("domain", new NetscapeDomainHandler());
+        registerAttribHandler("max-age", new BasicMaxAgeHandler());
+        registerAttribHandler("secure", new BasicSecureHandler());
+        registerAttribHandler("comment", new BasicCommentHandler());
+        registerAttribHandler("expires", new BasicExpiresHandler(
+                new String[] {"EEE, dd-MMM-yyyy HH:mm:ss z"}));
     }
 
     /**
@@ -85,186 +87,45 @@
       * 
       * @link http://wp.netscape.com/newsref/std/cookie_spec.html
       * 
-      * @param host the host from which the <tt>Set-Cookie</tt> value was
-      * received
-      * @param port the port from which the <tt>Set-Cookie</tt> value was
-      * received
-      * @param path the path from which the <tt>Set-Cookie</tt> value was
-      * received
-      * @param secure <tt>true</tt> when the <tt>Set-Cookie</tt> value was
-      * received over secure conection
       * @param header the <tt>Set-Cookie</tt> received from the server
       * @return an array of <tt>Cookie</tt>s parsed from the Set-Cookie value
       * @throws MalformedCookieException if an exception occurs during parsing
       * 
       * @since 3.0
       */
-    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.");
-        }
+    public Cookie[] parse(final Header header, final CookieOrigin origin) 
+            throws MalformedCookieException {
         if (header == null) {
-            throw new IllegalArgumentException("Header may not be null.");
+            throw new IllegalArgumentException("Header may not be null");
         }
-
-        if (path.trim().equals("")) {
-            path = PATH_DELIM;
+        if (origin == null) {
+            throw new IllegalArgumentException("Cookie origin may not be null");
         }
-        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 (int j = 0; j < parameters.length; j++) {
-                parseAttribute(parameters[j], cookie);
-            }
-        }
-        return new Cookie[] {cookie};
+        String headervalue = header.getValue();
+        return parse(new HeaderElement[] { HeaderElement.parse(headervalue) }, origin);
     }
 
-
-    /**
-      * Parse the cookie attribute and update the corresponsing {@link Cookie}
-      * properties as defined by the Netscape draft specification
-      *
-      * @param attribute {@link NameValuePair} cookie attribute from the
-      * <tt>Set- Cookie</tt>
-      * @param cookie {@link Cookie} to be updated
-      * @throws MalformedCookieException if an exception occurs during parsing
-      */
-    public void parseAttribute(
-        final NameValuePair attribute, final Cookie cookie)
-        throws MalformedCookieException {
-            
-        if (attribute == null) {
-            throw new IllegalArgumentException("Attribute may not be null.");
+    public Header[] formatCookies(final Cookie[] cookies) {
+        if (cookies == null) {
+            throw new IllegalArgumentException("Cookie array may not be null");
         }
-        if (cookie == null) {
-            throw new IllegalArgumentException("Cookie may not be null.");
+        if (cookies.length == 0) {
+            throw new IllegalArgumentException("Cookie array may not be empty");
         }
-        final String paramName = attribute.getName().toLowerCase();
-        final String paramValue = attribute.getValue();
-
-        if (paramName.equals("expires")) {
-
-            if (paramValue == null) {
-                throw new MalformedCookieException(
-                    "Missing value for expires attribute");
+        CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.length);
+        for (int i = 0; i < cookies.length; i++) {
+            Cookie cookie = cookies[i];
+            if (i > 0) {
+                buffer.append("; ");
             }
-            try {
-                DateFormat expiryFormat = new SimpleDateFormat(
-                    "EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US);
-                Date date = expiryFormat.parse(paramValue);
-                cookie.setExpiryDate(date);
-            } catch (ParseException e) {
-                throw new MalformedCookieException("Invalid expires "
-                    + "attribute: " + e.getMessage());
+            buffer.append(cookie.getName());
+            String s = cookie.getValue();
+            if (s != null) {
+                buffer.append("=");
+                buffer.append(s);
             }
-        } else {
-            super.parseAttribute(attribute, cookie);
         }
+        return new Header[] { new Header("Cookie", buffer.toString()) };
     }
 
-    /**
-     * Performs domain-match as described in the Netscape draft.
-     * @param host The target host.
-     * @param domain The cookie domain attribute.
-     * @return true if the specified host matches the given domain.
-     */
-    public boolean domainMatch(final String host, final String domain) {
-        return host.endsWith(domain);
-    }
-
-    /**
-      * Performs Netscape draft compliant {@link Cookie} validation
-      *
-      * @param host the host from which the {@link Cookie} was received
-      * @param port the port from which the {@link Cookie} was received
-      * @param path the path from which the {@link Cookie} was received
-      * @param secure <tt>true</tt> when the {@link Cookie} was received 
-      * using a secure connection
-      * @param cookie The cookie to validate.
-      * @throws MalformedCookieException if an exception occurs during
-      * validation
-      */
-    public void validate(String host, int port, String path, 
-        boolean secure, final Cookie cookie) 
-        throws MalformedCookieException {
-            
-        LOG.trace("enterNetscapeDraftCookieProcessor "
-            + "RCF2109CookieProcessor.validate(Cookie)");
-        // Perform generic validation
-        super.validate(host, port, path, secure, cookie);
-        // Perform Netscape Cookie draft specific validation
-        if (host.indexOf(".") >= 0) {
-            int domainParts = new StringTokenizer(cookie.getDomain(), ".")
-                .countTokens();
-
-            if (isSpecialDomain(cookie.getDomain())) {
-                if (domainParts < 2) {
-                    throw new MalformedCookieException("Domain attribute \""
-                        + cookie.getDomain() 
-                        + "\" violates the Netscape cookie specification for "
-                        + "special domains");
-                }
-            } else {
-                if (domainParts < 3) {
-                    throw new MalformedCookieException("Domain attribute \""
-                        + cookie.getDomain() 
-                        + "\" violates the Netscape cookie specification");
-                }            
-            }
-        }
-    }
-    
-    /**
-     * Checks if the given domain is in one of the seven special
-     * top level domains defined by the Netscape cookie specification.
-     * @param domain The domain.
-     * @return True if the specified domain is "special"
-     */
-    private static boolean isSpecialDomain(final String domain) {
-        final String ucDomain = domain.toUpperCase();
-        if (ucDomain.endsWith(".COM") 
-           || ucDomain.endsWith(".EDU")
-           || ucDomain.endsWith(".NET")
-           || ucDomain.endsWith(".GOV")
-           || ucDomain.endsWith(".MIL")
-           || ucDomain.endsWith(".ORG")
-           || ucDomain.endsWith(".INT")) {
-            return true;
-        }
-        return false;
-    }
 }

Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestAllCookieImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestAllCookieImpl.java?rev=415068&r1=415067&r2=415068&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestAllCookieImpl.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestAllCookieImpl.java Sat Jun 17 14:51:43 2006
@@ -40,8 +40,9 @@
         TestSuite suite = new TestSuite();
         suite.addTest(TestAbstractCookieSpec.suite());
         suite.addTest(TestBasicCookieAttribHandlers.suite());
-        suite.addTest(TestBrowserCompatCookieAttribHandlers.suite());
+        suite.addTest(TestNetscapeCookieAttribHandlers.suite());
         suite.addTest(TestBrowserCompatSpec.suite());
+        suite.addTest(TestCookieNetscapeDraft.suite());
         return suite;
     }
 

Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBasicCookieAttribHandlers.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBasicCookieAttribHandlers.java?rev=415068&r1=415067&r2=415068&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBasicCookieAttribHandlers.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBasicCookieAttribHandlers.java Sat Jun 17 14:51:43 2006
@@ -58,6 +58,156 @@
         junit.textui.TestRunner.main(testCaseName);
     }
 
+    public void testBasicDomainParse() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieAttributeHandler h = new BasicDomainHandler();
+        h.parse(cookie, "www.somedomain.com");
+        assertEquals("www.somedomain.com", cookie.getDomain());
+        assertTrue(cookie.isDomainAttributeSpecified());
+    }
+
+    public void testBasicDomainParseInvalid() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieAttributeHandler h = new BasicDomainHandler();
+        try {
+            h.parse(cookie, "");
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+        try {
+            h.parse(cookie, null);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+    }
+
+    public void testBasicDomainValidate1() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false); 
+        CookieAttributeHandler h = new BasicDomainHandler();
+        
+        cookie.setDomain(".somedomain.com");
+        h.validate(cookie, origin);
+
+        cookie.setDomain(".otherdomain.com");
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+        cookie.setDomain("www.otherdomain.com");
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+    }
+
+    public void testBasicDomainValidate2() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false); 
+        CookieAttributeHandler h = new BasicDomainHandler();
+        
+        cookie.setDomain("somehost");
+        h.validate(cookie, origin);
+
+        cookie.setDomain("otherhost");
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+    }
+
+    public void testBasicDomainValidate3() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false); 
+        CookieAttributeHandler h = new BasicDomainHandler();
+        
+        cookie.setDomain(".somedomain.com");
+        h.validate(cookie, origin);
+    }
+
+    public void testBasicDomainValidate4() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false); 
+        CookieAttributeHandler h = new BasicDomainHandler();
+        
+        cookie.setDomain(null);
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+    }
+    
+    public void testBasicDomainMatch1() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false); 
+        CookieAttributeHandler h = new BasicDomainHandler();
+
+        cookie.setDomain("somedomain.com");
+        assertTrue(h.match(cookie, origin));
+        
+        cookie.setDomain(".somedomain.com");
+        assertTrue(h.match(cookie, origin));
+    }
+
+    public void testBasicDomainMatch2() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false); 
+        CookieAttributeHandler h = new BasicDomainHandler();
+
+        cookie.setDomain("somedomain.com");
+        assertTrue(h.match(cookie, origin));
+        
+        cookie.setDomain(".somedomain.com");
+        assertTrue(h.match(cookie, origin));
+
+        cookie.setDomain(null);
+        assertFalse(h.match(cookie, origin));
+    }
+
+    public void testBasicDomainInvalidInput() throws Exception {
+        CookieAttributeHandler h = new BasicDomainHandler();
+        try {
+            h.parse(null, null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            h.validate(null, null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            h.validate(new Cookie("name", "value"), null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            h.match(null, null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            h.match(new Cookie("name", "value"), null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+
     public void testBasicPathParse() throws Exception {
         Cookie cookie = new Cookie("name", "value"); 
         CookieAttributeHandler h = new BasicPathHandler();

Copied: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieNetscapeDraft.java (from r413725, jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/cookie/TestCookieNetscapeDraft.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieNetscapeDraft.java?p2=jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieNetscapeDraft.java&p1=jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/cookie/TestCookieNetscapeDraft.java&r1=413725&r2=415068&rev=415068&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/cookie/TestCookieNetscapeDraft.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieNetscapeDraft.java Sat Jun 17 14:51:43 2006
@@ -1,5 +1,5 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieNetscapeDraft.java,v 1.2 2004/04/24 23:28:04 olegk Exp $
+ * $HeadURL$
  * $Revision$
  * $Date$
  * ====================================================================
@@ -26,17 +26,18 @@
  *
  */
 
-package org.apache.commons.httpclient.cookie;
+package org.apache.http.cookie.impl;
+
+import org.apache.http.Header;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.cookie.CookieOrigin;
+import org.apache.http.cookie.CookieSpec;
+import org.apache.http.cookie.MalformedCookieException;
 
 import junit.framework.Test;
+import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-import org.apache.commons.httpclient.Cookie;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.NameValuePair;
-
-
 /**
  * Test cases for Netscape cookie draft
  *
@@ -44,7 +45,7 @@
  * 
  * @version $Revision$
  */
-public class TestCookieNetscapeDraft extends TestCookieBase {
+public class TestCookieNetscapeDraft extends TestCase {
 
     // ------------------------------------------------------------ Constructor
 
@@ -52,120 +53,21 @@
         super(name);
     }
 
-
     // ------------------------------------------------------- TestCase Methods
 
-
     public static Test suite() {
         return new TestSuite(TestCookieNetscapeDraft.class);
     }
 
-    public void testParseAttributeInvalidAttrib() throws Exception {
-        CookieSpec cookiespec = new NetscapeDraftSpec();
-        try {
-            cookiespec.parseAttribute(null, null);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testParseAttributeInvalidCookie() throws Exception {
-        CookieSpec cookiespec = new NetscapeDraftSpec();
-        try {
-            cookiespec.parseAttribute(new NameValuePair("name", "value"), null);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testParseAttributeInvalidCookieExpires() throws Exception {
-        CookieSpec cookiespec = new NetscapeDraftSpec();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.parseAttribute(new NameValuePair("expires", null), cookie);
-            fail("MalformedCookieException must have been thrown");
-        } catch (MalformedCookieException expected) {
-        }
-    }
-
-    public void testParseWithNullHost() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new NetscapeDraftSpec();
-        try {
-            Cookie[] parsed = cookieParse(cookiespec, null, 80, "/", false, header);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithBlankHost() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new NetscapeDraftSpec();
-        try {
-            Cookie[] parsed = cookieParse(cookiespec, "  ", 80, "/", false, header);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithNullPath() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new NetscapeDraftSpec();
-        try {
-            Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, null, false, header);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithBlankPath() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new NetscapeDraftSpec();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "  ", false, header);
-        assertNotNull(parsed);
-        assertEquals(1, parsed.length);
-        assertEquals("/", parsed[0].getPath());
-    }
-
-    public void testParseWithNegativePort() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new NetscapeDraftSpec();
-        try {
-            Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", -80, null, false, header);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithInvalidHeader1() throws Exception {
-        CookieSpec cookiespec = new NetscapeDraftSpec();
-        try {
-            Cookie[] parsed = cookiespec.parse("127.0.0.1", 80, "/foo", false, (String)null);
-            fail("IllegalArgumentException should have been thrown.");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
     public void testParseAbsPath() throws Exception {
         Header header = new Header("Set-Cookie", "name1=value1;Path=/path/");
 
         CookieSpec cookiespec = new NetscapeDraftSpec();
-        Cookie[] parsed = cookieParse(cookiespec, "host", 80, "/path/", true, header);
+        CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookies.",1,parsed.length);
         assertEquals("Name","name1",parsed[0].getName());
         assertEquals("Value","value1",parsed[0].getValue());
@@ -177,7 +79,11 @@
         Header header = new Header("Set-Cookie", "name1=value1;Path=/");
 
         CookieSpec cookiespec = new NetscapeDraftSpec();
-        Cookie[] parsed = cookieParse(cookiespec, "host", 80, "/", true, header);
+        CookieOrigin origin = new CookieOrigin("host", 80, "/", true);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookies.",1,parsed.length);
         assertEquals("Name","name1",parsed[0].getName());
         assertEquals("Value","value1",parsed[0].getValue());
@@ -189,7 +95,11 @@
         Header header = new Header("Set-Cookie", "name1=value1;Path=whatever");
 
         CookieSpec cookiespec = new NetscapeDraftSpec();
-        Cookie[] parsed = cookieParse(cookiespec, "host", 80, "whatever", true, header);
+        CookieOrigin origin = new CookieOrigin("host", 80, "whatever", true);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookies.",1,parsed.length);
         assertEquals("Name","name1",parsed[0].getName());
         assertEquals("Value","value1",parsed[0].getValue());
@@ -202,9 +112,13 @@
 
         CookieSpec cookiespec = new NetscapeDraftSpec();
         try {
-            Cookie[] parsed = cookieParse(cookiespec, "a.com", 80, "/", false, header);
-            fail("HttpException exception should have been thrown");
-        } catch (HttpException e) {
+            CookieOrigin origin = new CookieOrigin("a.com", 80, "/", false);
+            Cookie[] parsed = cookiespec.parse(header, origin);
+            for (int i = 0; i < parsed.length; i++) {
+                cookiespec.validate(parsed[i], origin);
+            }
+            fail("MalformedCookieException exception should have been thrown");
+        } catch (MalformedCookieException e) {
             // expected
         }
     }
@@ -214,9 +128,13 @@
         
         CookieSpec cookiespec = new NetscapeDraftSpec();
         try {
-            Cookie[] parsed = cookieParse(cookiespec, "x.y.z", 80, "/", false, header);
-            fail("HttpException exception should have been thrown");
-        } catch (HttpException e) {
+            CookieOrigin origin = new CookieOrigin("x.y.z", 80, "/", false);
+            Cookie[] parsed = cookiespec.parse(header, origin);
+            for (int i = 0; i < parsed.length; i++) {
+                cookiespec.validate(parsed[i], origin);
+            }
+            fail("MalformedCookieException exception should have been thrown");
+        } catch (MalformedCookieException e) {
             // expected
         }
     }
@@ -224,15 +142,16 @@
     /**
      * Tests Netscape specific cookie formatting.
      */
-    
     public void testNetscapeCookieFormatting() throws Exception {
         Header header = new Header(
           "Set-Cookie", "name=value; path=/; domain=.mydomain.com");
         CookieSpec cookiespec = new NetscapeDraftSpec();
-        Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header );
-        cookiespec.validate("myhost.mydomain.com", 80, "/", false, cookies[0]);
-        String s = cookiespec.formatCookie(cookies[0]);
-        assertEquals("name=value", s);
+        CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
+        Cookie[] cookies = cookiespec.parse(header, origin);
+        cookiespec.validate(cookies[0], origin);
+        Header[] headers = cookiespec.formatCookies(cookies);
+        assertEquals(1, headers.length);
+        assertEquals("name=value", headers[0].getValue());
     }
     
     /**
@@ -242,16 +161,17 @@
         CookieSpec cookiespec = new NetscapeDraftSpec();
         Header header = new Header("Set-Cookie", 
             "name=value; path=/; domain=.mydomain.com; expires=Thu, 01-Jan-2070 00:00:10 GMT; comment=no_comment");
-        Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header );
-        cookiespec.validate("myhost.mydomain.com", 80, "/", false, cookies[0]);
+        CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
+        Cookie[] cookies = cookiespec.parse(header, origin);
+        cookiespec.validate(cookies[0], origin);
         header = new Header("Set-Cookie", 
             "name=value; path=/; domain=.mydomain.com; expires=Thu 01-Jan-2070 00:00:10 GMT; comment=no_comment");
         try {
-            cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header );
-            cookiespec.validate("myhost.mydomain.com", 80, "/", false, cookies[0]);
-            fail("MalformedCookieException must have been thrown");
-        }
-        catch (MalformedCookieException expected) {
+            cookies = cookiespec.parse(header, origin);
+            cookiespec.validate(cookies[0], origin);
+            fail("MalformedCookieException exception should have been thrown");
+        } catch (MalformedCookieException e) {
+            // expected
         }
     }
 
@@ -262,8 +182,9 @@
         CookieSpec cookiespec = new NetscapeDraftSpec();
         Header header = new Header("Set-Cookie", 
             "name=value; expires=Thu, 01-Jan-2006 00:00:00 ");
+        CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
         try {
-            cookiespec.parse("myhost.mydomain.com", 80, "/", false, header );
+            cookiespec.parse(header, origin);
             fail("MalformedCookieException should have been thrown");
         } catch (MalformedCookieException ex) {
             // expected
@@ -277,10 +198,56 @@
         Header header = new Header("Set-Cookie", "a=b,c");
 
         CookieSpec cookiespec = new NetscapeDraftSpec();
-        Cookie[] cookies = cookiespec.parse("localhost", 80, "/", false, header);
+        CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
+        Cookie[] cookies = cookiespec.parse(header, origin);
         assertEquals("number of cookies", 1, cookies.length);
         assertEquals("a", cookies[0].getName());
         assertEquals("b,c", cookies[0].getValue());
+    }
+ 
+    public void testFormatCookies() throws Exception {
+        Cookie c1 = new Cookie("name1", "value1");
+        c1.setDomain(".whatever.com");
+        c1.setDomainAttributeSpecified(true);
+        c1.setPath("/");
+        c1.setPathAttributeSpecified(true);
+
+        Cookie c2 = new Cookie("name2", "value2");
+        Cookie c3 = new Cookie("name3", null);
+        
+        CookieSpec cookiespec = new NetscapeDraftSpec();
+        Header[] headers = cookiespec.formatCookies(new Cookie[] {c1, c2, c3});
+        assertNotNull(headers);
+        assertEquals(1, headers.length);
+        assertEquals("name1=value1; name2=value2; name3", headers[0].getValue());
+    }    
+
+    public void testInvalidInput() throws Exception {
+        CookieSpec cookiespec = new NetscapeDraftSpec();
+        try {
+            cookiespec.parse(null, null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            cookiespec.parse(new Header("Set-Cookie", "name=value"), null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            cookiespec.formatCookies(null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            cookiespec.formatCookies(new Cookie[] {});
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
     }
     
 }

Added: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestNetscapeCookieAttribHandlers.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestNetscapeCookieAttribHandlers.java?rev=415068&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestNetscapeCookieAttribHandlers.java (added)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestNetscapeCookieAttribHandlers.java Sat Jun 17 14:51:43 2006
@@ -0,0 +1,168 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ *  Copyright 2002-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.cookie.impl;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.http.cookie.Cookie;
+import org.apache.http.cookie.CookieAttributeHandler;
+import org.apache.http.cookie.CookieOrigin;
+import org.apache.http.cookie.MalformedCookieException;
+
+public class TestNetscapeCookieAttribHandlers extends TestCase {
+
+    public TestNetscapeCookieAttribHandlers(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestNetscapeCookieAttribHandlers.class);
+    }
+
+    // ------------------------------------------------------------------- Main
+    public static void main(String args[]) {
+        String[] testCaseName = { TestNetscapeCookieAttribHandlers.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public void testNetscapeDomainValidate1() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false); 
+        CookieAttributeHandler h = new NetscapeDomainHandler();
+        
+        cookie.setDomain("somehost");
+        h.validate(cookie, origin);
+
+        cookie.setDomain("otherhost");
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+    }
+
+    public void testNetscapeDomainValidate2() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false); 
+        CookieAttributeHandler h = new NetscapeDomainHandler();
+        
+        cookie.setDomain(".somedomain.com");
+        h.validate(cookie, origin);
+
+        cookie.setDomain(".otherdomain.com");
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+        cookie.setDomain("www.otherdomain.com");
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+    }
+
+    public void testNetscapeDomainValidate3() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false); 
+        CookieAttributeHandler h = new NetscapeDomainHandler();
+        
+        cookie.setDomain(".a.com");
+        h.validate(cookie, origin);
+
+        cookie.setDomain(".com");
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+    }
+
+    public void testNetscapeDomainValidate4() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("www.a.b.c", 80, "/", false); 
+        CookieAttributeHandler h = new NetscapeDomainHandler();
+        
+        cookie.setDomain(".a.b.c");
+        h.validate(cookie, origin);
+
+        cookie.setDomain(".b.c");
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+    }
+    
+    public void testNetscapeDomainMatch1() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false); 
+        CookieAttributeHandler h = new NetscapeDomainHandler();
+
+        cookie.setDomain(null);
+        assertFalse(h.match(cookie, origin));
+        
+        cookie.setDomain(".somedomain.com");
+        assertTrue(h.match(cookie, origin));
+    }
+
+    public void testNetscapeDomainMatch2() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("www.whatever.somedomain.com", 80, "/", false); 
+        CookieAttributeHandler h = new NetscapeDomainHandler();
+
+        cookie.setDomain(".somedomain.com");
+        assertTrue(h.match(cookie, origin));
+    }
+
+    public void testBrowserCompatDomainInvalidInput() throws Exception {
+        CookieAttributeHandler h = new NetscapeDomainHandler();
+        try {
+            h.match(null, null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            h.match(new Cookie("name", "value"), null);
+            fail("IllegalArgumentException must have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+    
+}
\ No newline at end of file

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestNetscapeCookieAttribHandlers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestNetscapeCookieAttribHandlers.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestNetscapeCookieAttribHandlers.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message