[Pkg-owncloud-commits] [php-sabredav] 04/30: proxy-principals no longer return CalDAV properties that they shouldn't have.

David Prévot taffit at moszumanska.debian.org
Tue Jan 26 16:19:39 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit e47a1531a4be014fa545bd31600158aa14c63bdb
Author: Evert Pot <me at evertpot.com>
Date:   Fri Jan 8 16:49:34 2016 -0500

    proxy-principals no longer return CalDAV properties that they shouldn't have.
    
    Fixes #755
---
 CHANGELOG.md                                       |  3 +++
 lib/CalDAV/Plugin.php                              | 21 +++++++++++----
 lib/CalDAV/Schedule/Plugin.php                     | 10 +++++++
 .../Sabre/CalDAV/Schedule/PluginPropertiesTest.php | 31 ++++++++++++++++++++++
 tests/Sabre/DAVServerTest.php                      |  2 +-
 5 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b57f2e1..7a0bf84 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ ChangeLog
 3.1.1 (????-??-??)
 ------------------
 
+* #755: The brower plugin and some operations would break when scheduling and
+  delegation would both be enabled.
+
 
 3.1.0 (2016-01-06)
 ------------------
diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php
index add6160..e389486 100644
--- a/lib/CalDAV/Plugin.php
+++ b/lib/CalDAV/Plugin.php
@@ -89,16 +89,26 @@ class Plugin extends DAV\ServerPlugin {
      * Returns the path to a principal's calendar home.
      *
      * The return url must not end with a slash.
+     * This function should return null in case a principal did not have
+     * a calendar home.
      *
      * @param string $principalUrl
      * @return string
      */
     function getCalendarHomeForPrincipal($principalUrl) {
 
-        // The default is a bit naive, but it can be overwritten.
-        list(, $nodeName) = Uri\split($principalUrl);
+        // The default behavior for most sabre/dav servers is that there is a
+        // principals root node, which contains users directly under it.
+        //
+        // This function assumes that there are two components in a principal
+        // path. If there's more, we don't return a calendar home. This
+        // excludes things like the calendar-proxy-read principal (which it
+        // should).
+        $parts = explode('/', trim($principalUrl, '/'));
+        if (count($parts)!==2) return;
+        if ($parts[0]!=='principals') return;
 
-        return self::CALENDAR_ROOT . '/' . $nodeName;
+        return self::CALENDAR_ROOT . '/' . $parts[1];
 
     }
 
@@ -329,8 +339,9 @@ class Plugin extends DAV\ServerPlugin {
 
             $propFind->handle('{' . self::NS_CALDAV . '}calendar-home-set', function() use ($principalUrl) {
 
-                $calendarHomePath = $this->getCalendarHomeForPrincipal($principalUrl) . '/';
-                return new Href($calendarHomePath);
+                $calendarHomePath = $this->getCalendarHomeForPrincipal($principalUrl);
+                if (is_null($calendarHomePath)) return null;
+                return new Href($calendarHomePath . '/');
 
             });
             // The calendar-user-address-set property is basically mapped to
diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index c9d3140..827d620 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -210,6 +210,9 @@ class Plugin extends ServerPlugin {
             $propFind->handle('{' . self::NS_CALDAV . '}schedule-outbox-URL', function() use ($principalUrl, $caldavPlugin) {
 
                 $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
+                if (!$calendarHomePath) {
+                    return null;
+                }
                 $outboxPath = $calendarHomePath . '/outbox/';
 
                 return new Href($outboxPath);
@@ -219,6 +222,9 @@ class Plugin extends ServerPlugin {
             $propFind->handle('{' . self::NS_CALDAV . '}schedule-inbox-URL', function() use ($principalUrl, $caldavPlugin) {
 
                 $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
+                if (!$calendarHomePath) {
+                    return null;
+                }
                 $inboxPath = $calendarHomePath . '/inbox/';
 
                 return new Href($inboxPath);
@@ -231,6 +237,10 @@ class Plugin extends ServerPlugin {
                 // meantime we just grab the first calendar in the home-set.
                 $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
 
+                if (!$calendarHomePath) {
+                    return null;
+                }
+
                 $sccs = '{' . self::NS_CALDAV . '}supported-calendar-component-set';
 
                 $result = $this->server->getPropertiesForPath($calendarHomePath, [
diff --git a/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php b/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
index aa2b9eb..b274990 100644
--- a/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
+++ b/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
@@ -20,6 +20,9 @@ class PluginPropertiesTest extends \Sabre\DAVServerTest {
 
             ]
         );
+        $this->principalBackend->addPrincipal([
+            'uri' => 'principals/user1/calendar-proxy-read'
+        ]);
 
     }
 
@@ -60,6 +63,34 @@ class PluginPropertiesTest extends \Sabre\DAVServerTest {
         $this->assertEquals('calendars/user1/default/', $prop->getHref());
 
     }
+    function testPrincipalPropertiesBadPrincipal() {
+
+        $props = $this->server->getPropertiesForPath('principals/user1/calendar-proxy-read', [
+            '{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL',
+            '{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
+            '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
+            '{urn:ietf:params:xml:ns:caldav}calendar-user-type',
+            '{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL',
+        ]);
+
+        $this->assertArrayHasKey(0, $props);
+        $this->assertArrayHasKey(200, $props[0]);
+        $this->assertArrayHasKey(404, $props[0]);
+
+        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL', $props[0][404]);
+        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL', $props[0][404]);
+
+        $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
+        $this->assertTrue($prop instanceof DAV\Xml\Property\Href);
+        $this->assertEquals(['/principals/user1/calendar-proxy-read/'], $prop->getHrefs());
+
+        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-type', $props[0][200]);
+        $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-type'];
+        $this->assertEquals('INDIVIDUAL', $prop);
+
+        $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL', $props[0][404]);
+
+    }
 
     /**
      * There are two properties for availability. The server should
diff --git a/tests/Sabre/DAVServerTest.php b/tests/Sabre/DAVServerTest.php
index f54add8..d329b5b 100644
--- a/tests/Sabre/DAVServerTest.php
+++ b/tests/Sabre/DAVServerTest.php
@@ -201,7 +201,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
         }
 
         if ($this->setupCardDAV || $this->setupCalDAV) {
-            $this->tree[] = new DAVACL\PrincipalCollection(
+            $this->tree[] = new CalDAV\Principal\Collection(
                 $this->principalBackend
             );
         }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list