From f0bef8881dd9861c615f56da058a165c2cc5ce86 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 17 Dec 2019 12:20:51 +0100 Subject: [PATCH] Restore old behavior allowing to set custom appstore Signed-off-by: Georg Ehrke --- lib/private/App/AppStore/Fetcher/AppFetcher.php | 5 ----- .../App/AppStore/Fetcher/CategoryFetcher.php | 1 - lib/private/App/AppStore/Fetcher/Fetcher.php | 8 +++++--- tests/lib/App/AppStore/Fetcher/AppFetcherTest.php | 4 +++- tests/lib/App/AppStore/Fetcher/FetcherBase.php | 15 +++++++++++++++ 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 49faa64bb5003..d97949421d834 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -68,7 +68,6 @@ public function __construct(Factory $appDataFactory, ); $this->fileName = 'apps.json'; - $this->setEndpoint(); $this->compareVersion = $compareVersion; $this->ignoreMaxVersion = true; } @@ -143,10 +142,6 @@ protected function fetch($ETag, $content) { return $response; } - private function setEndpoint() { - $this->endpointUrl = 'https://apps.nextcloud.com/api/v1/apps.json'; - } - /** * @param string $version * @param string $fileName diff --git a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php index 7fa0800762a3b..904c401c15377 100644 --- a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php +++ b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php @@ -53,6 +53,5 @@ public function __construct(Factory $appDataFactory, $logger ); $this->fileName = 'categories.json'; - $this->endpointUrl = 'https://apps.nextcloud.com/api/v1/categories.json'; } } diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index bcfea94959c6d..76a37bfa7de64 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -55,8 +55,6 @@ abstract class Fetcher { /** @var string */ protected $fileName; /** @var string */ - protected $endpointUrl; - /** @var string */ protected $version; /** @var string */ protected $channel; @@ -106,7 +104,7 @@ protected function fetch($ETag, $content) { } $client = $this->clientService->newClient(); - $response = $client->get($this->endpointUrl, $options); + $response = $client->get($this->getEndpoint(), $options); $responseJson = []; if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) { @@ -219,4 +217,8 @@ protected function getChannel() { public function setChannel(string $channel) { $this->channel = $channel; } + + protected function getEndpoint(): string { + return $this->config->getSystemValue('appstoreurl', 'https://apps.nextcloud.com/api/v1') . '/' . $this->fileName; + } } diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php index 9a11823404918..ac9ac06d19de9 100644 --- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -92,6 +92,8 @@ public function testGetWithFilter() { return true; } else if ($key === 'version') { return '11.0.0.2'; + } else if ($key === 'appstoreurl' && $default === 'https://apps.nextcloud.com/api/v1') { + return 'https://custom.appsstore.endpoint/api/v1'; } else { return $default; } @@ -122,7 +124,7 @@ public function testGetWithFilter() { $response = $this->createMock(IResponse::class); $client ->method('get') - ->with('https://apps.nextcloud.com/api/v1/apps.json') + ->with('https://custom.appsstore.endpoint/api/v1/apps.json') ->willReturn($response); $response ->expects($this->once()) diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 84584e5432fbd..9dac4dd749928 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -137,6 +137,11 @@ public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion() { $this->config ->expects($this->at(3)) ->method('getSystemValue') + ->with('appstoreurl', 'https://apps.nextcloud.com/api/v1') + ->willReturn('https://apps.nextcloud.com/api/v1'); + $this->config + ->expects($this->at(4)) + ->method('getSystemValue') ->with( $this->equalTo('version'), $this->anything() @@ -298,6 +303,11 @@ public function testGetWithAlreadyExistingFileAndNoVersion() { $this->config ->expects($this->at(3)) ->method('getSystemValue') + ->with('appstoreurl', 'https://apps.nextcloud.com/api/v1') + ->willReturn('https://apps.nextcloud.com/api/v1'); + $this->config + ->expects($this->at(4)) + ->method('getSystemValue') ->with( $this->equalTo('version'), $this->anything() @@ -382,6 +392,11 @@ public function testGetWithAlreadyExistingFileAndOutdatedVersion() { $this->config ->expects($this->at(3)) ->method('getSystemValue') + ->with('appstoreurl', 'https://apps.nextcloud.com/api/v1') + ->willReturn('https://apps.nextcloud.com/api/v1'); + $this->config + ->expects($this->at(4)) + ->method('getSystemValue') ->with( $this->equalTo('version'), $this->anything()