[Pkg-owncloud-commits] [php-sabredav] 05/11: Backport ca91f5a to 2.1 Workaround for broken Windows Phone client.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:15:16 UTC 2015


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

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

commit b0d5cc846614acbc8d387c83f1105c567b14f5d0
Author: Evert Pot <me at evertpot.com>
Date:   Sun Jul 19 19:01:52 2015 -0400

    Backport ca91f5a to 2.1
    Workaround for broken Windows Phone client.
    
    Fixes #691.
    See #685 for more detail.
    
    (cherry picked from commit ca91f5a9603e53cd4edef2749996ae600cf742a9)
---
 ChangeLog.md                      |  2 +-
 lib/CalDAV/Plugin.php             | 13 +++++
 tests/Sabre/CalDAV/PluginTest.php | 99 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+), 1 deletion(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index 995719a..01e70ed 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -6,7 +6,7 @@ ChangeLog
 
 * #657: Migration script would break when coming a cross an iCalendar object
   with no UID.
-
+* #691: Workaround for broken Windows Phone client.
 
 2.1.5 (2015-07-11)
 ------------------
diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php
index 2b8913f..6d4d612 100644
--- a/lib/CalDAV/Plugin.php
+++ b/lib/CalDAV/Plugin.php
@@ -614,6 +614,19 @@ class Plugin extends DAV\ServerPlugin {
 
         }
 
+        if ($node instanceof ICalendarObjectContainer && $depth === 0) {
+
+            if(strpos($this->server->httpRequest->getHeader('User-Agent'), 'MSFT-WP/') === 0) {
+                // Windows phone incorrectly supplied depth as 0, when it actually
+                // should have set depth to 1. We're implementing a workaround here
+                // to deal with this.
+                $depth = 1;
+            } else {
+                throw new BadRequest('A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1');
+            }
+
+        }
+
         // If we're dealing with a calendar, the calendar itself is responsible
         // for the calendar-query.
         if ($node instanceof ICalendarObjectContainer && $depth == 1) {
diff --git a/tests/Sabre/CalDAV/PluginTest.php b/tests/Sabre/CalDAV/PluginTest.php
index 343a5f6..867aead 100644
--- a/tests/Sabre/CalDAV/PluginTest.php
+++ b/tests/Sabre/CalDAV/PluginTest.php
@@ -721,6 +721,105 @@ END:VCALENDAR';
     }
 
     /**
+     * @depends testSupportedReportSetProperty
+     * @depends testCalendarMultiGetReport
+     */
+    function testCalendarQueryReportWindowsPhone() {
+
+        $body =
+            '<?xml version="1.0"?>' .
+            '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
+            '<d:prop>' .
+            '  <c:calendar-data>' .
+            '     <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
+            '  </c:calendar-data>' .
+            '  <d:getetag />' .
+            '</d:prop>' .
+            '<c:filter>' .
+            '  <c:comp-filter name="VCALENDAR">' .
+            '    <c:comp-filter name="VEVENT" />' .
+            '  </c:comp-filter>' .
+            '</c:filter>' .
+            '</c:calendar-query>';
+
+        $request = HTTP\Sapi::createFromServerArray(array(
+            'REQUEST_METHOD'  => 'REPORT',
+            'REQUEST_URI'     => '/calendars/user1/UUID-123467',
+            'HTTP_USER_AGENT' => 'MSFT-WP/8.10.14219 (gzip)',
+            'HTTP_DEPTH'      => '0',
+        ));
+        $request->setBody($body);
+
+        $this->server->httpRequest = $request;
+        $this->server->exec();
+
+        $this->assertEquals(207, $this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
+
+        $expectedIcal = TestUtil::getTestCalendarData();
+        $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal);
+        $expectedIcal->expand(
+            new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')),
+            new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC'))
+        );
+        $expectedIcal = str_replace("\r\n", "&#xD;\n", $expectedIcal->serialize());
+
+        $expected = <<<XML
+<?xml version="1.0"?>
+<d:multistatus xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
+<d:response>
+  <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
+  <d:propstat>
+    <d:prop>
+      <cal:calendar-data>$expectedIcal</cal:calendar-data>
+      <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
+    </d:prop>
+    <d:status>HTTP/1.1 200 OK</d:status>
+  </d:propstat>
+</d:response>
+</d:multistatus>
+XML;
+
+        $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
+
+    }
+
+    /**
+     * @depends testSupportedReportSetProperty
+     * @depends testCalendarMultiGetReport
+     */
+    function testCalendarQueryReportBadDepth() {
+
+        $body =
+            '<?xml version="1.0"?>' .
+            '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
+            '<d:prop>' .
+            '  <c:calendar-data>' .
+            '     <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
+            '  </c:calendar-data>' .
+            '  <d:getetag />' .
+            '</d:prop>' .
+            '<c:filter>' .
+            '  <c:comp-filter name="VCALENDAR">' .
+            '    <c:comp-filter name="VEVENT" />' .
+            '  </c:comp-filter>' .
+            '</c:filter>' .
+            '</c:calendar-query>';
+
+        $request = HTTP\Sapi::createFromServerArray(array(
+            'REQUEST_METHOD' => 'REPORT',
+            'REQUEST_URI'    => '/calendars/user1/UUID-123467',
+            'HTTP_DEPTH'     => '0',
+        ));
+        $request->setBody($body);
+
+        $this->server->httpRequest = $request;
+        $this->server->exec();
+
+        $this->assertEquals(400, $this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
+
+    }
+
+    /**
      * @depends testCalendarQueryReport
      */
     function testCalendarQueryReportNoCalData() {

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