changeset 1314:206d73d299d4

6349566: java.net.CookieManager doesn't set default domain Summary: Enforce default domain in CookieManager Reviewed-by: michaelm
author jccollet
date Mon, 25 May 2009 22:27:26 +0200
parents 3994c5c669cb
children dc3865883a5a
files src/share/classes/java/net/CookieManager.java test/java/net/CookieHandler/CookieManagerTest.java
diffstat 2 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/CookieManager.java	Sun May 24 16:35:32 2009 -0700
+++ b/src/share/classes/java/net/CookieManager.java	Mon May 25 22:27:26 2009 +0200
@@ -286,6 +286,14 @@
                             }
                             cookie.setPath(path);
                         }
+
+                        // As per RFC 2965, section 3.3.1:
+                        // Domain  Defaults to the effective request-host.  (Note that because
+                        // there is no dot at the beginning of effective request-host,
+                        // the default Domain can only domain-match itself.)
+                        if (cookie.getDomain() == null) {
+                            cookie.setDomain(uri.getHost());
+                        }
                         String ports = cookie.getPortlist();
                         if (ports != null) {
                             int port = uri.getPort();
--- a/test/java/net/CookieHandler/CookieManagerTest.java	Sun May 24 16:35:32 2009 -0700
+++ b/test/java/net/CookieHandler/CookieManagerTest.java	Mon May 25 22:27:26 2009 +0200
@@ -218,21 +218,22 @@
                 };
 
         // cookies without domain attributes
+        // RFC 2965 states that domain should default to host
         testPolicies[count] = CookiePolicy.ACCEPT_ALL;
         testCases[count++] = new CookieTestCase[]{
                 new CookieTestCase("Set-Cookie2",
                 "Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\"",
-                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\"",
+                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
                 "/acme/login"
                 ),
                 new CookieTestCase("Set-Cookie2",
                 "Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\"",
-                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\"",
+                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
                 "/acme/pickitem"
                 ),
                 new CookieTestCase("Set-Cookie2",
                 "Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\"",
-                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\"" + "; Shipping=\"FedEx\";$Path=\"/acme\"",
+                "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"" + "; Shipping=\"FedEx\";$Path=\"/acme\";$Domain=\""+localHostAddr+"\"",
                 "/acme/shipping"
                 )
                 };