aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2021-10-14 11:57:28 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2021-10-14 14:48:45 +0200
commit1f76423500f2562892b87effc112947e162f8a28 (patch)
treed3a2f4201e98dd62f3ca135c4b6c4faee1fdee2b
parented533bd128807ae4e41efb590d59afe05c26668c (diff)
downloadnextcloud-server-1f76423500f2562892b87effc112947e162f8a28.tar.gz
nextcloud-server-1f76423500f2562892b87effc112947e162f8a28.zip
Send the subscription key to the appstore requests
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
-rw-r--r--lib/private/App/AppStore/Fetcher/AppFetcher.php5
-rw-r--r--lib/private/App/AppStore/Fetcher/CategoryFetcher.php8
-rw-r--r--lib/private/App/AppStore/Fetcher/Fetcher.php14
-rw-r--r--tests/lib/App/AppStore/Fetcher/AppFetcherTest.php9
-rw-r--r--tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php3
-rw-r--r--tests/lib/App/AppStore/Fetcher/FetcherBase.php4
6 files changed, 33 insertions, 10 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php
index 7fa0c0c9ac5..6c201978e1f 100644
--- a/lib/private/App/AppStore/Fetcher/AppFetcher.php
+++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php
@@ -44,7 +44,7 @@ class AppFetcher extends Fetcher {
private $compareVersion;
/** @var IRegistry */
- private $registry;
+ protected $registry;
/** @var bool */
private $ignoreMaxVersion;
@@ -61,7 +61,8 @@ class AppFetcher extends Fetcher {
$clientService,
$timeFactory,
$config,
- $logger
+ $logger,
+ $registry
);
$this->compareVersion = $compareVersion;
diff --git a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php
index 8fd8529b662..afe051e6281 100644
--- a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php
+++ b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php
@@ -30,6 +30,7 @@ use OC\Files\AppData\Factory;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
+use OCP\Support\Subscription\IRegistry;
use Psr\Log\LoggerInterface;
class CategoryFetcher extends Fetcher {
@@ -37,14 +38,17 @@ class CategoryFetcher extends Fetcher {
IClientService $clientService,
ITimeFactory $timeFactory,
IConfig $config,
- LoggerInterface $logger) {
+ LoggerInterface $logger,
+ IRegistry $registry) {
parent::__construct(
$appDataFactory,
$clientService,
$timeFactory,
$config,
- $logger
+ $logger,
+ $registry
);
+
$this->fileName = 'categories.json';
$this->endpointName = 'categories.json';
}
diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php
index a70fc20ba1e..c02d77dec46 100644
--- a/lib/private/App/AppStore/Fetcher/Fetcher.php
+++ b/lib/private/App/AppStore/Fetcher/Fetcher.php
@@ -38,6 +38,7 @@ use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
+use OCP\Support\Subscription\IRegistry;
use Psr\Log\LoggerInterface;
abstract class Fetcher {
@@ -54,6 +55,9 @@ abstract class Fetcher {
protected $config;
/** @var LoggerInterface */
protected $logger;
+ /** @var IRegistry */
+ protected $registry;
+
/** @var string */
protected $fileName;
/** @var string */
@@ -67,12 +71,14 @@ abstract class Fetcher {
IClientService $clientService,
ITimeFactory $timeFactory,
IConfig $config,
- LoggerInterface $logger) {
+ LoggerInterface $logger,
+ IRegistry $registry) {
$this->appData = $appDataFactory->get('appstore');
$this->clientService = $clientService;
$this->timeFactory = $timeFactory;
$this->config = $config;
$this->logger = $logger;
+ $this->registry = $registry;
}
/**
@@ -103,6 +109,12 @@ abstract class Fetcher {
];
}
+ // If we have a valid subscription key, send it to the appstore
+ $subscriptionKey = $this->config->getAppValue('support', 'subscription_key');
+ if ($this->registry->delegateHasValidSubscription() && $subscriptionKey) {
+ $options['headers']['X-NC-Subscription-Key'] = $subscriptionKey;
+ }
+
$client = $this->clientService->newClient();
try {
$response = $client->get($this->getEndpoint(), $options);
diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
index 44869d353a4..f8f00ef73b8 100644
--- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
+++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
@@ -51,7 +51,7 @@ class AppFetcherTest extends TestCase {
protected $compareVersion;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;
- /** @var IRegistry */
+ /** @var IRegistry|\PHPUnit\Framework\MockObject\MockObject */
protected $registry;
/** @var AppFetcher */
protected $fetcher;
@@ -2067,7 +2067,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg==
$this->assertEquals(self::$expectedResponse['data'], $this->fetcher->get());
}
- public function testGetWhitelist() {
+ public function testGetAppsAllowlist() {
$this->config->method('getSystemValue')
->willReturnCallback(function ($key, $default) {
if ($key === 'appstoreenabled') {
@@ -2082,7 +2082,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg==
return $default;
}
});
-
+
$file = $this->createMock(ISimpleFile::class);
$folder = $this->createMock(ISimpleFolder::class);
$folder
@@ -2107,6 +2107,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg==
->willReturn($client);
$response = $this->createMock(IResponse::class);
$client
+ ->expects($this->once())
->method('get')
->with('https://custom.appsstore.endpoint/api/v1/apps.json')
->willReturn($response);
@@ -2123,7 +2124,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg==
->willReturn(1234);
$this->registry
- ->expects($this->once())
+ ->expects($this->exactly(2))
->method('delegateHasValidSubscription')
->willReturn(true);
diff --git a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php
index 47be7adcc7b..b83e405db61 100644
--- a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php
+++ b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php
@@ -34,7 +34,8 @@ class CategoryFetcherTest extends FetcherBase {
$this->clientService,
$this->timeFactory,
$this->config,
- $this->logger
+ $this->logger,
+ $this->registry
);
}
diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php
index 735df939965..03ba4187268 100644
--- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php
+++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php
@@ -33,6 +33,7 @@ use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
+use OCP\Support\Subscription\IRegistry;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -49,6 +50,8 @@ abstract class FetcherBase extends TestCase {
protected $config;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;
+ /** @var IRegistry|\PHPUnit\Framework\MockObject\MockObject */
+ protected $registry;
/** @var Fetcher */
protected $fetcher;
/** @var string */
@@ -68,6 +71,7 @@ abstract class FetcherBase extends TestCase {
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
+ $this->registry = $this->createMock(IRegistry::class);
}
public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() {