Skip to content

Commit

Permalink
Merge pull request #29235 from nextcloud/feat/appstore/enterprise
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Oct 15, 2021
2 parents 8df577b + 1f76423 commit b6a3ba1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
5 changes: 3 additions & 2 deletions lib/private/App/AppStore/Fetcher/AppFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AppFetcher extends Fetcher {
private $compareVersion;

/** @var IRegistry */
private $registry;
protected $registry;

/** @var bool */
private $ignoreMaxVersion;
Expand All @@ -61,7 +61,8 @@ public function __construct(Factory $appDataFactory,
$clientService,
$timeFactory,
$config,
$logger
$logger,
$registry
);

$this->compareVersion = $compareVersion;
Expand Down
8 changes: 6 additions & 2 deletions lib/private/App/AppStore/Fetcher/CategoryFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,25 @@
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 {
public function __construct(Factory $appDataFactory,
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';
}
Expand Down
14 changes: 13 additions & 1 deletion lib/private/App/AppStore/Fetcher/Fetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCP\Files\NotFoundException;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\Support\Subscription\IRegistry;
use Psr\Log\LoggerInterface;

abstract class Fetcher {
Expand All @@ -54,6 +55,9 @@ abstract class Fetcher {
protected $config;
/** @var LoggerInterface */
protected $logger;
/** @var IRegistry */
protected $registry;

/** @var string */
protected $fileName;
/** @var string */
Expand All @@ -67,12 +71,14 @@ public function __construct(Factory $appDataFactory,
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;
}

/**
Expand Down Expand Up @@ -103,6 +109,12 @@ protected function fetch($ETag, $content) {
];
}

// 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);
Expand Down
9 changes: 5 additions & 4 deletions tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2067,7 +2067,7 @@ public function testSetVersion() {
$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') {
Expand All @@ -2082,7 +2082,7 @@ public function testGetWhitelist() {
return $default;
}
});

$file = $this->createMock(ISimpleFile::class);
$folder = $this->createMock(ISimpleFolder::class);
$folder
Expand All @@ -2107,6 +2107,7 @@ public function testGetWhitelist() {
->willReturn($client);
$response = $this->createMock(IResponse::class);
$client
->expects($this->once())
->method('get')
->with('https://custom.appsstore.endpoint/api/v1/apps.json')
->willReturn($response);
Expand All @@ -2123,7 +2124,7 @@ public function testGetWhitelist() {
->willReturn(1234);

$this->registry
->expects($this->once())
->expects($this->exactly(2))
->method('delegateHasValidSubscription')
->willReturn(true);

Expand Down
3 changes: 2 additions & 1 deletion tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ protected function setUp(): void {
$this->clientService,
$this->timeFactory,
$this->config,
$this->logger
$this->logger,
$this->registry
);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/lib/App/AppStore/Fetcher/FetcherBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;

Expand All @@ -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 */
Expand All @@ -68,6 +71,7 @@ protected function setUp(): void {
$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() {
Expand Down

0 comments on commit b6a3ba1

Please sign in to comment.