[Pkg-owncloud-commits] [php-sabredav] 148/220: Fixed CalDAV tests.

David Prévot taffit at moszumanska.debian.org
Thu May 12 01:21:20 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 4e7d0a991fb91fa0abeec5281569504e5fd83127
Author: Evert Pot <me at evertpot.com>
Date:   Mon Apr 11 05:20:05 2016 -0400

    Fixed CalDAV tests.
---
 lib/CalDAV/Plugin.php                              |  2 +-
 lib/CalDAV/Schedule/Outbox.php                     | 14 +------
 lib/CalDAV/Schedule/Plugin.php                     |  6 +--
 lib/CalDAV/Schedule/SchedulingObject.php           | 16 ++------
 lib/DAVACL/Plugin.php                              |  3 ++
 tests/Sabre/CalDAV/ICSExportPluginTest.php         |  3 ++
 .../Sabre/CalDAV/Notifications/CollectionTest.php  | 11 ++----
 tests/Sabre/CalDAV/Notifications/NodeTest.php      | 11 ++----
 tests/Sabre/CalDAV/Notifications/PluginTest.php    |  5 +--
 tests/Sabre/CalDAV/Principal/UserTest.php          |  4 +-
 tests/Sabre/CalDAV/Schedule/InboxTest.php          | 43 +-------------------
 tests/Sabre/CalDAV/Schedule/OutboxTest.php         | 46 +---------------------
 .../Sabre/CalDAV/Schedule/SchedulingObjectTest.php | 34 ++++------------
 .../CalDAV/Subscriptions/SubscriptionTest.php      | 16 ++------
 tests/Sabre/DAV/Sharing/PluginTest.php             |  2 +-
 15 files changed, 39 insertions(+), 177 deletions(-)

diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php
index c1ddec5..71ba752 100644
--- a/lib/CalDAV/Plugin.php
+++ b/lib/CalDAV/Plugin.php
@@ -969,7 +969,7 @@ class Plugin extends DAV\ServerPlugin {
      */
     function getSupportedPrivilegeSet(INode $node, array &$supportedPrivilegeSet) {
 
-        if ($node instanceof ISharedNode) {
+        if ($node instanceof ICalendar) {
             $supportedPrivilegeSet['{DAV:}read']['aggregates']['{' . self::NS_CALDAV . '}read-free-busy'] = [
                 'abstract'   => false,
                 'aggregates' => [],
diff --git a/lib/CalDAV/Schedule/Outbox.php b/lib/CalDAV/Schedule/Outbox.php
index 341fd5b..29eefa7 100644
--- a/lib/CalDAV/Schedule/Outbox.php
+++ b/lib/CalDAV/Schedule/Outbox.php
@@ -92,12 +92,7 @@ class Outbox extends DAV\Collection implements IOutbox {
 
         return [
             [
-                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-query-freebusy',
-                'principal' => $this->getOwner(),
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent',
+                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-send',
                 'principal' => $this->getOwner(),
                 'protected' => true,
             ],
@@ -107,12 +102,7 @@ class Outbox extends DAV\Collection implements IOutbox {
                 'protected' => true,
             ],
             [
-                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-query-freebusy',
-                'principal' => $this->getOwner() . '/calendar-proxy-write',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent',
+                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-send',
                 'principal' => $this->getOwner() . '/calendar-proxy-write',
                 'protected' => true,
             ],
diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index a407980..668468d 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -586,7 +586,7 @@ class Plugin extends ServerPlugin {
 
         $ns = '{' . self::NS_CALDAV . '}';
         if ($node instanceof IOutbox) {
-            $supportedPrivilegeSet[$ns . 'schedule-send'][
+            $supportedPrivilegeSet[$ns . 'schedule-send'] = [
                 'abstract' => false,
                 'aggregates' => [
                     $ns . 'schedule-send-invite' => [
@@ -611,7 +611,7 @@ class Plugin extends ServerPlugin {
             ];
         }
         if ($node instanceof IInbox) {
-            $supportedPrivilegeSet[$ns . 'schedule-deliver'][
+            $supportedPrivilegeSet[$ns . 'schedule-deliver'] = [
                 'abstract' => false,
                 'aggregates' => [
                     $ns . 'schedule-deliver-invite' => [
@@ -771,7 +771,7 @@ class Plugin extends ServerPlugin {
 
         if ($componentType === 'VFREEBUSY' && $method === 'REQUEST') {
 
-            $acl && $acl->checkPrivileges($outboxPath, '{' . self::NS_CALDAV . '}schedule-query-freebusy');
+            $acl && $acl->checkPrivileges($outboxPath, '{' . self::NS_CALDAV . '}schedule-send-freebusy');
             $this->handleFreeBusyRequest($outboxNode, $vObject, $request, $response);
 
             // Destroy circular references so PHP can GC the object.
diff --git a/lib/CalDAV/Schedule/SchedulingObject.php b/lib/CalDAV/Schedule/SchedulingObject.php
index a36646e..6d9d3d5 100644
--- a/lib/CalDAV/Schedule/SchedulingObject.php
+++ b/lib/CalDAV/Schedule/SchedulingObject.php
@@ -134,22 +134,12 @@ class SchedulingObject extends \Sabre\CalDAV\CalendarObject implements IScheduli
         // The default ACL
         return [
             [
-                'privilege' => '{DAV:}read',
-                'principal' => $this->objectData['principaluri'],
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}write',
-                'principal' => $this->objectData['principaluri'],
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}read',
-                'principal' => $this->objectData['principaluri'] . '/calendar-proxy-write',
+                'privilege' => '{DAV:}all',
+                'principal' => '{DAV:}owner',
                 'protected' => true,
             ],
             [
-                'privilege' => '{DAV:}write',
+                'privilege' => '{DAV:}all',
                 'principal' => $this->objectData['principaluri'] . '/calendar-proxy-write',
                 'protected' => true,
             ],
diff --git a/lib/DAVACL/Plugin.php b/lib/DAVACL/Plugin.php
index 68acf75..114a587 100644
--- a/lib/DAVACL/Plugin.php
+++ b/lib/DAVACL/Plugin.php
@@ -644,6 +644,9 @@ class Plugin extends DAV\ServerPlugin {
             $current = array_pop($collected);
             $collected2[] = $current['privilege'];
 
+            if (!isset($flat[$current['privilege']])) {
+                throw new \Sabre\DAV\Exception('A node has the "' . $current['privilege'] . '" in its ACL list, but this privilege was not reported in the supportedPrivilegeSet list');
+            }
             foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) {
                 $collected2[] = $subPriv;
                 $collected[] = $flat[$subPriv];
diff --git a/tests/Sabre/CalDAV/ICSExportPluginTest.php b/tests/Sabre/CalDAV/ICSExportPluginTest.php
index 46a5bc1..1470a94 100644
--- a/tests/Sabre/CalDAV/ICSExportPluginTest.php
+++ b/tests/Sabre/CalDAV/ICSExportPluginTest.php
@@ -155,6 +155,9 @@ ICS
         $this->server->addPlugin(
             new DAVACL\Plugin()
         );
+        $this->server->addPlugin(
+            new Plugin()
+        );
 
         $this->autoLogin('admin');
 
diff --git a/tests/Sabre/CalDAV/Notifications/CollectionTest.php b/tests/Sabre/CalDAV/Notifications/CollectionTest.php
index e297985..6585f85 100644
--- a/tests/Sabre/CalDAV/Notifications/CollectionTest.php
+++ b/tests/Sabre/CalDAV/Notifications/CollectionTest.php
@@ -56,13 +56,8 @@ class CollectionTest extends \PHPUnit_Framework_TestCase {
         $col = $this->getInstance();
         $expected = [
             [
-                'privilege' => '{DAV:}read',
-                'principal' => $this->principalUri,
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}write',
-                'principal' => $this->principalUri,
+                'privilege' => '{DAV:}all',
+                'principal' => '{DAV:}owner',
                 'protected' => true,
             ],
         ];
@@ -72,7 +67,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase {
     }
 
     /**
-     * @expectedException Sabre\DAV\Exception\NotImplemented
+     * @expectedException \Sabre\DAV\Exception\Forbidden
      */
     function testSetACL() {
 
diff --git a/tests/Sabre/CalDAV/Notifications/NodeTest.php b/tests/Sabre/CalDAV/Notifications/NodeTest.php
index 8664069..6c6e02d 100644
--- a/tests/Sabre/CalDAV/Notifications/NodeTest.php
+++ b/tests/Sabre/CalDAV/Notifications/NodeTest.php
@@ -67,13 +67,8 @@ class NodeTest extends \PHPUnit_Framework_TestCase {
         $node = $this->getInstance();
         $expected = [
             [
-                'privilege' => '{DAV:}read',
-                'principal' => 'principals/user1',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}write',
-                'principal' => 'principals/user1',
+                'privilege' => '{DAV:}all',
+                'principal' => '{DAV:}owner',
                 'protected' => true,
             ],
         ];
@@ -83,7 +78,7 @@ class NodeTest extends \PHPUnit_Framework_TestCase {
     }
 
     /**
-     * @expectedException Sabre\DAV\Exception\NotImplemented
+     * @expectedException \Sabre\DAV\Exception\Forbidden
      */
     function testSetACL() {
 
diff --git a/tests/Sabre/CalDAV/Notifications/PluginTest.php b/tests/Sabre/CalDAV/Notifications/PluginTest.php
index da341b1..40cff5a 100644
--- a/tests/Sabre/CalDAV/Notifications/PluginTest.php
+++ b/tests/Sabre/CalDAV/Notifications/PluginTest.php
@@ -78,18 +78,17 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
         $httpRequest = new Request('GET', '/', ['Host' => 'sabredav.org']);
         $this->server->httpRequest = $httpRequest;
 
-        $props = $this->server->getPropertiesForPath('/principals/user1', [
+        $props = $this->server->getPropertiesForPath('principals/admin', [
             '{' . Plugin::NS_CALENDARSERVER . '}notification-URL',
         ]);
 
         $this->assertArrayHasKey(0, $props);
         $this->assertArrayHasKey(200, $props[0]);
 
-
         $this->assertArrayHasKey('{' . Plugin::NS_CALENDARSERVER . '}notification-URL', $props[0][200]);
         $prop = $props[0][200]['{' . Plugin::NS_CALENDARSERVER . '}notification-URL'];
         $this->assertTrue($prop instanceof DAV\Xml\Property\Href);
-        $this->assertEquals('calendars/user1/notifications/', $prop->getHref());
+        $this->assertEquals('calendars/admin/notifications/', $prop->getHref());
 
     }
 
diff --git a/tests/Sabre/CalDAV/Principal/UserTest.php b/tests/Sabre/CalDAV/Principal/UserTest.php
index 6f69313..420bb3b 100644
--- a/tests/Sabre/CalDAV/Principal/UserTest.php
+++ b/tests/Sabre/CalDAV/Principal/UserTest.php
@@ -103,8 +103,8 @@ class UserTest extends \PHPUnit_Framework_TestCase {
 
         $expected = [
             [
-                'privilege' => '{DAV:}read',
-                'principal' => '{DAV:}authenticated',
+                'privilege' => '{DAV:}all',
+                'principal' => '{DAV:}owner',
                 'protected' => true,
             ],
             [
diff --git a/tests/Sabre/CalDAV/Schedule/InboxTest.php b/tests/Sabre/CalDAV/Schedule/InboxTest.php
index 43cce7d..01c3488 100644
--- a/tests/Sabre/CalDAV/Schedule/InboxTest.php
+++ b/tests/Sabre/CalDAV/Schedule/InboxTest.php
@@ -40,54 +40,13 @@ class InboxTest extends \PHPUnit_Framework_TestCase {
                 'protected' => true,
             ],
             [
-                'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-deliver-invite',
-                'principal' => '{DAV:}authenticated',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-deliver-reply',
+                'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-deliver',
                 'principal' => '{DAV:}authenticated',
                 'protected' => true,
             ],
         ], $inbox->getACL());
 
         $ok = false;
-        try {
-            $inbox->setACL([]);
-        } catch (DAV\Exception\MethodNotAllowed $e) {
-            $ok = true;
-        }
-        if (!$ok) {
-            $this->fail('Exception was not emitted');
-        }
-
-    }
-
-    function testGetSupportedPrivilegeSet() {
-
-        $inbox = new Inbox(
-            new CalDAV\Backend\MockScheduling(),
-            'principals/user1'
-        );
-        $r = $inbox->getSupportedPrivilegeSet();
-
-        $ok = 0;
-        foreach ($r['aggregates'] as $priv) {
-
-            if ($priv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver') {
-                $ok++;
-                foreach ($priv['aggregates'] as $subpriv) {
-                    if ($subpriv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver-invite') {
-                        $ok++;
-                    }
-                    if ($subpriv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver-reply') {
-                        $ok++;
-                    }
-                }
-            }
-        }
-
-        $this->assertEquals(3, $ok, "We're missing one or more privileges");
 
     }
 
diff --git a/tests/Sabre/CalDAV/Schedule/OutboxTest.php b/tests/Sabre/CalDAV/Schedule/OutboxTest.php
index c9c8cee..04d4b12 100644
--- a/tests/Sabre/CalDAV/Schedule/OutboxTest.php
+++ b/tests/Sabre/CalDAV/Schedule/OutboxTest.php
@@ -17,13 +17,7 @@ class OutboxTest extends \PHPUnit_Framework_TestCase {
 
         $this->assertEquals([
             [
-                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-query-freebusy',
-                'principal' => 'principals/user1',
-                'protected' => true,
-            ],
-
-            [
-                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent',
+                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-send',
                 'principal' => 'principals/user1',
                 'protected' => true,
             ],
@@ -33,12 +27,7 @@ class OutboxTest extends \PHPUnit_Framework_TestCase {
                 'protected' => true,
             ],
             [
-                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-query-freebusy',
-                'principal' => 'principals/user1/calendar-proxy-write',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent',
+                'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-send',
                 'principal' => 'principals/user1/calendar-proxy-write',
                 'protected' => true,
             ],
@@ -54,37 +43,6 @@ class OutboxTest extends \PHPUnit_Framework_TestCase {
             ],
         ], $outbox->getACL());
 
-        $ok = false;
-        try {
-            $outbox->setACL([]);
-        } catch (DAV\Exception\MethodNotAllowed $e) {
-            $ok = true;
-        }
-        if (!$ok) {
-            $this->fail('Exception was not emitted');
-        }
-
     }
 
-    function testGetSupportedPrivilegeSet() {
-
-        $outbox = new Outbox('principals/user1');
-        $r = $outbox->getSupportedPrivilegeSet();
-
-        $ok = 0;
-        foreach ($r['aggregates'] as $priv) {
-
-            if ($priv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-query-freebusy') {
-                $ok++;
-            }
-            if ($priv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent') {
-                $ok++;
-            }
-        }
-
-        $this->assertEquals(2, $ok, "We're missing one or more privileges");
-
-    }
-
-
 }
diff --git a/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php b/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php
index 2d55513..7a5948f 100644
--- a/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php
+++ b/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php
@@ -174,22 +174,12 @@ ICS;
 
         $expected = [
             [
-                'privilege' => '{DAV:}read',
-                'principal' => 'principals/user1',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}write',
-                'principal' => 'principals/user1',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}read',
-                'principal' => 'principals/user1/calendar-proxy-write',
+                'privilege' => '{DAV:}all',
+                'principal' => '{DAV:}owner',
                 'protected' => true,
             ],
             [
-                'privilege' => '{DAV:}write',
+                'privilege' => '{DAV:}all',
                 'principal' => 'principals/user1/calendar-proxy-write',
                 'protected' => true,
             ],
@@ -214,22 +204,12 @@ ICS;
         $calendarObject = new SchedulingObject($backend, ['calendarid' => 1, 'uri' => 'foo', 'principaluri' => 'principals/user1' ]);
         $expected = [
             [
-                'privilege' => '{DAV:}read',
-                'principal' => 'principals/user1',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}write',
-                'principal' => 'principals/user1',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}read',
-                'principal' => 'principals/user1/calendar-proxy-write',
+                'privilege' => '{DAV:}all',
+                'principal' => '{DAV:}owner',
                 'protected' => true,
             ],
             [
-                'privilege' => '{DAV:}write',
+                'privilege' => '{DAV:}all',
                 'principal' => 'principals/user1/calendar-proxy-write',
                 'protected' => true,
             ],
@@ -245,7 +225,7 @@ ICS;
     }
 
     /**
-     * @expectedException Sabre\DAV\Exception\MethodNotAllowed
+     * @expectedException \Sabre\DAV\Exception\Forbidden
      */
     function testSetACL() {
 
diff --git a/tests/Sabre/CalDAV/Subscriptions/SubscriptionTest.php b/tests/Sabre/CalDAV/Subscriptions/SubscriptionTest.php
index 6806ea9..e4067e0 100644
--- a/tests/Sabre/CalDAV/Subscriptions/SubscriptionTest.php
+++ b/tests/Sabre/CalDAV/Subscriptions/SubscriptionTest.php
@@ -52,22 +52,12 @@ class SubscriptionTest extends \PHPUnit_Framework_TestCase {
 
         $acl = [
             [
-                'privilege' => '{DAV:}read',
-                'principal' => 'principals/user1',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}write',
+                'privilege' => '{DAV:}all',
                 'principal' => 'principals/user1',
                 'protected' => true,
             ],
             [
-                'privilege' => '{DAV:}read',
-                'principal' => 'principals/user1/calendar-proxy-write',
-                'protected' => true,
-            ],
-            [
-                'privilege' => '{DAV:}write',
+                'privilege' => '{DAV:}all',
                 'principal' => 'principals/user1/calendar-proxy-write',
                 'protected' => true,
             ],
@@ -94,7 +84,7 @@ class SubscriptionTest extends \PHPUnit_Framework_TestCase {
     }
 
     /**
-     * @expectedException \Sabre\DAV\Exception\MethodNotAllowed
+     * @expectedException \Sabre\DAV\Exception\Forbidden
      */
     function testSetACL() {
 
diff --git a/tests/Sabre/DAV/Sharing/PluginTest.php b/tests/Sabre/DAV/Sharing/PluginTest.php
index 0f0aba7..6aa09ca 100644
--- a/tests/Sabre/DAV/Sharing/PluginTest.php
+++ b/tests/Sabre/DAV/Sharing/PluginTest.php
@@ -175,7 +175,7 @@ class PluginTest extends \Sabre\DAVServerTest {
      */
     function testBrowserPostActionAccessDenied() {
 
-        $this->aclPlugin->allowAccessToNodesWithoutACL = false;
+        $this->aclPlugin->setDefaultAcl([]);
         $this->sharingPlugin->browserPostAction(
             'shareable',
             'share',

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



More information about the Pkg-owncloud-commits mailing list