From e13fb468cf45d6713c26109f1121ed5e2a0bbb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 4 Mar 2024 09:44:19 +0100 Subject: [PATCH] fix: Fetch custom app store url without internet connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/App/AppStore/Fetcher/Fetcher.php | 6 ++++-- tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php | 5 +++++ tests/lib/App/AppStore/Fetcher/FetcherBase.php | 9 ++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index 3fc5fd07573ba..a905be2ca7666 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -44,6 +44,7 @@ abstract class Fetcher { public const INVALIDATE_AFTER_SECONDS = 3600; public const RETRY_AFTER_FAILURE_SECONDS = 300; + public const APP_STORE_URL = 'https://apps.nextcloud.com/api/v1'; /** @var IAppData */ protected $appData; @@ -96,7 +97,7 @@ protected function fetch($ETag, $content) { ]; } - if ($this->config->getSystemValueString('appstoreurl', 'https://apps.nextcloud.com/api/v1') === 'https://apps.nextcloud.com/api/v1') { + if ($this->config->getSystemValueString('appstoreurl', self::APP_STORE_URL) === self::APP_STORE_URL) { // If we have a valid subscription key, send it to the appstore $subscriptionKey = $this->config->getAppValue('support', 'subscription_key'); if ($this->registry->delegateHasValidSubscription() && $subscriptionKey) { @@ -140,8 +141,9 @@ protected function fetch($ETag, $content) { public function get($allowUnstable = false) { $appstoreenabled = $this->config->getSystemValueBool('appstoreenabled', true); $internetavailable = $this->config->getSystemValueBool('has_internet_connection', true); + $isDefaultAppStore = $this->config->getSystemValueString('appstoreurl', self::APP_STORE_URL) === self::APP_STORE_URL; - if (!$appstoreenabled || !$internetavailable) { + if (!$appstoreenabled || (!$internetavailable && $isDefaultAppStore)) { return []; } diff --git a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php index 874a58fc6bab9..dbfca97f99935 100644 --- a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php @@ -64,6 +64,11 @@ public function testNoInternet() { } return $default; }); + $this->config + ->method('getSystemValueString') + ->willReturnCallback(function ($var, $default) { + return $default; + }); $this->appData ->expects($this->never()) ->method('getFolder'); diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index dbc3f2a687cd3..7645cbef59939 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -76,10 +76,13 @@ protected function setUp(): void { public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() { $this->config - ->expects($this->exactly(1)) ->method('getSystemValueString') - ->with($this->equalTo('version'), $this->anything()) - ->willReturn('11.0.0.2'); + ->willReturnCallback(function ($var, $default) { + if ($var === 'version') { + return '11.0.0.2'; + } + return $default; + }); $this->config->method('getSystemValueBool') ->willReturnArgument(1);