Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Application extends App implements IBootstrap {
public const APP_ID = 'app_api';
public const TEST_DEPLOY_APPID = 'test-deploy';
public const TEST_DEPLOY_INFO_XML = 'https://raw.githubusercontent.com/nextcloud/test-deploy/main/appinfo/info.xml';
public const MINIMUM_HARP_VERSION = '0.3.0';
public const MINIMUM_HARP_VERSION = '0.4.8';

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
Expand Down
7 changes: 4 additions & 3 deletions lib/SetupChecks/HarpVersionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ private function fulfillsMinimumVersionRequirement(string $version): bool {
}

private function getHarpVersion(DaemonConfig $daemonConfig): ?string {
$cacheKey = $daemonConfig->getName() . '_' . (string)crc32(json_encode($daemonConfig));
// With the minimum in the key, a version cached against an older minimum is asked again.
$cacheKey = $daemonConfig->getName() . '_' . (string)crc32(json_encode($daemonConfig)) . '_' . Application::MINIMUM_HARP_VERSION;
$version = $this->cache?->get($cacheKey);
if ($version === null) {
$version = $this->harpService->getHarpVersion($daemonConfig);
$oneWeek = 60 * 60 * 24 * 7;
$this->cache?->set($cacheKey, $version, $oneWeek);
$ttl = $version !== null && $this->fulfillsMinimumVersionRequirement($version) ? 60 * 60 * 24 * 7 : 60 * 60;
$this->cache?->set($cacheKey, $version, $ttl);
}
return $version;
}
Expand Down
63 changes: 63 additions & 0 deletions tests/php/SetupChecks/HarpVersionCheckTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\AppAPI\Tests\php\SetupChecks;

use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Db\DaemonConfig;
use OCA\AppAPI\Service\DaemonConfigService;
use OCA\AppAPI\Service\HarpService;
use OCA\AppAPI\SetupChecks\HarpVersionCheck;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IL10N;
use OCP\SetupCheck\SetupResult;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class HarpVersionCheckTest extends TestCase {

private function runCheck(?string $harpVersion, int $expectedCacheTtl): SetupResult {
$l10n = $this->createMock(IL10N::class);
$l10n->method('t')->willReturnCallback(fn (string $text, array $parameters = []) => vsprintf($text, $parameters));
$daemonConfigService = $this->createMock(DaemonConfigService::class);
$daemonConfigService->method('getRegisteredDaemonConfigs')->willReturn([
new DaemonConfig(['name' => 'harp_proxy', 'deploy_config' => ['harp' => ['exapp_direct' => false]]]),
]);
$harpService = $this->createMock(HarpService::class);
$harpService->method('getHarpVersion')->willReturn($harpVersion);
$cache = $this->createMock(ICache::class);
$cache->method('get')->willReturn(null);
// The minimum is part of the key, so a version cached by an older AppAPI is not reused after an upgrade.
$cache->expects(self::once())->method('set')->with(self::stringEndsWith('_' . Application::MINIMUM_HARP_VERSION), $harpVersion, $expectedCacheTtl);
$cacheFactory = $this->createMock(ICacheFactory::class);
$cacheFactory->method('isAvailable')->willReturn(true);
$cacheFactory->method('createDistributed')->willReturn($cache);

$check = new HarpVersionCheck($l10n, $this->createMock(LoggerInterface::class), $daemonConfigService, $harpService, $cacheFactory);
return $check->run();
}

public function testHarpWithoutRouteVerbChecksIsTooOld(): void {
$result = $this->runCheck('0.4.7', 60 * 60);
self::assertSame(SetupResult::WARNING, $result->getSeverity());
self::assertStringContainsString('"0.4.7", which is too old. The minimum required version is "0.4.8"', $result->getDescription());
}

public function testUnreachableHarpIsReported(): void {
$result = $this->runCheck(null, 60 * 60);
self::assertSame(SetupResult::WARNING, $result->getSeverity());
self::assertStringContainsString('Could not retrieve HaRP version from daemon "harp_proxy"', $result->getDescription());
}

public function testCurrentHarpPasses(): void {
$result = $this->runCheck('0.4.8', 60 * 60 * 24 * 7);
self::assertSame(SetupResult::SUCCESS, $result->getSeverity());
}
}
Loading