[Pkg-owncloud-commits] [php-sabredav] 26/36: Workaround for broken Windows Phone client.

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


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

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

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

    Workaround for broken Windows Phone client.
    
    Fixes #691.
    See #685 for more detail.
---
 CHANGELOG.md                      |  1 +
 lib/CalDAV/Plugin.php             | 13 +++++
 tests/Sabre/CalDAV/PluginTest.php | 99 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f8a67b..dc16d0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ ChangeLog
 * Now requires PHP 5.5
 * Upgraded to vobject 4, which is a lot faster.
 * Support for PHP 7.
+* #691: Workaround for broken Windows Phone client.
 
 
 3.0.2 (2015-??-??)
diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php
index 5fbeebf..6cb0ba2 100644
--- a/lib/CalDAV/Plugin.php
+++ b/lib/CalDAV/Plugin.php
@@ -577,6 +577,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 65fbfeb..f5d2fd0 100644
--- a/tests/Sabre/CalDAV/PluginTest.php
+++ b/tests/Sabre/CalDAV/PluginTest.php
@@ -733,6 +733,105 @@ XML;
     }
 
     /**
+     * @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