Android CookieOrigin - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android CookieOrigin class.

This code example shows how to use the following methods:
public class TestNetscapeCookieAttribHandlers { 
 
    @Test 
    public void testNetscapeDomainValidate1() throws Exception { 
        BasicClientCookie cookie = new BasicClientCookie("name", "value");
        CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
        CookieAttributeHandler h = new NetscapeDomainHandler();
 
        cookie.setDomain("somehost");
        h.validate(cookie, origin);
 
        cookie.setDomain("otherhost");
        try { 
            h.validate(cookie, origin);
            Assert.fail("MalformedCookieException should have been thrown");
        } catch (MalformedCookieException ex) {
            // expected 
        } 
    } 
 
5
CodeRank
This code example shows how to use the following methods:
    } 
 
    @Test 
    public void testRFC2109DomainValidate4() throws Exception { 
        BasicClientCookie cookie = new BasicClientCookie("name", "value");
        CookieOrigin origin = new CookieOrigin("www.a.b.c", 80, "/", false);
        CookieAttributeHandler h = new RFC2109DomainHandler();
 
        cookie.setDomain(".a.b.c");
        h.validate(cookie, origin);
 
        cookie.setDomain(".b.c");
        try { 
            h.validate(cookie, origin);
            Assert.fail("MalformedCookieException should have been thrown");
        } catch (MalformedCookieException ex) {
            // expected 
        } 
        cookie.setDomain(".a.a.b.c");
        try { 

5
CodeRank
This code example shows how to use the following methods:
    @Test 
    public void testNetscapeCookieFormatting() throws Exception { 
        Header header = new BasicHeader(
          "Set-Cookie", "name=value; path=/; domain=.mydomain.com"); 
        CookieSpec cookiespec = new NetscapeDraftSpec();
        CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
        List<Cookie> cookies = cookiespec.parse(header, origin);
        cookiespec.validate(cookies.get(0), origin);
        List<Header> headers = cookiespec.formatCookies(cookies);
        Assert.assertEquals(1, headers.size());
        Assert.assertEquals("name=value", headers.get(0).getValue());
    } 
 
    /** 
     * Tests Netscape specific expire attribute parsing. 
     */ 
    @Test 
    public void testNetscapeCookieExpireAttribute() throws Exception { 
        CookieSpec cookiespec = new NetscapeDraftSpec();
        Header header = new BasicHeader("Set-Cookie",
5
CodeRank
This code example shows how to use the following methods:
    } 
 
    @Test 
    public void testNetscapeCookieParsing() throws Exception { 
        CookieSpec cookiespec = new BestMatchSpec();
        CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
 
        Header header = new BasicHeader("Set-Cookie",
            "name=value; path=/; domain=.mydomain.com; expires=Thu, 01-Jan-2070 00:00:10 GMT; comment=no_comment"); 
        List<Cookie> cookies = cookiespec.parse(header, origin);
        cookiespec.validate(cookies.get(0), origin);
        Assert.assertEquals(1, cookies.size());
        header = new BasicHeader("Set-Cookie",
            "name=value; path=/; domain=.mydomain.com; expires=Thu, 01-Jan-2070 00:00:10 GMT; version=1"); 
        cookies = cookiespec.parse(header, origin);
        cookiespec.validate(cookies.get(0), origin);
        Assert.assertEquals(1, cookies.size());
    } 
 
    @Test 
    public void testCookieStandardCompliantParsing() throws Exception { 
5
CodeRank
This code example shows how to use the following methods:
    @Test 
    public void testParse() throws Exception { 
        BasicClientCookie cookie = new BasicClientCookie("name", "value");
 
        cookie.setDomain(".jp");
        Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.jp", 80, "/stuff", false)));
 
        cookie.setDomain(".ac.jp");
        Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.ac.jp", 80, "/stuff", false)));
 
        cookie.setDomain(".any.tokyo.jp");
        Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.any.tokyo.jp", 80, "/stuff", false)));
 
        // exception 
        cookie.setDomain(".metro.tokyo.jp");
        Assert.assertTrue(filter.match(cookie, new CookieOrigin("apache.metro.tokyo.jp", 80, "/stuff", false)));
    } 
 
    @Test 
    public void testUnicode() throws Exception { 
4
CodeRank
This code example shows how to use the following methods:
    @Test 
    public void testRFC2109CookieFormatting() throws Exception { 
        CookieSpec cookiespec = new RFC2109Spec(null, false); 
        Header header = new BasicHeader("Set-Cookie", 
            "name=\"value\"; version=1; path=\"/\"; domain=\".mydomain.com\""); 
        CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false); 
        List<Cookie> cookies  = cookiespec.parse(header, origin); 
        cookiespec.validate(cookies.get(0), origin); 
        List<Header> headers = cookiespec.formatCookies(cookies); 
        Assert.assertNotNull(headers); 
        Assert.assertEquals(1, headers.size()); 
        Assert.assertEquals("$Version=1; name=\"value\"; $Path=\"/\"; $Domain=\".mydomain.com\"", 
                headers.get(0).getValue()); 
 
        header = new BasicHeader( "Set-Cookie", 
            "name=value; path=/; domain=.mydomain.com"); 
        cookies = cookiespec.parse(header, origin); 
        cookiespec.validate(cookies.get(0), origin); 
        headers = cookiespec.formatCookies(cookies); 
        Assert.assertNotNull(headers); 

5
CodeRank
This code example shows how to use the following methods:
    } 
 
    @Test 
    public void testBasicDomainValidate2() throws Exception { 
        BasicClientCookie cookie = new BasicClientCookie("name", "value");
        CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
        CookieAttributeHandler h = new BasicDomainHandler();
 
        cookie.setDomain("somehost");
        h.validate(cookie, origin);
 
        cookie.setDomain("otherhost");
        try { 
            h.validate(cookie, origin);
            Assert.fail("MalformedCookieException should have been thrown");
        } catch (MalformedCookieException ex) {
            // expected 
        } 
    } 
 
5
CodeRank
This code example shows how to use the following methods:getHost
        // Validate the cookies domain attribute.  NOTE:  Domains without  
        // any dots are allowed to support hosts on private LANs that don't  
        // have DNS names.  Since they have no dots, to domain-match the  
        // request-host and domain must be identical for the cookie to sent  
        // back to the origin-server. 
        String host = origin.getHost();
        String domain = cookie.getDomain();
        if (domain == null) {
            throw new MalformedCookieException("Cookie domain may not be null");
        } 
        if (host.contains(".")) {
            // Not required to have at least two dots.  RFC 2965. 
            // A Set-Cookie2 with Domain=ajax.com will be accepted. 
 
            // domain must match host 
            if (!host.endsWith(domain)) {
                if (domain.startsWith(".")) {
                    domain = domain.substring(1, domain.length());
                } 
                if (!host.equals(domain)) { 
4
CodeRank
This code example shows how to use the following methods:isSecure
            throw new IllegalArgumentException("Cookie may not be null");
        } 
        if (origin == null) {
            throw new IllegalArgumentException("Cookie origin may not be null");
        } 
        return !cookie.isSecure() || origin.isSecure();
    } 
     
} 
5
CodeRank
This code example shows how to use the following methods:getPath
    public void validate(final Cookie cookie, final CookieOrigin origin) 
            throws MalformedCookieException { 
        if (!match(cookie, origin)) {
            throw new MalformedCookieException(
                "Illegal path attribute \"" + cookie.getPath() 
                + "\". Path of origin: \"" + origin.getPath() + "\"");
        } 
    } 
     
    public boolean match(final Cookie cookie, final CookieOrigin origin) {
        if (cookie == null) {
            throw new IllegalArgumentException("Cookie may not be null");
        } 
        if (origin == null) {
            throw new IllegalArgumentException("Cookie origin may not be null");
        } 
        String targetpath = origin.getPath();
        String topmostPath = cookie.getPath();
        if (topmostPath == null) {
            topmostPath = "/";

4
CodeRank

Related Android CookieOrigin Questions & Answers:

See Code Examples for Android CookieOrigin Methods: