jdk/test/java/net/CookieHandler/B6644726.java
changeset 4154 afd948aaf965
parent 480 c309ca1d3a86
child 5506 202f599c92aa
equal deleted inserted replaced
4153:c019b5df1bf5 4154:afd948aaf965
    21  * have any questions.
    21  * have any questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 6644726
    26  * @bug 6644726 6873543
    27  * @summary Cookie management issues
    27  * @summary Cookie management issues
    28  */
    28  */
    29 
    29 
    30 import java.net.*;
    30 import java.net.*;
    31 import java.util.*;
    31 import java.util.*;
   168             fail("Missing a cookie on port 80");
   168             fail("Missing a cookie on port 80");
   169         }
   169         }
   170         if (isIn(clst, "myCookie8=")) {
   170         if (isIn(clst, "myCookie8=")) {
   171             fail("A cookie with an invalid port list was returned");
   171             fail("A cookie with an invalid port list was returned");
   172         }
   172         }
       
   173 
       
   174         // Test httpOnly flag (CR# 6873543)
       
   175         lst.clear();
       
   176         map.clear();
       
   177         cm.getCookieStore().removeAll();
       
   178         lst.add("myCookie11=httpOnlyTest; httpOnly");
       
   179         map.put("Set-Cookie", lst);
       
   180         uri = new URI("http://www.sun.com/");
       
   181         cm.put(uri, map);
       
   182         m = cm.get(uri, emptyMap);
       
   183         clst = m.get("Cookie");
       
   184         // URI scheme was http: so we should get the cookie
       
   185         if (!isIn(clst, "myCookie11=")) {
       
   186             fail("Missing cookie with httpOnly flag");
       
   187         }
       
   188         uri = new URI("javascript://www.sun.com/");
       
   189         m = cm.get(uri, emptyMap);
       
   190         clst = m.get("Cookie");
       
   191         // URI scheme was neither http or https so we shouldn't get the cookie
       
   192         if (isIn(clst, "myCookie11=")) {
       
   193             fail("Should get the cookie with httpOnly when scheme is javascript:");
       
   194         }
   173     }
   195     }
   174 
   196 
   175     private static boolean isIn(List<String> lst, String cookie) {
   197     private static boolean isIn(List<String> lst, String cookie) {
   176         if (lst == null || lst.isEmpty()) {
   198         if (lst == null || lst.isEmpty()) {
   177             return false;
   199             return false;