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

[stable29] fix: Trusted server icon recovery without addressbook change #47428

Merged
merged 1 commit into from
Aug 23, 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
1 change: 1 addition & 0 deletions apps/federation/lib/BackgroundJob/GetSharedSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ protected function run($argument) {
// kill job after 30 days of trying
$deadline = $currentTime - $this->maxLifespan;
if ($created < $deadline) {
$this->logger->warning("The job to get the shared secret job is too old and gets stopped now without retention. Setting server status of '{$target}' to failure.");
$this->retainJob = false;
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
return;
Expand Down
1 change: 1 addition & 0 deletions apps/federation/lib/BackgroundJob/RequestSharedSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected function run($argument) {
// kill job after 30 days of trying
$deadline = $currentTime - $this->maxLifespan;
if ($created < $deadline) {
$this->logger->warning("The job to request the shared secret job is too old and gets stopped now without retention. Setting server status of '{$target}' to failure.");
$this->retainJob = false;
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
return;
Expand Down
4 changes: 4 additions & 0 deletions apps/federation/lib/SyncFederationAddressBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function syncThemAll(\Closure $callback) {
$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
} 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.
if ($this->dbHandler->getServerStatus($url) !== TrustedServers::STATUS_OK) {
$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK);
}
}
} catch (\Exception $ex) {
if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
Expand Down
31 changes: 31 additions & 0 deletions apps/federation/tests/SyncFederationAddressbooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,35 @@ public function testException() {
});
$this->assertEquals(2, count($this->callBacks));
}

public function testSuccessfulSyncWithoutChangesAfterFailure() {
/** @var DbHandler | MockObject $dbHandler */
$dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')
->disableOriginalConstructor()
->getMock();
$dbHandler->method('getAllServer')
->willReturn([
[
'url' => 'https://cloud.drop.box',
'url_hash' => 'sha1',
'shared_secret' => 'ilovenextcloud',
'sync_token' => '0'
]
]);
$dbHandler->method('getServerStatus')->willReturn(\OCA\Federation\TrustedServers::STATUS_FAILURE);
$dbHandler->expects($this->once())->method('setServerStatus')->
with('https://cloud.drop.box', 1);
$syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
->disableOriginalConstructor()
->getMock();
$syncService->expects($this->once())->method('syncRemoteAddressBook')
->willReturn('0');

/** @var \OCA\DAV\CardDAV\SyncService $syncService */
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger);
$s->syncThemAll(function ($url, $ex) {
$this->callBacks[] = [$url, $ex];
});
$this->assertEquals('1', count($this->callBacks));
}
}
Loading