Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addin caldav test suite for old endpoint #27792

Merged
merged 5 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ matrix:
env: DB=sqlite;TC=carddav
- php: 5.6
env: DB=sqlite;TC=caldav
- php: 5.6
env: DB=sqlite;TC=caldav-old-endpoint
- php: 5.6
env: DB=sqlite;TC=carddav-old-endpoint
- php: 5.6
env: DB=pgsql;TC=selenium;TEST_DAV=0
- php: 5.6
Expand Down
5 changes: 3 additions & 2 deletions apps/dav/appinfo/v1/caldav.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
$db = \OC::$server->getDatabaseConnection();
$config = \OC::$server->getConfig();
$random = \OC::$server->getSecureRandom();
$calDavBackend = new CalDavBackend($db, $principalBackend, $config, $random);
$calDavBackend = new CalDavBackend($db, $principalBackend, $config, $random, true);

$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);

Expand Down Expand Up @@ -79,8 +79,9 @@
$server->addPlugin(new Sabre\DAV\Browser\Plugin());
}

$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
$server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin());
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
$server->addPlugin(new OCA\DAV\CalDAV\Schedule\IMipPlugin( \OC::$server->getMailer(), \OC::$server->getLogger()));
$server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger()));

Expand Down
3 changes: 2 additions & 1 deletion apps/dav/appinfo/v1/carddav.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'principals/'
);
$db = \OC::$server->getDatabaseConnection();
$cardDavBackend = new CardDavBackend($db, $principalBackend);
$cardDavBackend = new CardDavBackend($db, $principalBackend, null, true);

$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);

Expand Down Expand Up @@ -76,6 +76,7 @@
$server->addPlugin(new Sabre\DAV\Browser\Plugin());
}

$server->addPlugin(new Sabre\DAV\Sync\Plugin());
$server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
$server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(\OC::$server->getLogger()));
$server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
Expand Down
43 changes: 26 additions & 17 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace OCA\DAV\CalDAV;

use Doctrine\DBAL\Connection;
use OCA\DAV\DAV\Sharing\IShareable;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCA\DAV\Connector\Sabre\Principal;
Expand Down Expand Up @@ -116,6 +117,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription

/** @var ISecureRandom */
private $random;
/** @var bool */
private $legacyMode;

/**
* CalDavBackend constructor.
Expand All @@ -127,12 +130,14 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
public function __construct(IDBConnection $db,
Principal $principalBackend,
IConfig $config,
ISecureRandom $random) {
ISecureRandom $random,
$legacyMode = false) {
$this->db = $db;
$this->principalBackend = $principalBackend;
$this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar');
$this->config = $config;
$this->random = $random;
$this->legacyMode = $legacyMode;
}

/**
Expand Down Expand Up @@ -189,7 +194,7 @@ function getCalendarsForUser($principalUri) {
$calendar = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], false),
'principaluri' => $this->convertPrincipal($row['principaluri']),
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
Expand Down Expand Up @@ -226,7 +231,7 @@ function getCalendarsForUser($principalUri) {
->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri')))
->andWhere($query->expr()->eq('s.type', $query->createParameter('type')))
->setParameter('type', 'calendar')
->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)
->setParameter('principaluri', $principals, Connection::PARAM_STR_ARRAY)
->execute();

while($row = $result->fetch()) {
Expand All @@ -240,12 +245,12 @@ function getCalendarsForUser($principalUri) {
$calendar = [
'id' => $row['id'],
'uri' => $uri,
'principaluri' => $principalUri,
'principaluri' => $this->convertPrincipal($principalUri),
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri']),
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ,
];

Expand Down Expand Up @@ -290,7 +295,7 @@ public function getUsersOwnCalendars($principalUri) {
$calendar = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], false),
'principaluri' => $this->convertPrincipal($row['principaluri']),
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
Expand Down Expand Up @@ -343,12 +348,12 @@ public function getPublicCalendars() {
$calendar = [
'id' => $row['id'],
'uri' => $row['publicuri'],
'principaluri' => $row['principaluri'],
'principaluri' => $this->convertPrincipal($row['principaluri']),
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri']),
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ,
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC,
];
Expand Down Expand Up @@ -407,12 +412,12 @@ public function getPublicCalendar($uri) {
$calendar = [
'id' => $row['id'],
'uri' => $row['publicuri'],
'principaluri' => $row['principaluri'],
'principaluri' => $this->convertPrincipal($row['principaluri']),
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri']),
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ,
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC,
];
Expand Down Expand Up @@ -461,7 +466,7 @@ public function getCalendarByUri($principal, $uri) {
$calendar = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $row['principaluri'],
'principaluri' => $this->convertPrincipal($row['principaluri']),
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
Expand Down Expand Up @@ -505,7 +510,7 @@ public function getCalendarById($calendarId) {
$calendar = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $row['principaluri'],
'principaluri' => $this->convertPrincipal($row['principaluri']),
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
Expand All @@ -529,8 +534,10 @@ public function getCalendarById($calendarId) {
* @param string $calendarUri
* @param array $properties
* @return int
* @throws DAV\Exception
*/
function createCalendar($principalUri, $calendarUri, array $properties) {
$principalUri = $this->convertPrincipal($principalUri, true);
$values = [
'principaluri' => $principalUri,
'uri' => $calendarUri,
Expand Down Expand Up @@ -580,6 +587,7 @@ function createCalendar($principalUri, $calendarUri, array $properties) {
*
* Read the PropPatch documentation for more info and examples.
*
* @param mixed $calendarId
* @param PropPatch $propPatch
* @return void
*/
Expand Down Expand Up @@ -639,11 +647,11 @@ function deleteCalendar($calendarId) {
/**
* Delete all of an user's shares
*
* @param string $principaluri
* @param string $principalUri
* @return void
*/
function deleteAllSharesForUser($principaluri) {
$this->sharingBackend->deleteAllSharesByUser($principaluri);
function deleteAllSharesForUser($principalUri) {
$this->sharingBackend->deleteAllSharesByUser($principalUri);
}

/**
Expand Down Expand Up @@ -1657,10 +1665,11 @@ public function applyShareAcl($resourceId, $acl) {
return $this->sharingBackend->applyShareAcl($resourceId, $acl);
}

private function convertPrincipal($principalUri, $toV2) {
private function convertPrincipal($principalUri, $toV2 = null) {
if ($this->principalBackend->getPrincipalPrefix() === 'principals') {
list(, $name) = URLUtil::splitPath($principalUri);
if ($toV2 === true) {
$toV2 = $toV2 === null ? !$this->legacyMode : $toV2;
if ($toV2) {
return "principals/users/$name";
}
return "principals/$name";
Expand Down
37 changes: 37 additions & 0 deletions apps/dav/lib/CalDAV/Schedule/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @author Thomas Müller <[email protected]>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @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 <http://www.gnu.org/licenses/>
*
*/


namespace OCA\DAV\CalDAV\Schedule;


class Plugin extends \Sabre\CalDAV\Schedule\Plugin {

public function getAddressesForPrincipal($principal) {
$result = parent::getAddressesForPrincipal($principal);
if ($result === null) {
return [];
}

return $result;
}

}
13 changes: 9 additions & 4 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class CardDavBackend implements BackendInterface, SyncSupport {

/** @var EventDispatcherInterface */
private $dispatcher;
/** @var bool */
private $legacyMode;

/**
* CardDavBackend constructor.
Expand All @@ -76,11 +78,13 @@ class CardDavBackend implements BackendInterface, SyncSupport {
*/
public function __construct(IDBConnection $db,
Principal $principalBackend,
EventDispatcherInterface $dispatcher = null) {
EventDispatcherInterface $dispatcher = null,
$legacyMode = false) {
$this->db = $db;
$this->principalBackend = $principalBackend;
$this->dispatcher = $dispatcher;
$this->sharingBackend = new Backend($this->db, $principalBackend, 'addressbook');
$this->legacyMode = $legacyMode;
}

/**
Expand Down Expand Up @@ -114,7 +118,7 @@ function getUsersOwnAddressBooks($principalUri) {
$addressBooks[$row['id']] = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $this->convertPrincipal($row['principaluri'], false),
'principaluri' => $this->convertPrincipal($row['principaluri']),
'{DAV:}displayname' => $row['displayname'],
'{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
Expand Down Expand Up @@ -999,10 +1003,11 @@ public function applyShareAcl($addressBookId, $acl) {
return $this->sharingBackend->applyShareAcl($addressBookId, $acl);
}

private function convertPrincipal($principalUri, $toV2) {
private function convertPrincipal($principalUri, $toV2 = null) {
if ($this->principalBackend->getPrincipalPrefix() === 'principals') {
list(, $name) = URLUtil::splitPath($principalUri);
if ($toV2 === true) {
$toV2 = $toV2 === null ? !$this->legacyMode : $toV2;
if ($toV2) {
return "principals/users/$name";
}
return "principals/$name";
Expand Down
21 changes: 3 additions & 18 deletions apps/dav/lib/Connector/LegacyDAVACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,9 @@
class LegacyDAVACL extends DavAclPlugin {

/**
* Converts the v1 principal `principal/<username>` to the new v2
* `principal/users/<username>` which is required for permission checks
*
* @inheritdoc
*/
function getCurrentUserPrincipal() {
$principalV1 = parent::getCurrentUserPrincipal();
if (is_null($principalV1)) {
return $principalV1;
}
return $this->convertPrincipal($principalV1, true);
}


/**
* @inheritdoc
*/
function getCurrentUserPrincipals() {
public function getCurrentUserPrincipals() {
$principalV2 = $this->getCurrentUserPrincipal();

if (is_null($principalV2)) return [];
Expand All @@ -72,7 +57,7 @@ private function convertPrincipal($principal, $toV2) {
return "principals/$name";
}

function propFind(PropFind $propFind, INode $node) {
public function propFind(PropFind $propFind, INode $node) {
/* Overload current-user-principal */
$propFind->handle('{DAV:}current-user-principal', function () {
if ($url = parent::getCurrentUserPrincipal()) {
Expand All @@ -81,6 +66,6 @@ function propFind(PropFind $propFind, INode $node) {
return new Principal(Principal::UNAUTHENTICATED);
}
});
parent::propFind($propFind, $node);
return parent::propFind($propFind, $node);
}
}
2 changes: 1 addition & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function __construct(IRequest $request, $baseUri) {
// calendar plugins
$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$this->server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin());
$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
$this->server->addPlugin(new IMipPlugin($mailer, $logger));
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
Expand Down
21 changes: 21 additions & 0 deletions apps/dav/tests/travis/caldav-old-endpoint/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`


cd "$SCRIPTPATH"
if [ ! -f CalDAVTester/testcaldav.py ]; then
git clone https://github.com/apple/ccs-caldavtester.git CalDAVTester
fi
if [ ! -f pycalendar/setup.py ]; then
git clone https://github.com/apple/ccs-pycalendar.git pycalendar
fi

# create test user
cd "$SCRIPTPATH/../../../../../"
OC_PASS=user01 php occ user:add --password-from-env user01
php occ dav:create-calendar user01 calendar
php occ dav:create-calendar user01 shared
OC_PASS=user02 php occ user:add --password-from-env user02
php occ dav:create-calendar user02 calendar
cd "$SCRIPTPATH/../../../../../"
Loading