[Pkg-owncloud-commits] [php-sabredav] 144/275: Unittests are really close. Few minor bugfixes.
David Prévot
taffit at moszumanska.debian.org
Thu Sep 25 14:56:01 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit c7634abe856502ce479b212d2678963944ce6e39
Author: Evert Pot <me at evertpot.com>
Date: Mon Aug 11 17:01:53 2014 -0400
Unittests are really close. Few minor bugfixes.
---
lib/CalDAV/ICalendar.php | 5 +-
lib/CalDAV/Schedule/Inbox.php | 5 +
lib/CalDAV/Schedule/Plugin.php | 24 +-
tests/Sabre/CalDAV/Schedule/InboxTest.php | 5 +
.../Sabre/CalDAV/Schedule/ScheduleDeliverTest.php | 276 ++++++++++++++++++++-
.../Sabre/CalDAV/Schedule/SchedulingObjectTest.php | 40 +++
6 files changed, 342 insertions(+), 13 deletions(-)
diff --git a/lib/CalDAV/ICalendar.php b/lib/CalDAV/ICalendar.php
index d09ee24..871b1c6 100644
--- a/lib/CalDAV/ICalendar.php
+++ b/lib/CalDAV/ICalendar.php
@@ -2,9 +2,8 @@
namespace Sabre\CalDAV;
-use
- Sabre\DAV,
- Sabre\DAVACL;
+use Sabre\DAV;
+use Sabre\DAVACL;
/**
* Calendar interface
diff --git a/lib/CalDAV/Schedule/Inbox.php b/lib/CalDAV/Schedule/Inbox.php
index 03f0e4c..14fbaa8 100644
--- a/lib/CalDAV/Schedule/Inbox.php
+++ b/lib/CalDAV/Schedule/Inbox.php
@@ -171,6 +171,11 @@ class Inbox extends DAV\Collection implements IInbox {
'principal' => '{DAV:}authenticated',
'protected' => true,
],
+ [
+ 'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver-reply',
+ 'principal' => '{DAV:}authenticated',
+ 'protected' => true,
+ ],
];
}
diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index 21c45e0..052d9d6 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -442,20 +442,20 @@ class Plugin extends ServerPlugin {
);
if (!count($result)) {
- $iTipMessage->scheduleStatus = '3.7; Could not find principal with email: ' . $iTipMessage->recipient;
+ $iTipMessage->scheduleStatus = '3.7;Could not find principal.';
return;
}
if (!isset($result[0][200][$caldavNS . 'schedule-inbox-URL'])) {
- $iTipMessage->scheduleStatus = '5.2; Could not find local inbox';
+ $iTipMessage->scheduleStatus = '5.2;Could not find local inbox';
return;
}
if (!isset($result[0][200][$caldavNS . 'calendar-home-set'])) {
- $iTipMessage->scheduleStatus = '5.2; Could not locate a calendar-home-set';
+ $iTipMessage->scheduleStatus = '5.2;Could not locate a calendar-home-set';
return;
}
if (!isset($result[0][200][$caldavNS . 'schedule-default-calendar-URL'])) {
- $iTipMessage->scheduleStatus = '5.2; Could not find a schedule-default-calendar-URL property';
+ $iTipMessage->scheduleStatus = '5.2;Could not find a schedule-default-calendar-URL property';
return;
}
@@ -463,11 +463,14 @@ class Plugin extends ServerPlugin {
$homePath = $result[0][200][$caldavNS . 'calendar-home-set']->getHref();
$inboxPath = $result[0][200][$caldavNS . 'schedule-inbox-URL']->getHref();
- // Note that we are bypassing ACL on purpose by calling this directly.
- // We may need to look a bit deeper into this later. Supporting ACL
- // here would be nice.
- if (!$aclPlugin->checkPrivileges($inboxPath, '{' . self::NS_CALDAV . '}schedule-deliver-invite', DAVACL\Plugin::R_PARENT, false)) {
- $iTipMessage->scheduleStatus = '3.8; organizer did not have the schedule-deliver-invite privilege on the attendees inbox';
+ if ($iTipMessage->method === 'REPLY') {
+ $privilege = 'schedule-deliver-reply';
+ } else {
+ $privilege = 'schedule-deliver-invite';
+ }
+
+ if (!$aclPlugin->checkPrivileges($inboxPath, $caldavNS . $privilege, DAVACL\Plugin::R_PARENT, false)) {
+ $iTipMessage->scheduleStatus = '3.8;organizer did not have the '.$privilege.' privilege on the attendees inbox';
return;
}
@@ -511,6 +514,9 @@ class Plugin extends ServerPlugin {
return;
}
+ // Note that we are bypassing ACL on purpose by calling this directly.
+ // We may need to look a bit deeper into this later. Supporting ACL
+ // here would be nice.
if ($isNewNode) {
$calendar = $this->server->tree->getNodeForPath($calendarPath);
$calendar->createFile($newFileName, $newObject->serialize());
diff --git a/tests/Sabre/CalDAV/Schedule/InboxTest.php b/tests/Sabre/CalDAV/Schedule/InboxTest.php
index c704f2c..6007a72 100644
--- a/tests/Sabre/CalDAV/Schedule/InboxTest.php
+++ b/tests/Sabre/CalDAV/Schedule/InboxTest.php
@@ -43,6 +43,11 @@ class InboxTest extends \PHPUnit_Framework_TestCase {
'principal' => '{DAV:}authenticated',
'protected' => true,
),
+ array(
+ 'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-deliver-reply',
+ 'principal' => '{DAV:}authenticated',
+ 'protected' => true,
+ ),
), $inbox->getACL());
$ok = false;
diff --git a/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php b/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php
index 9764569..ebc1930 100644
--- a/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php
+++ b/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php
@@ -45,6 +45,21 @@ ICS;
$this->deliver(null, $newObject);
$this->assertItemsInInbox('user2', 1);
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE;SCHEDULE-STATUS="1.2;Message delivered locally":mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals(
+ $expected,
+ $newObject
+ );
+
}
function testNewOnWrongCollection() {
@@ -63,6 +78,7 @@ ICS;
$this->deliver(null, $newObject);
$this->assertItemsInInbox('user2', 0);
+
}
function testNewInviteSchedulingDisabled() {
@@ -103,6 +119,22 @@ ICS;
$this->deliver($oldObject, $newObject);
$this->assertItemsInInbox('user2', 1);
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE;SCHEDULE-STATUS="1.2;Message delivered locally":mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals(
+ $expected,
+ $newObject
+ );
+
+
}
function testUpdatedInviteSchedulingDisabled() {
@@ -245,12 +277,226 @@ ICS;
$this->assertItemsInInbox('user2', 1);
$this->assertItemsInInbox('user1', 0);
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER;SCHEDULE-STATUS="1.2;Message delivered locally":mailto:user2.sabredav at sabredav.org
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav at sabredav.org
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user3.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals(
+ $expected,
+ $newObject
+ );
+
}
+
+ function testInviteUnknownUser() {
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user3.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->deliver(null, $newObject);
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE;SCHEDULE-STATUS="3.7;Could not find principal.":mailto:user3.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals(
+ $expected,
+ $newObject
+ );
+
+ }
+
+ function testInviteNoInboxUrl() {
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->server->on('propFind', function($propFind) {
+ $propFind->set('{' . Plugin::NS_CALDAV . '}schedule-inbox-URL', null, 403);
+ });
+ $this->deliver(null, $newObject);
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE;SCHEDULE-STATUS="5.2;Could not find local inbox":mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals(
+ $expected,
+ $newObject
+ );
+
+ }
+
+ function testInviteNoCalendarHomeSet() {
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->server->on('propFind', function($propFind) {
+ $propFind->set('{' . Plugin::NS_CALDAV . '}calendar-home-set', null, 403);
+ });
+ $this->deliver(null, $newObject);
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE;SCHEDULE-STATUS="5.2;Could not locate a calendar-home-set":mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals(
+ $expected,
+ $newObject
+ );
+
+ }
+ function testInviteNoDefaultCalendar() {
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->server->on('propFind', function($propFind) {
+ $propFind->set('{' . Plugin::NS_CALDAV . '}schedule-default-calendar-URL', null, 403);
+ });
+ $this->deliver(null, $newObject);
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE;SCHEDULE-STATUS="5.2;Could not find a schedule-default-calendar-URL property":mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals(
+ $expected,
+ $newObject
+ );
+
+ }
+ function testInviteNoScheduler() {
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->server->removeAllListeners('schedule');
+ $this->deliver(null, $newObject);
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE;SCHEDULE-STATUS="5.2;There was no system capable of delivering the scheduling message":mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals(
+ $expected,
+ $newObject
+ );
+
+ }
+ function testInviteNoACLPlugin() {
+
+ $this->setupACL = false;
+ parent::setUp();
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->deliver(null, $newObject);
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE;SCHEDULE-STATUS="5.2;There was no system capable of delivering the scheduling message":mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals(
+ $expected,
+ $newObject
+ );
+
+ }
+
protected $calendarObjectUri;
- function deliver($oldObject, $newObject, $disableScheduling = false) {
+ function deliver($oldObject, &$newObject, $disableScheduling = false) {
if ($disableScheduling) {
$this->server->httpRequest->setHeader('Schedule-Reply','F');
@@ -271,6 +517,9 @@ ICS;
$stream,
$modified
);
+ if ($modified) {
+ $newObject = $stream;
+ }
} elseif ($oldObject && !$newObject) {
// delete
@@ -291,10 +540,15 @@ ICS;
$this->server->tree->getNodeForPath(dirname($this->calendarObjectUri)),
$modified
);
+
+ if ($modified) {
+ $newObject = $stream;
+ }
}
}
+
/**
* Creates or updates a node at the specified path.
*
@@ -327,5 +581,25 @@ ICS;
}
+ function assertVObjEquals($expected, $actual) {
+
+ $format = function($data) {
+
+ $data = trim($data, "\r\n");
+ $data = str_replace("\r","", $data);
+ // Unfolding lines.
+ $data = str_replace("\n ", "", $data);
+
+ return $data;
+
+ };
+
+ $this->assertEquals(
+ $format($expected),
+ $format($actual)
+ );
+
+ }
+
}
diff --git a/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php b/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php
index 3345463..d163d07 100644
--- a/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php
+++ b/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php
@@ -355,4 +355,44 @@ ICS;
$this->assertEquals(4, $obj->getSize());
}
+
+ function testGetContentType() {
+
+ $objectInfo = array(
+ 'uri' => 'foo',
+ 'calendarid' => 1,
+ );
+
+ $backend = new Backend\MockScheduling(array(), array());
+ $obj = new SchedulingObject($backend, $objectInfo);
+ $this->assertEquals('text/calendar; charset=utf-8', $obj->getContentType());
+
+ }
+
+ function testGetContentType2() {
+
+ $objectInfo = array(
+ 'uri' => 'foo',
+ 'calendarid' => 1,
+ 'component' => 'VEVENT',
+ );
+
+ $backend = new Backend\MockScheduling(array(), array());
+ $obj = new SchedulingObject($backend, $objectInfo);
+ $this->assertEquals('text/calendar; charset=utf-8; component=VEVENT', $obj->getContentType());
+
+ }
+ function testGetACL2() {
+
+ $objectInfo = array(
+ 'uri' => 'foo',
+ 'calendarid' => 1,
+ 'acl' => [],
+ );
+
+ $backend = new Backend\MockScheduling(array(), array());
+ $obj = new SchedulingObject($backend, $objectInfo);
+ $this->assertEquals([], $obj->getACL());
+
+ }
}
--
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