Search in sources :

Example 61 with CookieManager

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

the class CookiesTest method testCookieStoreUriDropsFragment.

public void testCookieStoreUriDropsFragment() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    cookieStore.add(new URI("http://a.com/a/foo#fragment"), new HttpCookie("a", "android"));
    assertEquals(Arrays.asList(new URI("http://a.com")), cookieStore.getURIs());
}
Also used : CookieStore(java.net.CookieStore) URI(java.net.URI) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager)

Example 62 with CookieManager

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

the class CookiesTest method testNoCookieHeaderSentIfNoCookiesMatch.

public void testNoCookieHeaderSentIfNoCookiesMatch() throws IOException, URISyntaxException {
    CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
    Map<String, List<String>> cookieHeaders = cookieManager.get(new URI("http://android.com/foo/bar/"), EMPTY_COOKIES_MAP);
    assertTrue(cookieHeaders.toString(), cookieHeaders.isEmpty() || (cookieHeaders.size() == 1 && cookieHeaders.get("Cookie").isEmpty()));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 63 with CookieManager

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

the class CookiesTest method testMatchingPathsAccepted.

public void testMatchingPathsAccepted() 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=/foo"));
    assertEquals("/foo", cookieStore.getCookie("a").getPath());
}
Also used : URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 64 with CookieManager

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

the class CookiesTest method testResponseWithMultipleCookieHeaderLines.

public void testResponseWithMultipleCookieHeaderLines() throws Exception {
    TestCookieStore cookieStore = new TestCookieStore();
    CookieManager cookieManager = new CookieManager(cookieStore, ACCEPT_ORIGINAL_SERVER);
    cookieManager.put(new URI("http://android.com"), cookieHeaders("a=android", "b=banana"));
    List<HttpCookie> cookies = sortedCopy(cookieStore.cookies);
    assertEquals(2, cookies.size());
    HttpCookie cookieA = cookies.get(0);
    assertEquals("a", cookieA.getName());
    assertEquals("android", cookieA.getValue());
    HttpCookie cookieB = cookies.get(1);
    assertEquals("b", cookieB.getName());
    assertEquals("banana", cookieB.getValue());
}
Also used : URI(java.net.URI) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager)

Example 65 with CookieManager

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

the class CookiesTest method testCookieStoreGet.

public void testCookieStoreGet() throws Exception {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    HttpCookie cookiePort1 = createCookie("a1", "android", "a.com", "/path1");
    HttpCookie cookiePort2 = createCookie("a2", "android", "a.com", "/path2");
    HttpCookie secureCookie = createCookie("a3", "android", "a.com", "/path3");
    secureCookie.setSecure(true);
    HttpCookie notSecureCookie = createCookie("a4", "android", "a.com", "/path4");
    HttpCookie bCookie = createCookie("b1", "android", "b.com", "/path5");
    cookieStore.add(new URI("http://a.com:443/path1"), cookiePort1);
    cookieStore.add(new URI("http://a.com:8080/path2"), cookiePort2);
    cookieStore.add(new URI("https://a.com:443/path3"), secureCookie);
    cookieStore.add(new URI("https://a.com:443/path4"), notSecureCookie);
    cookieStore.add(new URI("https://b.com:8080/path5"), bCookie);
    List<HttpCookie> expectedStoreCookies = new ArrayList<>();
    expectedStoreCookies.add(cookiePort1);
    expectedStoreCookies.add(cookiePort2);
    expectedStoreCookies.add(secureCookie);
    expectedStoreCookies.add(notSecureCookie);
    // The default CookieStore implementation on Android is currently responsible for matching
    // the host/domain but not handling other cookie rules: it ignores the scheme (e.g. "secure"
    // checks), port and path.
    // The tests below fail on the RI. It looks like in the RI it is CookieStoreImpl that is
    // enforcing "secure" checks.
    assertEquals(expectedStoreCookies, cookieStore.get(new URI("http://a.com:443/anypath")));
    assertEquals(expectedStoreCookies, cookieStore.get(new URI("http://a.com:8080/anypath")));
    assertEquals(expectedStoreCookies, cookieStore.get(new URI("https://a.com/anypath")));
    assertEquals(expectedStoreCookies, cookieStore.get(new URI("http://a.com/anypath")));
}
Also used : CookieStore(java.net.CookieStore) ArrayList(java.util.ArrayList) HttpCookie(java.net.HttpCookie) 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