aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php')
-rw-r--r--apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php94
1 files changed, 45 insertions, 49 deletions
diff --git a/apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php b/apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php
index 32fd9f452b5..eefbc53fd22 100644
--- a/apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php
+++ b/apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php
@@ -1,22 +1,10 @@
<?php
+
+declare(strict_types=1);
/**
- * @author Piotr Mrowczynski piotr@owncloud.com
- *
- * @copyright Copyright (c) 2019, ownCloud GmbH
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2019 ownCloud GmbH
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\DAV\Tests\unit\DAV;
@@ -28,34 +16,34 @@ use OCA\Files_Versions\Sabre\VersionFile;
use OCA\Files_Versions\Versions\IVersion;
use OCP\Files\File;
use OCP\Files\Folder;
+use OCP\Files\Storage\ISharedStorage;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
use OCP\Share\IAttributes;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\Server;
use Sabre\DAV\Tree;
use Sabre\HTTP\RequestInterface;
use Test\TestCase;
class ViewOnlyPluginTest extends TestCase {
-
+ private Tree&MockObject $tree;
+ private RequestInterface&MockObject $request;
+ private Folder&MockObject $userFolder;
private ViewOnlyPlugin $plugin;
- /** @var Tree | \PHPUnit\Framework\MockObject\MockObject */
- private $tree;
- /** @var RequestInterface | \PHPUnit\Framework\MockObject\MockObject */
- private $request;
- /** @var Folder | \PHPUnit\Framework\MockObject\MockObject */
- private $userFolder;
public function setUp(): void {
+ parent::setUp();
+
$this->userFolder = $this->createMock(Folder::class);
- $this->plugin = new ViewOnlyPlugin(
- $this->userFolder,
- );
$this->request = $this->createMock(RequestInterface::class);
$this->tree = $this->createMock(Tree::class);
-
$server = $this->createMock(Server::class);
+
+ $this->plugin = new ViewOnlyPlugin(
+ $this->userFolder,
+ );
$server->tree = $this->tree;
$this->plugin->initialize($server);
@@ -78,32 +66,36 @@ class ViewOnlyPluginTest extends TestCase {
$storage = $this->createMock(IStorage::class);
$file->method('getStorage')->willReturn($storage);
- $storage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(false);
+ $storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(false);
$this->assertTrue($this->plugin->checkViewOnly($this->request));
}
- public function providesDataForCanGet(): array {
+ public static function providesDataForCanGet(): array {
return [
// has attribute permissions-download enabled - can get file
- [false, true, true],
+ [false, true, true, true],
// has no attribute permissions-download - can get file
- [false, null, true],
- // has attribute permissions-download disabled- cannot get the file
- [false, false, false],
+ [false, null, true, true],
// has attribute permissions-download enabled - can get file version
- [true, true, true],
+ [true, true, true, true],
// has no attribute permissions-download - can get file version
- [true, null, true],
- // has attribute permissions-download disabled- cannot get the file version
- [true, false, false],
+ [true, null, true, true],
+ // has attribute permissions-download disabled - cannot get the file
+ [false, false, false, false],
+ // has attribute permissions-download disabled - cannot get the file version
+ [true, false, false, false],
+
+ // Has global allowViewWithoutDownload option enabled
+ // has attribute permissions-download disabled - can get file
+ [false, false, false, true],
+ // has attribute permissions-download disabled - can get file version
+ [true, false, false, true],
];
}
- /**
- * @dataProvider providesDataForCanGet
- */
- public function testCanGet(bool $isVersion, ?bool $attrEnabled, bool $expectCanDownloadFile): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('providesDataForCanGet')]
+ public function testCanGet(bool $isVersion, ?bool $attrEnabled, bool $expectCanDownloadFile, bool $allowViewWithoutDownload): void {
$nodeInfo = $this->createMock(File::class);
if ($isVersion) {
$davPath = 'versions/alice/versions/117/123456';
@@ -144,24 +136,28 @@ class ViewOnlyPluginTest extends TestCase {
$this->request->expects($this->once())->method('getPath')->willReturn($davPath);
$this->tree->expects($this->once())
- ->method('getNodeForPath')
- ->with($davPath)
- ->willReturn($davNode);
+ ->method('getNodeForPath')
+ ->with($davPath)
+ ->willReturn($davNode);
$storage = $this->createMock(SharedStorage::class);
$share = $this->createMock(IShare::class);
$nodeInfo->expects($this->once())
->method('getStorage')
->willReturn($storage);
- $storage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(true);
+ $storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(true);
$storage->method('getShare')->willReturn($share);
$extAttr = $this->createMock(IAttributes::class);
$share->method('getAttributes')->willReturn($extAttr);
$extAttr->expects($this->once())
- ->method('getAttribute')
- ->with('permissions', 'download')
- ->willReturn($attrEnabled);
+ ->method('getAttribute')
+ ->with('permissions', 'download')
+ ->willReturn($attrEnabled);
+
+ $share->expects($this->once())
+ ->method('canSeeContent')
+ ->willReturn($allowViewWithoutDownload);
if (!$expectCanDownloadFile) {
$this->expectException(Forbidden::class);