Browse Source

Migrate dav application from ILogger to LoggerInterface

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
tags/v25.0.0beta1
Côme Chilliet 2 years ago
parent
commit
e2531f8503
No account linked to committer's email address
42 changed files with 199 additions and 369 deletions
  1. 5
    5
      apps/dav/lib/AppInfo/Application.php
  2. 4
    11
      apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php
  3. 7
    18
      apps/dav/lib/CalDAV/CalDavBackend.php
  4. 3
    6
      apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php
  5. 3
    10
      apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
  6. 3
    10
      apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
  7. 2
    10
      apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php
  8. 3
    13
      apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php
  9. 2
    8
      apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php
  10. 2
    8
      apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php
  11. 5
    17
      apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
  12. 12
    22
      apps/dav/lib/CalDAV/WebcalCaching/RefreshWebcalService.php
  13. 7
    11
      apps/dav/lib/CardDAV/PhotoCache.php
  14. 6
    9
      apps/dav/lib/CardDAV/SyncService.php
  15. 5
    12
      apps/dav/lib/Comments/CommentNode.php
  16. 4
    5
      apps/dav/lib/Comments/EntityCollection.php
  17. 4
    5
      apps/dav/lib/Comments/EntityTypeCollection.php
  18. 3
    11
      apps/dav/lib/Comments/RootCollection.php
  19. 2
    1
      apps/dav/lib/Connector/Sabre/Auth.php
  20. 13
    12
      apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php
  21. 7
    8
      apps/dav/lib/Connector/Sabre/File.php
  22. 3
    14
      apps/dav/lib/Connector/Sabre/ServerFactory.php
  23. 4
    4
      apps/dav/lib/HookManager.php
  24. 3
    9
      apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php
  25. 6
    7
      apps/dav/lib/RootCollection.php
  26. 10
    11
      apps/dav/lib/Server.php
  27. 3
    3
      apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
  28. 5
    7
      apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
  29. 3
    3
      apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php
  30. 0
    16
      apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php
  31. 0
    17
      apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php
  32. 3
    3
      apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php
  33. 3
    3
      apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
  34. 16
    15
      apps/dav/tests/unit/CalDAV/WebcalCaching/RefreshWebcalServiceTest.php
  35. 4
    4
      apps/dav/tests/unit/CardDAV/SyncServiceTest.php
  36. 4
    4
      apps/dav/tests/unit/Comments/CommentsNodeTest.php
  37. 3
    3
      apps/dav/tests/unit/Comments/EntityCollectionTest.php
  38. 3
    3
      apps/dav/tests/unit/Comments/EntityTypeCollectionTest.php
  39. 1
    2
      apps/dav/tests/unit/Comments/RootCollectionTest.php
  40. 17
    24
      apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php
  41. 3
    2
      apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php
  42. 3
    3
      apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php

+ 5
- 5
apps/dav/lib/AppInfo/Application.php View File

use OCP\AppFramework\IAppContainer; use OCP\AppFramework\IAppContainer;
use OCP\Calendar\IManager as ICalendarManager; use OCP\Calendar\IManager as ICalendarManager;
use OCP\Contacts\IManager as IContactsManager; use OCP\Contacts\IManager as IContactsManager;
use OCP\ILogger;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\IUser; use OCP\IUser;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\EventDispatcher\GenericEvent;
use Throwable; use Throwable;


return new PhotoCache( return new PhotoCache(
$server->getAppDataDir('dav-photocache'), $server->getAppDataDir('dav-photocache'),
$c->get(ILogger::class)
$c->get(LoggerInterface::class)
); );
}); });


$job->run([]); $job->run([]);
$serverContainer->getJobList()->setLastRun($job); $serverContainer->getJobList()->setLastRun($job);
} catch (Exception $ex) { } catch (Exception $ex) {
$serverContainer->getLogger()->logException($ex);
$serverContainer->get(LoggerInterface::class)->error($ex->getMessage(), ['exception' => $ex]);
} }
}; };


} }


public function registerCalendarReminders(NotificationProviderManager $manager, public function registerCalendarReminders(NotificationProviderManager $manager,
ILogger $logger): void {
LoggerInterface $logger): void {
try { try {
$manager->registerProvider(AudioProvider::class); $manager->registerProvider(AudioProvider::class);
$manager->registerProvider(EmailProvider::class); $manager->registerProvider(EmailProvider::class);
$manager->registerProvider(PushProvider::class); $manager->registerProvider(PushProvider::class);
} catch (Throwable $ex) { } catch (Throwable $ex) {
$logger->logException($ex);
$logger->error($ex->getMessage(), ['exception' => $ex]);
} }
} }
} }

+ 4
- 11
apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php View File

use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\QueuedJob; use OCP\BackgroundJob\QueuedJob;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\ILogger;
use Psr\Log\LoggerInterface;


/** /**
* Class BuildReminderIndexBackgroundJob * Class BuildReminderIndexBackgroundJob
/** @var ReminderService */ /** @var ReminderService */
private $reminderService; private $reminderService;


/** @var ILogger */
private $logger;
private LoggerInterface $logger;


/** @var IJobList */ /** @var IJobList */
private $jobList; private $jobList;


/** /**
* BuildReminderIndexBackgroundJob constructor. * BuildReminderIndexBackgroundJob constructor.
*
* @param IDBConnection $db
* @param ReminderService $reminderService
* @param ILogger $logger
* @param IJobList $jobList
* @param ITimeFactory $timeFactory
*/ */
public function __construct(IDBConnection $db, public function __construct(IDBConnection $db,
ReminderService $reminderService, ReminderService $reminderService,
ILogger $logger,
LoggerInterface $logger,
IJobList $jobList, IJobList $jobList,
ITimeFactory $timeFactory) { ITimeFactory $timeFactory) {
parent::__construct($timeFactory); parent::__construct($timeFactory);
try { try {
$this->reminderService->onCalendarObjectCreate($row); $this->reminderService->onCalendarObjectCreate($row);
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex);
$this->logger->error($ex->getMessage(), ['exception' => $ex]);
} }


if (($this->timeFactory->getTime() - $startTime) > 15) { if (($this->timeFactory->getTime() - $startTime) > 15) {

+ 7
- 18
apps/dav/lib/CalDAV/CalDavBackend.php View File

use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
use RuntimeException; use RuntimeException;
use Sabre\CalDAV\Backend\AbstractBackend; use Sabre\CalDAV\Backend\AbstractBackend;
use Sabre\CalDAV\Backend\SchedulingSupport; use Sabre\CalDAV\Backend\SchedulingSupport;
/** @var ISecureRandom */ /** @var ISecureRandom */
private $random; private $random;


/** @var ILogger */
private $logger;
private LoggerInterface $logger;


/** @var IEventDispatcher */ /** @var IEventDispatcher */
private $dispatcher; private $dispatcher;


/** /**
* CalDavBackend constructor. * CalDavBackend constructor.
*
* @param IDBConnection $db
* @param Principal $principalBackend
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param ISecureRandom $random
* @param ILogger $logger
* @param IEventDispatcher $dispatcher
* @param EventDispatcherInterface $legacyDispatcher
* @param bool $legacyEndpoint
*/ */
public function __construct(IDBConnection $db, public function __construct(IDBConnection $db,
Principal $principalBackend, Principal $principalBackend,
IUserManager $userManager, IUserManager $userManager,
IGroupManager $groupManager, IGroupManager $groupManager,
ISecureRandom $random, ISecureRandom $random,
ILogger $logger,
LoggerInterface $logger,
IEventDispatcher $dispatcher, IEventDispatcher $dispatcher,
EventDispatcherInterface $legacyDispatcher, EventDispatcherInterface $legacyDispatcher,
IConfig $config, IConfig $config,
try { try {
$matches = $this->validateFilterForObject($row, $filters); $matches = $this->validateFilterForObject($row, $filters);
} catch (ParseException $ex) { } catch (ParseException $ex) {
$this->logger->logException($ex, [
$this->logger->error('Caught parsing exception for calendar data. This usually indicates invalid calendar data. calendar-id:'.$calendarId.' uri:'.$row['uri'], [
'app' => 'dav', 'app' => 'dav',
'message' => 'Caught parsing exception for calendar data. This usually indicates invalid calendar data. calendar-id:'.$calendarId.' uri:'.$row['uri']
'exception' => $ex,
]); ]);
continue; continue;
} catch (InvalidDataException $ex) { } catch (InvalidDataException $ex) {
$this->logger->logException($ex, [
$this->logger->error('Caught invalid data exception for calendar data. This usually indicates invalid calendar data. calendar-id:'.$calendarId.' uri:'.$row['uri'], [
'app' => 'dav', 'app' => 'dav',
'message' => 'Caught invalid data exception for calendar data. This usually indicates invalid calendar data. calendar-id:'.$calendarId.' uri:'.$row['uri']
'exception' => $ex,
]); ]);
continue; continue;
} }

+ 3
- 6
apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php View File

namespace OCA\DAV\CalDAV\ICSExportPlugin; namespace OCA\DAV\CalDAV\ICSExportPlugin;


use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use Psr\Log\LoggerInterface;
use Sabre\HTTP\ResponseInterface; use Sabre\HTTP\ResponseInterface;
use Sabre\VObject\DateTimeParser; use Sabre\VObject\DateTimeParser;
use Sabre\VObject\InvalidDataException; use Sabre\VObject\InvalidDataException;
/** @var IConfig */ /** @var IConfig */
private $config; private $config;


/** @var ILogger */
private $logger;
private LoggerInterface $logger;


/** @var string */ /** @var string */
private const DEFAULT_REFRESH_INTERVAL = 'PT4H'; private const DEFAULT_REFRESH_INTERVAL = 'PT4H';


/** /**
* ICSExportPlugin constructor. * ICSExportPlugin constructor.
*
* @param IConfig $config
*/ */
public function __construct(IConfig $config, ILogger $logger) {
public function __construct(IConfig $config, LoggerInterface $logger) {
$this->config = $config; $this->config = $config;
$this->logger = $logger; $this->logger = $logger;
} }

+ 3
- 10
apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php View File

use OCA\DAV\CalDAV\Reminder\INotificationProvider; use OCA\DAV\CalDAV\Reminder\INotificationProvider;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory; use OCP\L10N\IFactory as L10NFactory;
use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VEvent; use Sabre\VObject\Component\VEvent;
use Sabre\VObject\DateTimeParser; use Sabre\VObject\DateTimeParser;
use Sabre\VObject\Property; use Sabre\VObject\Property;
/** @var string */ /** @var string */
public const NOTIFICATION_TYPE = ''; public const NOTIFICATION_TYPE = '';


/** @var ILogger */
protected $logger;
protected LoggerInterface $logger;


/** @var L10NFactory */ /** @var L10NFactory */
protected $l10nFactory; protected $l10nFactory;
/** @var IConfig */ /** @var IConfig */
protected $config; protected $config;


/**
* @param ILogger $logger
* @param L10NFactory $l10nFactory
* @param IConfig $config
* @param IUrlGenerator $urlGenerator
*/
public function __construct(ILogger $logger,
public function __construct(LoggerInterface $logger,
L10NFactory $l10nFactory, L10NFactory $l10nFactory,
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
IConfig $config) { IConfig $config) {

+ 3
- 10
apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php View File

use DateTime; use DateTime;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\L10N\IFactory as L10NFactory; use OCP\L10N\IFactory as L10NFactory;
use OCP\Mail\IEMailTemplate; use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
use Psr\Log\LoggerInterface;
use Sabre\VObject; use Sabre\VObject;
use Sabre\VObject\Component\VEvent; use Sabre\VObject\Component\VEvent;
use Sabre\VObject\Parameter; use Sabre\VObject\Parameter;
/** @var IMailer */ /** @var IMailer */
private $mailer; private $mailer;


/**
* @param IConfig $config
* @param IMailer $mailer
* @param ILogger $logger
* @param L10NFactory $l10nFactory
* @param IUrlGenerator $urlGenerator
*/
public function __construct(IConfig $config, public function __construct(IConfig $config,
IMailer $mailer, IMailer $mailer,
ILogger $logger,
LoggerInterface $logger,
L10NFactory $l10nFactory, L10NFactory $l10nFactory,
IURLGenerator $urlGenerator) { IURLGenerator $urlGenerator) {
parent::__construct($logger, $l10nFactory, $urlGenerator, $config); parent::__construct($logger, $l10nFactory, $urlGenerator, $config);
$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
} }
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex, ['app' => 'dav']);
$this->logger->error($ex->getMessage(), ['app' => 'dav', 'exception' => $ex]);
} }
} }
} }

+ 2
- 10
apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php View File

use OCA\DAV\AppInfo\Application; use OCA\DAV\AppInfo\Application;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory; use OCP\L10N\IFactory as L10NFactory;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\Notification\INotification; use OCP\Notification\INotification;
use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VEvent; use Sabre\VObject\Component\VEvent;
use Sabre\VObject\Property; use Sabre\VObject\Property;


/** @var ITimeFactory */ /** @var ITimeFactory */
private $timeFactory; private $timeFactory;


/**
* @param IConfig $config
* @param IManager $manager
* @param ILogger $logger
* @param L10NFactory $l10nFactory
* @param IUrlGenerator $urlGenerator
* @param ITimeFactory $timeFactory
*/
public function __construct(IConfig $config, public function __construct(IConfig $config,
IManager $manager, IManager $manager,
ILogger $logger,
LoggerInterface $logger,
L10NFactory $l10nFactory, L10NFactory $l10nFactory,
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
ITimeFactory $timeFactory) { ITimeFactory $timeFactory) {

+ 3
- 13
apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php View File

use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\PropPatch; use Sabre\DAV\PropPatch;
use Sabre\DAVACL\PrincipalBackend\BackendInterface; use Sabre\DAVACL\PrincipalBackend\BackendInterface;
use function array_intersect; use function array_intersect;
/** @var IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;


/** @var ILogger */
private $logger;
private LoggerInterface $logger;


/** @var ProxyMapper */ /** @var ProxyMapper */
private $proxyMapper; private $proxyMapper;
/** @var string */ /** @var string */
private $cuType; private $cuType;


/**
* @param IDBConnection $dbConnection
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param ILogger $logger
* @param string $principalPrefix
* @param string $dbPrefix
* @param string $cuType
*/
public function __construct(IDBConnection $dbConnection, public function __construct(IDBConnection $dbConnection,
IUserSession $userSession, IUserSession $userSession,
IGroupManager $groupManager, IGroupManager $groupManager,
ILogger $logger,
LoggerInterface $logger,
ProxyMapper $proxyMapper, ProxyMapper $proxyMapper,
string $principalPrefix, string $principalPrefix,
string $dbPrefix, string $dbPrefix,

+ 2
- 8
apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php View File

use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;


/** /**
* Class ResourcePrincipalBackend * Class ResourcePrincipalBackend


/** /**
* ResourcePrincipalBackend constructor. * ResourcePrincipalBackend constructor.
*
* @param IDBConnection $dbConnection
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param ILogger $logger
* @param ProxyMapper $proxyMapper
*/ */
public function __construct(IDBConnection $dbConnection, public function __construct(IDBConnection $dbConnection,
IUserSession $userSession, IUserSession $userSession,
IGroupManager $groupManager, IGroupManager $groupManager,
ILogger $logger,
LoggerInterface $logger,
ProxyMapper $proxyMapper) { ProxyMapper $proxyMapper) {
parent::__construct($dbConnection, $userSession, $groupManager, $logger, parent::__construct($dbConnection, $userSession, $groupManager, $logger,
$proxyMapper, 'principals/calendar-resources', 'resource', 'RESOURCE'); $proxyMapper, 'principals/calendar-resources', 'resource', 'RESOURCE');

+ 2
- 8
apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php View File

use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;


/** /**
* Class RoomPrincipalBackend * Class RoomPrincipalBackend


/** /**
* RoomPrincipalBackend constructor. * RoomPrincipalBackend constructor.
*
* @param IDBConnection $dbConnection
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param ILogger $logger
* @param ProxyMapper $proxyMapper
*/ */
public function __construct(IDBConnection $dbConnection, public function __construct(IDBConnection $dbConnection,
IUserSession $userSession, IUserSession $userSession,
IGroupManager $groupManager, IGroupManager $groupManager,
ILogger $logger,
LoggerInterface $logger,
ProxyMapper $proxyMapper) { ProxyMapper $proxyMapper) {
parent::__construct($dbConnection, $userSession, $groupManager, $logger, parent::__construct($dbConnection, $userSession, $groupManager, $logger,
$proxyMapper, 'principals/calendar-rooms', 'room', 'ROOM'); $proxyMapper, 'principals/calendar-rooms', 'room', 'ROOM');

+ 5
- 17
apps/dav/lib/CalDAV/Schedule/IMipPlugin.php View File

use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\L10N\IFactory as L10NFactory; use OCP\L10N\IFactory as L10NFactory;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use OCP\Util; use OCP\Util;
use Psr\Log\LoggerInterface;
use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin; use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin;
use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VEvent; use Sabre\VObject\Component\VEvent;
/** @var IMailer */ /** @var IMailer */
private $mailer; private $mailer;


/** @var ILogger */
private $logger;
private LoggerInterface $logger;


/** @var ITimeFactory */ /** @var ITimeFactory */
private $timeFactory; private $timeFactory;
public const METHOD_CANCEL = 'cancel'; public const METHOD_CANCEL = 'cancel';
public const IMIP_INDENT = 15; // Enough for the length of all body bullet items, in all languages public const IMIP_INDENT = 15; // Enough for the length of all body bullet items, in all languages


/**
* @param IConfig $config
* @param IMailer $mailer
* @param ILogger $logger
* @param ITimeFactory $timeFactory
* @param L10NFactory $l10nFactory
* @param IUrlGenerator $urlGenerator
* @param Defaults $defaults
* @param ISecureRandom $random
* @param IDBConnection $db
* @param string $userId
*/
public function __construct(IConfig $config, IMailer $mailer, ILogger $logger,
public function __construct(IConfig $config, IMailer $mailer,
LoggerInterface $logger,
ITimeFactory $timeFactory, L10NFactory $l10nFactory, ITimeFactory $timeFactory, L10NFactory $l10nFactory,
IURLGenerator $urlGenerator, Defaults $defaults, IURLGenerator $urlGenerator, Defaults $defaults,
ISecureRandom $random, IDBConnection $db, IUserManager $userManager, ISecureRandom $random, IDBConnection $db, IUserManager $userManager,
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
} }
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex, ['app' => 'dav']);
$this->logger->error($ex->getMessage(), ['app' => 'dav', 'exception' => $ex]);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
} }
} }

+ 12
- 22
apps/dav/lib/CalDAV/WebcalCaching/RefreshWebcalService.php View File

use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\Http\Client\LocalServerException; use OCP\Http\Client\LocalServerException;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\PropPatch; use Sabre\DAV\PropPatch;
use Sabre\DAV\Xml\Property\Href; use Sabre\DAV\Xml\Property\Href;
/** @var IConfig */ /** @var IConfig */
private $config; private $config;


/** @var ILogger */
private $logger;
private LoggerInterface $logger;


public const REFRESH_RATE = '{http://apple.com/ns/ical/}refreshrate'; public const REFRESH_RATE = '{http://apple.com/ns/ical/}refreshrate';
public const STRIP_ALARMS = '{http://calendarserver.org/ns/}subscribed-strip-alarms'; public const STRIP_ALARMS = '{http://calendarserver.org/ns/}subscribed-strip-alarms';


/** /**
* RefreshWebcalJob constructor. * RefreshWebcalJob constructor.
*
* @param CalDavBackend $calDavBackend
* @param IClientService $clientService
* @param IConfig $config
* @param ILogger $logger
*/ */
public function __construct(CalDavBackend $calDavBackend, IClientService $clientService, IConfig $config, ILogger $logger) {
public function __construct(CalDavBackend $calDavBackend,
IClientService $clientService,
IConfig $config,
LoggerInterface $logger) {
$this->calDavBackend = $calDavBackend; $this->calDavBackend = $calDavBackend;
$this->clientService = $clientService; $this->clientService = $clientService;
$this->config = $config; $this->config = $config;
$this->logger = $logger; $this->logger = $logger;
} }


/**
* @param string $principalUri
* @param string $uri
*/
public function refreshSubscription(string $principalUri, string $uri) { public function refreshSubscription(string $principalUri, string $uri) {
$subscription = $this->getSubscription($principalUri, $uri); $subscription = $this->getSubscription($principalUri, $uri);
$mutations = []; $mutations = [];
try { try {
$this->calDavBackend->createCalendarObject($subscription['id'], $uri, $calendarData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); $this->calDavBackend->createCalendarObject($subscription['id'], $uri, $calendarData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
} catch (NoInstancesException | BadRequest $ex) { } catch (NoInstancesException | BadRequest $ex) {
$this->logger->logException($ex);
$this->logger->error($ex->getMessage(), ['exception' => $ex]);
} }
} }


} catch (ParseException $ex) { } catch (ParseException $ex) {
$subscriptionId = $subscription['id']; $subscriptionId = $subscription['id'];


$this->logger->logException($ex);
$this->logger->warning("Subscription $subscriptionId could not be refreshed due to a parsing error");
$this->logger->error("Subscription $subscriptionId could not be refreshed due to a parsing error", ['exception' => $ex]);
} }
} }


return $vCalendar->serialize(); return $vCalendar->serialize();
} }
} catch (LocalServerException $ex) { } catch (LocalServerException $ex) {
$this->logger->logException($ex, [
'message' => "Subscription $subscriptionId was not refreshed because it violates local access rules",
'level' => ILogger::WARN,
$this->logger->warning("Subscription $subscriptionId was not refreshed because it violates local access rules", [
'exception' => $ex,
]); ]);


return null; return null;
} catch (Exception $ex) { } catch (Exception $ex) {
$this->logger->logException($ex, [
'message' => "Subscription $subscriptionId could not be refreshed due to a network error",
'level' => ILogger::WARN,
$this->logger->warning("Subscription $subscriptionId could not be refreshed due to a network error", [
'exception' => $ex,
]); ]);


return null; return null;

+ 7
- 11
apps/dav/lib/CardDAV/PhotoCache.php View File

use OCP\Files\NotPermittedException; use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder; use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ILogger;
use Psr\Log\LoggerInterface;
use Sabre\CardDAV\Card; use Sabre\CardDAV\Card;
use Sabre\VObject\Document; use Sabre\VObject\Document;
use Sabre\VObject\Parameter; use Sabre\VObject\Parameter;
/** @var IAppData */ /** @var IAppData */
protected $appData; protected $appData;


/** @var ILogger */
protected $logger;
protected LoggerInterface $logger;


/** /**
* PhotoCache constructor. * PhotoCache constructor.
*
* @param IAppData $appData
* @param ILogger $logger
*/ */
public function __construct(IAppData $appData, ILogger $logger) {
public function __construct(IAppData $appData, LoggerInterface $logger) {
$this->appData = $appData; $this->appData = $appData;
$this->logger = $logger; $this->logger = $logger;
} }
$vObject = $this->readCard($node->get()); $vObject = $this->readCard($node->get());
return $this->getPhotoFromVObject($vObject); return $this->getPhotoFromVObject($vObject);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, [
'message' => 'Exception during vcard photo parsing'
$this->logger->error('Exception during vcard photo parsing', [
'exception' => $e
]); ]);
} }
return false; return false;
'body' => $val 'body' => $val
]; ];
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, [
'message' => 'Exception during vcard photo parsing'
$this->logger->error('Exception during vcard photo parsing', [
'exception' => $e
]); ]);
} }
return false; return false;

+ 6
- 9
apps/dav/lib/CardDAV/SyncService.php View File



use OC\Accounts\AccountManager; use OC\Accounts\AccountManager;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Client; use Sabre\DAV\Client;
use Sabre\DAV\Xml\Response\MultiStatus; use Sabre\DAV\Xml\Response\MultiStatus;
use Sabre\DAV\Xml\Service; use Sabre\DAV\Xml\Service;
/** @var IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;


/** @var ILogger */
private $logger;
private LoggerInterface $logger;


/** @var array */ /** @var array */
private $localSystemAddressBook; private $localSystemAddressBook;


/** /**
* SyncService constructor. * SyncService constructor.
*
* @param CardDavBackend $backend
* @param IUserManager $userManager
* @param ILogger $logger
* @param AccountManager $accountManager
*/ */
public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, Converter $converter) {
public function __construct(CardDavBackend $backend,
IUserManager $userManager,
LoggerInterface $logger,
Converter $converter) {
$this->backend = $backend; $this->backend = $backend;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->logger = $logger; $this->logger = $logger;

+ 5
- 12
apps/dav/lib/Comments/CommentNode.php View File

use OCP\Comments\IComment; use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManager;
use OCP\Comments\MessageTooLongException; use OCP\Comments\MessageTooLongException;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\MethodNotAllowed; use Sabre\DAV\Exception\MethodNotAllowed;
/** @var ICommentsManager */ /** @var ICommentsManager */
protected $commentsManager; protected $commentsManager;


/** @var ILogger */
protected $logger;
protected LoggerInterface $logger;


/** @var array list of properties with key being their name and value their setter */ /** @var array list of properties with key being their name and value their setter */
protected $properties = []; protected $properties = [];


/** /**
* CommentNode constructor. * CommentNode constructor.
*
* @param ICommentsManager $commentsManager
* @param IComment $comment
* @param IUserManager $userManager
* @param IUserSession $userSession
* @param ILogger $logger
*/ */
public function __construct( public function __construct(
ICommentsManager $commentsManager, ICommentsManager $commentsManager,
IComment $comment, IComment $comment,
IUserManager $userManager, IUserManager $userManager,
IUserSession $userSession, IUserSession $userSession,
ILogger $logger
LoggerInterface $logger
) { ) {
$this->commentsManager = $commentsManager; $this->commentsManager = $commentsManager;
$this->comment = $comment; $this->comment = $comment;
$this->commentsManager->save($this->comment); $this->commentsManager->save($this->comment);
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'dav/comments']);
$this->logger->error($e->getMessage(), ['app' => 'dav/comments', 'exception' => $e]);
if ($e instanceof MessageTooLongException) { if ($e instanceof MessageTooLongException) {
$msg = 'Message exceeds allowed character limit of '; $msg = 'Message exceeds allowed character limit of ';
throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e);
try { try {
$displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']);
} catch (\OutOfBoundsException $e) { } catch (\OutOfBoundsException $e) {
$this->logger->logException($e);
$this->logger->error($e->getMessage(), ['exception' => $e]);
// No displayname, upon client's discretion what to display. // No displayname, upon client's discretion what to display.
$displayName = ''; $displayName = '';
} }

+ 4
- 5
apps/dav/lib/Comments/EntityCollection.php View File



use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException; use OCP\Comments\NotFoundException;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\IProperties; use Sabre\DAV\IProperties;
use Sabre\DAV\PropPatch; use Sabre\DAV\PropPatch;
/** @var string */ /** @var string */
protected $id; protected $id;


/** @var ILogger */
protected $logger;
protected LoggerInterface $logger;


/** /**
* @param string $id * @param string $id
* @param ICommentsManager $commentsManager * @param ICommentsManager $commentsManager
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IUserSession $userSession * @param IUserSession $userSession
* @param ILogger $logger
* @param LoggerInterface $logger
*/ */
public function __construct( public function __construct(
$id, $id,
ICommentsManager $commentsManager, ICommentsManager $commentsManager,
IUserManager $userManager, IUserManager $userManager,
IUserSession $userSession, IUserSession $userSession,
ILogger $logger
LoggerInterface $logger
) { ) {
foreach (['id', 'name'] as $property) { foreach (['id', 'name'] as $property) {
$$property = trim($$property); $$property = trim($$property);

+ 4
- 5
apps/dav/lib/Comments/EntityTypeCollection.php View File

namespace OCA\DAV\Comments; namespace OCA\DAV\Comments;


use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManager;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\MethodNotAllowed; use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Exception\NotFound;


*/ */
class EntityTypeCollection extends RootCollection { class EntityTypeCollection extends RootCollection {


/** @var ILogger */
protected $logger;
protected LoggerInterface $logger;


/** @var IUserManager */ /** @var IUserManager */
protected $userManager; protected $userManager;
* @param ICommentsManager $commentsManager * @param ICommentsManager $commentsManager
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IUserSession $userSession * @param IUserSession $userSession
* @param ILogger $logger
* @param LoggerInterface $logger
* @param \Closure $childExistsFunction * @param \Closure $childExistsFunction
*/ */
public function __construct( public function __construct(
ICommentsManager $commentsManager, ICommentsManager $commentsManager,
IUserManager $userManager, IUserManager $userManager,
IUserSession $userSession, IUserSession $userSession,
ILogger $logger,
LoggerInterface $logger,
\Closure $childExistsFunction \Closure $childExistsFunction
) { ) {
$name = trim($name); $name = trim($name);

+ 3
- 11
apps/dav/lib/Comments/RootCollection.php View File



use OCP\Comments\CommentsEntityEvent; use OCP\Comments\CommentsEntityEvent;
use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManager;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotAuthenticated; use Sabre\DAV\Exception\NotAuthenticated;
use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Exception\NotFound;
/** @var string */ /** @var string */
protected $name = 'comments'; protected $name = 'comments';


/** @var ILogger */
protected $logger;
protected LoggerInterface $logger;


/** @var IUserManager */ /** @var IUserManager */
protected $userManager; protected $userManager;
/** @var EventDispatcherInterface */ /** @var EventDispatcherInterface */
protected $dispatcher; protected $dispatcher;


/**
* @param ICommentsManager $commentsManager
* @param IUserManager $userManager
* @param IUserSession $userSession
* @param EventDispatcherInterface $dispatcher
* @param ILogger $logger
*/
public function __construct( public function __construct(
ICommentsManager $commentsManager, ICommentsManager $commentsManager,
IUserManager $userManager, IUserManager $userManager,
IUserSession $userSession, IUserSession $userSession,
EventDispatcherInterface $dispatcher, EventDispatcherInterface $dispatcher,
ILogger $logger) {
LoggerInterface $logger) {
$this->commentsManager = $commentsManager; $this->commentsManager = $commentsManager;
$this->logger = $logger; $this->logger = $logger;
$this->userManager = $userManager; $this->userManager = $userManager;

+ 2
- 1
apps/dav/lib/Connector/Sabre/Auth.php View File

use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden; use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
use OCP\IRequest; use OCP\IRequest;
use OCP\ISession; use OCP\ISession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Auth\Backend\AbstractBasic; use Sabre\DAV\Auth\Backend\AbstractBasic;
use Sabre\DAV\Exception\NotAuthenticated; use Sabre\DAV\Exception\NotAuthenticated;
use Sabre\DAV\Exception\ServiceUnavailable; use Sabre\DAV\Exception\ServiceUnavailable;
} catch (Exception $e) { } catch (Exception $e) {
$class = get_class($e); $class = get_class($e);
$msg = $e->getMessage(); $msg = $e->getMessage();
\OC::$server->getLogger()->logException($e);
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
throw new ServiceUnavailable("$class: $msg"); throw new ServiceUnavailable("$class: $msg");
} }
} }

+ 13
- 12
apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php View File

use OCA\DAV\Connector\Sabre\Exception\FileLocked; use OCA\DAV\Connector\Sabre\Exception\FileLocked;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden; use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\ILogger;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\Conflict; use Sabre\DAV\Exception\Conflict;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
/** @var string */ /** @var string */
private $appName; private $appName;


/** @var ILogger */
private $logger;
private LoggerInterface $logger;


/** /**
* @param string $loggerAppName app name to use when logging * @param string $loggerAppName app name to use when logging
* @param ILogger $logger
* @param LoggerInterface $logger
*/ */
public function __construct($loggerAppName, $logger) {
public function __construct($loggerAppName, LoggerInterface $logger) {
$this->appName = $loggerAppName; $this->appName = $loggerAppName;
$this->logger = $logger; $this->logger = $logger;
} }
*/ */
public function logException(\Throwable $ex) { public function logException(\Throwable $ex) {
$exceptionClass = get_class($ex); $exceptionClass = get_class($ex);
$level = ILogger::FATAL;
if (isset($this->nonFatalExceptions[$exceptionClass]) || if (isset($this->nonFatalExceptions[$exceptionClass]) ||
( (
$exceptionClass === ServiceUnavailable::class && $exceptionClass === ServiceUnavailable::class &&
$ex->getMessage() === 'System in maintenance mode.' $ex->getMessage() === 'System in maintenance mode.'
) )
) { ) {
$level = ILogger::DEBUG;
$this->logger->debug($ex->getMessage(), [
'app' => $this->appName,
'exception' => $ex,
]);
} else {
$this->logger->critical($ex->getMessage(), [
'app' => $this->appName,
'exception' => $ex,
]);
} }

$this->logger->logException($ex, [
'app' => $this->appName,
'level' => $level,
]);
} }
} }

+ 7
- 8
apps/dav/lib/Connector/Sabre/File.php View File

use OCP\Files\Storage; use OCP\Files\Storage;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\L10N\IFactory as IL10NFactory; use OCP\L10N\IFactory as IL10NFactory;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException; use OCP\Lock\LockedException;
use OCP\Share\IManager; use OCP\Share\IManager;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception; use Sabre\DAV\Exception;
use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
} else { } else {
$target = $partStorage->fopen($internalPartPath, 'wb'); $target = $partStorage->fopen($internalPartPath, 'wb');
if ($target === false) { if ($target === false) {
\OC::$server->getLogger()->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']);
\OC::$server->get(LoggerInterface::class)->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']);
// because we have no clue about the cause we can only throw back a 500/Internal Server Error // because we have no clue about the cause we can only throw back a 500/Internal Server Error
throw new Exception($this->l10n->t('Could not write file contents')); throw new Exception($this->l10n->t('Could not write file contents'));
} }
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$context = [];

if ($e instanceof LockedException) { if ($e instanceof LockedException) {
$context['level'] = ILogger::DEBUG;
\OC::$server->get(LoggerInterface::class)->debug($e->getMessage(), ['exception' => $e]);
} else {
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
} }


\OC::$server->getLogger()->logException($e, $context);
if ($needsPartFile) { if ($needsPartFile) {
$partStorage->unlink($internalPartPath); $partStorage->unlink($internalPartPath);
} }
$renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath);
$fileExists = $storage->file_exists($internalPath); $fileExists = $storage->file_exists($internalPath);
if ($renameOkay === false || $fileExists === false) { if ($renameOkay === false || $fileExists === false) {
\OC::$server->getLogger()->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']);
\OC::$server->get(LoggerInterface::class)->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']);
throw new Exception($this->l10n->t('Could not rename part file to final file')); throw new Exception($this->l10n->t('Could not rename part file to final file'));
} }
} catch (ForbiddenException $ex) { } catch (ForbiddenException $ex) {
$renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath); $renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath);
$fileExists = $targetStorage->file_exists($targetInternalPath); $fileExists = $targetStorage->file_exists($targetInternalPath);
if ($renameOkay === false || $fileExists === false) { if ($renameOkay === false || $fileExists === false) {
\OC::$server->getLogger()->error('\OC\Files\Filesystem::rename() failed', ['app' => 'webdav']);
\OC::$server->get(LoggerInterface::class)->error('\OC\Files\Filesystem::rename() failed', ['app' => 'webdav']);
// only delete if an error occurred and the target file was already created // only delete if an error occurred and the target file was already created
if ($fileExists) { if ($fileExists) {
// set to null to avoid double-deletion when handling exception // set to null to avoid double-deletion when handling exception

+ 3
- 14
apps/dav/lib/Connector/Sabre/ServerFactory.php View File

use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IPreview; use OCP\IPreview;
use OCP\IRequest; use OCP\IRequest;
use OCP\ITagManager; use OCP\ITagManager;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\SabrePluginEvent; use OCP\SabrePluginEvent;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Auth\Plugin; use Sabre\DAV\Auth\Plugin;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;


class ServerFactory { class ServerFactory {
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var ILogger */
private $logger;
private LoggerInterface $logger;
/** @var IDBConnection */ /** @var IDBConnection */
private $databaseConnection; private $databaseConnection;
/** @var IUserSession */ /** @var IUserSession */
/** @var IL10N */ /** @var IL10N */
private $l10n; private $l10n;


/**
* @param IConfig $config
* @param ILogger $logger
* @param IDBConnection $databaseConnection
* @param IUserSession $userSession
* @param IMountManager $mountManager
* @param ITagManager $tagManager
* @param IRequest $request
* @param IPreview $previewManager
*/
public function __construct( public function __construct(
IConfig $config, IConfig $config,
ILogger $logger,
LoggerInterface $logger,
IDBConnection $databaseConnection, IDBConnection $databaseConnection,
IUserSession $userSession, IUserSession $userSession,
IMountManager $mountManager, IMountManager $mountManager,

+ 4
- 4
apps/dav/lib/HookManager.php View File

'{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(),
'components' => 'VEVENT' 'components' => 'VEVENT'
]); ]);
} catch (\Exception $ex) {
\OC::$server->getLogger()->logException($ex);
} catch (\Exception $e) {
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
} }
} }
if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) { if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) {
$this->cardDav->createAddressBook($principal, CardDavBackend::PERSONAL_ADDRESSBOOK_URI, [ $this->cardDav->createAddressBook($principal, CardDavBackend::PERSONAL_ADDRESSBOOK_URI, [
'{DAV:}displayname' => CardDavBackend::PERSONAL_ADDRESSBOOK_NAME, '{DAV:}displayname' => CardDavBackend::PERSONAL_ADDRESSBOOK_NAME,
]); ]);
} catch (\Exception $ex) {
\OC::$server->getLogger()->logException($ex);
} catch (\Exception $e) {
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
} }
} }
} }

+ 3
- 9
apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php View File

use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\CalDavBackend;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\ILogger;
use OCP\Migration\IOutput; use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep; use OCP\Migration\IRepairStep;
use Psr\Log\LoggerInterface;
use Sabre\VObject\InvalidDataException; use Sabre\VObject\InvalidDataException;


class CalDAVRemoveEmptyValue implements IRepairStep { class CalDAVRemoveEmptyValue implements IRepairStep {
/** @var CalDavBackend */ /** @var CalDavBackend */
private $calDavBackend; private $calDavBackend;


/** @var ILogger */
private $logger;
private LoggerInterface $logger;


/**
* @param IDBConnection $db
* @param CalDavBackend $calDavBackend
* @param ILogger $logger
*/
public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) {
public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, LoggerInterface $logger) {
$this->db = $db; $this->db = $db;
$this->calDavBackend = $calDavBackend; $this->calDavBackend = $calDavBackend;
$this->logger = $logger; $this->logger = $logger;

+ 6
- 7
apps/dav/lib/RootCollection.php View File

public function __construct() { public function __construct() {
$l10n = \OC::$server->getL10N('dav'); $l10n = \OC::$server->getL10N('dav');
$random = \OC::$server->getSecureRandom(); $random = \OC::$server->getSecureRandom();
$logger = \OC::$server->getLogger();
$psrLogger = \OC::$server->get(LoggerInterface::class);
$logger = \OC::$server->get(LoggerInterface::class);
$userManager = \OC::$server->getUserManager(); $userManager = \OC::$server->getUserManager();
$userSession = \OC::$server->getUserSession(); $userSession = \OC::$server->getUserSession();
$groupManager = \OC::$server->getGroupManager(); $groupManager = \OC::$server->getGroupManager();
$legacyDispatcher, $legacyDispatcher,
$config $config
); );
$userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $psrLogger);
$userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger);
$userCalendarRoot->disableListing = $disableListing; $userCalendarRoot->disableListing = $disableListing;


$resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $psrLogger);
$resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger);
$resourceCalendarRoot->disableListing = $disableListing; $resourceCalendarRoot->disableListing = $disableListing;
$roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $psrLogger);
$roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger);
$roomCalendarRoot->disableListing = $disableListing; $roomCalendarRoot->disableListing = $disableListing;


$publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $psrLogger);
$publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger);
$publicCalendarRoot->disableListing = $disableListing; $publicCalendarRoot->disableListing = $disableListing;


$systemTagCollection = new SystemTag\SystemTagsByIdCollection( $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
$userManager, $userManager,
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getEventDispatcher(), \OC::$server->getEventDispatcher(),
\OC::$server->getLogger()
$logger
); );


$pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));

+ 10
- 11
apps/dav/lib/Server.php View File

*/ */
namespace OCA\DAV; namespace OCA\DAV;


use OCA\DAV\Connector\Sabre\RequestIdHeaderPlugin;
use OCP\Diagnostics\IEventLogger;
use OCP\Profiler\IProfiler;
use OCA\DAV\Profiler\ProfilerPlugin;
use OCP\AppFramework\Http\Response;
use Psr\Log\LoggerInterface;
use OCA\DAV\AppInfo\PluginManager; use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\BulkUpload\BulkUploadPlugin;
use OCA\DAV\CalDAV\BirthdayService; use OCA\DAV\CalDAV\BirthdayService;
use OCA\DAV\CardDAV\HasPhotoPlugin; use OCA\DAV\CardDAV\HasPhotoPlugin;
use OCA\DAV\CardDAV\ImageExportPlugin; use OCA\DAV\CardDAV\ImageExportPlugin;
use OCA\DAV\Connector\Sabre\FilesReportPlugin; use OCA\DAV\Connector\Sabre\FilesReportPlugin;
use OCA\DAV\Connector\Sabre\PropfindCompressionPlugin; use OCA\DAV\Connector\Sabre\PropfindCompressionPlugin;
use OCA\DAV\Connector\Sabre\QuotaPlugin; use OCA\DAV\Connector\Sabre\QuotaPlugin;
use OCA\DAV\Connector\Sabre\RequestIdHeaderPlugin;
use OCA\DAV\Connector\Sabre\SharesPlugin; use OCA\DAV\Connector\Sabre\SharesPlugin;
use OCA\DAV\Connector\Sabre\TagsPlugin; use OCA\DAV\Connector\Sabre\TagsPlugin;
use OCA\DAV\DAV\CustomPropertiesBackend; use OCA\DAV\DAV\CustomPropertiesBackend;
use OCA\DAV\Events\SabrePluginAuthInitEvent; use OCA\DAV\Events\SabrePluginAuthInitEvent;
use OCA\DAV\Files\BrowserErrorPagePlugin; use OCA\DAV\Files\BrowserErrorPagePlugin;
use OCA\DAV\Files\LazySearchBackend; use OCA\DAV\Files\LazySearchBackend;
use OCA\DAV\BulkUpload\BulkUploadPlugin;
use OCA\DAV\Profiler\ProfilerPlugin;
use OCA\DAV\Provisioning\Apple\AppleProvisioningPlugin; use OCA\DAV\Provisioning\Apple\AppleProvisioningPlugin;
use OCA\DAV\SystemTag\SystemTagPlugin; use OCA\DAV\SystemTag\SystemTagPlugin;
use OCA\DAV\Upload\ChunkingPlugin; use OCA\DAV\Upload\ChunkingPlugin;
use OCP\AppFramework\Http\Response;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest; use OCP\IRequest;
use OCP\Profiler\IProfiler;
use OCP\SabrePluginEvent; use OCP\SabrePluginEvent;
use Psr\Log\LoggerInterface;
use Sabre\CardDAV\VCFExportPlugin; use Sabre\CardDAV\VCFExportPlugin;
use Sabre\DAV\Auth\Plugin; use Sabre\DAV\Auth\Plugin;
use Sabre\DAV\UUIDUtil; use Sabre\DAV\UUIDUtil;


$this->request = $request; $this->request = $request;
$this->baseUri = $baseUri; $this->baseUri = $baseUri;
$logger = \OC::$server->getLogger();
$logger = \OC::$server->get(LoggerInterface::class);
$dispatcher = \OC::$server->getEventDispatcher(); $dispatcher = \OC::$server->getEventDispatcher();
/** @var IEventDispatcher $newDispatcher */ /** @var IEventDispatcher $newDispatcher */
$newDispatcher = \OC::$server->query(IEventDispatcher::class); $newDispatcher = \OC::$server->query(IEventDispatcher::class);
// calendar plugins // calendar plugins
if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) {
$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
$this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger()));
$this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), $logger));
$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig())); $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
$this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
$this->server->addPlugin(new HasPhotoPlugin()); $this->server->addPlugin(new HasPhotoPlugin());
$this->server->addPlugin(new ImageExportPlugin(new PhotoCache( $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(
\OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getAppDataDir('dav-photocache'),
\OC::$server->getLogger())
$logger)
)); ));
} }


\OC::$server->getShareManager(), \OC::$server->getShareManager(),
$view $view
)); ));
$logger = \OC::$server->get(LoggerInterface::class);
$this->server->addPlugin( $this->server->addPlugin(
new BulkUploadPlugin($userFolder, $logger) new BulkUploadPlugin($userFolder, $logger)
); );

+ 3
- 3
apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php View File

use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use OCP\Share\IManager as ShareManager; use OCP\Share\IManager as ShareManager;
use Psr\Log\LoggerInterface;
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
use Sabre\DAV\Xml\Property\Href; use Sabre\DAV\Xml\Property\Href;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;


/** @var ISecureRandom */ /** @var ISecureRandom */
private $random; private $random;
/** @var ILogger */
/** @var LoggerInterface*/
private $logger; private $logger;


public const UNIT_TEST_USER = 'principals/users/caldav-unit-test'; public const UNIT_TEST_USER = 'principals/users/caldav-unit-test';


$db = \OC::$server->getDatabaseConnection(); $db = \OC::$server->getDatabaseConnection();
$this->random = \OC::$server->getSecureRandom(); $this->random = \OC::$server->getSecureRandom();
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->backend = new CalDavBackend( $this->backend = new CalDavBackend(
$db, $db,

+ 5
- 7
apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php View File

use OCP\IConfig; use OCP\IConfig;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;


/** @var ISecureRandom */ /** @var ISecureRandom */
private $random; private $random;
/** @var ILogger */
/** @var LoggerInterface */
private $logger; private $logger;


protected function setUp(): void { protected function setUp(): void {
$this->userManager = $this->createMock(IUserManager::class); $this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class); $this->groupManager = $this->createMock(IGroupManager::class);
$this->random = \OC::$server->getSecureRandom(); $this->random = \OC::$server->getSecureRandom();
$this->logger = $this->createMock(ILogger::class);
$this->psrLogger = $this->createMock(LoggerInterface::class);
$this->logger = $this->createMock(LoggerInterface::class);
$dispatcher = $this->createMock(IEventDispatcher::class); $dispatcher = $this->createMock(IEventDispatcher::class);
$legacyDispatcher = $this->createMock(EventDispatcherInterface::class); $legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
$config = $this->createMock(IConfig::class); $config = $this->createMock(IConfig::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);


$this->publicCalendarRoot = new PublicCalendarRoot($this->backend, $this->publicCalendarRoot = new PublicCalendarRoot($this->backend,
$this->l10n, $this->config, $this->psrLogger);
$this->l10n, $this->config, $this->logger);
} }


protected function tearDown(): void { protected function tearDown(): void {
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);


$calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->psrLogger);
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$publicUri = $calendar->setPublishStatus(true); $publicUri = $calendar->setPublishStatus(true);


$calendarInfo = $this->backend->getPublicCalendar($publicUri); $calendarInfo = $this->backend->getPublicCalendar($publicUri);
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->psrLogger);
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger);


return $calendar; return $calendar;
} }

+ 3
- 3
apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php View File

use OCA\DAV\CalDAV\Reminder\NotificationProvider\AbstractProvider; use OCA\DAV\CalDAV\Reminder\NotificationProvider\AbstractProvider;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory; use OCP\L10N\IFactory as L10NFactory;
use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCalendar;
use Test\TestCase; use Test\TestCase;


abstract class AbstractNotificationProviderTest extends TestCase { abstract class AbstractNotificationProviderTest extends TestCase {


/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger; protected $logger;


/** @var L10NFactory|\PHPUnit\Framework\MockObject\MockObject */ /** @var L10NFactory|\PHPUnit\Framework\MockObject\MockObject */
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();


$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->l10nFactory = $this->createMock(L10NFactory::class); $this->l10nFactory = $this->createMock(L10NFactory::class);
$this->l10n = $this->createMock(IL10N::class); $this->l10n = $this->createMock(IL10N::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class); $this->urlGenerator = $this->createMock(IURLGenerator::class);

+ 0
- 16
apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php View File

use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider; use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory; use OCP\L10N\IFactory as L10NFactory;
class EmailProviderTest extends AbstractNotificationProviderTest { class EmailProviderTest extends AbstractNotificationProviderTest {
public const USER_EMAIL = 'frodo@hobb.it'; public const USER_EMAIL = 'frodo@hobb.it';


/** @var ILogger|MockObject */
protected $logger;

/** @var L10NFactory|MockObject */
protected $l10nFactory;

/** @var IL10N|MockObject */
protected $l10n;

/** @var IURLGenerator|MockObject */
protected $urlGenerator;

/** @var IConfig|MockObject */
protected $config;

/** @var IMailer|MockObject */ /** @var IMailer|MockObject */
private $mailer; private $mailer;



+ 0
- 17
apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php View File

use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory; use OCP\L10N\IFactory as L10NFactory;


class PushProviderTest extends AbstractNotificationProviderTest { class PushProviderTest extends AbstractNotificationProviderTest {


/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;

/** @var L10NFactory|\PHPUnit\Framework\MockObject\MockObject */
protected $l10nFactory;

/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
protected $l10n;

/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
protected $urlGenerator;

/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
protected $config;

/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
private $manager; private $manager;


protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();


$this->config = $this->createMock(IConfig::class);
$this->manager = $this->createMock(IManager::class); $this->manager = $this->createMock(IManager::class);
$this->timeFactory = $this->createMock(ITimeFactory::class); $this->timeFactory = $this->createMock(ITimeFactory::class);



+ 3
- 3
apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php View File

use OCA\DAV\CalDAV\Proxy\Proxy; use OCA\DAV\CalDAV\Proxy\Proxy;
use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\PropPatch; use Sabre\DAV\PropPatch;
use Test\TestCase; use Test\TestCase;


/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
protected $groupManager; protected $groupManager;


/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger; protected $logger;


/** @var ProxyMapper|\PHPUnit\Framework\MockObject\MockObject */ /** @var ProxyMapper|\PHPUnit\Framework\MockObject\MockObject */


$this->userSession = $this->createMock(IUserSession::class); $this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(IGroupManager::class); $this->groupManager = $this->createMock(IGroupManager::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->proxyMapper = $this->createMock(ProxyMapper::class); $this->proxyMapper = $this->createMock(ProxyMapper::class);
} }



+ 3
- 3
apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php View File

use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Mail\IMessage; use OCP\Mail\IMessage;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\ITip\Message; use Sabre\VObject\ITip\Message;
use Test\TestCase; use Test\TestCase;
$this->emailAttachment = $this->createMock(IAttachment::class); $this->emailAttachment = $this->createMock(IAttachment::class);
$this->mailer->method('createAttachment')->willReturn($this->emailAttachment); $this->mailer->method('createAttachment')->willReturn($this->emailAttachment);


/** @var ILogger|MockObject $logger */
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
/** @var LoggerInterface|MockObject $logger */
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();


$this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock(); $this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
$this->timeFactory->method('getTime')->willReturn(1496912528); // 2017-01-01 $this->timeFactory->method('getTime')->willReturn(1496912528); // 2017-01-01

+ 16
- 15
apps/dav/tests/unit/CalDAV/WebcalCaching/RefreshWebcalServiceTest.php View File

use OCP\Http\Client\IResponse; use OCP\Http\Client\IResponse;
use OCP\Http\Client\LocalServerException; use OCP\Http\Client\LocalServerException;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\BadRequest;
use Sabre\VObject; use Sabre\VObject;
use Sabre\VObject\Recur\NoInstancesException; use Sabre\VObject\Recur\NoInstancesException;
/** @var IConfig | MockObject */ /** @var IConfig | MockObject */
private $config; private $config;


/** @var ILogger | MockObject */
/** @var LoggerInterface | MockObject */
private $logger; private $logger;


protected function setUp(): void { protected function setUp(): void {
$this->caldavBackend = $this->createMock(CalDavBackend::class); $this->caldavBackend = $this->createMock(CalDavBackend::class);
$this->clientService = $this->createMock(IClientService::class); $this->clientService = $this->createMock(IClientService::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
} }


/** /**


$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
} }
/** /**
* @param string $body * @param string $body
* @param string $contentType * @param string $contentType
$this->caldavBackend->expects($this->once()) $this->caldavBackend->expects($this->once())
->method('createCalendarObject') ->method('createCalendarObject')
->with(42, 'uri-1.ics', $result, 1); ->with(42, 'uri-1.ics', $result, 1);
$noInstanceException = new NoInstancesException("can't add calendar object"); $noInstanceException = new NoInstancesException("can't add calendar object");
$this->caldavBackend->expects($this->once()) $this->caldavBackend->expects($this->once())
->method("createCalendarObject") ->method("createCalendarObject")
->willThrowException($noInstanceException); ->willThrowException($noInstanceException);
$this->logger->expects($this->once()) $this->logger->expects($this->once())
->method('logException')
->with($noInstanceException);
->method('error')
->with($noInstanceException->getMessage(), ['exception' => $noInstanceException]);


$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
} }
$this->caldavBackend->expects($this->once()) $this->caldavBackend->expects($this->once())
->method('createCalendarObject') ->method('createCalendarObject')
->with(42, 'uri-1.ics', $result, 1); ->with(42, 'uri-1.ics', $result, 1);
$badRequestException = new BadRequest("can't add reach calendar url"); $badRequestException = new BadRequest("can't add reach calendar url");
$this->caldavBackend->expects($this->once()) $this->caldavBackend->expects($this->once())
->method("createCalendarObject") ->method("createCalendarObject")
->willThrowException($badRequestException); ->willThrowException($badRequestException);
$this->logger->expects($this->once()) $this->logger->expects($this->once())
->method('logException')
->with($badRequestException);
->method('error')
->with($badRequestException->getMessage(), ['exception' => $badRequestException]);


$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
} }
->with('dav', 'webcalAllowLocalAccess', 'no') ->with('dav', 'webcalAllowLocalAccess', 'no')
->willReturn('no'); ->willReturn('no');


$exception = new LocalServerException();
$client->expects($this->once()) $client->expects($this->once())
->method('get') ->method('get')
->willThrowException(new LocalServerException());
->willThrowException($exception);


$this->logger->expects($this->once()) $this->logger->expects($this->once())
->method('logException')
->with($this->isInstanceOf(LocalServerException::class), $this->anything());
->method('warning')
->with($this->anything(), ['exception' => $exception]);


$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
} }

+ 4
- 4
apps/dav/tests/unit/CardDAV/SyncServiceTest.php View File

use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\Converter; use OCA\DAV\CardDAV\Converter;
use OCA\DAV\CardDAV\SyncService; use OCA\DAV\CardDAV\SyncService;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VCard; use Sabre\VObject\Component\VCard;
use Test\TestCase; use Test\TestCase;




/** @var IUserManager $userManager */ /** @var IUserManager $userManager */
$userManager = $this->getMockBuilder(IUserManager::class)->disableOriginalConstructor()->getMock(); $userManager = $this->getMockBuilder(IUserManager::class)->disableOriginalConstructor()->getMock();
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
$converter = $this->createMock(Converter::class); $converter = $this->createMock(Converter::class);


$ss = new SyncService($backend, $userManager, $logger, $converter); $ss = new SyncService($backend, $userManager, $logger, $converter);
public function testUpdateAndDeleteUser($activated, $createCalls, $updateCalls, $deleteCalls) { public function testUpdateAndDeleteUser($activated, $createCalls, $updateCalls, $deleteCalls) {
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backend */ /** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backend */
$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock(); $backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();


$backend->expects($this->exactly($createCalls))->method('createCard'); $backend->expects($this->exactly($createCalls))->method('createCard');
$backend->expects($this->exactly($updateCalls))->method('updateCard'); $backend->expects($this->exactly($updateCalls))->method('updateCard');
*/ */
private function getSyncServiceMock($backend, $response) { private function getSyncServiceMock($backend, $response) {
$userManager = $this->getMockBuilder(IUserManager::class)->disableOriginalConstructor()->getMock(); $userManager = $this->getMockBuilder(IUserManager::class)->disableOriginalConstructor()->getMock();
$logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock();
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
$converter = $this->createMock(Converter::class); $converter = $this->createMock(Converter::class);
/** @var SyncService | \PHPUnit\Framework\MockObject\MockObject $ss */ /** @var SyncService | \PHPUnit\Framework\MockObject\MockObject $ss */
$ss = $this->getMockBuilder(SyncService::class) $ss = $this->getMockBuilder(SyncService::class)

+ 4
- 4
apps/dav/tests/unit/Comments/CommentsNodeTest.php View File

use OCP\Comments\IComment; use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManager;
use OCP\Comments\MessageTooLongException; use OCP\Comments\MessageTooLongException;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\PropPatch; use Sabre\DAV\PropPatch;


class CommentsNodeTest extends \Test\TestCase { class CommentsNodeTest extends \Test\TestCase {
$this->userSession = $this->getMockBuilder(IUserSession::class) $this->userSession = $this->getMockBuilder(IUserSession::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();


->method('save'); ->method('save');


$this->logger->expects($this->once()) $this->logger->expects($this->once())
->method('logException');
->method('error');


$this->node->updateComment($msg); $this->node->updateComment($msg);
} }
->method('save'); ->method('save');


$this->logger->expects($this->once()) $this->logger->expects($this->once())
->method('logException');
->method('error');


// imagine 'foo' has >1k characters. comment is mocked anyway. // imagine 'foo' has >1k characters. comment is mocked anyway.
$this->node->updateComment('foo'); $this->node->updateComment('foo');

+ 3
- 3
apps/dav/tests/unit/Comments/EntityCollectionTest.php View File

use OCA\DAV\Comments\EntityCollection; use OCA\DAV\Comments\EntityCollection;
use OCP\Comments\IComment; use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManager;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;


class EntityCollectionTest extends \Test\TestCase { class EntityCollectionTest extends \Test\TestCase {


protected $commentsManager; protected $commentsManager;
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
protected $userManager; protected $userManager;
/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger; protected $logger;
/** @var EntityCollection */ /** @var EntityCollection */
protected $collection; protected $collection;
$this->userSession = $this->getMockBuilder(IUserSession::class) $this->userSession = $this->getMockBuilder(IUserSession::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();



+ 3
- 3
apps/dav/tests/unit/Comments/EntityTypeCollectionTest.php View File



use OCA\DAV\Comments\EntityCollection as EntityCollectionImplemantation; use OCA\DAV\Comments\EntityCollection as EntityCollectionImplemantation;
use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManager;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use Psr\Log\LoggerInterface;


class EntityTypeCollectionTest extends \Test\TestCase { class EntityTypeCollectionTest extends \Test\TestCase {


protected $commentsManager; protected $commentsManager;
/** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject */ /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject */
protected $userManager; protected $userManager;
/** @var \OCP\ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger; protected $logger;
/** @var \OCA\DAV\Comments\EntityTypeCollection */ /** @var \OCA\DAV\Comments\EntityTypeCollection */
protected $collection; protected $collection;
$this->userSession = $this->getMockBuilder(IUserSession::class) $this->userSession = $this->getMockBuilder(IUserSession::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();



+ 1
- 2
apps/dav/tests/unit/Comments/RootCollectionTest.php View File

use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation; use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation;
use OCP\Comments\CommentsEntityEvent; use OCP\Comments\CommentsEntityEvent;
use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManager;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
$this->userManager, $this->userManager,
$this->userSession, $this->userSession,
$this->dispatcher, $this->dispatcher,
$this->createMock(ILogger::class)
$this->logger
); );
} }



+ 17
- 24
apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php View File

* @author Robin Appelman <robin@icewind.nl> * @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl> * @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu> * @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Côme Chilliet <come.chilliet@nextcloud.com>
* *
* @license AGPL-3.0 * @license AGPL-3.0
* *
use OC\Log; use OC\Log;
use OC\SystemConfig; use OC\SystemConfig;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath; use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin as PluginToTest;
use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\ServiceUnavailable; use Sabre\DAV\Exception\ServiceUnavailable;
use Sabre\DAV\Server; use Sabre\DAV\Server;
use Test\TestCase; use Test\TestCase;


class TestLogger extends Log {
public $message;
public $level;

public function writeLog(string $app, $entry, int $level) {
$this->level = $level;
$this->message = $entry;
}
}

class ExceptionLoggerPluginTest extends TestCase { class ExceptionLoggerPluginTest extends TestCase {


/** @var Server */ /** @var Server */
private $server; private $server;


/** @var PluginToTest */
/** @var ExceptionLoggerPlugin */
private $plugin; private $plugin;


/** @var TestLogger | \PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface | \PHPUnit\Framework\MockObject\MockObject */
private $logger; private $logger;


private function init() { private function init() {
}); });


$this->server = new Server(); $this->server = new Server();
$this->logger = new TestLogger(new Log\File(\OC::$SERVERROOT.'/data/nextcloud.log', '', $config), $config);
$this->plugin = new PluginToTest('unit-test', $this->logger);
$this->logger = $this->createMock(LoggerInterface::class);
$this->plugin = new ExceptionLoggerPlugin('unit-test', $this->logger);
$this->plugin->initialize($this->server); $this->plugin->initialize($this->server);
} }


/** /**
* @dataProvider providesExceptions * @dataProvider providesExceptions
*/ */
public function testLogging($expectedLogLevel, $expectedMessage, $exception) {
public function testLogging(string $expectedLogLevel, \Throwable $e) {
$this->init(); $this->init();
$this->plugin->logException($exception);


$this->assertEquals($expectedLogLevel, $this->logger->level);
$this->assertEquals(get_class($exception), $this->logger->message['Exception']);
$this->assertEquals($expectedMessage, $this->logger->message['Message']);
$this->logger->expects($this->once())
->method($expectedLogLevel)
->with($e->getMessage(), ['app' => 'unit-test','exception' => $e]);

$this->plugin->logException($e);
} }


public function providesExceptions() { public function providesExceptions() {
return [ return [
[0, '', new NotFound()],
[0, 'System in maintenance mode.', new ServiceUnavailable('System in maintenance mode.')],
[4, 'Upgrade needed', new ServiceUnavailable('Upgrade needed')],
[4, 'This path leads to nowhere', new InvalidPath('This path leads to nowhere')]
['debug', new NotFound()],
['debug', new ServiceUnavailable('System in maintenance mode.')],
['critical', new ServiceUnavailable('Upgrade needed')],
['critical', new InvalidPath('This path leads to nowhere')]
]; ];
} }
} }

+ 3
- 2
apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php View File

use OCA\DAV\Connector\Sabre\Server; use OCA\DAV\Connector\Sabre\Server;
use OCA\DAV\Connector\Sabre\ServerFactory; use OCA\DAV\Connector\Sabre\ServerFactory;
use OCP\IRequest; use OCP\IRequest;
use Psr\Log\LoggerInterface;
use Sabre\HTTP\Request; use Sabre\HTTP\Request;
use Test\TestCase; use Test\TestCase;
use Test\Traits\MountProviderTrait; use Test\Traits\MountProviderTrait;


$this->serverFactory = new ServerFactory( $this->serverFactory = new ServerFactory(
\OC::$server->getConfig(), \OC::$server->getConfig(),
\OC::$server->getLogger(),
\OC::$server->get(LoggerInterface::class),
\OC::$server->getDatabaseConnection(), \OC::$server->getDatabaseConnection(),
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getMountManager(), \OC::$server->getMountManager(),
$body = $this->getStream($body); $body = $this->getStream($body);
} }
$this->logout(); $this->logout();
$exceptionPlugin = new ExceptionPlugin('webdav', null);
$exceptionPlugin = new ExceptionPlugin('webdav', \OC::$server->get(LoggerInterface::class));
$server = $this->getSabreServer($view, $user, $password, $exceptionPlugin); $server = $this->getSabreServer($view, $user, $password, $exceptionPlugin);
$request = new Request($method, $url, $headers, $body); $request = new Request($method, $url, $headers, $body);



+ 3
- 3
apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php View File



use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\Migration\CalDAVRemoveEmptyValue; use OCA\DAV\Migration\CalDAVRemoveEmptyValue;
use OCP\ILogger;
use OCP\Migration\IOutput; use OCP\Migration\IOutput;
use Psr\Log\LoggerInterface;
use Sabre\VObject\InvalidDataException; use Sabre\VObject\InvalidDataException;
use Test\TestCase; use Test\TestCase;


*/ */
class CalDAVRemoveEmptyValueTest extends TestCase { class CalDAVRemoveEmptyValueTest extends TestCase {


/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $logger; private $logger;


/** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject */ /** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject */
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();


$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->backend = $this->createMock(CalDavBackend::class); $this->backend = $this->createMock(CalDavBackend::class);
$this->output = $this->createMock(IOutput::class); $this->output = $this->createMock(IOutput::class);
} }

Loading…
Cancel
Save