Skip to content

Commit

Permalink
fix: Fetch custom app store url without internet connection
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl authored and backportbot[bot] committed Mar 4, 2024
1 parent b6edd43 commit 0b1fcf0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/private/App/AppStore/Fetcher/Fetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,7 +110,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) {
Expand Down Expand Up @@ -153,8 +154,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 [];
}

Expand Down
5 changes: 5 additions & 0 deletions tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
9 changes: 6 additions & 3 deletions tests/lib/App/AppStore/Fetcher/FetcherBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 0b1fcf0

Please sign in to comment.