Search in sources :

Example 1 with CookieAttributeHandler

use of org.apache.http.cookie.CookieAttributeHandler in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainValidate1.

@Test
public void testDomainValidate1() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain("somehost");
    h.validate(cookie, origin);
    cookie.setDomain("otherhost");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 2 with CookieAttributeHandler

use of org.apache.http.cookie.CookieAttributeHandler in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainMatch1.

@Test
public void testDomainMatch1() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain(null);
    Assert.assertFalse(h.match(cookie, origin));
    cookie.setDomain(".somedomain.com");
    Assert.assertTrue(h.match(cookie, origin));
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 3 with CookieAttributeHandler

use of org.apache.http.cookie.CookieAttributeHandler in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainHostPortValidate.

@Test
public void testDomainHostPortValidate() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain("somehost:80");
    h.validate(cookie, origin);
    cookie.setDomain("somehost:1234");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 4 with CookieAttributeHandler

use of org.apache.http.cookie.CookieAttributeHandler in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainValidate2.

@Test
public void testDomainValidate2() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain(".somedomain.com");
    h.validate(cookie, origin);
    cookie.setDomain(".otherdomain.com");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
    cookie.setDomain("www.otherdomain.com");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 5 with CookieAttributeHandler

use of org.apache.http.cookie.CookieAttributeHandler in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainValidate3.

@Test
public void testDomainValidate3() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain(".a.com");
    h.validate(cookie, origin);
    cookie.setDomain(".com");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Aggregations

CookieAttributeHandler (org.apache.http.cookie.CookieAttributeHandler)15 MalformedCookieException (org.apache.http.cookie.MalformedCookieException)11 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)9 Test (org.junit.Test)9 CookieOrigin (org.apache.http.cookie.CookieOrigin)8 ArrayList (java.util.ArrayList)6 HeaderElement (org.apache.http.HeaderElement)6 NameValuePair (org.apache.http.NameValuePair)6 Cookie (org.apache.http.cookie.Cookie)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ClientCookie (org.apache.http.cookie.ClientCookie)3