[Pkg-owncloud-commits] [php-sabredav] 116/220: Lots of new unittests.

David Prévot taffit at moszumanska.debian.org
Thu May 12 01:21:15 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 78da7b5160d479027c3fb8f357b4e99a630d4f44
Author: Evert Pot <me at evertpot.com>
Date:   Wed Mar 30 02:49:15 2016 -0400

    Lots of new unittests.
---
 lib/DAV/Sharing/Plugin.php                        |   7 +-
 lib/DAVACL/Plugin.php                             |  11 +-
 tests/Sabre/CalDAV/SharingPluginTest.php          |  59 ++++++----
 tests/Sabre/DAV/Sharing/PluginTest.php            | 136 ++++++++++++++++++++++
 tests/Sabre/DAV/Sharing/ShareResourceTest.php     |  57 +++++++++
 tests/Sabre/DAV/Xml/Element/ShareeTest.php        |  98 ++++++++++++++++
 tests/Sabre/DAV/Xml/Request/ShareResourceTest.php |   1 +
 tests/Sabre/DAVServerTest.php                     |   8 +-
 8 files changed, 345 insertions(+), 32 deletions(-)

diff --git a/lib/DAV/Sharing/Plugin.php b/lib/DAV/Sharing/Plugin.php
index 23b9067..7774956 100644
--- a/lib/DAV/Sharing/Plugin.php
+++ b/lib/DAV/Sharing/Plugin.php
@@ -113,12 +113,7 @@ class Plugin extends ServerPlugin {
      */
     function shareResource($path, array $sharees) {
 
-        try {
-            $node = $this->server->tree->getNodeForPath($path);
-        } catch (DAV\Exception\NotFound $e) {
-            // If the target node is not found, we stop executing.
-            return;
-        }
+        $node = $this->server->tree->getNodeForPath($path);
 
         if (!$node instanceof ISharedNode) {
 
diff --git a/lib/DAVACL/Plugin.php b/lib/DAVACL/Plugin.php
index f025bdc..469fbb4 100644
--- a/lib/DAVACL/Plugin.php
+++ b/lib/DAVACL/Plugin.php
@@ -5,6 +5,7 @@ namespace Sabre\DAVACL;
 use Sabre\DAV;
 use Sabre\DAV\INode;
 use Sabre\DAV\Exception\BadRequest;
+use Sabre\DAV\Exception\NotFound;
 use Sabre\HTTP\RequestInterface;
 use Sabre\HTTP\ResponseInterface;
 use Sabre\Uri;
@@ -587,7 +588,13 @@ class Plugin extends DAV\ServerPlugin {
         $collections = $this->principalCollectionSet;
         foreach ($collections as $collection) {
 
-            $principalCollection = $this->server->tree->getNodeForPath($collection);
+            try {
+                $principalCollection = $this->server->tree->getNodeForPath($collection);
+            } catch (NotFound $e) {
+                // Ignore and move on
+                continue;
+            }
+
             if (!$principalCollection instanceof IPrincipalCollection) {
                 // Not a principal collection, we're simply going to ignore
                 // this.
@@ -1081,7 +1088,7 @@ class Plugin extends DAV\ServerPlugin {
             // Looking up the principal
             try {
                 $principal = $this->server->tree->getNodeForPath($newAce['principal']);
-            } catch (DAV\Exception\NotFound $e) {
+            } catch (NotFound $e) {
                 throw new Exception\NotRecognizedPrincipal('The specified principal (' . $newAce['principal'] . ') does not exist');
             }
             if (!($principal instanceof IPrincipal)) {
diff --git a/tests/Sabre/CalDAV/SharingPluginTest.php b/tests/Sabre/CalDAV/SharingPluginTest.php
index 4041360..6e9e884 100644
--- a/tests/Sabre/CalDAV/SharingPluginTest.php
+++ b/tests/Sabre/CalDAV/SharingPluginTest.php
@@ -51,6 +51,18 @@ class SharingPluginTest extends \Sabre\DAVServerTest {
 
     }
 
+    /**
+     * @expectedException \LogicException
+     */
+    function testSetupWithoutCoreSharingPlugin() {
+
+        $server = new DAV\Server();
+        $server->addPlugin(
+            new SharingPlugin()
+        );
+
+    }
+
     function testGetFeatures() {
 
         $this->assertEquals(['calendarserver-sharing'], $this->caldavSharingPlugin->getFeatures());
@@ -309,13 +321,14 @@ RRR;
 
     }
 
+
     function testUnpublish() {
 
-        $request = HTTP\Sapi::createFromServerArray([
-            'REQUEST_METHOD' => 'POST',
-            'REQUEST_URI'    => '/calendars/user1/cal1',
-            'CONTENT_TYPE'   => 'text/xml',
-        ]);
+        $request = new HTTP\Request(
+            'POST',
+            '/calendars/user1/cal1',
+            ['Content-Type' => 'text/xml']
+        );
 
         $xml = '<?xml version="1.0"?>
 <cs:unpublish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
@@ -330,46 +343,46 @@ RRR;
 
     function testPublishWrongUrl() {
 
-        $request = HTTP\Sapi::createFromServerArray([
-            'REQUEST_METHOD' => 'POST',
-            'REQUEST_URI'    => '/calendars/user1/cal2',
-            'CONTENT_TYPE'   => 'text/xml',
-        ]);
+        $request = new HTTP\Request(
+            'POST',
+            '/calendars/user1',
+            ['Content-Type' => 'text/xml']
+        );
 
         $xml = '<?xml version="1.0"?>
 <cs:publish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
 ';
 
         $request->setBody($xml);
-        $this->request($request, 403);
+        $this->request($request, 501);
 
     }
 
     function testUnpublishWrongUrl() {
 
-        $request = HTTP\Sapi::createFromServerArray([
-            'REQUEST_METHOD' => 'POST',
-            'REQUEST_URI'    => '/calendars/user1/cal2',
-            'CONTENT_TYPE'   => 'text/xml',
-        ]);
-
+        $request = new HTTP\Request(
+            'POST',
+            '/calendars/user1',
+            ['Content-Type' => 'text/xml']
+        );
         $xml = '<?xml version="1.0"?>
 <cs:unpublish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
 ';
 
         $request->setBody($xml);
 
-        $this->request($request, 403);
+        $this->request($request, 501);
 
     }
 
     function testUnknownXmlDoc() {
 
-        $request = HTTP\Sapi::createFromServerArray([
-            'REQUEST_METHOD' => 'POST',
-            'REQUEST_URI'    => '/calendars/user1/cal2',
-            'CONTENT_TYPE'   => 'text/xml',
-        ]);
+
+        $request = new HTTP\Request(
+            'POST',
+            '/calendars/user1/cal2',
+            ['Content-Type' => 'text/xml']
+        );
 
         $xml = '<?xml version="1.0"?>
 <cs:foo-bar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />';
diff --git a/tests/Sabre/DAV/Sharing/PluginTest.php b/tests/Sabre/DAV/Sharing/PluginTest.php
index 00e619d..0f0aba7 100644
--- a/tests/Sabre/DAV/Sharing/PluginTest.php
+++ b/tests/Sabre/DAV/Sharing/PluginTest.php
@@ -8,6 +8,8 @@ use Sabre\DAV\Xml\Property;
 class PluginTest extends \Sabre\DAVServerTest {
 
     protected $setupSharing = true;
+    protected $setupACL = true;
+    protected $autoLogin = 'admin';
 
     function setUpTree() {
 
@@ -51,4 +53,138 @@ class PluginTest extends \Sabre\DAVServerTest {
 
     }
 
+    function testGetPluginInfo() {
+
+        $result = $this->sharingPlugin->getPluginInfo();
+        $this->assertInternalType('array', $result);
+        $this->assertEquals('sharing', $result['name']);
+
+    }
+
+    function testHtmlActionsPanel() {
+
+        $node = new \Sabre\DAV\Mock\Collection('foo');
+        $html = '';
+
+        $this->assertNull(
+            $this->sharingPlugin->htmlActionsPanel($node, $html, 'foo/bar')
+        );
+
+        $this->assertEquals(
+            '',
+            $html
+        );
+
+        $node = new \Sabre\DAV\Mock\SharedNode('foo', \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER);
+        $html = '';
+
+        $this->assertNull(
+            $this->sharingPlugin->htmlActionsPanel($node, $html, 'shareable')
+        );
+        $this->assertContains(
+            'Share this resource',
+            $html
+        );
+
+    }
+
+    function testBrowserPostActionUnknownAction() {
+
+        $this->assertNull($this->sharingPlugin->browserPostAction(
+            'shareable',
+            'foo',
+            []
+        ));
+
+    }
+
+    function testBrowserPostActionSuccess() {
+
+        $this->assertFalse($this->sharingPlugin->browserPostAction(
+            'shareable',
+            'share',
+            [
+                'access' => 'read',
+                'href'   => 'mailto:foo at example.org',
+            ]
+        ));
+
+        $expected = [
+            new \Sabre\DAV\Xml\Element\Sharee([
+                'href'         => 'mailto:foo at example.org',
+                'access'       => \Sabre\DAV\Sharing\Plugin::ACCESS_READ,
+                'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_NORESPONSE,
+            ])
+        ];
+        $this->assertEquals(
+            $expected,
+            $this->tree[0]->getInvites()
+        );
+
+    }
+
+    /**
+     * @expectedException \Sabre\DAV\Exception\BadRequest
+     */
+    function testBrowserPostActionNoHref() {
+
+        $this->sharingPlugin->browserPostAction(
+            'shareable',
+            'share',
+            [
+                'access' => 'read',
+            ]
+        );
+
+    }
+
+    /**
+     * @expectedException \Sabre\DAV\Exception\BadRequest
+     */
+    function testBrowserPostActionNoAccess() {
+
+        $this->sharingPlugin->browserPostAction(
+            'shareable',
+            'share',
+            [
+                'href' => 'mailto:foo at example.org',
+            ]
+        );
+
+    }
+
+
+    /**
+     * @expectedException \Sabre\DAV\Exception\BadRequest
+     */
+    function testBrowserPostActionBadAccess() {
+
+        $this->sharingPlugin->browserPostAction(
+            'shareable',
+            'share',
+            [
+                'href'   => 'mailto:foo at example.org',
+                'access' => 'bleed',
+            ]
+        );
+
+    }
+
+    /**
+     * @expectedException \Sabre\DAV\Exception\Forbidden
+     */
+    function testBrowserPostActionAccessDenied() {
+
+        $this->aclPlugin->allowAccessToNodesWithoutACL = false;
+        $this->sharingPlugin->browserPostAction(
+            'shareable',
+            'share',
+            [
+                'access' => 'read',
+                'href'   => 'mailto:foo at example.org',
+            ]
+        );
+
+    }
+
 }
diff --git a/tests/Sabre/DAV/Sharing/ShareResourceTest.php b/tests/Sabre/DAV/Sharing/ShareResourceTest.php
index 122ccfa..9598111 100644
--- a/tests/Sabre/DAV/Sharing/ShareResourceTest.php
+++ b/tests/Sabre/DAV/Sharing/ShareResourceTest.php
@@ -150,4 +150,61 @@ XML;
 
     }
 
+    function testShareResourceNotFound() {
+
+        $body = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:share-resource xmlns:D="DAV:">
+ <D:sharee>
+   <D:href>mailto:eric at example.com</D:href>
+   <D:prop>
+     <D:displayname>Eric York</D:displayname>
+   </D:prop>
+   <D:comment>Shared workspace</D:comment>
+   <D:share-access>
+     <D:read-write />
+   </D:share-access>
+ </D:sharee>
+</D:share-resource>
+XML;
+        $request = new Request('POST', '/not-found', ['Content-Type' => 'application/davsharing+xml; charset="utf-8"'], $body);
+
+        $response = $this->request($request, 404);
+
+    }
+
+    function testShareResourceNotISharedNode() {
+
+        $body = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:share-resource xmlns:D="DAV:">
+ <D:sharee>
+   <D:href>mailto:eric at example.com</D:href>
+   <D:prop>
+     <D:displayname>Eric York</D:displayname>
+   </D:prop>
+   <D:comment>Shared workspace</D:comment>
+   <D:share-access>
+     <D:read-write />
+   </D:share-access>
+ </D:sharee>
+</D:share-resource>
+XML;
+        $request = new Request('POST', '/', ['Content-Type' => 'application/davsharing+xml; charset="utf-8"'], $body);
+
+        $response = $this->request($request, 403);
+
+    }
+
+    function testShareResourceUnknownDoc() {
+
+        $body = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:blablabla xmlns:D="DAV:" />
+XML;
+        $request = new Request('POST', '/shareable', ['Content-Type' => 'application/davsharing+xml; charset="utf-8"'], $body);
+        $response = $this->request($request, 400);
+
+    }
+
 }
diff --git a/tests/Sabre/DAV/Xml/Element/ShareeTest.php b/tests/Sabre/DAV/Xml/Element/ShareeTest.php
new file mode 100644
index 0000000..bdd4bbd
--- /dev/null
+++ b/tests/Sabre/DAV/Xml/Element/ShareeTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Sabre\DAV\Xml\Element;
+
+use Sabre\DAV\Xml\XmlTest;
+use Sabre\DAV\Sharing\Plugin;
+
+class ShareeTest extends XmlTest {
+
+    /**
+     * @expectedException \InvalidArgumentException
+     */
+    function testShareeUnknownPropertyInConstructor() {
+
+        new Sharee(['foo' => 'bar']);
+
+    }
+
+    function testDeserialize() {
+
+        $xml = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:sharee xmlns:D="DAV:">
+   <D:href>mailto:eric at example.com</D:href>
+   <D:prop>
+     <D:displayname>Eric York</D:displayname>
+   </D:prop>
+   <D:comment>Shared workspace</D:comment>
+   <D:share-access>
+     <D:read-write />
+   </D:share-access>
+</D:sharee>
+XML;
+
+        $result = $this->parse($xml, [
+            '{DAV:}sharee' => 'Sabre\\DAV\\Xml\\Element\\Sharee'
+        ]);
+
+        $expected = new Sharee([
+            'href'       => 'mailto:eric at example.com',
+            'properties' => ['{DAV:}displayname' => 'Eric York'],
+            'comment'    => 'Shared workspace',
+            'access'     => Plugin::ACCESS_READWRITE,
+        ]);
+        $this->assertEquals(
+            $expected,
+            $result['value']
+        );
+
+    }
+
+    /**
+     * @expectedException \Sabre\DAV\Exception\BadRequest
+     */
+    function testDeserializeNoHref() {
+
+        $xml = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:sharee xmlns:D="DAV:">
+   <D:prop>
+     <D:displayname>Eric York</D:displayname>
+   </D:prop>
+   <D:comment>Shared workspace</D:comment>
+   <D:share-access>
+     <D:read-write />
+   </D:share-access>
+</D:sharee>
+XML;
+
+        $this->parse($xml, [
+            '{DAV:}sharee' => 'Sabre\\DAV\\Xml\\Element\\Sharee'
+        ]);
+
+    }
+
+
+    /**
+     * @expectedException \Sabre\DAV\Exception\BadRequest
+     */
+    function testDeserializeNoShareeAccess() {
+
+        $xml = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:sharee xmlns:D="DAV:">
+   <D:href>mailto:eric at example.com</D:href>
+   <D:prop>
+     <D:displayname>Eric York</D:displayname>
+   </D:prop>
+   <D:comment>Shared workspace</D:comment>
+</D:sharee>
+XML;
+
+        $this->parse($xml, [
+            '{DAV:}sharee' => 'Sabre\\DAV\\Xml\\Element\\Sharee'
+        ]);
+
+    }
+}
diff --git a/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php b/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php
index 250c1e1..5f96c49 100644
--- a/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php
+++ b/tests/Sabre/DAV/Xml/Request/ShareResourceTest.php
@@ -71,4 +71,5 @@ XML;
 
     }
 
+
 }
diff --git a/tests/Sabre/DAVServerTest.php b/tests/Sabre/DAVServerTest.php
index b175be8..4485003 100644
--- a/tests/Sabre/DAVServerTest.php
+++ b/tests/Sabre/DAVServerTest.php
@@ -152,6 +152,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
         }
         if ($this->setupACL) {
             $this->aclPlugin = new DAVACL\Plugin();
+            $this->aclPlugin->adminPrincipals = ['principals/admin'];
             $this->server->addPlugin($this->aclPlugin);
         }
         if ($this->setupLocks) {
@@ -215,6 +216,11 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
         $authBackend = new DAV\Auth\Backend\Mock();
         $authBackend->setPrincipal('principals/' . $userName);
         $this->authPlugin = new DAV\Auth\Plugin($authBackend);
+
+        // If the auth plugin already exists, we're removing its hooks:
+        if ($oldAuth = $this->server->getPlugin('auth')) {
+            $this->server->removeListener('beforeMethod', [$oldAuth, 'beforeMethod']);
+        }
         $this->server->addPlugin($this->authPlugin);
 
         // This will trigger the actual login procedure
@@ -239,7 +245,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
             );
         }
 
-        if ($this->setupCardDAV || $this->setupCalDAV) {
+        if ($this->setupCardDAV || $this->setupCalDAV || $this->setupACL) {
             $this->tree[] = new CalDAV\Principal\Collection(
                 $this->principalBackend
             );

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