Skip to content

Commit 65439b8

Browse files
authored
Merge pull request #59973 from nextcloud/backport/59693/stable24
2 parents a472bd2 + 828b575 commit 65439b8

9 files changed

Lines changed: 282 additions & 2 deletions

File tree

.drone.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,32 @@ trigger:
941941
- pull_request
942942
- push
943943

944+
---
945+
kind: pipeline
946+
name: integration-caldav-delegation
947+
948+
steps:
949+
- name: submodules
950+
image: ghcr.io/nextcloud/continuous-integration-alpine-git:latest
951+
commands:
952+
- git submodule update --init
953+
- name: integration-caldav-delegation
954+
image: ghcr.io/nextcloud/continuous-integration-integration-php7.4:latest
955+
commands:
956+
- curl -O -L https://getcomposer.org/download/2.9.2/composer.phar && chmod +x composer.phar && mv composer.phar /usr/local/bin/composer
957+
- bash tests/drone-run-integration-tests.sh || exit 0
958+
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
959+
- cd build/integration
960+
- ./run.sh features/caldav-delegation.feature
961+
962+
trigger:
963+
branch:
964+
- master
965+
- stable*
966+
event:
967+
- pull_request
968+
- push
969+
944970
---
945971
kind: pipeline
946972
name: integration-comments
@@ -2034,6 +2060,6 @@ trigger:
20342060
- push
20352061
---
20362062
kind: signature
2037-
hmac: 0c4d3ce2e129d533e7f69584b295db9d7e3fbf3324e96499f85fa68197b8da61
2063+
hmac: 38ca65cb4503091595c6e8738015c61b4623b74f0e789daf312389613d87879a
20382064

20392065
...

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
'OCA\\DAV\\CalDAV\\Outbox' => $baseDir . '/../lib/CalDAV/Outbox.php',
5858
'OCA\\DAV\\CalDAV\\Plugin' => $baseDir . '/../lib/CalDAV/Plugin.php',
5959
'OCA\\DAV\\CalDAV\\Principal\\Collection' => $baseDir . '/../lib/CalDAV/Principal/Collection.php',
60+
'OCA\\DAV\\CalDAV\\Principal\\ProxyRead' => $baseDir . '/../lib/CalDAV/Principal/ProxyRead.php',
61+
'OCA\\DAV\\CalDAV\\Principal\\ProxyWrite' => $baseDir . '/../lib/CalDAV/Principal/ProxyWrite.php',
6062
'OCA\\DAV\\CalDAV\\Principal\\User' => $baseDir . '/../lib/CalDAV/Principal/User.php',
6163
'OCA\\DAV\\CalDAV\\Proxy\\Proxy' => $baseDir . '/../lib/CalDAV/Proxy/Proxy.php',
6264
'OCA\\DAV\\CalDAV\\Proxy\\ProxyMapper' => $baseDir . '/../lib/CalDAV/Proxy/ProxyMapper.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class ComposerStaticInitDAV
7272
'OCA\\DAV\\CalDAV\\Outbox' => __DIR__ . '/..' . '/../lib/CalDAV/Outbox.php',
7373
'OCA\\DAV\\CalDAV\\Plugin' => __DIR__ . '/..' . '/../lib/CalDAV/Plugin.php',
7474
'OCA\\DAV\\CalDAV\\Principal\\Collection' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/Collection.php',
75+
'OCA\\DAV\\CalDAV\\Principal\\ProxyRead' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/ProxyRead.php',
76+
'OCA\\DAV\\CalDAV\\Principal\\ProxyWrite' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/ProxyWrite.php',
7577
'OCA\\DAV\\CalDAV\\Principal\\User' => __DIR__ . '/..' . '/../lib/CalDAV/Principal/User.php',
7678
'OCA\\DAV\\CalDAV\\Proxy\\Proxy' => __DIR__ . '/..' . '/../lib/CalDAV/Proxy/Proxy.php',
7779
'OCA\\DAV\\CalDAV\\Proxy\\ProxyMapper' => __DIR__ . '/..' . '/../lib/CalDAV/Proxy/ProxyMapper.php',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\CalDAV\Principal;
11+
12+
use Sabre\DAVACL;
13+
14+
class ProxyRead extends \Sabre\CalDAV\Principal\ProxyRead implements DAVACL\IACL {
15+
use DAVACL\ACLTrait;
16+
17+
/**
18+
* @inheritDoc
19+
*/
20+
public function getOwner() {
21+
return $this->principalInfo['uri'];
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\CalDAV\Principal;
11+
12+
use Sabre\DAVACL;
13+
14+
class ProxyWrite extends \Sabre\CalDAV\Principal\ProxyWrite implements DAVACL\IACL {
15+
use DAVACL\ACLTrait;
16+
17+
/**
18+
* @inheritDoc
19+
*/
20+
public function getOwner() {
21+
return $this->principalInfo['uri'];
22+
}
23+
}

apps/dav/lib/CalDAV/Principal/User.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,44 @@ public function getACL() {
5151
];
5252
return $acl;
5353
}
54+
55+
/**
56+
* Returns a specific child node, referenced by its name.
57+
*
58+
* @param string $name
59+
*
60+
* @return \Sabre\DAV\INode
61+
*/
62+
public function getChild($name) {
63+
$principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/' . $name);
64+
if (!$principal) {
65+
throw new \Sabre\DAV\Exception\NotFound("Node with name $name was not found");
66+
}
67+
if ($name === 'calendar-proxy-read') {
68+
return new ProxyRead($this->principalBackend, $this->principalProperties);
69+
}
70+
71+
if ($name === 'calendar-proxy-write') {
72+
return new ProxyWrite($this->principalBackend, $this->principalProperties);
73+
}
74+
75+
throw new \Sabre\DAV\Exception\NotFound("Node with name $name was not found");
76+
}
77+
78+
/**
79+
* Returns an array with all the child nodes.
80+
*
81+
* @return \Sabre\DAV\INode[]
82+
*/
83+
public function getChildren() {
84+
$r = [];
85+
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-read')) {
86+
$r[] = new ProxyRead($this->principalBackend, $this->principalProperties);
87+
}
88+
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-write')) {
89+
$r[] = new ProxyWrite($this->principalBackend, $this->principalProperties);
90+
}
91+
92+
return $r;
93+
}
5494
}

build/integration/features/bootstrap/CalDavContext.php

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ public function afterScenario() {
7878
}
7979
}
8080

81+
/** @AfterScenario @caldav-delegation */
82+
public function afterDelegationScenario() {
83+
foreach (['calendar-proxy-read', 'calendar-proxy-write'] as $proxyType) {
84+
try {
85+
$propPatch = new \Sabre\DAV\Xml\Request\PropPatch();
86+
$propPatch->properties = ['{DAV:}group-member-set' => new \Sabre\DAV\Xml\Property\Href([])];
87+
$xml = new \Sabre\Xml\Service();
88+
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
89+
$this->client->request(
90+
'PROPPATCH',
91+
$this->baseUrl . '/remote.php/dav/principals/users/admin/' . $proxyType,
92+
[
93+
'headers' => ['Content-Type' => 'application/xml; charset=UTF-8'],
94+
'body' => $body,
95+
'auth' => ['admin', 'admin'],
96+
]
97+
);
98+
} catch (\GuzzleHttp\Exception\ClientException $e) {
99+
}
100+
}
101+
}
102+
81103
/**
82104
* @When :user requests calendar :calendar on the endpoint :endpoint
83105
* @param string $user
@@ -104,6 +126,80 @@ public function requestsCalendar($user, $calendar, $endpoint) {
104126
}
105127
}
106128

129+
/**
130+
* @Then The CalDAV response should contain a property :key
131+
* @throws \Exception
132+
*/
133+
public function theCaldavResponseShouldContainAProperty(string $key) {
134+
/** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
135+
$multiStatus = $this->responseXml['value'];
136+
$responses = $multiStatus->getResponses()[0]->getResponseProperties();
137+
if (!isset($responses[200])) {
138+
throw new \Exception(
139+
sprintf(
140+
'Expected code 200 got [%s]',
141+
implode(',', array_keys($responses)),
142+
)
143+
);
144+
}
145+
146+
$props = $responses[200];
147+
if (!array_key_exists($key, $props)) {
148+
throw new \Exception(
149+
sprintf(
150+
'Expected property %s in %s',
151+
$key,
152+
json_encode($props, JSON_PRETTY_PRINT),
153+
)
154+
);
155+
}
156+
}
157+
158+
/**
159+
* @Then The CalDAV response should contain an href :href
160+
* @throws \Exception
161+
*/
162+
public function theCaldavResponseShouldContainAnHref(string $href) {
163+
/** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
164+
$multiStatus = $this->responseXml['value'];
165+
foreach ($multiStatus->getResponses() as $response) {
166+
if ($response->getHref() === $href) {
167+
return;
168+
}
169+
}
170+
throw new \Exception(
171+
sprintf(
172+
'Expected href %s not found in response',
173+
$href,
174+
)
175+
);
176+
}
177+
178+
/**
179+
* @Then The CalDAV response should be multi status
180+
* @throws \Exception
181+
*/
182+
public function theCaldavResponseShouldBeMultiStatus() {
183+
if ($this->response->getStatusCode() !== 207) {
184+
throw new \Exception(
185+
sprintf(
186+
'Expected code 207 got %s',
187+
$this->response->getStatusCode()
188+
)
189+
);
190+
}
191+
192+
$body = $this->response->getBody()->getContents();
193+
if ($body && substr($body, 0, 1) === '<') {
194+
$reader = new Sabre\Xml\Reader();
195+
$reader->xml($body);
196+
$reader->elementMap['{DAV:}multistatus'] = \Sabre\DAV\Xml\Response\MultiStatus::class;
197+
$reader->elementMap['{DAV:}response'] = \Sabre\DAV\Xml\Element\Response::class;
198+
$reader->elementMap['{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL'] = \Sabre\DAV\Xml\Property\Href::class;
199+
$this->responseXml = $reader->parse();
200+
}
201+
}
202+
107203
/**
108204
* @Then The CalDAV HTTP status code should be :code
109205
* @param int $code
@@ -233,4 +329,42 @@ public function t($amount) {
233329
);
234330
}
235331
}
332+
/**
333+
* @Given :user updates property :key to href :value of principal :principal on the endpoint :endpoint
334+
*/
335+
public function updatesHrefPropertyOfPrincipal(
336+
string $user,
337+
string $key,
338+
string $value,
339+
string $principal,
340+
string $endpoint
341+
) {
342+
$davUrl = $this->baseUrl . $endpoint . $principal;
343+
$password = ($user === 'admin') ? 'admin' : '123456';
344+
345+
$propPatch = new \Sabre\DAV\Xml\Request\PropPatch();
346+
$propPatch->properties = [$key => new \Sabre\DAV\Xml\Property\Href($value)];
347+
348+
$xml = new \Sabre\Xml\Service();
349+
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
350+
351+
try {
352+
$this->response = $this->client->request(
353+
'PROPPATCH',
354+
$davUrl,
355+
[
356+
'headers' => [
357+
'Content-Type' => 'application/xml; charset=UTF-8',
358+
],
359+
'body' => $body,
360+
'auth' => [
361+
$user,
362+
$password,
363+
],
364+
]
365+
);
366+
} catch (\GuzzleHttp\Exception\ClientException $e) {
367+
$this->response = $e->getResponse();
368+
}
369+
}
236370
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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"
24+
25+
Scenario: Admin cannot grant User1 access to User0's calendar account
26+
Given user "admin" exists
27+
And user "user0" exists
28+
And user "user1" exists
29+
When "admin" updates property "{DAV:}group-member-set" to href "/remote.php/dav/principals/users/user1" of principal "users/user0/calendar-proxy-write" on the endpoint "/remote.php/dav/principals/"
30+
Then The CalDAV HTTP status code should be "404"

build/integration/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ else
2626
fi
2727
NC_DATADIR=$($OCC config:system:get datadirectory)
2828

29-
composer install
29+
composer install --no-audit
3030

3131
# avoid port collision on jenkins - use $EXECUTOR_NUMBER
3232
if [ -z "$EXECUTOR_NUMBER" ]; then

0 commit comments

Comments
 (0)