1
0
mirror of https://github.com/etesync/android synced 2024-11-22 16:08:13 +00:00

Messing around with trailing slash again and again + tests (fixes #349)

This commit is contained in:
rfc2822 2014-11-03 19:30:07 +01:00
parent 7501f87d03
commit 58efd9ba03
3 changed files with 73 additions and 10 deletions

View File

@ -558,7 +558,7 @@ public class WebDavResource {
}
// about which resource is this response?
if (location.equals(href)) { // about ourselves
if (location.equals(href) || URIUtils.ensureTrailingSlash(location).equals(href)) { // about ourselves
this.properties.putAll(properties);
if (supportedComponents != null)
this.supportedComponents = supportedComponents;

View File

@ -6,6 +6,60 @@ exports.getBodyParts = function(conf) {
/* base URL, provide default DAV here */
new RoboHydraHeadDAV({ path: "/dav/" }),
/* multistatus parsing */
new RoboHydraHeadDAV({
path: "/dav/collection-response-with-trailing-slash",
handler: function(req,res,next) {
if (req.method == "PROPFIND") {
res.statusCode = 207;
res.write('\<?xml version="1.0" encoding="utf-8" ?>\
<multistatus xmlns="DAV:">\
<response>\
<href>/dav/collection-response-with-trailing-slash/</href> \
<propstat>\
<prop>\
<current-user-principal>\
<href>/principals/ok</href>\
</current-user-principal>\
<resourcetype>\
<collection/>\
</resourcetype>\
</prop>\
<status>HTTP/1.1 200 OK</status>\
</propstat>\
</response>\
</multistatus>\
');
}
}
}),
new RoboHydraHeadDAV({
path: "/dav/collection-response-without-trailing-slash",
handler: function(req,res,next) {
if (req.method == "PROPFIND") {
res.statusCode = 207;
res.write('\<?xml version="1.0" encoding="utf-8" ?>\
<multistatus xmlns="DAV:">\
<response>\
<href>/dav/collection-response-without-trailing-slash</href> \
<propstat>\
<prop>\
<current-user-principal>\
<href>/principals/ok</href>\
</current-user-principal>\
<resourcetype>\
<collection/>\
</resourcetype>\
</prop>\
<status>HTTP/1.1 200 OK</status>\
</propstat>\
</response>\
</multistatus>\
');
}
}
}),
/* principal URL */
new RoboHydraHeadDAV({
path: "/dav/principals/users/test",

View File

@ -23,15 +23,7 @@ import org.apache.commons.io.IOUtils;
import android.content.res.AssetManager;
import android.test.InstrumentationTestCase;
import at.bitfire.davdroid.test.Constants;
import at.bitfire.davdroid.webdav.DavException;
import at.bitfire.davdroid.webdav.DavHttpClient;
import at.bitfire.davdroid.webdav.DavMultiget;
import at.bitfire.davdroid.webdav.HttpException;
import at.bitfire.davdroid.webdav.HttpPropfind;
import at.bitfire.davdroid.webdav.HttpPropfind.Mode;
import at.bitfire.davdroid.webdav.NotFoundException;
import at.bitfire.davdroid.webdav.PreconditionFailedException;
import at.bitfire.davdroid.webdav.WebDavResource;
import at.bitfire.davdroid.webdav.WebDavResource.PutMode;
import ch.boye.httpclientandroidlib.impl.client.CloseableHttpClient;
@ -122,7 +114,7 @@ public class WebDavResourceTest extends InstrumentationTestCase {
public void testPropfindCalendars() throws IOException, HttpException, DavException {
WebDavResource dav = new WebDavResource(davCollection, "calendars/test");
dav.propfind(HttpPropfind.Mode.CALDAV_COLLECTIONS);
dav.propfind(Mode.CALDAV_COLLECTIONS);
assertEquals(3, dav.getMembers().size());
assertEquals("0xFF00FF", dav.getMembers().get(2).getColor());
for (WebDavResource member : dav.getMembers()) {
@ -134,6 +126,23 @@ public class WebDavResourceTest extends InstrumentationTestCase {
}
}
public void testPropfindTrailingSlashes() throws IOException, HttpException, DavException {
final String principalOK = "/principals/ok";
String requestPaths[] = {
"/dav/collection-response-with-trailing-slash",
"/dav/collection-response-with-trailing-slash/",
"/dav/collection-response-without-trailing-slash",
"/dav/collection-response-without-trailing-slash/"
};
for (String path : requestPaths) {
WebDavResource davSlash = new WebDavResource(davCollection, path);
davSlash.propfind(Mode.CARDDAV_COLLECTIONS);
assertEquals(principalOK, davSlash.getCurrentUserPrincipal());
}
}
/* test normal HTTP/WebDAV */