Search in sources :

Example 66 with CookieManager

use of java.net.CookieManager in project j2objc by google.

the class CookiesTest method testCookieStoreGetWithSecure.

// TODO(tball): enable when libcore is updated with latest fixes.
/**
     * Regression test for http://b/25682357 /
     * https://code.google.com/p/android/issues/detail?id=193475
     * CookieStoreImpl.get(URI) not handling ports properly in the absence of an explicit cookie
     * Domain.
     *
    public void testCookieStoreGetWithPort() throws Exception {
        CookieStore cookieStore = new CookieManager().getCookieStore();
        HttpCookie cookie = new HttpCookie("theme", "light");
        // Deliberately not setting the cookie domain or path.
        cookieStore.add(new URI("http://a.com:12345"), cookie);

        // CookieStoreImpl must ignore the port during retrieval when domain is not set.
        assertEquals(1, cookieStore.get(new URI("http://a.com:12345/path1")).size());
        assertEquals(1, cookieStore.get(new URI("http://a.com/path1")).size());
    }
    */
public void testCookieStoreGetWithSecure() throws Exception {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    HttpCookie cookie = createCookie("theme", "light", "a.com", "/path");
    cookie.setSecure(true);
    cookieStore.add(new URI("https://a.com/path"), cookie);
    // CookieStoreImpl on Android ignores the "Secure" attribute. The RI implements the secure
    // check in CookieStoreImpl. For safety / app compatibility, if this is changed Android
    // should probably implement it in both places.
    assertEquals(1, cookieStore.get(new URI("http://a.com/path")).size());
    assertEquals(1, cookieStore.get(new URI("https://a.com/path")).size());
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie) URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 67 with CookieManager

use of java.net.CookieManager in project j2objc by google.

the class CookiesTest method testCookieStoreEviction.

public void testCookieStoreEviction() throws Exception {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    HttpCookie themeCookie = createCookie("theme", "light", "a.com", "/");
    cookieStore.add(new URI("http://a.com/"), themeCookie);
    HttpCookie sidCookie = createCookie("sid", "mysid", "a.com", "/");
    cookieStore.add(new URI("http://a.com/"), sidCookie);
    HttpCookie replacementThemeCookie = createCookie("theme", "dark", "a.com", "/");
    cookieStore.add(new URI("http://a.com/"), replacementThemeCookie);
    // toString() is used below to avoid confusion with assertEquals():
    // HttpCookie.equals() is implemented so that it only checks name, path and domain
    // attributes but we also want to check the value.
    assertEquals("[sid=\"mysid\";$Path=\"/\";$Domain=\"a.com\", " + "theme=\"dark\";$Path=\"/\";$Domain=\"a.com\"]", cookieStore.get(new URI("http://a.com/")).toString());
    HttpCookie replacementSidCookie = createCookie("sid", "mynewsid", "A.cOm", "/");
    cookieStore.add(new URI("http://a.com/"), replacementSidCookie);
    assertEquals("[theme=\"dark\";$Path=\"/\";$Domain=\"a.com\", " + "sid=\"mynewsid\";$Path=\"/\";$Domain=\"a.com\"]", cookieStore.get(new URI("http://a.com/")).toString());
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie) URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 68 with CookieManager

use of java.net.CookieManager in project j2objc by google.

the class CookiesTest method testCookieStoreRemoveRequiresUri.

public void testCookieStoreRemoveRequiresUri() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    HttpCookie cookieA = new HttpCookie("a", "android");
    cookieStore.add(new URI("http://android.com/source/"), cookieA);
    assertFalse(// RI6 fails this
    "Expected remove() to take the cookie URI into account.", cookieStore.remove(new URI("http://code.google.com/"), cookieA));
    assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie) URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 69 with CookieManager

use of java.net.CookieManager in project j2objc by google.

the class CookiesTest method testNonMatchingPathsRejected.

public void testNonMatchingPathsRejected() throws Exception {
    TestCookieStore cookieStore = new TestCookieStore();
    CookieManager cookieManager = new CookieManager(cookieStore, ACCEPT_ORIGINAL_SERVER);
    cookieManager.put(new URI("http://android.com/foo/bar"), cookieHeaders("a=android;path=/baz/bar"));
    assertEquals("Expected to reject cookies whose path is not a prefix of the request path", Collections.<HttpCookie>emptyList(), // RI6 fails this
    cookieStore.cookies);
}
Also used : URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 70 with CookieManager

use of java.net.CookieManager in project j2objc by google.

the class CookiesTest method testCookieManagerGet_hostChecks.

public void testCookieManagerGet_hostChecks() throws Exception {
    CookieManager cookieManager = new CookieManager();
    cookieManager.put(new URI("http://a.com/"), cookieHeaders("a1=android"));
    cookieManager.put(new URI("http://b.com/"), cookieHeaders("b1=android"));
    assertManagerCookiesMatch(cookieManager, "http://a.com/", "a1=android");
    assertManagerCookiesMatch(cookieManager, "http://b.com/", "b1=android");
}
Also used : URI(java.net.URI) CookieManager(java.net.CookieManager)

Aggregations

CookieManager (java.net.CookieManager)94 HttpCookie (java.net.HttpCookie)53 URI (java.net.URI)50 CookieStore (java.net.CookieStore)28 Test (org.junit.Test)16 MockResponse (com.google.mockwebserver.MockResponse)14 MockWebServer (com.google.mockwebserver.MockWebServer)14 List (java.util.List)9 MockResponse (okhttp3.mockwebserver.MockResponse)9 ArrayList (java.util.ArrayList)7 MockWebServer (okhttp3.mockwebserver.MockWebServer)7 RecordedRequest (com.google.mockwebserver.RecordedRequest)6 IOException (java.io.IOException)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Project (com.kickstarter.models.Project)3 Headers (com.koushikdutta.async.http.Headers)3 OkHttpClient (okhttp3.OkHttpClient)3 RefTag (com.kickstarter.libs.RefTag)2