aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federation')
-rw-r--r--apps/federation/lib/SyncFederationAddressBooks.php23
-rw-r--r--apps/federation/lib/TrustedServers.php9
-rw-r--r--apps/federation/tests/SyncFederationAddressbooksTest.php4
-rw-r--r--apps/federation/tests/TrustedServersTest.php58
4 files changed, 84 insertions, 10 deletions
diff --git a/apps/federation/lib/SyncFederationAddressBooks.php b/apps/federation/lib/SyncFederationAddressBooks.php
index 05144b40879..d11f92b76ef 100644
--- a/apps/federation/lib/SyncFederationAddressBooks.php
+++ b/apps/federation/lib/SyncFederationAddressBooks.php
@@ -34,7 +34,7 @@ class SyncFederationAddressBooks {
$url = $trustedServer['url'];
$callback($url, null);
$sharedSecret = $trustedServer['shared_secret'];
- $syncToken = $trustedServer['sync_token'];
+ $oldSyncToken = $trustedServer['sync_token'];
$endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
$cardDavUser = $endPoints['carddav-user'] ?? 'system';
@@ -49,10 +49,25 @@ class SyncFederationAddressBooks {
$targetBookProperties = [
'{DAV:}displayname' => $url
];
+
try {
- $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
- if ($newToken !== $syncToken) {
- $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
+ $syncToken = $oldSyncToken;
+
+ do {
+ [$syncToken, $truncated] = $this->syncService->syncRemoteAddressBook(
+ $url,
+ $cardDavUser,
+ $addressBookUrl,
+ $sharedSecret,
+ $syncToken,
+ $targetBookId,
+ $targetPrincipal,
+ $targetBookProperties
+ );
+ } while ($truncated);
+
+ if ($syncToken !== $oldSyncToken) {
+ $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $syncToken);
} else {
$this->logger->debug("Sync Token for $url unchanged from previous sync");
// The server status might have been changed to a failure status in previous runs.
diff --git a/apps/federation/lib/TrustedServers.php b/apps/federation/lib/TrustedServers.php
index 3b849c80f17..3d15cfac448 100644
--- a/apps/federation/lib/TrustedServers.php
+++ b/apps/federation/lib/TrustedServers.php
@@ -116,12 +116,13 @@ class TrustedServers {
$this->trustedServersCache = $this->dbHandler->getAllServer();
}
- $server = array_filter($this->trustedServersCache, fn ($server) => $server['id'] === $id);
- if (empty($server)) {
- throw new \Exception('No server found with ID: ' . $id);
+ foreach ($this->trustedServersCache as $server) {
+ if ($server['id'] === $id) {
+ return $server;
+ }
}
- return $server[0];
+ throw new \Exception('No server found with ID: ' . $id);
}
/**
diff --git a/apps/federation/tests/SyncFederationAddressbooksTest.php b/apps/federation/tests/SyncFederationAddressbooksTest.php
index 8b075204859..ff03f5cf442 100644
--- a/apps/federation/tests/SyncFederationAddressbooksTest.php
+++ b/apps/federation/tests/SyncFederationAddressbooksTest.php
@@ -45,7 +45,7 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
->with('https://cloud.example.org', 1, '1');
$syncService = $this->createMock(SyncService::class);
$syncService->expects($this->once())->method('syncRemoteAddressBook')
- ->willReturn('1');
+ ->willReturn(['1', false]);
/** @var SyncService $syncService */
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger);
@@ -96,7 +96,7 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
->with('https://cloud.example.org', 1);
$syncService = $this->createMock(SyncService::class);
$syncService->expects($this->once())->method('syncRemoteAddressBook')
- ->willReturn('0');
+ ->willReturn(['0', false]);
/** @var SyncService $syncService */
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger);
diff --git a/apps/federation/tests/TrustedServersTest.php b/apps/federation/tests/TrustedServersTest.php
index c8477f637cb..0c900f6edf7 100644
--- a/apps/federation/tests/TrustedServersTest.php
+++ b/apps/federation/tests/TrustedServersTest.php
@@ -144,6 +144,64 @@ class TrustedServersTest extends TestCase {
);
}
+ public static function dataTestGetServer() {
+ return [
+ [
+ 15,
+ [
+ 'id' => 15,
+ 'otherData' => 'first server',
+ ]
+ ],
+ [
+ 16,
+ [
+ 'id' => 16,
+ 'otherData' => 'second server',
+ ]
+ ],
+ [
+ 42,
+ [
+ 'id' => 42,
+ 'otherData' => 'last server',
+ ]
+ ],
+ [
+ 108,
+ null
+ ],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetServer')]
+ public function testGetServer(int $id, ?array $expectedServer): void {
+ $servers = [
+ [
+ 'id' => 15,
+ 'otherData' => 'first server',
+ ],
+ [
+ 'id' => 16,
+ 'otherData' => 'second server',
+ ],
+ [
+ 'id' => 42,
+ 'otherData' => 'last server',
+ ],
+ ];
+ $this->dbHandler->expects($this->once())->method('getAllServer')->willReturn($servers);
+
+ if ($expectedServer === null) {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('No server found with ID: ' . $id);
+ }
+
+ $this->assertEquals(
+ $expectedServer,
+ $this->trustedServers->getServer($id)
+ );
+ }
public function testIsTrustedServer(): void {
$this->dbHandler->expects($this->once())