From d1104954aa0c60c7200d401447da4b480293ef23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 25 Jan 2016 17:50:39 +0100 Subject: [PATCH] Migrate from CardDAV sharing to more generalk DAV sharing --- apps/dav/lib/carddav/addressbook.php | 10 +- apps/dav/lib/carddav/carddavbackend.php | 10 +- .../sharing/ishareable.php} | 12 +- .../lib/{carddav => dav}/sharing/plugin.php | 20 +- .../sharing/xml/sharerequest.php | 4 +- apps/dav/lib/server.php | 1 - .../tests/CalDAV/sharing-calendars.xml | 573 ++++++++++++++++++ .../tests/unit/carddav/sharing/plugintest.php | 8 +- .../dav/tests/unit/dav/sharing/plugintest.php | 83 +++ 9 files changed, 685 insertions(+), 36 deletions(-) rename apps/dav/lib/{carddav/sharing/ishareableaddressbook.php => dav/sharing/ishareable.php} (85%) rename apps/dav/lib/{carddav => dav}/sharing/plugin.php (91%) rename apps/dav/lib/{carddav => dav}/sharing/xml/sharerequest.php (97%) create mode 100644 apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml create mode 100644 apps/dav/tests/unit/dav/sharing/plugintest.php diff --git a/apps/dav/lib/carddav/addressbook.php b/apps/dav/lib/carddav/addressbook.php index 2cfaa7b708..6c3caecddf 100644 --- a/apps/dav/lib/carddav/addressbook.php +++ b/apps/dav/lib/carddav/addressbook.php @@ -20,10 +20,10 @@ */ namespace OCA\DAV\CardDAV; -use OCA\DAV\CardDAV\Sharing\IShareableAddressBook; +use OCA\DAV\DAV\Sharing\IShareable; use Sabre\DAV\Exception\NotFound; -class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareableAddressBook { +class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { public function __construct(CardDavBackend $carddavBackend, array $addressBookInfo) { parent::__construct($carddavBackend, $addressBookInfo); @@ -82,14 +82,14 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareableAddres } // add the current user - if (isset($this->addressBookInfo['{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'])) { - $owner = $this->addressBookInfo['{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal']; + if (isset($this->addressBookInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'])) { + $owner = $this->addressBookInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal']; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $owner, 'protected' => true, ]; - if ($this->addressBookInfo['{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only']) { + if ($this->addressBookInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only']) { $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $owner, diff --git a/apps/dav/lib/carddav/carddavbackend.php b/apps/dav/lib/carddav/carddavbackend.php index 28f6099b63..81a3ba7c51 100644 --- a/apps/dav/lib/carddav/carddavbackend.php +++ b/apps/dav/lib/carddav/carddavbackend.php @@ -136,8 +136,8 @@ class CardDavBackend implements BackendInterface, SyncSupport { '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', - '{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], - '{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $row['access'] === self::ACCESS_READ, + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $row['access'] === self::ACCESS_READ, ]; } $result->closeCursor(); @@ -893,7 +893,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', 'status' => 1, 'readOnly' => ($row['access'] === self::ACCESS_READ), - '{'.\OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD.'}principal' => $p['uri'] + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal' => $p['uri'] ]; } @@ -1001,13 +1001,13 @@ class CardDavBackend implements BackendInterface, SyncSupport { foreach ($shares as $share) { $acl[] = [ 'privilege' => '{DAV:}read', - 'principal' => $share['{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], 'protected' => true, ]; if (!$share['readOnly']) { $acl[] = [ 'privilege' => '{DAV:}write', - 'principal' => $share['{' . \OCA\DAV\CardDAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], 'protected' => true, ]; } diff --git a/apps/dav/lib/carddav/sharing/ishareableaddressbook.php b/apps/dav/lib/dav/sharing/ishareable.php similarity index 85% rename from apps/dav/lib/carddav/sharing/ishareableaddressbook.php rename to apps/dav/lib/dav/sharing/ishareable.php index 8e348a9099..e82c03a6af 100644 --- a/apps/dav/lib/carddav/sharing/ishareableaddressbook.php +++ b/apps/dav/lib/dav/sharing/ishareable.php @@ -18,20 +18,20 @@ * along with this program. If not, see * */ -namespace OCA\DAV\CardDAV\Sharing; -use Sabre\CardDAV\IAddressBook; +namespace OCA\DAV\DAV\Sharing; +use Sabre\DAV\INode; /** - * This interface represents a Calendar that can be shared with other users. + * This interface represents a dav resource that can be shared with other users. * */ -interface IShareableAddressBook extends IAddressBook { +interface IShareable extends INode { /** * Updates the list of shares. * * The first array is a list of people that are to be added to the - * addressbook. + * resource. * * Every element in the add array has the following properties: * * href - A url. Usually a mailto: address @@ -48,7 +48,7 @@ interface IShareableAddressBook extends IAddressBook { function updateShares(array $add, array $remove); /** - * Returns the list of people whom this addressbook is shared with. + * Returns the list of people whom this resource is shared with. * * Every element in this array should have the following properties: * * href - Often a mailto: address diff --git a/apps/dav/lib/carddav/sharing/plugin.php b/apps/dav/lib/dav/sharing/plugin.php similarity index 91% rename from apps/dav/lib/carddav/sharing/plugin.php rename to apps/dav/lib/dav/sharing/plugin.php index d25b84d01f..d3fdd8aa96 100644 --- a/apps/dav/lib/carddav/sharing/plugin.php +++ b/apps/dav/lib/dav/sharing/plugin.php @@ -19,7 +19,8 @@ * along with this program. If not, see * */ -namespace OCA\DAV\CardDAV\Sharing; + +namespace OCA\DAV\DAV\Sharing; use OCA\DAV\Connector\Sabre\Auth; use OCP\IRequest; @@ -27,8 +28,6 @@ use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; -use Sabre\DAV\XMLUtil; -use Sabre\DAVACL\IACL; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; @@ -69,9 +68,7 @@ class Plugin extends ServerPlugin { * @return string[] */ function getFeatures() { - - return ['oc-addressbook-sharing']; - + return ['oc-resource-sharing']; } /** @@ -83,9 +80,7 @@ class Plugin extends ServerPlugin { * @return string */ function getPluginName() { - - return 'carddav-sharing'; - + return 'oc-resource-sharing'; } /** @@ -101,14 +96,13 @@ class Plugin extends ServerPlugin { */ function initialize(Server $server) { $this->server = $server; - $server->resourceTypeMapping['OCA\\DAV\CardDAV\\ISharedAddressbook'] = '{' . \Sabre\CardDAV\Plugin::NS_CARDDAV . '}shared'; - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\CardDAV\\Sharing\\Xml\\ShareRequest'; + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; $this->server->on('method:POST', [$this, 'httpPost']); } /** - * We intercept this to handle POST requests on calendars. + * We intercept this to handle POST requests on a dav resource. * * @param RequestInterface $request * @param ResponseInterface $response @@ -153,7 +147,7 @@ class Plugin extends ServerPlugin { case '{' . self::NS_OWNCLOUD . '}share' : // We can only deal with IShareableCalendar objects - if (!$node instanceof IShareableAddressBook) { + if (!$node instanceof IShareable) { return; } diff --git a/apps/dav/lib/carddav/sharing/xml/sharerequest.php b/apps/dav/lib/dav/sharing/xml/sharerequest.php similarity index 97% rename from apps/dav/lib/carddav/sharing/xml/sharerequest.php rename to apps/dav/lib/dav/sharing/xml/sharerequest.php index bd55dd4073..776fb446b6 100644 --- a/apps/dav/lib/carddav/sharing/xml/sharerequest.php +++ b/apps/dav/lib/dav/sharing/xml/sharerequest.php @@ -18,9 +18,9 @@ * along with this program. If not, see * */ -namespace OCA\DAV\CardDAV\Sharing\Xml; +namespace OCA\DAV\DAV\Sharing\Xml; -use OCA\DAV\CardDAV\Sharing\Plugin; +use OCA\DAV\DAV\Sharing\Plugin; use Sabre\Xml\Reader; use Sabre\Xml\XmlDeserializable; diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 7519a631d5..5af6905208 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -79,7 +79,6 @@ class Server { $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); $this->server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin()); $this->server->addPlugin(new IMipPlugin($mailer, $logger)); - $this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin()); $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); $this->server->addPlugin(new CardDAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); diff --git a/apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml b/apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml new file mode 100644 index 0000000000..fa20a6e486 --- /dev/null +++ b/apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml @@ -0,0 +1,573 @@ + + + + + + + + Test calendar sharing calendars + + + caldav + shared-calendars + + + + + DELETEALL + $notificationpath1:/ + + + DELETEALL + $notificationpath2:/ + + + MKCALENDAR + $calendarhome1:/shared/ + + statusCode + + + + PROPPATCH + $calendarhome1:/shared/ + + text/xml; charset=utf-8 + Resource/Common/PROPPATCH/calendar-transp-opaque.xml + + + + + + + POST invitation + + POST + $calendarhome1:/shared/ + + text/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/1.xml + + + statusCode + + + + + Check Sharee notification collection + + WAITCOUNT 1 + $notificationpath2:/ + + + GETNEW + $notificationpath2:/ + + xmlDataMatch + + filepath + Resource/CalDAV/sharing/calendars/read-write/2.xml + + + filter + {http://calendarserver.org/ns/}dtstamp + {http://calendarserver.org/ns/}uid + + + + {http://calendarserver.org/ns/}invite-notification/{http://calendarserver.org/ns/}uid + $inviteuid: + + + + + Sharee replies ACCEPTED + + POST + $calendarhome2:/ + + application/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/3.xml + + + statusCode + + + {DAV:}href + $sharedcalendar: + + + + + Shared calendar exists + + PROPFIND + $sharedcalendar:/ +
+ Depth + 0 +
+ + text/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/4.xml + + + xmlElementMatch + + exists + $verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:] + $verify-property-prefix:/{DAV:}resourcetype/{DAV:}collection + $verify-property-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:caldav}calendar + $verify-property-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind + $verify-property-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}transparent + + + notexists + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}admin + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}all + + +
+
+ + Shared calendar exists Depth:1 + + PROPFIND + $calendarhome2:/ +
+ Depth + 1 +
+ + text/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/4.xml + + + xmlElementMatch + + parent + $multistatus-response-prefix:[^{DAV:}href=$sharedcalendar:/] + + + exists + $verify-response-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:] + $verify-response-prefix:/{DAV:}resourcetype/{DAV:}collection + $verify-response-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:caldav}calendar + $verify-response-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared + $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read + $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write + $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind + $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind + $verify-response-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}transparent + + + notexists + $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}admin + $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}all + + +
+
+ + Shared calendar has invite property + + PROPFIND + $sharedcalendar:/ +
+ Depth + 0 +
+ + text/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/5.xml + + + propfindItems + + okprops + {http://calendarserver.org/ns/}invite + + + + xmlElementMatch + + exists + $verify-property-prefix:/{http://calendarserver.org/ns/}invite + $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}organizer + $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}organizer/{DAV:}href[=$principaluri1:] + $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}organizer/{http://calendarserver.org/ns/}common-name[=$username1:] + $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user + $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user/{DAV:}href[=$cuaddrurn2:] + $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user/{http://calendarserver.org/ns/}access/{http://calendarserver.org/ns/}read-write + $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user/{http://calendarserver.org/ns/}invite-accepted + + +
+
+ + Original calendar unchanged + + PROPFIND + $calendarhome1:/shared/ +
+ Depth + 0 +
+ + text/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/4.xml + + + xmlElementMatch + + exists + $verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:] + $verify-property-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}opaque + + +
+
+ + Sharee creates event + + PUT + $sharedcalendar:/1.ics + + text/calendar; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/5.ics + + + statusCode + + + + + Sharer sees event + + GET + $calendarhome1:/shared/1.ics + + calendarDataMatch + + filepath + Resource/CalDAV/sharing/calendars/read-write/5.ics + + + + + + Sharer changes event + + PUT + $calendarhome1:/shared/1.ics + + text/calendar; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/6.ics + + + statusCode + + + + + Sharee sees changed event + + GET + $sharedcalendar:/1.ics + + calendarDataMatch + + filepath + Resource/CalDAV/sharing/calendars/read-write/6.ics + + + + + + Sharer creates event + + PUT + $calendarhome1:/shared/2.ics + + text/calendar; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/7.ics + + + statusCode + + + + + Sharee sees new event + + GET + $sharedcalendar:/2.ics + + calendarDataMatch + + filepath + Resource/CalDAV/sharing/calendars/read-write/7.ics + + + + + + Sharee changes event + + PUT + $sharedcalendar:/2.ics + + text/calendar; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-write/8.ics + + + statusCode + + + + + Sharer sees changed event + + GET + $calendarhome1:/shared/2.ics + + calendarDataMatch + + filepath + Resource/CalDAV/sharing/calendars/read-write/8.ics + + + + +
+ + + + Set property on Inbox + + PROPPATCH + $inboxpath2:/ + + text/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/defaultcalendar/1.xml + + + propfindItems + + badprops + {urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL + + + + + + Verify property on inbox + + PROPFIND + $inboxpath2:/ +
+ Depth + 0 +
+ + text/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/defaultcalendar/2.xml + + + propfindItems + + okprops + $calendarpath2:]]> + + +
+
+
+ + + + POST invitation + + POST + $calendarhome1:/shared/ + + text/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-only/1.xml + + + statusCode + + + + + Check Sharee notification collection + + WAITCOUNT 1 + $notificationpath2:/ + + + GETNEW + $notificationpath2:/ + + xmlDataMatch + + filepath + Resource/CalDAV/sharing/calendars/read-only/2.xml + + + filter + {http://calendarserver.org/ns/}dtstamp + {http://calendarserver.org/ns/}uid + + + + {http://calendarserver.org/ns/}invite-notification/{http://calendarserver.org/ns/}uid + $inviteuid: + + + + + Sharee replies ACCEPTED + + POST + $calendarhome2:/ + + application/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-only/3.xml + + + statusCode + + + {DAV:}href + $sharedcalendar: + + + + + Shared calendar exists + + PROPFIND + $sharedcalendar:/ +
+ Depth + 0 +
+ + text/xml; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-only/4.xml + + + xmlElementMatch + + exists + $verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:] + $verify-property-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read + + + notexists + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}admin + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}all + + +
+
+ + Create event + + PUT + $sharedcalendar:/3.ics + + text/calendar; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-only/5.ics + + + statusCode + + status + 403 + + + + + + Sharer creates event + + PUT + $calendarhome1:/shared/4.ics + + text/calendar; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-only/6.ics + + + statusCode + + + + + Sharee sees new event + + GET + $sharedcalendar:/4.ics + + calendarDataMatch + + filepath + Resource/CalDAV/sharing/calendars/read-only/6.ics + + + + + + Sharee cannot change event + + PUT + $sharedcalendar:/4.ics + + text/calendar; charset=utf-8 + Resource/CalDAV/sharing/calendars/read-only/7.ics + + + statusCode + + status + 403 + + + + +
+ + + + DELETEALL + $notificationpath1:/ + $notificationpath2:/ + $notificationpath3:/ + $notificationpath4:/ + + + +
diff --git a/apps/dav/tests/unit/carddav/sharing/plugintest.php b/apps/dav/tests/unit/carddav/sharing/plugintest.php index 19ee075fb4..f7159c2d22 100644 --- a/apps/dav/tests/unit/carddav/sharing/plugintest.php +++ b/apps/dav/tests/unit/carddav/sharing/plugintest.php @@ -22,8 +22,8 @@ namespace OCA\DAV\Tests\Unit\CardDAV; -use OCA\DAV\CardDAV\Sharing\IShareableAddressBook; -use OCA\DAV\CardDAV\Sharing\Plugin; +use OCA\DAV\DAV\Sharing\IShareable; +use OCA\DAV\DAV\Sharing\Plugin; use OCA\DAV\Connector\Sabre\Auth; use OCP\IRequest; use Sabre\DAV\Server; @@ -38,7 +38,7 @@ class PluginTest extends TestCase { private $plugin; /** @var Server */ private $server; - /** @var IShareableAddressBook | \PHPUnit_Framework_MockObject_MockObject */ + /** @var IShareable | \PHPUnit_Framework_MockObject_MockObject */ private $book; public function setUp() { @@ -55,7 +55,7 @@ class PluginTest extends TestCase { $root = new SimpleCollection('root'); $this->server = new \Sabre\DAV\Server($root); /** @var SimpleCollection $node */ - $this->book = $this->getMockBuilder('OCA\DAV\CardDAV\Sharing\IShareableAddressBook')->disableOriginalConstructor()->getMock(); + $this->book = $this->getMockBuilder('OCA\DAV\DAV\Sharing\IShareable')->disableOriginalConstructor()->getMock(); $this->book->method('getName')->willReturn('addressbook1.vcf'); $root->addChild($this->book); $this->plugin->initialize($this->server); diff --git a/apps/dav/tests/unit/dav/sharing/plugintest.php b/apps/dav/tests/unit/dav/sharing/plugintest.php new file mode 100644 index 0000000000..ce6c96f1bf --- /dev/null +++ b/apps/dav/tests/unit/dav/sharing/plugintest.php @@ -0,0 +1,83 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\DAV\Tests\Unit\DAV; + + +use OCA\DAV\DAV\Sharing\IShareable; +use OCA\DAV\DAV\Sharing\Plugin; +use OCA\DAV\Connector\Sabre\Auth; +use OCP\IRequest; +use Sabre\DAV\Server; +use Sabre\DAV\SimpleCollection; +use Sabre\HTTP\Request; +use Sabre\HTTP\Response; +use Test\TestCase; + +class PluginTest extends TestCase { + + /** @var Plugin */ + private $plugin; + /** @var Server */ + private $server; + /** @var IShareable | \PHPUnit_Framework_MockObject_MockObject */ + private $book; + + public function setUp() { + parent::setUp(); + + /** @var Auth | \PHPUnit_Framework_MockObject_MockObject $authBackend */ + $authBackend = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Auth')->disableOriginalConstructor()->getMock(); + $authBackend->method('isDavAuthenticated')->willReturn(true); + + /** @var IRequest $request */ + $request = $this->getMockBuilder('OCP\IRequest')->disableOriginalConstructor()->getMock(); + $this->plugin = new Plugin($authBackend, $request); + + $root = new SimpleCollection('root'); + $this->server = new \Sabre\DAV\Server($root); + /** @var SimpleCollection $node */ + $this->book = $this->getMockBuilder('OCA\DAV\DAV\Sharing\IShareable')-> + disableOriginalConstructor()-> + getMock(); + $this->book->method('getName')->willReturn('addressbook1.vcf'); + $root->addChild($this->book); + $this->plugin->initialize($this->server); + } + + public function testSharing() { + + $this->book->expects($this->once())->method('updateShares')->with([[ + 'href' => 'principal:principals/admin', + 'commonName' => null, + 'summary' => null, + 'readOnly' => false + ]], ['mailto:wilfredo@example.com']); + + // setup request + $request = new Request(); + $request->addHeader('Content-Type', 'application/xml'); + $request->setUrl('addressbook1.vcf'); + $request->setBody('principal:principals/admin mailto:wilfredo@example.com'); + $response = new Response(); + $this->plugin->httpPost($request, $response); + } +}