Skip to content

Commit dbe50ea

Browse files
test(appstore): cover stale cache filtering in AppFetcher
Verify that stale app data still respects the App Store allowlist. Signed-off-by: Josh <josh.t.richards@gmail.com>
1 parent 683fa0d commit dbe50ea

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

tests/lib/App/AppStore/Fetcher/AppFetcherTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,4 +2249,92 @@ public function testGetAppsAllowlistCustomAppstore(): void {
22492249
$this->assertEquals(count($apps), 1);
22502250
$this->assertEquals($apps[0]['id'], 'contacts');
22512251
}
2252+
2253+
public function testGetAppliesAllowlistToStaleCachedData(): void {
2254+
$this->config->method('getSystemValueString')
2255+
->willReturnCallback(function (string $key, string $default): string {
2256+
if ($key === 'version') {
2257+
return '11.0.0.2';
2258+
}
2259+
2260+
return $default;
2261+
});
2262+
2263+
$this->config
2264+
->method('getSystemValueBool')
2265+
->willReturnArgument(1);
2266+
2267+
$this->config
2268+
->method('getSystemValue')
2269+
->willReturnCallback(function (string $key, mixed $default = null): mixed {
2270+
if ($key === 'appsallowlist') {
2271+
return ['allowed_app'];
2272+
}
2273+
2274+
return $default;
2275+
});
2276+
2277+
$this->config
2278+
->method('getAppValue')
2279+
->willReturnCallback(function (string $app, string $key, string $default): string {
2280+
if ($key === 'appstore-fetcher-lastFailure') {
2281+
return (string)time();
2282+
}
2283+
2284+
return $default;
2285+
});
2286+
2287+
$file = $this->createMock(ISimpleFile::class);
2288+
$folder = $this->createMock(ISimpleFolder::class);
2289+
2290+
$this->appData
2291+
->expects($this->once())
2292+
->method('getFolder')
2293+
->with('/')
2294+
->willReturn($folder);
2295+
2296+
$folder
2297+
->expects($this->once())
2298+
->method('getFile')
2299+
->with('apps.json')
2300+
->willReturn($file);
2301+
2302+
$now = time();
2303+
2304+
$file
2305+
->expects($this->once())
2306+
->method('getContent')
2307+
->willReturn(json_encode([
2308+
'timestamp' => $now - 3601,
2309+
'data' => [
2310+
[
2311+
'id' => 'allowed_app',
2312+
],
2313+
[
2314+
'id' => 'blocked_app',
2315+
],
2316+
],
2317+
'ncversion' => '11.0.0.2',
2318+
]));
2319+
2320+
$this->timeFactory
2321+
->expects($this->exactly(2))
2322+
->method('getTime')
2323+
->willReturn($now);
2324+
2325+
$this->clientService
2326+
->expects($this->never())
2327+
->method('newClient');
2328+
2329+
$this->registry
2330+
->expects($this->once())
2331+
->method('delegateHasValidSubscription')
2332+
->willReturn(true);
2333+
2334+
$this->assertSame([
2335+
[
2336+
'id' => 'allowed_app',
2337+
],
2338+
], $this->fetcher->get());
2339+
}
22522340
}

0 commit comments

Comments
 (0)