From 88fc8c94ce2175d7ffd00462b922ab1a61f9c083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 16 Sep 2025 17:50:01 +0200 Subject: [PATCH] fix(dav): Fix PHP warnings triggered by tests in dav application MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/CalDAV/Federation/CalendarFederationProvider.php | 7 +++++++ .../dav/lib/CalDAV/Federation/FederationSharingService.php | 4 ++-- .../CalDAV/Federation/CalendarFederationProviderTest.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php b/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php index aef3c75ca38..de5f5b987d2 100644 --- a/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php +++ b/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php @@ -63,6 +63,13 @@ class CalendarFederationProvider implements ICloudFederationProvider { } $rawProtocol = $share->getProtocol(); + if (!isset($rawProtocol[ICalendarFederationProtocol::PROP_VERSION])) { + throw new ProviderCouldNotAddShareException( + 'No protocol version', + '', + Http::STATUS_BAD_REQUEST, + ); + } switch ($rawProtocol[ICalendarFederationProtocol::PROP_VERSION]) { case CalendarFederationProtocolV1::VERSION: try { diff --git a/apps/dav/lib/CalDAV/Federation/FederationSharingService.php b/apps/dav/lib/CalDAV/Federation/FederationSharingService.php index 8dcb8c7cebc..57df75b01a0 100644 --- a/apps/dav/lib/CalDAV/Federation/FederationSharingService.php +++ b/apps/dav/lib/CalDAV/Federation/FederationSharingService.php @@ -46,10 +46,10 @@ class FederationSharingService { */ private function decodeRemoteUserPrincipal(string $principal): ?string { // Expected format: principals/remote-users/abcdef123 - [$prefix, $collection, $encodedId] = explode('/', $principal); - if ($prefix !== 'principals' || $collection !== 'remote-users') { + if (!str_starts_with($principal, 'principals/remote-users/')) { return null; } + $encodedId = substr($principal, strlen('principals/remote-users/')); $decodedId = base64_decode($encodedId); if (!is_string($decodedId)) { diff --git a/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationProviderTest.php b/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationProviderTest.php index aba2f927934..8e436897789 100644 --- a/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationProviderTest.php +++ b/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationProviderTest.php @@ -175,7 +175,7 @@ class CalendarFederationProviderTest extends TestCase { ->method('add'); $this->expectException(ProviderCouldNotAddShareException::class); - $this->expectExceptionMessage('Unknown protocol version'); + $this->expectExceptionMessage('No protocol version'); $this->expectExceptionCode(400); $this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share)); }