Skip to content

Commit

Permalink
Merge pull request #48418 from nextcloud/config-carddav-sync-request-…
Browse files Browse the repository at this point in the history
…timeout

feat: configurable request timeout for carddav sync
  • Loading branch information
ChristophWurst authored Oct 18, 2024
2 parents e65f310 + 742764b commit 0c67541
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
10 changes: 8 additions & 2 deletions apps/dav/lib/CardDAV/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

use OCP\AppFramework\Db\TTransactional;
use OCP\AppFramework\Http;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -33,20 +35,23 @@ class SyncService {
private Converter $converter;
protected string $certPath;
private IClientService $clientService;
private IConfig $config;

public function __construct(CardDavBackend $backend,
IUserManager $userManager,
IDBConnection $dbConnection,
LoggerInterface $logger,
Converter $converter,
IClientService $clientService) {
IClientService $clientService,
IConfig $config) {
$this->backend = $backend;
$this->userManager = $userManager;
$this->logger = $logger;
$this->converter = $converter;
$this->certPath = '';
$this->dbConnection = $dbConnection;
$this->clientService = $clientService;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -150,7 +155,8 @@ protected function requestSyncReport(string $url, string $userName, string $addr
$options = [
'auth' => [$userName, $sharedSecret],
'body' => $this->buildSyncCollectionRequestBody($syncToken),
'headers' => ['Content-Type' => 'application/xml']
'headers' => ['Content-Type' => 'application/xml'],
'timeout' => $this->config->getSystemValueInt('carddav_sync_request_timeout', IClient::DEFAULT_REQUEST_TIMEOUT)
];

$response = $client->request(
Expand Down
12 changes: 9 additions & 3 deletions apps/dav/tests/unit/CardDAV/SyncServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCA\DAV\CardDAV\SyncService;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -33,6 +34,7 @@ class SyncServiceTest extends TestCase {
protected LoggerInterface $logger;
protected Converter $converter;
protected IClient $client;
protected IConfig $config;
protected SyncService $service;
public function setUp(): void {
$addressBook = [
Expand All @@ -53,6 +55,7 @@ public function setUp(): void {
$this->logger = new NullLogger();
$this->converter = $this->createMock(Converter::class);
$this->client = $this->createMock(IClient::class);
$this->config = $this->createMock(IConfig::class);

$clientService = $this->createMock(IClientService::class);
$clientService->method('newClient')
Expand All @@ -64,7 +67,8 @@ public function setUp(): void {
$this->dbConnection,
$this->logger,
$this->converter,
$clientService
$clientService,
$this->config
);
}

Expand Down Expand Up @@ -305,8 +309,9 @@ public function testEnsureSystemAddressBookExists(): void {
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
$converter = $this->createMock(Converter::class);
$clientService = $this->createMock(IClientService::class);
$config = $this->createMock(IConfig::class);

$ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService);
$ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService, $config);
$ss->ensureSystemAddressBookExists('principals/users/adam', 'contacts', []);
}

Expand Down Expand Up @@ -360,8 +365,9 @@ public function testUpdateAndDeleteUser($activated, $createCalls, $updateCalls,
->willReturn($this->createMock(VCard::class));

$clientService = $this->createMock(IClientService::class);
$config = $this->createMock(IConfig::class);

$ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService);
$ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService, $config);
$ss->updateUser($user);

$ss->updateUser($user);
Expand Down
7 changes: 7 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@
*/
'davstorage.request_timeout' => 30,

/**
* The timeout in seconds for synchronizing address books, e.g. federated system address books (as run by `occ federation:sync-addressbooks`).
*
* Defaults to ``30`` seconds
*/
'carddav_sync_request_timeout' => 30,

/**
* `true` enabled a relaxed session timeout, where the session timeout would no longer be
* handled by Nextcloud but by either the PHP garbage collection or the expiration of
Expand Down

0 comments on commit 0c67541

Please sign in to comment.