Skip to content

Commit e27577a

Browse files
committed
test(integration): write integration tests for calendar delegation
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent 98203ef commit e27577a

2 files changed

Lines changed: 71 additions & 60 deletions

File tree

build/integration/features/bootstrap/CalDavContext.php

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -122,34 +122,6 @@ public function requestsCalendar($user, $calendar, $endpoint) {
122122
}
123123
}
124124

125-
/**
126-
* @When :user requests principal :principal on the endpoint :endpoint
127-
*/
128-
public function requestsPrincipal(string $user, string $principal, string $endpoint): void {
129-
$davUrl = $this->baseUrl . $endpoint . $principal;
130-
131-
$password = ($user === 'admin') ? 'admin' : '123456';
132-
try {
133-
$this->response = $this->client->request(
134-
'PROPFIND',
135-
$davUrl,
136-
[
137-
'headers' => [
138-
'Content-Type' => 'application/xml; charset=UTF-8',
139-
'Depth' => 0,
140-
],
141-
'body' => '<x0:propfind xmlns:x0="DAV:"><x0:prop><x0:displayname/><x1:calendar-user-type xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x1:calendar-user-address-set xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x0:principal-URL/><x0:alternate-URI-set/><x2:email-address xmlns:x2="http://sabredav.org/ns"/><x3:language xmlns:x3="http://nextcloud.com/ns"/><x1:calendar-home-set xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x1:schedule-inbox-URL xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x1:schedule-outbox-URL xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x1:schedule-default-calendar-URL xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x3:resource-type xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-type xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-make xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-model xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-is-electric xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-range xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-seating-capacity xmlns:x3="http://nextcloud.com/ns"/><x3:resource-contact-person xmlns:x3="http://nextcloud.com/ns"/><x3:resource-contact-person-vcard xmlns:x3="http://nextcloud.com/ns"/><x3:room-type xmlns:x3="http://nextcloud.com/ns"/><x3:room-seating-capacity xmlns:x3="http://nextcloud.com/ns"/><x3:room-building-address xmlns:x3="http://nextcloud.com/ns"/><x3:room-building-story xmlns:x3="http://nextcloud.com/ns"/><x3:room-building-room-number xmlns:x3="http://nextcloud.com/ns"/><x3:room-features xmlns:x3="http://nextcloud.com/ns"/><x0:principal-collection-set/><x0:supported-report-set/></x0:prop></x0:propfind>',
142-
'auth' => [
143-
$user,
144-
$password,
145-
],
146-
]
147-
);
148-
} catch (\GuzzleHttp\Exception\ClientException $e) {
149-
$this->response = $e->getResponse();
150-
}
151-
}
152-
153125
/**
154126
* @Then The CalDAV response should contain a property :key
155127
* @throws \Exception
@@ -179,37 +151,6 @@ public function theCaldavResponseShouldContainAProperty(string $key): void {
179151
}
180152
}
181153

182-
/**
183-
* @Then The CalDAV response should contain a property :key with a href value :value
184-
* @throws \Exception
185-
*/
186-
public function theCaldavResponseShouldContainAPropertyWithHrefValue(
187-
string $key,
188-
string $value,
189-
): void {
190-
/** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
191-
$multiStatus = $this->responseXml['value'];
192-
$responses = $multiStatus->getResponses()[0]->getResponseProperties();
193-
if (!isset($responses[200])) {
194-
throw new \Exception(
195-
sprintf(
196-
'Expected code 200 got [%s]',
197-
implode(',', array_keys($responses)),
198-
)
199-
);
200-
}
201-
202-
$props = $responses[200];
203-
if (!array_key_exists($key, $props)) {
204-
throw new \Exception("Cannot find property \"$key\"");
205-
}
206-
207-
$actualValue = $props[$key]->getHref();
208-
if ($actualValue !== $value) {
209-
throw new \Exception("Property \"$key\" found with value \"$actualValue\", expected \"$value\"");
210-
}
211-
}
212-
213154
/**
214155
* @Then The CalDAV response should contain an href :href
215156
* @throws \Exception
@@ -384,4 +325,67 @@ public function t($amount) {
384325
);
385326
}
386327
}
328+
329+
/**
330+
* @When :user sends a create calendar request to :calendar on the endpoint :endpoint
331+
*/
332+
public function sendsCreateCalendarRequest(string $user, string $calendar, string $endpoint) {
333+
$davUrl = $this->baseUrl . $endpoint . $calendar;
334+
$password = ($user === 'admin') ? 'admin' : '123456';
335+
336+
try {
337+
$this->response = $this->client->request(
338+
'MKCALENDAR',
339+
$davUrl,
340+
[
341+
'body' => '<c:mkcalendar xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:" xmlns:a="http://apple.com/ns/ical/" xmlns:o="http://owncloud.org/ns"><d:set><d:prop><d:displayname>test</d:displayname><o:calendar-enabled>1</o:calendar-enabled><a:calendar-color>#21213D</a:calendar-color><c:supported-calendar-component-set><c:comp name="VEVENT"/></c:supported-calendar-component-set></d:prop></d:set></c:mkcalendar>',
342+
'auth' => [
343+
$user,
344+
$password,
345+
],
346+
]
347+
);
348+
} catch (GuzzleException $e) {
349+
$this->response = $e->getResponse();
350+
}
351+
}
352+
353+
/**
354+
* @Given :user updates property :key to href :value of principal :principal on the endpoint :endpoint
355+
*/
356+
public function updatesHrefPropertyOfPrincipal(
357+
string $user,
358+
string $key,
359+
string $value,
360+
string $principal,
361+
string $endpoint,
362+
): void {
363+
$davUrl = $this->baseUrl . $endpoint . $principal;
364+
$password = ($user === 'admin') ? 'admin' : '123456';
365+
366+
$propPatch = new \Sabre\DAV\Xml\Request\PropPatch();
367+
$propPatch->properties = [$key => new \Sabre\DAV\Xml\Property\Href($value)];
368+
369+
$xml = new \Sabre\Xml\Service();
370+
$body = $xml->write('{DAV:}propertyupdate', $propPatch, '/');
371+
372+
try {
373+
$this->response = $this->client->request(
374+
'PROPPATCH',
375+
$davUrl,
376+
[
377+
'headers' => [
378+
'Content-Type' => 'application/xml; charset=UTF-8',
379+
],
380+
'body' => $body,
381+
'auth' => [
382+
$user,
383+
$password,
384+
],
385+
]
386+
);
387+
} catch (\GuzzleHttp\Exception\ClientException $e) {
388+
$this->response = $e->getResponse();
389+
}
390+
}
387391
}

build/integration/features/caldav-delegation.feature

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ Feature: calendar delegation
2020
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/"
2121
Then The CalDAV response should be multi status
2222
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"
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"

0 commit comments

Comments
 (0)