diff --git a/lib/private/Server.php b/lib/private/Server.php index 2804acbbb79..d2c3ce778a9 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1048,7 +1048,7 @@ class Server extends ServerContainer implements IServerContainer { $c->getAppDataDir('js'), $c->get(IURLGenerator::class), $this->get(ICacheFactory::class), - $c->get(SystemConfig::class), + $c->get(\OCP\IConfig::class), $c->get(LoggerInterface::class) ); }); diff --git a/lib/private/Template/JSCombiner.php b/lib/private/Template/JSCombiner.php index 7ee76990d90..4b963aa5e4a 100644 --- a/lib/private/Template/JSCombiner.php +++ b/lib/private/Template/JSCombiner.php @@ -9,13 +9,13 @@ declare(strict_types=1); namespace OC\Template; -use OC\SystemConfig; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\ICache; use OCP\ICacheFactory; +use OCP\IConfig; use OCP\IURLGenerator; use Psr\Log\LoggerInterface; @@ -26,14 +26,14 @@ class JSCombiner { protected IAppData $appData, protected IURLGenerator $urlGenerator, protected ICacheFactory $cacheFactory, - protected SystemConfig $config, + protected IConfig $config, protected LoggerInterface $logger, ) { $this->depsCache = $this->cacheFactory->createDistributed('JS-' . md5($this->urlGenerator->getBaseUrl())); } public function process(string $root, string $file, string $app): bool { - if ($this->config->getValue('debug') || !$this->config->getValue('installed')) { + if ($this->config->getSystemValueBool('debug') || !$this->config->getSystemValueBool('installed')) { return false; } diff --git a/lib/private/Template/ResourceLocator.php b/lib/private/Template/ResourceLocator.php index d954c2cff2e..05024b20a93 100644 --- a/lib/private/Template/ResourceLocator.php +++ b/lib/private/Template/ResourceLocator.php @@ -18,7 +18,6 @@ abstract class ResourceLocator { protected array $mapping; protected string $serverroot; - protected string $webroot; protected array $resources = []; @@ -30,7 +29,6 @@ abstract class ResourceLocator { \OC::$SERVERROOT => \OC::$WEBROOT ]; $this->serverroot = \OC::$SERVERROOT; - $this->webroot = \OC::$WEBROOT; $this->theme = $config->getSystemValueString('theme', ''); @@ -53,7 +51,7 @@ abstract class ResourceLocator { try { $this->doFind($resource); } catch (ResourceNotFoundException $e) { - $resourceApp = substr($resource, 0, strpos($resource, '/')); + [$resourceApp] = explode('/', $resource, 2); $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); } } @@ -62,7 +60,7 @@ abstract class ResourceLocator { try { $this->doFindTheme($resource); } catch (ResourceNotFoundException $e) { - $resourceApp = substr($resource, 0, strpos($resource, '/')); + [$resourceApp] = explode('/', $resource, 2); $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); } } diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index af2b731baa9..f18e6064bfa 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -12,6 +12,7 @@ use OC\AppFramework\Bootstrap\Coordinator; use OC\Installer; use OC\Repair; use OC\Repair\Events\RepairErrorEvent; +use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; use OCP\Authentication\IAlternativeLogin; use OCP\EventDispatcher\IEventDispatcher; @@ -426,7 +427,11 @@ class OC_App { $info['level'] = self::supportedApp; } - $appPath = self::getAppPath($app); + try { + $appPath = $appManager->getAppPath($app); + } catch (AppPathNotFoundException) { + $appPath = false; + } if ($appPath !== false) { $appIcon = $appPath . '/img/' . $app . '.svg'; if (file_exists($appIcon)) { diff --git a/tests/lib/Template/CSSResourceLocatorTest.php b/tests/lib/Template/CSSResourceLocatorTest.php index fc82c9c3e57..2db9899d0f9 100644 --- a/tests/lib/Template/CSSResourceLocatorTest.php +++ b/tests/lib/Template/CSSResourceLocatorTest.php @@ -1,5 +1,7 @@ method('get')->with('css')->willReturn($this->appData); return new CSSResourceLocator( $this->logger, + $this->createMock(IConfig::class), + Server::get(IAppManager::class), 'theme', ['core' => 'map'], ['3rd' => 'party'], @@ -74,8 +73,8 @@ class CSSResourceLocatorTest extends \Test\TestCase { return rmdir($directory); } - private function randomString() { - return sha1(uniqid(mt_rand(), true)); + private function randomString(): string { + return sha1(random_bytes(10)); } public function testFindWithAppPathSymlink(): void { diff --git a/tests/lib/Template/JSCombinerTest.php b/tests/lib/Template/JSCombinerTest.php index bc286695bc7..52ed7e7056c 100644 --- a/tests/lib/Template/JSCombinerTest.php +++ b/tests/lib/Template/JSCombinerTest.php @@ -1,5 +1,7 @@ appData = $this->createMock(IAppData::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->config = $this->createMock(SystemConfig::class); + $this->config = $this->createMock(IConfig::class); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->depsCache = $this->createMock(ICache::class); $this->cacheFactory->expects($this->atLeastOnce()) @@ -61,7 +58,7 @@ class JSCombinerTest extends \Test\TestCase { public function testProcessDebugMode(): void { $this->config ->expects($this->once()) - ->method('getValue') + ->method('getSystemValueBool') ->with('debug') ->willReturn(true); @@ -72,7 +69,7 @@ class JSCombinerTest extends \Test\TestCase { public function testProcessNotInstalled(): void { $this->config ->expects($this->exactly(2)) - ->method('getValue') + ->method('getSystemValueBool') ->willReturnMap([ ['debug', false], ['installed', false] @@ -85,10 +82,10 @@ class JSCombinerTest extends \Test\TestCase { public function testProcessUncachedFileNoAppDataFolder(): void { $this->config ->expects($this->exactly(2)) - ->method('getValue') + ->method('getSystemValueBool') ->willReturnMap([ - ['debug', '', false], - ['installed', '', true], + ['debug', false], + ['installed', true], ]); $folder = $this->createMock(ISimpleFolder::class); $this->appData->expects($this->once())->method('getFolder')->with('awesomeapp')->willThrowException(new NotFoundException()); @@ -121,10 +118,10 @@ class JSCombinerTest extends \Test\TestCase { public function testProcessUncachedFile(): void { $this->config ->expects($this->exactly(2)) - ->method('getValue') + ->method('getSystemValueBool') ->willReturnMap([ - ['debug', '', false], - ['installed', '', true], + ['debug', false], + ['installed', true], ]); $folder = $this->createMock(ISimpleFolder::class); $this->appData->expects($this->once())->method('getFolder')->with('awesomeapp')->willReturn($folder); @@ -155,10 +152,10 @@ class JSCombinerTest extends \Test\TestCase { public function testProcessCachedFile(): void { $this->config ->expects($this->exactly(2)) - ->method('getValue') + ->method('getSystemValueBool') ->willReturnMap([ - ['debug', '', false], - ['installed', '', true], + ['debug', false], + ['installed', true], ]); $folder = $this->createMock(ISimpleFolder::class); $this->appData->expects($this->once())->method('getFolder')->with('awesomeapp')->willReturn($folder); @@ -192,10 +189,10 @@ class JSCombinerTest extends \Test\TestCase { public function testProcessCachedFileMemcache(): void { $this->config ->expects($this->exactly(2)) - ->method('getValue') + ->method('getSystemValueBool') ->willReturnMap([ - ['debug', '', false], - ['installed', '', true], + ['debug', false], + ['installed', true], ]); $folder = $this->createMock(ISimpleFolder::class); $this->appData->expects($this->once()) diff --git a/tests/lib/Template/JSResourceLocatorTest.php b/tests/lib/Template/JSResourceLocatorTest.php index 89ab8e66dd7..599346e03d8 100644 --- a/tests/lib/Template/JSResourceLocatorTest.php +++ b/tests/lib/Template/JSResourceLocatorTest.php @@ -1,5 +1,7 @@ appData = $this->createMock(IAppData::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->config = $this->createMock(SystemConfig::class); + $this->config = $this->createMock(IConfig::class); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->logger = $this->createMock(LoggerInterface::class); $this->appManager = $this->createMock(IAppManager::class); } - private function jsResourceLocator() { + private function jsResourceLocator(): JSResourceLocator { $jsCombiner = new JSCombiner( $this->appData, $this->urlGenerator, @@ -52,6 +49,7 @@ class JSResourceLocatorTest extends \Test\TestCase { ); return new JSResourceLocator( $this->logger, + $this->config, $jsCombiner, $this->appManager, ); @@ -69,8 +67,8 @@ class JSResourceLocatorTest extends \Test\TestCase { return rmdir($directory); } - private function randomString() { - return sha1(uniqid(mt_rand(), true)); + private function randomString(): string { + return sha1(random_bytes(10)); } public function testFindWithAppPathSymlink(): void { diff --git a/tests/lib/Template/ResourceLocatorTest.php b/tests/lib/Template/ResourceLocatorTest.php index e1e783a38bd..25a0c2479d9 100644 --- a/tests/lib/Template/ResourceLocatorTest.php +++ b/tests/lib/Template/ResourceLocatorTest.php @@ -1,5 +1,7 @@ logger = $this->createMock(LoggerInterface::class); + $this->config = $this->createMock(IConfig::class); } - /** - * @param string $theme - * @return \PHPUnit\Framework\MockObject\MockObject - */ - public function getResourceLocator($theme) { - $systemConfig = $this->createMock(SystemConfig::class); - $systemConfig + public function getResourceLocator(string $theme): ResourceLocator&MockObject { + $this->config ->expects($this->any()) - ->method('getValue') + ->method('getSystemValueString') ->with('theme', '') ->willReturn($theme); - $this->overwriteService(SystemConfig::class, $systemConfig); - return $this->getMockForAbstractClass('OC\Template\ResourceLocator', - [$this->logger], + return $this->getMockForAbstractClass(ResourceLocator::class, + [$this->logger, $this->config], '', true, true, true, []); } @@ -47,16 +45,10 @@ class ResourceLocatorTest extends \Test\TestCase { $locator->expects($this->once()) ->method('doFindTheme') ->with('foo'); - /** @var ResourceLocator $locator */ $locator->find(['foo']); } public function testFindNotFound(): void { - $systemConfig = $this->createMock(SystemConfig::class); - $systemConfig->method('getValue') - ->with('theme', '') - ->willReturn('theme'); - $this->overwriteService(SystemConfig::class, $systemConfig); $locator = $this->getResourceLocator('theme', ['core' => 'map'], ['3rd' => 'party'], ['foo' => 'bar']); $locator->expects($this->once()) @@ -70,13 +62,11 @@ class ResourceLocatorTest extends \Test\TestCase { $this->logger->expects($this->exactly(2)) ->method('debug') ->with($this->stringContains('map/foo')); - /** @var ResourceLocator $locator */ $locator->find(['foo']); } public function testAppendIfExist(): void { $locator = $this->getResourceLocator('theme'); - /** @var ResourceLocator $locator */ $method = new \ReflectionMethod($locator, 'appendIfExist'); $method->setAccessible(true); diff --git a/tests/lib/TemplateLayoutTest.php b/tests/lib/TemplateLayoutTest.php index ce5d2f6dd0b..918c06bebb7 100644 --- a/tests/lib/TemplateLayoutTest.php +++ b/tests/lib/TemplateLayoutTest.php @@ -44,7 +44,13 @@ class TemplateLayoutTest extends \Test\TestCase { } #[\PHPUnit\Framework\Attributes\DataProvider('dataVersionHash')] - public function testVersionHash($path, $file, $installed, $debug, $expected): void { + public function testVersionHash( + string|false $path, + string|false $file, + bool $installed, + bool $debug, + string $expected, + ): void { $this->appManager->expects(self::any()) ->method('getAppVersion') ->willReturnCallback(fn ($appId) => match ($appId) { @@ -59,8 +65,8 @@ class TemplateLayoutTest extends \Test\TestCase { $this->config->expects(self::atLeastOnce()) ->method('getSystemValueBool') ->willReturnMap([ - ['installed', false, $installed], - ['debug', false, $debug], + ['installed', $installed], + ['debug', $debug], ]); $this->config->expects(self::any()) ->method('getAppValue')