mirror of
https://github.com/etesync/android
synced 2025-05-11 19:38:54 +00:00
Don't disable per-session cookie management + test (closes #525)
This commit is contained in:
parent
81d7813614
commit
18c08bc9dd
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* 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.webdav;
|
||||||
|
|
||||||
|
import android.test.InstrumentationTestCase;
|
||||||
|
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGetHC4;
|
||||||
|
import org.apache.http.client.methods.HttpPostHC4;
|
||||||
|
import org.apache.http.client.methods.HttpRequestBaseHC4;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import at.bitfire.davdroid.TestConstants;
|
||||||
|
import lombok.Cleanup;
|
||||||
|
|
||||||
|
public class DavHttpClientTest extends InstrumentationTestCase {
|
||||||
|
final static URI testCookieURI = TestConstants.roboHydra.resolve("/dav/testCookieStore");
|
||||||
|
|
||||||
|
CloseableHttpClient httpClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
httpClient = DavHttpClient.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
httpClient.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testCookies() throws IOException {
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
|
||||||
|
HttpGetHC4 get = new HttpGetHC4(testCookieURI);
|
||||||
|
get.setHeader("Accept", "text/xml");
|
||||||
|
|
||||||
|
// at first, DavHttpClient doesn't send a cookie
|
||||||
|
try {
|
||||||
|
response = httpClient.execute(get);
|
||||||
|
assertEquals(412, response.getStatusLine().getStatusCode());
|
||||||
|
} finally {
|
||||||
|
if (response != null)
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST sets a cookie to DavHttpClient
|
||||||
|
try {
|
||||||
|
response = httpClient.execute(new HttpPostHC4(testCookieURI));
|
||||||
|
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||||
|
} finally {
|
||||||
|
if (response != null)
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// and now DavHttpClient sends a cookie for GET, too
|
||||||
|
try {
|
||||||
|
response = httpClient.execute(get);
|
||||||
|
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||||
|
} finally {
|
||||||
|
if (response != null)
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
// vim: ts=4:sw=4
|
||||||
|
|
||||||
var roboHydraHeadDAV = require("../headdav");
|
var roboHydraHeadDAV = require("../headdav");
|
||||||
|
|
||||||
exports.getBodyParts = function(conf) {
|
exports.getBodyParts = function(conf) {
|
||||||
@ -6,6 +8,26 @@ exports.getBodyParts = function(conf) {
|
|||||||
/* base URL, provide default DAV here */
|
/* base URL, provide default DAV here */
|
||||||
new RoboHydraHeadDAV({ path: "/dav/" }),
|
new RoboHydraHeadDAV({ path: "/dav/" }),
|
||||||
|
|
||||||
|
/* test cookie:
|
||||||
|
* POST /dav/testCookieStore will cause the mock server to set a cookie
|
||||||
|
* GET /dav/testCookieStore will cause the mock server to check the request cookie
|
||||||
|
* and return 412 Precondition failed when it's not set correctly
|
||||||
|
*/
|
||||||
|
new RoboHydraHeadDAV({
|
||||||
|
path: "/dav/testCookieStore",
|
||||||
|
handler: function(req,res,next) {
|
||||||
|
var cookie = 'sess=MY_SESSION_12345';
|
||||||
|
if (req.method == "POST") {
|
||||||
|
res.statusCode = 200;
|
||||||
|
res.headers['Set-Cookie'] = cookie;
|
||||||
|
res.send("Setting cookie");
|
||||||
|
} else {
|
||||||
|
res.statusCode = (req.headers['cookie'] == cookie) ? 200 : 412;
|
||||||
|
res.send("Checking cookie");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
/* multistatus parsing */
|
/* multistatus parsing */
|
||||||
new RoboHydraHeadDAV({
|
new RoboHydraHeadDAV({
|
||||||
path: "/dav/collection-response-with-trailing-slash",
|
path: "/dav/collection-response-with-trailing-slash",
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// vim: ts=4:sw=4
|
||||||
|
|
||||||
var roboHydra = require("robohydra"),
|
var roboHydra = require("robohydra"),
|
||||||
roboHydraHeads = roboHydra.heads,
|
roboHydraHeads = roboHydra.heads,
|
||||||
roboHydraHead = roboHydraHeads.RoboHydraHead;
|
roboHydraHead = roboHydraHeads.RoboHydraHead;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// vim: ts=4:sw=4
|
||||||
|
|
||||||
var roboHydra = require("robohydra"),
|
var roboHydra = require("robohydra"),
|
||||||
roboHydraHeads = roboHydra.heads,
|
roboHydraHeads = roboHydra.heads,
|
||||||
roboHydraHead = roboHydraHeads.RoboHydraHead;
|
roboHydraHead = roboHydraHeads.RoboHydraHead;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
package at.bitfire.davdroid.webdav;
|
package at.bitfire.davdroid.webdav;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
@ -43,6 +44,7 @@ public class DavHttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressLint("LogTagMismatch")
|
||||||
public static CloseableHttpClient create() {
|
public static CloseableHttpClient create() {
|
||||||
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
|
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
|
||||||
// limits per DavHttpClient (= per DavSyncAdapter extends AbstractThreadedSyncAdapter)
|
// limits per DavHttpClient (= per DavSyncAdapter extends AbstractThreadedSyncAdapter)
|
||||||
@ -55,8 +57,7 @@ public class DavHttpClient {
|
|||||||
.setDefaultRequestConfig(defaultRqConfig)
|
.setDefaultRequestConfig(defaultRqConfig)
|
||||||
.setRetryHandler(DavHttpRequestRetryHandler.INSTANCE)
|
.setRetryHandler(DavHttpRequestRetryHandler.INSTANCE)
|
||||||
.setRedirectStrategy(DavRedirectStrategy.INSTANCE)
|
.setRedirectStrategy(DavRedirectStrategy.INSTANCE)
|
||||||
.setUserAgent("DAVdroid/" + Constants.APP_VERSION)
|
.setUserAgent("DAVdroid/" + Constants.APP_VERSION);
|
||||||
.disableCookieManagement();
|
|
||||||
|
|
||||||
if (Log.isLoggable("Wire", Log.DEBUG)) {
|
if (Log.isLoggable("Wire", Log.DEBUG)) {
|
||||||
Log.i(TAG, "Wire logging active, disabling HTTP compression");
|
Log.i(TAG, "Wire logging active, disabling HTTP compression");
|
||||||
|
Loading…
Reference in New Issue
Block a user