diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index 7aec5f3251efd..3cd2940d0bcef 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -151,8 +151,8 @@ public function get($allowUnstable = false): array { if (is_array($jsonBlob)) { // No caching when the version has been updated if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { - // If the timestamp is older than 3600 seconds request the files new - $invalidateAfterSeconds = self::INVALIDATE_AFTER_SECONDS; + // If the timestamp is old, request the files new + $invalidateAfterSeconds = static::INVALIDATE_AFTER_SECONDS; if ($allowUnstable) { $invalidateAfterSeconds = self::INVALIDATE_AFTER_SECONDS_UNSTABLE; diff --git a/tests/lib/App/AppStore/Fetcher/AppDiscoverFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppDiscoverFetcherTest.php index 49314d5128357..ba3ade56d5864 100644 --- a/tests/lib/App/AppStore/Fetcher/AppDiscoverFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppDiscoverFetcherTest.php @@ -38,6 +38,26 @@ protected function setUp(): void { ); } + public function testGetUsesTwoHourOldDiscoverCache(): void { + $this->config->method('getSystemValueBool')->willReturnArgument(1); + $this->config->method('getSystemValueString')->willReturnArgument(1); + $this->fetcher->setVersion('11.0.0.2'); + + $folder = $this->createMock(ISimpleFolder::class); + $file = $this->createMock(ISimpleFile::class); + $this->appData->expects($this->once())->method('getFolder')->with('/')->willReturn($folder); + $folder->expects($this->once())->method('getFile')->with('discover.json')->willReturn($file); + $file->expects($this->once()) + ->method('getContent') + ->willReturn('{"timestamp":1200,"data":[{"id":"MyApp"}],"ncversion":"11.0.0.2"}'); + + $this->timeFactory->method('getTime')->willReturn(1200 + 2 * 3600); + $this->clientService->expects($this->never())->method('newClient'); + $file->expects($this->never())->method('putContent'); + + $this->assertSame([['id' => 'MyApp']], $this->fetcher->get()); + } + public function testAppstoreDisabled(): void { $this->config ->method('getSystemValueBool') diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 3a0d30a32653a..c1ec2b7316404 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -195,7 +195,7 @@ public function testGetWithAlreadyExistingFileAndOutdatedTimestamp(): void { ->method('getFile') ->with($this->fileName) ->willReturn($file); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":90002,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; $file ->expects($this->once()) ->method('putContent') @@ -211,8 +211,8 @@ public function testGetWithAlreadyExistingFileAndOutdatedTimestamp(): void { ->expects($this->exactly(2)) ->method('getTime') ->willReturnOnConsecutiveCalls( - 4801, - 1502 + 90001, + 90002, ); $client = $this->createMock(IClient::class); $this->clientService @@ -458,7 +458,7 @@ public function testGetMatchingETag(): void { ->willReturn($file); $origData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; - $newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; + $newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":90002,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; $file ->expects($this->once()) ->method('putContent') @@ -474,8 +474,8 @@ public function testGetMatchingETag(): void { ->expects($this->exactly(2)) ->method('getTime') ->willReturnOnConsecutiveCalls( - 4801, - 4802 + 90001, + 90002, ); $client = $this->createMock(IClient::class); $this->clientService @@ -541,7 +541,7 @@ public function testGetNoMatchingETag(): void { ->method('getFile') ->with($this->fileName) ->willReturn($file); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}'; + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":90002,"ncversion":"11.0.0.2","ETag":"\"newETag\""}'; $file ->expects($this->once()) ->method('putContent') @@ -557,8 +557,8 @@ public function testGetNoMatchingETag(): void { ->expects($this->exactly(2)) ->method('getTime') ->willReturnOnConsecutiveCalls( - 4801, - 4802, + 90001, + 90002, ); $client = $this->createMock(IClient::class); $this->clientService