Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configurable request timeout for carddav sync #48418

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading