From ab517bd87dbf2939abd86d653b792e6ae1c32c69 Mon Sep 17 00:00:00 2001 From: rfc2822 Date: Sat, 9 Nov 2013 01:36:09 +0100 Subject: [PATCH] Always append trailing slash to address-book/calendar home set to avoid redirections --- .../syncadapter/QueryServerDialogFragment.java | 4 ++-- src/at/bitfire/davdroid/webdav/WebDavResource.java | 4 ++++ test/robohydra/plugins/dav-default/index.js | 12 ++++++++---- .../davdroid/webdav/test/WebDavResourceTest.java | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/at/bitfire/davdroid/syncadapter/QueryServerDialogFragment.java b/src/at/bitfire/davdroid/syncadapter/QueryServerDialogFragment.java index ea94e666..7610e7c3 100644 --- a/src/at/bitfire/davdroid/syncadapter/QueryServerDialogFragment.java +++ b/src/at/bitfire/davdroid/syncadapter/QueryServerDialogFragment.java @@ -153,7 +153,7 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC // (4/5) get address books if (serverInfo.isCardDAV()) { - WebDavResource homeSetAddressBooks = new WebDavResource(principal, pathAddressBooks); + WebDavResource homeSetAddressBooks = new WebDavResource(principal, pathAddressBooks, true); homeSetAddressBooks.propfind(Mode.MEMBERS_COLLECTIONS); List addressBooks = new LinkedList(); @@ -175,7 +175,7 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC // (5/5) get calendars if (serverInfo.isCalDAV()) { - WebDavResource homeSetCalendars = new WebDavResource(principal, pathCalendars); + WebDavResource homeSetCalendars = new WebDavResource(principal, pathCalendars, true); homeSetCalendars.propfind(Mode.MEMBERS_COLLECTIONS); List calendars = new LinkedList(); diff --git a/src/at/bitfire/davdroid/webdav/WebDavResource.java b/src/at/bitfire/davdroid/webdav/WebDavResource.java index 87bae3f1..b4814b9b 100644 --- a/src/at/bitfire/davdroid/webdav/WebDavResource.java +++ b/src/at/bitfire/davdroid/webdav/WebDavResource.java @@ -132,6 +132,10 @@ public class WebDavResource { client = parent.client; } + public WebDavResource(WebDavResource parent, String member, boolean trailingSlash) { + this(parent, (trailingSlash && !member.endsWith("/")) ? (member + "/") : member); + } + public WebDavResource(WebDavResource parent, String member, String ETag) { this(parent, member); properties.put(Property.ETAG, ETag); diff --git a/test/robohydra/plugins/dav-default/index.js b/test/robohydra/plugins/dav-default/index.js index 043db786..e563755e 100644 --- a/test/robohydra/plugins/dav-default/index.js +++ b/test/robohydra/plugins/dav-default/index.js @@ -22,7 +22,7 @@ exports.getBodyParts = function(conf) { \ \ \ - /dav/addressbooks/test/\ + /dav/addressbooks/test\ \ \ /dav/calendars/test/\ @@ -39,9 +39,13 @@ exports.getBodyParts = function(conf) { /* address-book home set */ new RoboHydraHeadDAV({ - path: "/dav/addressbooks/test", + path: "/dav/addressbooks/test/", handler: function(req,res,next) { - if (req.method == "PROPFIND" && req.rawBody.toString().match(/addressbook-description/)) { + if (!req.url.match(/\/$/)) { + res.statusCode = 302; + res.headers['location'] = "/dav/addressbooks/test/"; + } + else if (req.method == "PROPFIND" && req.rawBody.toString().match(/addressbook-description/)) { res.statusCode = 207; res.write('\\ \ @@ -77,7 +81,7 @@ exports.getBodyParts = function(conf) { /* calendar home set */ new RoboHydraHeadDAV({ - path: "/dav/calendars/test", + path: "/dav/calendars/test/", handler: function(req,res,next) { if (req.method == "PROPFIND" && req.rawBody.toString().match(/addressbook-description/)) { res.statusCode = 207; diff --git a/test/src/at/bitfire/davdroid/webdav/test/WebDavResourceTest.java b/test/src/at/bitfire/davdroid/webdav/test/WebDavResourceTest.java index d2d506d2..7146bc86 100644 --- a/test/src/at/bitfire/davdroid/webdav/test/WebDavResourceTest.java +++ b/test/src/at/bitfire/davdroid/webdav/test/WebDavResourceTest.java @@ -90,12 +90,12 @@ public class WebDavResourceTest extends InstrumentationTestCase { public void testPropfindHomeSets() throws IOException, HttpException { WebDavResource dav = new WebDavResource(davCollection, "principals/users/test"); dav.propfind(HttpPropfind.Mode.HOME_SETS); - assertEquals("/dav/addressbooks/test/", dav.getAddressbookHomeSet()); + assertEquals("/dav/addressbooks/test", dav.getAddressbookHomeSet()); assertEquals("/dav/calendars/test/", dav.getCalendarHomeSet()); } public void testPropfindAddressBooks() throws IOException, HttpException { - WebDavResource dav = new WebDavResource(davCollection, "addressbooks/test"); + WebDavResource dav = new WebDavResource(davCollection, "addressbooks/test", true); dav.propfind(HttpPropfind.Mode.MEMBERS_COLLECTIONS); assertEquals(2, dav.getMembers().size()); for (WebDavResource member : dav.getMembers()) { @@ -108,7 +108,7 @@ public class WebDavResourceTest extends InstrumentationTestCase { } public void testPropfindCalendars() throws IOException, HttpException { - WebDavResource dav = new WebDavResource(davCollection, "calendars/test"); + WebDavResource dav = new WebDavResource(davCollection, "calendars/test", true); dav.propfind(HttpPropfind.Mode.MEMBERS_COLLECTIONS); assertEquals(3, dav.getMembers().size()); for (WebDavResource member : dav.getMembers()) {