Files
Simon L.andClaude Opus 5.5 d18936a8a4 fix(preview): harden the MovieRemote provider and its ffmpeg-over-ip client
- Open the video on the storage, so it is not locked while the server works
- Take the size from the opened stream instead of the filecache
- Limit the data the server may read of videos on non-local storages to
  20 MB, like the Movie provider
- Track the stream position after failed seeks and report short reads as
  I/O errors instead of end of file
- Send a cancel message when a run is aborted
- Enforce the deadline while writing with non-blocking writes
- Catch all errors and give up after the first failed connection
- Report the reason of TLS errors, verify IPv6 literals and document the
  certificate bundle that is used
- Register MovieRemote before Movie and log if no address is configured
- Use the default timeout for values below 1

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Simon L. <szaimen@e.mail.de>
2026-11-05 10:19:05 +01:00

89 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\Preview\GeneratorHelper;
use OC\Preview\IMagickSupport;
use OC\Preview\Movie;
use OC\Preview\MovieRemote;
use OC\PreviewManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\IBinaryFinder;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
class PreviewManagerTest extends TestCase {
private IConfig&MockObject $config;
private LoggerInterface&MockObject $logger;
private PreviewManager $previewManager;
private array $systemConfig = [];
#[\Override]
protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->config->method('getSystemValueBool')->willReturn(true);
$this->config->method('getSystemValue')->willReturnCallback(fn (string $key, mixed $default) => $this->systemConfig[$key] ?? $default);
$this->config->method('getSystemValueString')->willReturnCallback(fn (string $key, string $default) => $this->systemConfig[$key] ?? $default);
$this->logger = $this->createMock(LoggerInterface::class);
$container = $this->createMock(ContainerInterface::class);
$container->method('get')->with(LoggerInterface::class)->willReturn($this->logger);
$binaryFinder = $this->createMock(IBinaryFinder::class);
$binaryFinder->method('findBinaryPath')->willReturn(false);
$this->previewManager = new PreviewManager(
$this->config,
$this->createMock(IRootFolder::class),
$this->createMock(IEventDispatcher::class),
$this->createMock(GeneratorHelper::class),
null,
$this->createMock(Coordinator::class),
$container,
$binaryFinder,
$this->createMock(IMagickSupport::class),
);
}
/**
* @return list<class-string>
*/
private function getVideoProviders(): array {
return array_map(fn (\Closure $provider): string => $provider()::class, $this->previewManager->getProviders()['/video\/.*/'] ?? []);
}
public function testMovieRemoteIsTriedBeforeMovie(): void {
$this->systemConfig = [
'enabledPreviewProviders' => [Movie::class, MovieRemote::class],
'preview_ffmpeg_path' => '/usr/bin/ffmpeg',
'preview_ffmpeg_address' => 'ffmpeg-over-ip:5050',
];
$this->assertSame([MovieRemote::class, Movie::class], $this->getVideoProviders());
}
public function testMovieRemoteWithoutAddress(): void {
$this->systemConfig = [
'enabledPreviewProviders' => [MovieRemote::class],
];
$this->logger->expects($this->once())
->method('error')
->with($this->stringContains('preview_ffmpeg_address'));
$this->assertSame([], $this->getVideoProviders());
$this->assertFalse($this->previewManager->isMimeSupported('video/mp4'));
}
}