Skip to content

Commit 0172b1d

Browse files
authored
Merge pull request #59693 from nextcloud/test/calendar-delegation
test(integration): add tests for calendar delegation
2 parents 535b234 + c9ec852 commit 0172b1d

2 files changed

Lines changed: 75 additions & 14 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: AGPL-3.0-or-later
3+
Feature: calendar delegation
4+
Calendar delegation grants another user/principal control of a calendar account,
5+
including all calendars the delegator can access.
6+
7+
@caldav-delegation
8+
Scenario: admin grants user0 read access to her calendar account
9+
Given user "admin" exists
10+
And user "user0" exists
11+
When "admin" updates property "{DAV:}group-member-set" to href "/remote.php/dav/principals/users/user0" of principal "users/admin/calendar-proxy-read" on the endpoint "/remote.php/dav/principals/"
12+
Then The CalDAV response should be multi status
13+
And The CalDAV response should contain an href "/remote.php/dav/principals/users/admin/calendar-proxy-read"
14+
And The CalDAV response should contain a property "{DAV:}group-member-set"
15+
16+
@caldav-delegation
17+
Scenario: admin grants write access to her calendar account
18+
Given user "admin" exists
19+
And user "user0" exists
20+
When "admin" updates property "{DAV:}group-member-set" to href "/remote.php/dav/principals/users/user0" of principal "users/admin/calendar-proxy-write" on the endpoint "/remote.php/dav/principals/"
21+
Then The CalDAV response should be multi status
22+
And The CalDAV response should contain an href "/remote.php/dav/principals/users/admin/calendar-proxy-write"
23+
And The CalDAV response should contain a property "{DAV:}group-member-set"

build/integration/features/bootstrap/CalDavContext.php

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,39 @@ public function setUpScenario() {
4040

4141
/** @AfterScenario */
4242
public function afterScenario() {
43-
$davUrl = $this->baseUrl . '/remote.php/dav/calendars/admin/MyCalendar';
44-
try {
45-
$this->client->delete(
46-
$davUrl,
47-
[
48-
'auth' => [
49-
'admin',
50-
'admin',
51-
],
52-
'headers' => [
53-
'X-NC-CalDAV-No-Trashbin' => '1',
43+
foreach (['MyCalendar', 'MyCalendar2'] as $calendarName) {
44+
try {
45+
$this->client->delete(
46+
$this->baseUrl . '/remote.php/dav/calendars/admin/' . $calendarName,
47+
[
48+
'auth' => ['admin', 'admin'],
49+
'headers' => ['X-NC-CalDAV-No-Trashbin' => '1'],
5450
]
55-
]
56-
);
57-
} catch (\GuzzleHttp\Exception\ClientException $e) {
51+
);
52+
} catch (\GuzzleHttp\Exception\ClientException $e) {
53+
}
54+
}
55+
}
56+
57+
/** @AfterScenario @caldav-delegation */
58+
public function afterDelegationScenario() {
59+
foreach (['calendar-proxy-read', 'calendar-proxy-write'] as $proxyType) {
60+
try {
61+
$propPatch = new \Sabre\DAV\Xml\Request\PropPatch();
62+
$propPatch->properties = ['{DAV:}group-member-set' => new \Sabre\DAV\Xml\Property\Href([])];
63+
$xml = new \Sabre\Xml\Service();
64+
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
65+
$this->client->request(
66+
'PROPPATCH',
67+
$this->baseUrl . '/remote.php/dav/principals/users/admin/' . $proxyType,
68+
[
69+
'headers' => ['Content-Type' => 'application/xml; charset=UTF-8'],
70+
'body' => $body,
71+
'auth' => ['admin', 'admin'],
72+
]
73+
);
74+
} catch (\GuzzleHttp\Exception\ClientException $e) {
75+
}
5876
}
5977
}
6078

@@ -172,6 +190,26 @@ public function theCaldavResponseShouldContainAPropertyWithHrefValue(
172190
}
173191
}
174192

193+
/**
194+
* @Then The CalDAV response should contain an href :href
195+
* @throws \Exception
196+
*/
197+
public function theCaldavResponseShouldContainAnHref(string $href): void {
198+
/** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
199+
$multiStatus = $this->responseXml['value'];
200+
foreach ($multiStatus->getResponses() as $response) {
201+
if ($response->getHref() === $href) {
202+
return;
203+
}
204+
}
205+
throw new \Exception(
206+
sprintf(
207+
'Expected href %s not found in response',
208+
$href,
209+
)
210+
);
211+
}
212+
175213
/**
176214
* @Then The CalDAV response should be multi status
177215
* @throws \Exception

0 commit comments

Comments
 (0)