[Pkg-owncloud-commits] [php-sabredav] 97/163: Fix for #443.

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:54:58 UTC 2014


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

taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.

commit 73baff2b16987101e128563f9606748cd670ea6f
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Mon Apr 28 21:39:35 2014 -0400

    Fix for #443.
    
    Thanks to @DominikTo and @armin-hackmann for doing the research and
    coming up with a solution. Sorry for taking so long.
---
 ChangeLog.md                                       |   3 +
 lib/Sabre/CalDAV/Plugin.php                        |  14 ++-
 tests/Sabre/CalDAV/Backend/Mock.php                |   2 +-
 .../Subscriptions/CreateSubscriptionTest.php       | 115 +++++++++++++++++++++
 tests/Sabre/DAVServerTest.php                      |   7 ++
 5 files changed, 138 insertions(+), 3 deletions(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index dfc4bf9..86c867a 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -14,10 +14,13 @@ ChangeLog
 * Fixed: Issue #428: Etag check with `If:` fails if the target is a collection.
 * Fixed: Issues #430, #431, #433: Locks plugin didn't not properly release
   filesystem based locks.
+* Fixed: #443. Support for creating new calendar subscriptions for OS X 10.9.2
+  and up.
 * Removed: `Sabre\DAV\Server::NODE_*` constants.
 * Moved all precondition checking into a central place, instead of having to
   think about it on a per-method basis.
 
+
 1.9.0-alpha2 (2014-01-14)
 -------------------------
 
diff --git a/lib/Sabre/CalDAV/Plugin.php b/lib/Sabre/CalDAV/Plugin.php
index 4162e4e..905a799 100644
--- a/lib/Sabre/CalDAV/Plugin.php
+++ b/lib/Sabre/CalDAV/Plugin.php
@@ -334,7 +334,17 @@ class Plugin extends DAV\ServerPlugin {
             }
         }
 
-        $resourceType = array('{DAV:}collection','{urn:ietf:params:xml:ns:caldav}calendar');
+        // iCal abuses MKCALENDAR since iCal 10.9.2 to create server-stored
+        // subscriptions. Before that it used MKCOL which was the correct way
+        // to do this.
+        //
+        // If the body had a {DAV:}resourcetype, it means we stumbled upon this
+        // request, and we simply use it instead of the pre-defined list.
+        if (isset($properties['{DAV:}resourcetype'])) {
+            $resourceType = $properties['{DAV:}resourcetype']->getValue();
+        } else {
+            $resourceType = ['{DAV:}collection','{urn:ietf:params:xml:ns:caldav}calendar'];
+        }
 
         $this->server->createCollection($path,$resourceType,$properties);
 
@@ -500,7 +510,7 @@ class Plugin extends DAV\ServerPlugin {
         $xpath->registerNameSpace('dav','urn:DAV');
 
         $expand = $xpath->query('/cal:calendar-multiget/dav:prop/cal:calendar-data/cal:expand');
-        if ($expand->length>0) {
+        if ($expand->length > 0) {
             $expandElem = $expand->item(0);
             $start = $expandElem->getAttribute('start');
             $end = $expandElem->getAttribute('end');
diff --git a/tests/Sabre/CalDAV/Backend/Mock.php b/tests/Sabre/CalDAV/Backend/Mock.php
index 4c64c96..3282e49 100644
--- a/tests/Sabre/CalDAV/Backend/Mock.php
+++ b/tests/Sabre/CalDAV/Backend/Mock.php
@@ -11,7 +11,7 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor
     private $notifications;
     private $shares = array();
 
-    function __construct(array $calendars, array $calendarData, array $notifications = array()) {
+    function __construct(array $calendars = [], array $calendarData = [], array $notifications = []) {
 
         $this->calendars = $calendars;
         $this->calendarData = $calendarData;
diff --git a/tests/Sabre/CalDAV/Subscriptions/CreateSubscriptionTest.php b/tests/Sabre/CalDAV/Subscriptions/CreateSubscriptionTest.php
new file mode 100644
index 0000000..6085d6c
--- /dev/null
+++ b/tests/Sabre/CalDAV/Subscriptions/CreateSubscriptionTest.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace Sabre\CalDAV\Subscriptions;
+
+use Sabre\CalDAV;
+use Sabre\HTTP\Request;
+
+class CreateSubscriptionTest extends \Sabre\DAVServerTest {
+
+    protected $setupCalDAV = true;
+    protected $setupCalDAVSubscriptions = true;
+
+    /**
+     * OS X 10.7 - 10.9.1
+     */
+    function testMKCOL() {
+
+        $body = <<<XML
+<A:mkcol xmlns:A="DAV:">
+    <A:set>
+        <A:prop>
+            <B:subscribed-strip-attachments xmlns:B="http://calendarserver.org/ns/" />
+            <B:subscribed-strip-todos xmlns:B="http://calendarserver.org/ns/" />
+            <A:resourcetype>
+                <A:collection />
+                <B:subscribed xmlns:B="http://calendarserver.org/ns/" />
+            </A:resourcetype>
+            <E:calendar-color xmlns:E="http://apple.com/ns/ical/">#1C4587FF</E:calendar-color>
+            <A:displayname>Jewish holidays</A:displayname>
+            <C:calendar-description xmlns:C="urn:ietf:params:xml:ns:caldav">Foo</C:calendar-description>
+            <E:calendar-order xmlns:E="http://apple.com/ns/ical/">19</E:calendar-order>
+            <B:source xmlns:B="http://calendarserver.org/ns/">
+                <A:href>webcal://www.example.org/</A:href>
+            </B:source>
+            <E:refreshrate xmlns:E="http://apple.com/ns/ical/">P1W</E:refreshrate>
+            <B:subscribed-strip-alarms xmlns:B="http://calendarserver.org/ns/" />
+        </A:prop>
+    </A:set>
+</A:mkcol>
+XML;
+
+        $headers = [
+            'Content-Type' => 'application/xml',
+        ];
+        $request = new Request('MKCOL', '/calendars/user1/subscription1', $headers, $body); 
+
+        $response = $this->request($request);
+        $this->assertEquals(201, $response->getStatus());
+        $subscriptions = $this->caldavBackend->getSubscriptionsForUser('principals/user1');
+        $this->assertSubscription($subscriptions[0]); 
+
+    
+    }
+    /**
+     * OS X 10.9.2 and up
+     */
+    function testMKCALENDAR() {
+
+        $body = <<<XML
+<B:mkcalendar xmlns:B="urn:ietf:params:xml:ns:caldav">
+    <A:set xmlns:A="DAV:">
+        <A:prop>
+            <B:supported-calendar-component-set>
+                <B:comp name="VEVENT" />
+            </B:supported-calendar-component-set>
+            <C:subscribed-strip-alarms xmlns:C="http://calendarserver.org/ns/" />
+            <C:subscribed-strip-attachments xmlns:C="http://calendarserver.org/ns/" />
+            <A:resourcetype>
+                <A:collection />
+                <C:subscribed xmlns:C="http://calendarserver.org/ns/" />
+            </A:resourcetype>
+            <D:refreshrate xmlns:D="http://apple.com/ns/ical/">P1W</D:refreshrate>
+            <C:source xmlns:C="http://calendarserver.org/ns/">
+                <A:href>webcal://www.example.org/</A:href>
+            </C:source>
+            <D:calendar-color xmlns:D="http://apple.com/ns/ical/">#1C4587FF</D:calendar-color>
+            <D:calendar-order xmlns:D="http://apple.com/ns/ical/">19</D:calendar-order>
+            <B:calendar-description>Foo</B:calendar-description>
+            <C:subscribed-strip-todos xmlns:C="http://calendarserver.org/ns/" />
+            <A:displayname>Jewish holidays</A:displayname>
+        </A:prop>
+    </A:set>
+</B:mkcalendar>
+XML;
+
+        $headers = [
+            'Content-Type' => 'application/xml',
+        ];
+        $request = new Request('MKCALENDAR', '/calendars/user1/subscription1', $headers, $body); 
+
+        $response = $this->request($request);
+        $this->assertEquals(201, $response->getStatus());
+        $subscriptions = $this->caldavBackend->getSubscriptionsForUser('principals/user1');
+        $this->assertSubscription($subscriptions[0]); 
+
+    }
+
+    function assertSubscription($subscription) {
+
+        $this->assertEquals('', $subscription['{http://calendarserver.org/ns/}subscribed-strip-attachments']);
+        $this->assertEquals('', $subscription['{http://calendarserver.org/ns/}subscribed-strip-todos']);
+        $this->assertEquals('#1C4587FF', $subscription['{http://apple.com/ns/ical/}calendar-color']);
+        $this->assertEquals('Jewish holidays', $subscription['{DAV:}displayname']);
+        $this->assertEquals('Foo', $subscription['{urn:ietf:params:xml:ns:caldav}calendar-description']);
+        $this->assertEquals('19', $subscription['{http://apple.com/ns/ical/}calendar-order']);
+        $this->assertEquals('webcal://www.example.org/', $subscription['{http://calendarserver.org/ns/}source']->getHref());
+        $this->assertEquals('P1W', $subscription['{http://apple.com/ns/ical/}refreshrate']);
+        $this->assertEquals('subscription1', $subscription['uri']);
+        $this->assertEquals('principals/user1', $subscription['principaluri']);
+        $this->assertEquals('webcal://www.example.org/', $subscription['source']);
+        $this->assertEquals(['principals/user1', 1], $subscription['id']);
+
+    }
+
+}
diff --git a/tests/Sabre/DAVServerTest.php b/tests/Sabre/DAVServerTest.php
index e9f0ca1..b28cb5a 100644
--- a/tests/Sabre/DAVServerTest.php
+++ b/tests/Sabre/DAVServerTest.php
@@ -37,6 +37,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
     protected $setupCardDAV = false;
     protected $setupACL = false;
     protected $setupCalDAVSharing = false;
+    protected $setupCalDAVSubscriptions = false;
 
     protected $caldavCalendars = array();
     protected $caldavCalendarObjects = array();
@@ -102,6 +103,9 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
             $this->caldavSharingPlugin = new CalDAV\SharingPlugin();
             $this->server->addPlugin($this->caldavSharingPlugin);
         }
+        if ($this->setupCalDAVSubscriptions) {
+            $this->server->addPlugin(new CalDAV\Subscriptions\Plugin());
+        }
         if ($this->setupCardDAV) {
             $this->carddavPlugin = new CardDAV\Plugin();
             $this->server->addPlugin($this->carddavPlugin);
@@ -172,6 +176,9 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
 
     function setUpBackends() {
 
+        if ($this->setupCalDAVSubscriptions && is_null($this->caldavBackend)) {
+            $this->caldavBackend = new CalDAV\Backend\MockSubscriptionSupport($this->caldavCalendars, $this->caldavCalendarObjects);
+        }
         if ($this->setupCalDAV && is_null($this->caldavBackend)) {
             $this->caldavBackend = new CalDAV\Backend\Mock($this->caldavCalendars, $this->caldavCalendarObjects);
         }

-- 
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