commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie TestCookieCompatibilitySpec.java TestCookieIgnoreSpec.java
Date Tue, 27 Apr 2004 22:35:21 GMT
olegk       2004/04/27 15:35:21

  Modified:    httpclient/src/java/org/apache/commons/httpclient/cookie
                        CookieSpec.java CookieSpecBase.java
                        IgnoreCookiesSpec.java RFC2109Spec.java
               httpclient/src/test/org/apache/commons/httpclient/cookie
                        TestCookieCompatibilitySpec.java
                        TestCookieIgnoreSpec.java
  Log:
  PR #28566 (Handling sub-domain cookies)
  
  Changelog:
  
  * CookieSpec interface extended to expose path & domain matching methods
  * Browser compatibility domain matching algorithm modified to mimic the (mis-)behavior of
common browsers
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  Changes    Path
  1.9       +19 -3     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpec.java
  
  Index: CookieSpec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpec.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CookieSpec.java	18 Apr 2004 23:51:37 -0000	1.8
  +++ CookieSpec.java	27 Apr 2004 22:35:21 -0000	1.9
  @@ -151,6 +151,22 @@
           final Cookie cookies[]);
   
       /**
  +     * Performs domain-match as defined by the cookie specification.
  +     * @param host The target host.
  +     * @param domain The cookie domain attribute.
  +     * @return true if the specified host matches the given domain.
  +     */
  +    boolean domainMatch(final String host, final String domain);
  +
  +    /**
  +     * Performs path-match as defined by the cookie specification.
  +     * @param path The target path.
  +     * @param topmostPath The cookie path attribute.
  +     * @return true if the paths match
  +     */
  +    boolean pathMatch(final String path, final String topmostPath);
  +
  +    /**
        * Create a <tt>"Cookie"</tt> header value for an array of cookies.
        *
        * @param cookie the cookie to be formatted as string
  
  
  
  1.26      +12 -19    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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- CookieSpecBase.java	24 Apr 2004 23:51:57 -0000	1.25
  +++ CookieSpecBase.java	27 Apr 2004 22:35:21 -0000	1.26
  @@ -485,30 +485,23 @@
       }
   
       /**
  -     * Performs a domain-match as described in RFC2109.
  -     * @param host The host to check.
  -     * @param domain The domain.
  +     * Performs domain-match as implemented in common browsers.
  +     * @param host The target host.
  +     * @param domain The cookie domain attribute.
        * @return true if the specified host matches the given domain.
        */
  -    private static boolean domainMatch(String host, String domain) {
  -        boolean match = host.equals(domain) 
  -            || (domain.startsWith(".") && host.endsWith(domain));
  -
  -        return match;
  +    public boolean domainMatch(final String host, final String domain) {
  +        return host.endsWith(domain);
       }
   
       /**
  -     * Performs a path-match slightly smarter than a straight-forward startsWith
  -     * check.
  -     * @param path The path to check.
  -     * @param topmostPath The path to check against.
  +     * Performs path-match as implemented in common browsers.
  +     * @param path The target path.
  +     * @param topmostPath The cookie path attribute.
        * @return true if the paths match
        */
  -    private static boolean pathMatch(
  -        final String path, final String topmostPath) {
  -            
  +    public boolean pathMatch(final String path, final String topmostPath) {
           boolean match = path.startsWith (topmostPath);
  -        
           // 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()) {
  
  
  
  1.4       +17 -3     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java
  
  Index: IgnoreCookiesSpec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IgnoreCookiesSpec.java	18 Apr 2004 23:51:37 -0000	1.3
  +++ IgnoreCookiesSpec.java	27 Apr 2004 22:35:21 -0000	1.4
  @@ -119,4 +119,18 @@
           throws MalformedCookieException, IllegalArgumentException {
       }
   
  +    /**
  +     * @return <code>false</code>
  +     */
  +    public boolean domainMatch(final String host, final String domain) {
  +        return false;
  +    }
  +
  +    /**
  +     * @return <code>false</code>
  +     */
  +    public boolean pathMatch(final String path, final String topmostPath) {
  +        return false;
  +    }
  +
   }
  
  
  
  1.19      +16 -3     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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- RFC2109Spec.java	25 Apr 2004 11:57:39 -0000	1.18
  +++ RFC2109Spec.java	27 Apr 2004 22:35:21 -0000	1.19
  @@ -162,6 +162,18 @@
           }
       }
   
  +    /**
  +     * Performs domain-match as defined by the RFC2109.
  +     * @param host The target host.
  +     * @param domain The cookie domain attribute.
  +     * @return true if the specified host matches the given domain.
  +     */
  +    public boolean domainMatch(String host, String domain) {
  +        boolean match = host.equals(domain) 
  +            || (domain.startsWith(".") && host.endsWith(domain));
  +
  +        return match;
  +    }
   
       /**
        * Return a name/value string suitable for sending in a <tt>"Cookie"</tt>
  @@ -267,4 +279,5 @@
           }
           return buffer.toString();
       }
  +
   }
  
  
  
  1.5       +15 -6     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java
  
  Index: TestCookieCompatibilitySpec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestCookieCompatibilitySpec.java	25 Apr 2004 11:57:39 -0000	1.4
  +++ TestCookieCompatibilitySpec.java	27 Apr 2004 22:35:21 -0000	1.5
  @@ -778,8 +778,7 @@
       }
   
       /**
  -     * Tests if that invalid second domain level cookie gets 
  -     * rejected in the strict mode, but gets accepted in the
  +     * Tests if invalid second domain level cookie gets accepted in the
        * browser compatibility mode.
        */
       public void testSecondDomainLevelCookie() throws Exception {
  @@ -937,6 +936,16 @@
           assertEquals("name1", matched[0].getName());
           assertEquals("name2", matched[1].getName());
           assertEquals("name3", matched[2].getName());
  +    }
  +
  +    public void testInvalidMatchDomain() throws Exception {
  +        Cookie cookie = new Cookie("beta.gamma.com", "name", null, "/", null, false); 
  +        cookie.setDomainAttributeSpecified(true);
  +        cookie.setPathAttributeSpecified(true);
  +
  +        CookieSpec cookiespec = new CookieSpecBase();
  +        cookiespec.validate("alpha.beta.gamma.com", 80, "/", false, cookie);
  +        assertTrue(cookiespec.match("alpha.beta.gamma.com", 80, "/", false, cookie));
       }
   
       public void testFormatInvalidCookie() throws Exception {
  
  
  
  1.3       +7 -4      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java
  
  Index: TestCookieIgnoreSpec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestCookieIgnoreSpec.java	25 Apr 2004 11:57:39 -0000	1.2
  +++ TestCookieIgnoreSpec.java	27 Apr 2004 22:35:21 -0000	1.3
  @@ -104,6 +104,9 @@
           cookiespec.validate("host", 80, "/", false, (Cookie)null);
           cookiespec.match("host", 80, "/", false, (Cookie)null);
           cookiespec.match("host", 80, "/", false, (Cookie [])null);
  +        cookiespec.domainMatch(null, null);
  +        cookiespec.pathMatch(null, null);
  +        cookiespec.match("host", 80, "/", false, (Cookie [])null);
           cookiespec.formatCookie(null);
           cookiespec.formatCookies(null);
           cookiespec.formatCookieHeader((Cookie)null);
  
  
  

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


Mime
View raw message