summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-01-15 15:39:45 +0100
committerJoas Schilling <coding@schilljs.com>2024-01-16 11:58:05 +0100
commit5d8dfe81fd1d851ecec103d8b85194fe03ab56b3 (patch)
tree2c0e91d0ec3801692e2a7a10a81864cef4e6519e /tests/lib
parent4209f3d208afd0e0eefcee403c934c8211182274 (diff)
downloadnextcloud-server-5d8dfe81fd1d851ecec103d8b85194fe03ab56b3.tar.gz
nextcloud-server-5d8dfe81fd1d851ecec103d8b85194fe03ab56b3.zip
fix(appstore): Only send subscription keys to valid appstores
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/App/AppStore/Fetcher/AppFetcherTest.php105
1 files changed, 101 insertions, 4 deletions
diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
index a2d56838b07..c7fb0244dda 100644
--- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
+++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
@@ -2088,14 +2088,109 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg==
->willReturnCallback(function ($key, $default) {
if ($key === 'version') {
return '11.0.0.2';
- } elseif ($key === 'appstoreurl' && $default === 'https://apps.nextcloud.com/api/v1') {
- return 'https://custom.appsstore.endpoint/api/v1';
+ }
+ if ($key === 'appsallowlist') {
+ return ['contacts'];
+ }
+ return $default;
+ });
+ $this->config->method('getSystemValueString')
+ ->willReturnCallback(function ($key, $default) {
+ return $default;
+ });
+ $this->config->method('getAppValue')
+ ->willReturnCallback(function ($app, $key, $default) {
+ if ($app === 'support' && $key === 'subscription_key') {
+ return 'subscription-key';
+ }
+ return $default;
+ });
+ $this->config
+ ->method('getSystemValueBool')
+ ->willReturnArgument(1);
+
+ $file = $this->createMock(ISimpleFile::class);
+ $folder = $this->createMock(ISimpleFolder::class);
+ $folder
+ ->expects($this->once())
+ ->method('getFile')
+ ->with('apps.json')
+ ->willThrowException(new NotFoundException());
+ $folder
+ ->expects($this->once())
+ ->method('newFile')
+ ->with('apps.json')
+ ->willReturn($file);
+ $this->appData
+ ->expects($this->once())
+ ->method('getFolder')
+ ->with('/')
+ ->willReturn($folder);
+ $client = $this->createMock(IClient::class);
+ $this->clientService
+ ->expects($this->once())
+ ->method('newClient')
+ ->willReturn($client);
+ $response = $this->createMock(IResponse::class);
+ $client
+ ->expects($this->once())
+ ->method('get')
+ ->with('https://apps.nextcloud.com/api/v1/apps.json', [
+ 'timeout' => 60,
+ 'headers' => [
+ 'X-NC-Subscription-Key' => 'subscription-key',
+ ],
+ ])
+ ->willReturn($response);
+ $response
+ ->expects($this->once())
+ ->method('getBody')
+ ->willReturn(self::$responseJson);
+ $response->method('getHeader')
+ ->with($this->equalTo('ETag'))
+ ->willReturn('"myETag"');
+ $this->timeFactory
+ ->expects($this->once())
+ ->method('getTime')
+ ->willReturn(1234);
+
+ $this->registry
+ ->expects($this->exactly(2))
+ ->method('delegateHasValidSubscription')
+ ->willReturn(true);
+
+ $file
+ ->expects($this->once())
+ ->method('putContent');
+ $file
+ ->method('getContent')
+ ->willReturn(json_encode(self::$expectedResponse));
+
+ $apps = array_values($this->fetcher->get());
+ $this->assertEquals(count($apps), 1);
+ $this->assertEquals($apps[0]['id'], 'contacts');
+ }
+
+ public function testGetAppsAllowlistCustomAppstore(): void {
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'version') {
+ return '11.0.0.2';
} elseif ($key === 'appsallowlist') {
return ['contacts'];
+ } elseif ($key === 'appstoreurl') {
+ return 'https://custom.appsstore.endpoint/api/v1';
} else {
return $default;
}
});
+ $this->config->method('getSystemValueString')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'appstoreurl') {
+ return 'https://custom.appsstore.endpoint/api/v1';
+ }
+ return $default;
+ });
$this->config
->method('getSystemValueBool')
->with('appstoreenabled', true)
@@ -2127,7 +2222,9 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg==
$client
->expects($this->once())
->method('get')
- ->with('https://custom.appsstore.endpoint/api/v1/apps.json')
+ ->with('https://custom.appsstore.endpoint/api/v1/apps.json', [
+ 'timeout' => 60,
+ ])
->willReturn($response);
$response
->expects($this->once())
@@ -2142,7 +2239,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg==
->willReturn(1234);
$this->registry
- ->expects($this->exactly(2))
+ ->expects($this->exactly(1))
->method('delegateHasValidSubscription')
->willReturn(true);