2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\CalDAV;
|
|
|
|
|
|
|
|
use Sabre\DAV;
|
2016-05-28 15:46:24 +00:00
|
|
|
use Sabre\DAV\Xml\Element\Sharee;
|
2013-10-21 22:46:31 +00:00
|
|
|
use Sabre\HTTP;
|
|
|
|
|
|
|
|
class SharingPluginTest extends \Sabre\DAVServerTest {
|
|
|
|
|
|
|
|
protected $setupCalDAV = true;
|
|
|
|
protected $setupCalDAVSharing = true;
|
|
|
|
protected $setupACL = true;
|
|
|
|
protected $autoLogin = 'user1';
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->caldavCalendars = [
|
|
|
|
[
|
2013-10-21 22:46:31 +00:00
|
|
|
'principaluri' => 'principals/user1',
|
2016-05-28 15:46:24 +00:00
|
|
|
'id' => 1,
|
|
|
|
'uri' => 'cal1',
|
|
|
|
],
|
|
|
|
[
|
2013-10-21 22:46:31 +00:00
|
|
|
'principaluri' => 'principals/user1',
|
2016-05-28 15:46:24 +00:00
|
|
|
'id' => 2,
|
|
|
|
'uri' => 'cal2',
|
|
|
|
'share-access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
|
|
|
|
],
|
|
|
|
[
|
2013-10-21 22:46:31 +00:00
|
|
|
'principaluri' => 'principals/user1',
|
2016-05-28 15:46:24 +00:00
|
|
|
'id' => 3,
|
|
|
|
'uri' => 'cal3',
|
|
|
|
],
|
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// Making the logged in user an admin, for full access:
|
|
|
|
$this->aclPlugin->adminPrincipals[] = 'principals/user2';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSimple() {
|
|
|
|
|
|
|
|
$this->assertInstanceOf('Sabre\\CalDAV\\SharingPlugin', $this->server->getPlugin('caldav-sharing'));
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
'caldav-sharing',
|
|
|
|
$this->caldavSharingPlugin->getPluginInfo()['name']
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \LogicException
|
|
|
|
*/
|
|
|
|
function testSetupWithoutCoreSharingPlugin() {
|
|
|
|
|
|
|
|
$server = new DAV\Server();
|
|
|
|
$server->addPlugin(
|
|
|
|
new SharingPlugin()
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-21 22:46:31 +00:00
|
|
|
function testGetFeatures() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(['calendarserver-sharing'], $this->caldavSharingPlugin->getFeatures());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBeforeGetShareableCalendar() {
|
|
|
|
|
|
|
|
// Forcing the server to authenticate:
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response());
|
2016-05-28 15:46:24 +00:00
|
|
|
$props = $this->server->getProperties('calendars/user1/cal1', [
|
2013-10-21 22:46:31 +00:00
|
|
|
'{' . Plugin::NS_CALENDARSERVER . '}invite',
|
|
|
|
'{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes',
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']);
|
|
|
|
$this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\AllowedSharingModes', $props['{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBeforeGetSharedCalendar() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$props = $this->server->getProperties('calendars/user1/cal2', [
|
2013-10-21 22:46:31 +00:00
|
|
|
'{' . Plugin::NS_CALENDARSERVER . '}shared-url',
|
|
|
|
'{' . Plugin::NS_CALENDARSERVER . '}invite',
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']);
|
2016-05-28 15:46:24 +00:00
|
|
|
//$this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $props['{' . Plugin::NS_CALENDARSERVER . '}shared-url']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testUpdateResourceType() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->caldavBackend->updateInvites(1,
|
|
|
|
[
|
|
|
|
new Sharee([
|
2013-10-21 22:46:31 +00:00
|
|
|
'href' => 'mailto:joe@example.org',
|
2016-05-28 15:46:24 +00:00
|
|
|
])
|
|
|
|
]
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
2016-05-28 15:46:24 +00:00
|
|
|
$result = $this->server->updateProperties('calendars/user1/cal1', [
|
2016-05-11 00:26:44 +00:00
|
|
|
'{DAV:}resourcetype' => new DAV\Xml\Property\ResourceType(['{DAV:}collection'])
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'{DAV:}resourcetype' => 200
|
|
|
|
], $result);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(0, count($this->caldavBackend->getInvites(1)));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUpdatePropertiesPassThru() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$result = $this->server->updateProperties('calendars/user1/cal3', [
|
2013-10-21 22:46:31 +00:00
|
|
|
'{DAV:}foo' => 'bar',
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'{DAV:}foo' => 200,
|
|
|
|
], $result);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUnknownMethodNoPOST() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'PATCH',
|
|
|
|
'REQUEST_URI' => '/',
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(501, $response->status, $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUnknownMethodNoXML() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'POST',
|
|
|
|
'REQUEST_URI' => '/',
|
|
|
|
'CONTENT_TYPE' => 'text/plain',
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(501, $response->status, $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUnknownMethodNoNode() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'POST',
|
|
|
|
'REQUEST_URI' => '/foo',
|
|
|
|
'CONTENT_TYPE' => 'text/xml',
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(501, $response->status, $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testShareRequest() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request('POST', '/calendars/user1/cal1', ['Content-Type' => 'text/xml']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$xml = <<<RRR
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<cs:share xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
|
|
|
|
<cs:set>
|
|
|
|
<d:href>mailto:joe@example.org</d:href>
|
|
|
|
<cs:common-name>Joe Shmoe</cs:common-name>
|
|
|
|
<cs:read-write />
|
|
|
|
</cs:set>
|
|
|
|
<cs:remove>
|
|
|
|
<d:href>mailto:nancy@example.org</d:href>
|
|
|
|
</cs:remove>
|
|
|
|
</cs:share>
|
|
|
|
RRR;
|
|
|
|
|
|
|
|
$request->setBody($xml);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
new Sharee([
|
|
|
|
'href' => 'mailto:joe@example.org',
|
|
|
|
'properties' => [
|
|
|
|
'{DAV:}displayname' => 'Joe Shmoe',
|
|
|
|
],
|
|
|
|
'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
|
|
|
|
'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_NORESPONSE,
|
|
|
|
'comment' => '',
|
|
|
|
]),
|
|
|
|
],
|
|
|
|
$this->caldavBackend->getInvites(1)
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
// Wiping out tree cache
|
|
|
|
$this->server->tree->markDirty('');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
// Verifying that the calendar is now marked shared.
|
2016-05-28 15:46:24 +00:00
|
|
|
$props = $this->server->getProperties('calendars/user1/cal1', ['{DAV:}resourcetype']);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->assertTrue(
|
|
|
|
$props['{DAV:}resourcetype']->is('{http://calendarserver.org/ns/}shared-owner')
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testShareRequestNoShareableCalendar() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'POST',
|
|
|
|
'/calendars/user1/cal2',
|
|
|
|
['Content-Type' => 'text/xml']
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<cs:share xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
|
|
|
|
<cs:set>
|
|
|
|
<d:href>mailto:joe@example.org</d:href>
|
|
|
|
<cs:common-name>Joe Shmoe</cs:common-name>
|
|
|
|
<cs:read-write />
|
|
|
|
</cs:set>
|
|
|
|
<cs:remove>
|
|
|
|
<d:href>mailto:nancy@example.org</d:href>
|
|
|
|
</cs:remove>
|
|
|
|
</cs:share>
|
|
|
|
';
|
|
|
|
|
|
|
|
$request->setBody($xml);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 403);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testInviteReply() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'POST',
|
|
|
|
'REQUEST_URI' => '/calendars/user1',
|
|
|
|
'CONTENT_TYPE' => 'text/xml',
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<cs:invite-reply xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
|
|
|
|
<cs:hosturl><d:href>/principals/owner</d:href></cs:hosturl>
|
|
|
|
<cs:invite-accepted />
|
|
|
|
</cs:invite-reply>
|
|
|
|
';
|
|
|
|
|
|
|
|
$request->setBody($xml);
|
|
|
|
$response = $this->request($request);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(200, $response->status, $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testInviteBadXML() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'POST',
|
|
|
|
'REQUEST_URI' => '/calendars/user1',
|
|
|
|
'CONTENT_TYPE' => 'text/xml',
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<cs:invite-reply xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
|
|
|
|
</cs:invite-reply>
|
|
|
|
';
|
|
|
|
$request->setBody($xml);
|
|
|
|
$response = $this->request($request);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(400, $response->status, $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testInviteWrongUrl() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'POST',
|
|
|
|
'REQUEST_URI' => '/calendars/user1/cal1',
|
|
|
|
'CONTENT_TYPE' => 'text/xml',
|
2016-05-28 15:46:24 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<cs:invite-reply xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
|
|
|
|
<cs:hosturl><d:href>/principals/owner</d:href></cs:hosturl>
|
|
|
|
</cs:invite-reply>
|
|
|
|
';
|
|
|
|
$request->setBody($xml);
|
|
|
|
$response = $this->request($request);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(501, $response->status, $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
// If the plugin did not handle this request, it must ensure that the
|
|
|
|
// body is still accessible by other plugins.
|
|
|
|
$this->assertEquals($xml, $request->getBody(true));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPublish() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request('POST', '/calendars/user1/cal1', ['Content-Type' => 'text/xml']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<cs:publish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
|
|
|
|
';
|
|
|
|
|
|
|
|
$request->setBody($xml);
|
|
|
|
|
|
|
|
$response = $this->request($request);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(202, $response->status, $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
|
2013-10-21 22:46:31 +00:00
|
|
|
function testUnpublish() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'POST',
|
|
|
|
'/calendars/user1/cal1',
|
|
|
|
['Content-Type' => 'text/xml']
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<cs:unpublish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
|
|
|
|
';
|
|
|
|
|
|
|
|
$request->setBody($xml);
|
|
|
|
|
|
|
|
$response = $this->request($request);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(200, $response->status, $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPublishWrongUrl() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'POST',
|
|
|
|
'/calendars/user1',
|
|
|
|
['Content-Type' => 'text/xml']
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<cs:publish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
|
|
|
|
';
|
|
|
|
|
|
|
|
$request->setBody($xml);
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->request($request, 501);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUnpublishWrongUrl() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'POST',
|
|
|
|
'/calendars/user1',
|
|
|
|
['Content-Type' => 'text/xml']
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<cs:unpublish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
|
|
|
|
';
|
|
|
|
|
|
|
|
$request->setBody($xml);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->request($request, 501);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUnknownXmlDoc() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
|
|
|
|
$request = new HTTP\Request(
|
|
|
|
'POST',
|
|
|
|
'/calendars/user1/cal2',
|
|
|
|
['Content-Type' => 'text/xml']
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<cs:foo-bar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />';
|
|
|
|
|
|
|
|
$request->setBody($xml);
|
|
|
|
|
|
|
|
$response = $this->request($request);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(501, $response->status, $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|