Merge pull request #10712 from nextcloud/fix/noid/check_if_provider_is_available_before_use

Check if a preview provider is available before using it
This commit is contained in:
blizzz 2018-08-20 13:21:16 +02:00 committed by GitHub
commit 4b92a0986c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -184,6 +184,10 @@ class Generator {
continue;
}
if (!$provider->isAvailable($file)) {
continue;
}
$maxWidth = (int)$this->config->getSystemValue('preview_max_x', 4096);
$maxHeight = (int)$this->config->getSystemValue('preview_max_y', 4096);

View File

@ -150,16 +150,24 @@ class GeneratorTest extends \Test\TestCase {
}));
$invalidProvider = $this->createMock(IProvider::class);
$invalidProvider->method('isAvailable')
->willReturn(true);
$unavailableProvider = $this->createMock(IProvider::class);
$unavailableProvider->method('isAvailable')
->willReturn(false);
$validProvider = $this->createMock(IProvider::class);
$validProvider->method('isAvailable')
->with($file)
->willReturn(true);
$this->previewManager->method('getProviders')
->willReturn([
'/image\/png/' => ['wrongProvider'],
'/myMimeType/' => ['brokenProvider', 'invalidProvider', 'validProvider'],
'/myMimeType/' => ['brokenProvider', 'invalidProvider', 'unavailableProvider', 'validProvider'],
]);
$this->helper->method('getProvider')
->will($this->returnCallback(function($provider) use ($invalidProvider, $validProvider) {
->will($this->returnCallback(function($provider) use ($invalidProvider, $validProvider, $unavailableProvider) {
if ($provider === 'wrongProvider') {
$this->fail('Wrongprovider should not be constructed!');
} else if ($provider === 'brokenProvider') {
@ -168,6 +176,8 @@ class GeneratorTest extends \Test\TestCase {
return $invalidProvider;
} else if ($provider === 'validProvider') {
return $validProvider;
} else if ($provider === 'unavailableProvider') {
return $unavailableProvider;
}
$this->fail('Unexpected provider requested');
}));