mirror of
https://github.com/etesync/android
synced 2025-01-15 02:01:13 +00:00
ff901ce91f
* HttpClient: authentication that is limited to a host name is never preemptive * DavResourceFinder: service configuration == null means that this service is not available * new SQLite database for CalDAV/CardDAV services * added AccountDetailsFragment, which asks for account name and then finishes account creation * updated AccountListFragment
65 lines
2.0 KiB
Java
65 lines
2.0 KiB
Java
/*
|
||
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
|
||
* All rights reserved. This program and the accompanying materials
|
||
* are made available under the terms of the GNU Public License v3.0
|
||
* which accompanies this distribution, and is available at
|
||
* http://www.gnu.org/licenses/gpl.html
|
||
*/
|
||
|
||
package at.bitfire.davdroid;
|
||
|
||
import android.test.InstrumentationTestCase;
|
||
|
||
import java.io.IOException;
|
||
import java.net.URISyntaxException;
|
||
|
||
import okhttp3.HttpUrl;
|
||
import okhttp3.OkHttpClient;
|
||
import okhttp3.Request;
|
||
import okhttp3.mockwebserver.MockResponse;
|
||
import okhttp3.mockwebserver.MockWebServer;
|
||
|
||
public class HttpClientTest extends InstrumentationTestCase {
|
||
|
||
MockWebServer server;
|
||
OkHttpClient httpClient;
|
||
|
||
@Override
|
||
public void setUp() throws IOException {
|
||
httpClient = HttpClient.create(getInstrumentation().getTargetContext().getApplicationContext());
|
||
|
||
server = new MockWebServer();
|
||
server.start();
|
||
}
|
||
|
||
@Override
|
||
public void tearDown() throws IOException {
|
||
server.shutdown();
|
||
}
|
||
|
||
public void testCookies() throws IOException, InterruptedException, URISyntaxException {
|
||
HttpUrl url = server.url("/");
|
||
|
||
// set cookie in first response
|
||
server.enqueue(new MockResponse()
|
||
.setResponseCode(200)
|
||
.setHeader("Set-Cookie", "theme=light; path=/")
|
||
.setBody("Cookie set"));
|
||
httpClient.newCall(new Request.Builder()
|
||
.get().url(url)
|
||
.build()).execute();
|
||
assertNull(server.takeRequest().getHeader("Cookie"));
|
||
|
||
// cookie should be sent with second request
|
||
server.enqueue(new MockResponse()
|
||
.setResponseCode(200));
|
||
httpClient.newCall(new Request.Builder()
|
||
.get().url(url)
|
||
.build()).execute();
|
||
//assertEquals("theme=light", server.takeRequest().getHeader("Cookie"));
|
||
|
||
// doesn't work for URLs with ports, see https://code.google.com/p/android/issues/detail?id=193475
|
||
}
|
||
|
||
}
|