Browse Source

fix(dav): Fix PHP warnings triggered by tests in dav application

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/54905/head
Côme Chilliet 3 weeks ago
parent
commit
88fc8c94ce
No known key found for this signature in database GPG Key ID: A3E2F658B28C760A
  1. 7
      apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php
  2. 4
      apps/dav/lib/CalDAV/Federation/FederationSharingService.php
  3. 2
      apps/dav/tests/unit/CalDAV/Federation/CalendarFederationProviderTest.php

7
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 {

4
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)) {

2
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));
}

Loading…
Cancel
Save