diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2024-03-08 08:14:05 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2024-03-21 18:37:21 +0100 |
commit | 3dea99f42b4a8956f0cbe6a726e30afedace39a4 (patch) | |
tree | 4e2089efd219e48d2666e865b2fb129d45e0ea92 /apps/dav/tests/unit | |
parent | a7dfec070a1dda79ade7cfea91b3dc7e74d184a6 (diff) | |
download | nextcloud-server-3dea99f42b4a8956f0cbe6a726e30afedace39a4.tar.gz nextcloud-server-3dea99f42b4a8956f0cbe6a726e30afedace39a4.zip |
fix(dav): Add retention time to sync token cleanup
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav/tests/unit')
3 files changed, 38 insertions, 14 deletions
diff --git a/apps/dav/tests/unit/BackgroundJob/PruneOutdatedSyncTokensJobTest.php b/apps/dav/tests/unit/BackgroundJob/PruneOutdatedSyncTokensJobTest.php index be6298b3372..20169072687 100644 --- a/apps/dav/tests/unit/BackgroundJob/PruneOutdatedSyncTokensJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/PruneOutdatedSyncTokensJobTest.php @@ -29,6 +29,7 @@ declare(strict_types=1); */ namespace OCA\DAV\Tests\unit\BackgroundJob; +use InvalidArgumentException; use OCA\DAV\AppInfo\Application; use OCA\DAV\BackgroundJob\PruneOutdatedSyncTokensJob; use OCA\DAV\CalDAV\CalDavBackend; @@ -72,18 +73,27 @@ class PruneOutdatedSyncTokensJobTest extends TestCase { /** * @dataProvider dataForTestRun */ - public function testRun(string $configValue, int $actualLimit, int $deletedCalendarSyncTokens, int $deletedAddressBookSyncTokens): void { - $this->config->expects($this->once()) + public function testRun(string $configToKeep, string $configRetentionDays, int $actualLimit, int $retentionDays, int $deletedCalendarSyncTokens, int $deletedAddressBookSyncTokens): void { + $this->config->expects($this->exactly(2)) ->method('getAppValue') - ->with(Application::APP_ID, 'totalNumberOfSyncTokensToKeep', '10000') - ->willReturn($configValue); + ->with(Application::APP_ID, self::anything(), self::anything()) + ->willReturnCallback(function ($app, $key) use ($configToKeep, $configRetentionDays) { + switch ($key) { + case 'totalNumberOfSyncTokensToKeep': + return $configToKeep; + case 'syncTokensRetentionDays': + return $configRetentionDays; + default: + throw new InvalidArgumentException(); + } + }); $this->calDavBackend->expects($this->once()) ->method('pruneOutdatedSyncTokens') ->with($actualLimit) ->willReturn($deletedCalendarSyncTokens); $this->cardDavBackend->expects($this->once()) ->method('pruneOutdatedSyncTokens') - ->with($actualLimit) + ->with($actualLimit, $retentionDays) ->willReturn($deletedAddressBookSyncTokens); $this->logger->expects($this->once()) ->method('info') @@ -97,8 +107,9 @@ class PruneOutdatedSyncTokensJobTest extends TestCase { public function dataForTestRun(): array { return [ - ['100', 100, 2, 3], - ['0', 1, 0, 0] + ['100', '2', 100, 7 * 24 * 3600, 2, 3], + ['100', '14', 100, 14 * 24 * 3600, 2, 3], + ['0', '60', 1, 60 * 24 * 3600, 0, 0] ]; } } diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index c85c13e3f21..ef4cfb2aaab 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -46,6 +46,7 @@ use Sabre\DAV\Exception\NotFound; use Sabre\DAV\PropPatch; use Sabre\DAV\Xml\Property\Href; use Sabre\DAVACL\IACL; +use function time; /** * Class CalDavBackendTest @@ -1357,7 +1358,12 @@ END:VEVENT END:VCALENDAR EOD; $this->backend->updateCalendarObject($calendarId, $uri, $calData); - $deleted = $this->backend->pruneOutdatedSyncTokens(0); + + // Keep everything + $deleted = $this->backend->pruneOutdatedSyncTokens(0, 0); + self::assertSame(0, $deleted); + + $deleted = $this->backend->pruneOutdatedSyncTokens(0, time()); // At least one from the object creation and one from the object update $this->assertGreaterThanOrEqual(2, $deleted); $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 1); @@ -1423,7 +1429,7 @@ EOD; $this->assertEmpty($changes['deleted']); // Delete all but last change - $deleted = $this->backend->pruneOutdatedSyncTokens(1); + $deleted = $this->backend->pruneOutdatedSyncTokens(1, time()); $this->assertEquals(1, $deleted); // We had two changes before, now one // Only update should remain @@ -1433,7 +1439,8 @@ EOD; $this->assertEmpty($changes['deleted']); // Check that no crash occurs when prune is called without current changes - $deleted = $this->backend->pruneOutdatedSyncTokens(1); + $deleted = $this->backend->pruneOutdatedSyncTokens(1, time()); + self::assertSame(0, $deleted); } public function testSearchAndExpandRecurrences() { diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php index ea80187f554..942718f7ce5 100644 --- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php +++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php @@ -60,6 +60,7 @@ use Sabre\DAV\PropPatch; use Sabre\VObject\Component\VCard; use Sabre\VObject\Property\Text; use Test\TestCase; +use function time; /** * Class CardDavBackendTest @@ -880,7 +881,12 @@ class CardDavBackendTest extends TestCase { $uri = $this->getUniqueID('card'); $this->backend->createCard($addressBookId, $uri, $this->vcardTest0); $this->backend->updateCard($addressBookId, $uri, $this->vcardTest1); - $deleted = $this->backend->pruneOutdatedSyncTokens(0); + + // Do not delete anything if week data as old as ts=0 + $deleted = $this->backend->pruneOutdatedSyncTokens(0, 0); + self::assertSame(0, $deleted); + + $deleted = $this->backend->pruneOutdatedSyncTokens(0, time()); // At least one from the object creation and one from the object update $this->assertGreaterThanOrEqual(2, $deleted); $changes = $this->backend->getChangesForAddressBook($addressBookId, $syncToken, 1); @@ -912,7 +918,7 @@ class CardDavBackendTest extends TestCase { $this->assertEmpty($changes['deleted']); // Delete all but last change - $deleted = $this->backend->pruneOutdatedSyncTokens(1); + $deleted = $this->backend->pruneOutdatedSyncTokens(1, time()); $this->assertEquals(1, $deleted); // We had two changes before, now one // Only update should remain @@ -920,8 +926,8 @@ class CardDavBackendTest extends TestCase { $this->assertEmpty($changes['added']); $this->assertEquals(1, count($changes['modified'])); $this->assertEmpty($changes['deleted']); - + // Check that no crash occurs when prune is called without current changes - $deleted = $this->backend->pruneOutdatedSyncTokens(1); + $deleted = $this->backend->pruneOutdatedSyncTokens(1, time()); } } |