コード例 #1
0
 @Test
 public void testInvalidInput() throws Exception {
   CookieSpec cookiespec = new BrowserCompatSpec();
   try {
     cookiespec.parse(null, null);
     Assert.fail("IllegalArgumentException must have been thrown");
   } catch (IllegalArgumentException ex) {
     // expected
   }
   try {
     cookiespec.parse(new BasicHeader("Set-Cookie", "name=value"), null);
     Assert.fail("IllegalArgumentException must have been thrown");
   } catch (IllegalArgumentException ex) {
     // expected
   }
   try {
     cookiespec.validate(null, null);
     Assert.fail("IllegalArgumentException must have been thrown");
   } catch (IllegalArgumentException ex) {
     // expected
   }
   try {
     cookiespec.validate(new BasicClientCookie("name", null), null);
     Assert.fail("IllegalArgumentException must have been thrown");
   } catch (IllegalArgumentException ex) {
     // expected
   }
   try {
     cookiespec.match(null, null);
     Assert.fail("IllegalArgumentException must have been thrown");
   } catch (IllegalArgumentException ex) {
     // expected
   }
   try {
     cookiespec.match(new BasicClientCookie("name", null), null);
     Assert.fail("IllegalArgumentException must have been thrown");
   } catch (IllegalArgumentException ex) {
     // expected
   }
   try {
     cookiespec.formatCookies(null);
     Assert.fail("IllegalArgumentException must have been thrown");
   } catch (IllegalArgumentException ex) {
     // expected
   }
   try {
     List<Cookie> cookies = new ArrayList<Cookie>();
     cookiespec.formatCookies(cookies);
     Assert.fail("IllegalArgumentException must have been thrown");
   } catch (IllegalArgumentException ex) {
     // expected
   }
 }
コード例 #2
0
 @Test
 public void testMatchNullCookiePath() throws Exception {
   CookieSpec cookiespec = new BrowserCompatSpec();
   BasicClientCookie cookie = new BasicClientCookie("name", "value");
   cookie.setDomain("host");
   CookieOrigin origin = new CookieOrigin("host", 80, "/", false);
   Assert.assertTrue(cookiespec.match(cookie, origin));
 }
コード例 #3
0
 @Test
 public void testCookieMismatch3() throws Exception {
   CookieSpec cookiespec = new BrowserCompatSpec();
   BasicClientCookie cookie = new BasicClientCookie("name", "value");
   cookie.setDomain("host");
   cookie.setPath("/foobar");
   CookieOrigin origin = new CookieOrigin("host", 80, "/foo", false);
   Assert.assertFalse(cookiespec.match(cookie, origin));
 }
コード例 #4
0
 @Test
 public void testCookieMatch3() throws Exception {
   CookieSpec cookiespec = new BrowserCompatSpec();
   BasicClientCookie cookie = new BasicClientCookie("name", "value");
   cookie.setDomain(".whatever.com");
   cookie.setPath("/");
   CookieOrigin origin = new CookieOrigin(".really.whatever.com", 80, "/", false);
   Assert.assertTrue(cookiespec.match(cookie, origin));
 }
コード例 #5
0
  @Test
  public void testInvalidSecondDomainLevelCookieMatch2() throws Exception {
    BasicClientCookie cookie = new BasicClientCookie("name", null);
    cookie.setDomain("sourceforge.net");
    cookie.setAttribute(ClientCookie.DOMAIN_ATTR, cookie.getDomain());
    cookie.setPath("/");
    cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath());

    CookieSpec cookiespec = new BrowserCompatSpec();
    CookieOrigin origin = new CookieOrigin("antisourceforge.net", 80, "/", false);
    Assert.assertFalse(cookiespec.match(cookie, origin));
  }
コード例 #6
0
 private List<Cookie> filter(CookieOrigin origin) {
   List<Cookie> matchedCookies = new ArrayList<Cookie>();
   Date now = new Date();
   CookieSpec cookieSpec = createSpec();
   for (Cookie cookie : store.getCookies()) {
     if (!cookie.isExpired(now)) {
       if (cookieSpec.match(cookie, origin)) {
         matchedCookies.add(cookie);
       }
     }
   }
   return matchedCookies;
 }
コード例 #7
0
  @Test
  public void testInvalidMatchDomain() throws Exception {
    BasicClientCookie cookie = new BasicClientCookie("name", null);
    cookie.setDomain("beta.gamma.com");
    cookie.setAttribute(ClientCookie.DOMAIN_ATTR, cookie.getDomain());
    cookie.setPath("/");
    cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath());

    CookieSpec cookiespec = new BrowserCompatSpec();
    CookieOrigin origin = new CookieOrigin("alpha.beta.gamma.com", 80, "/", false);
    cookiespec.validate(cookie, origin);
    Assert.assertTrue(cookiespec.match(cookie, origin));
  }