2015-02-12 14:29:01 +03:00
|
|
|
<?php
|
2016-01-12 17:02:16 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Markus Goetz <markus@woboq.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Stefan Weil <sw@weilnetz.de>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2020-12-16 16:54:15 +03:00
|
|
|
* @author Vincent Petry <vincent@nextcloud.com>
|
2016-01-12 17:02:16 +03:00
|
|
|
*
|
|
|
|
* @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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-01-12 17:02:16 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2016-05-25 17:04:15 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\Connector\Sabre;
|
2015-02-12 14:29:01 +03:00
|
|
|
|
2017-10-25 01:03:28 +03:00
|
|
|
use OC\User\User;
|
2018-01-24 20:10:16 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\Directory;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\File;
|
2016-06-06 18:01:27 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\FilesPlugin;
|
2017-10-25 01:03:28 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\Node;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Files\FileInfo;
|
2015-12-09 19:31:14 +03:00
|
|
|
use OCP\Files\StorageNotAvailableException;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IPreview;
|
|
|
|
use OCP\IRequest;
|
2016-04-12 16:51:09 +03:00
|
|
|
use Sabre\DAV\PropFind;
|
|
|
|
use Sabre\DAV\PropPatch;
|
2017-10-24 16:26:53 +03:00
|
|
|
use Sabre\DAV\Server;
|
|
|
|
use Sabre\DAV\Tree;
|
2016-10-13 13:15:10 +03:00
|
|
|
use Sabre\HTTP\RequestInterface;
|
|
|
|
use Sabre\HTTP\ResponseInterface;
|
2019-11-22 12:20:07 +03:00
|
|
|
use Sabre\Xml\Service;
|
2016-04-12 16:51:09 +03:00
|
|
|
use Test\TestCase;
|
2015-12-09 19:31:14 +03:00
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
2016-05-25 17:04:15 +03:00
|
|
|
class FilesPluginTest extends TestCase {
|
2020-04-10 17:54:27 +03:00
|
|
|
public const GETETAG_PROPERTYNAME = FilesPlugin::GETETAG_PROPERTYNAME;
|
|
|
|
public const FILEID_PROPERTYNAME = FilesPlugin::FILEID_PROPERTYNAME;
|
|
|
|
public const INTERNAL_FILEID_PROPERTYNAME = FilesPlugin::INTERNAL_FILEID_PROPERTYNAME;
|
|
|
|
public const SIZE_PROPERTYNAME = FilesPlugin::SIZE_PROPERTYNAME;
|
|
|
|
public const PERMISSIONS_PROPERTYNAME = FilesPlugin::PERMISSIONS_PROPERTYNAME;
|
|
|
|
public const LASTMODIFIED_PROPERTYNAME = FilesPlugin::LASTMODIFIED_PROPERTYNAME;
|
|
|
|
public const DOWNLOADURL_PROPERTYNAME = FilesPlugin::DOWNLOADURL_PROPERTYNAME;
|
|
|
|
public const OWNER_ID_PROPERTYNAME = FilesPlugin::OWNER_ID_PROPERTYNAME;
|
|
|
|
public const OWNER_DISPLAY_NAME_PROPERTYNAME = FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME;
|
|
|
|
public const DATA_FINGERPRINT_PROPERTYNAME = FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME;
|
|
|
|
public const HAS_PREVIEW_PROPERTYNAME = FilesPlugin::HAS_PREVIEW_PROPERTYNAME;
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Sabre\DAV\Server | \PHPUnit\Framework\MockObject\MockObject
|
2015-02-12 14:29:01 +03:00
|
|
|
*/
|
|
|
|
private $server;
|
|
|
|
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Sabre\DAV\Tree | \PHPUnit\Framework\MockObject\MockObject
|
2015-02-12 14:29:01 +03:00
|
|
|
*/
|
|
|
|
private $tree;
|
|
|
|
|
|
|
|
/**
|
2016-06-06 18:01:27 +03:00
|
|
|
* @var FilesPlugin
|
2015-02-12 14:29:01 +03:00
|
|
|
*/
|
|
|
|
private $plugin;
|
|
|
|
|
2016-04-18 12:18:50 +03:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OCP\IConfig | \PHPUnit\Framework\MockObject\MockObject
|
2016-04-18 12:18:50 +03:00
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2016-06-09 12:29:20 +03:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OCP\IRequest | \PHPUnit\Framework\MockObject\MockObject
|
2016-06-09 12:29:20 +03:00
|
|
|
*/
|
|
|
|
private $request;
|
|
|
|
|
2016-07-26 14:15:12 +03:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OCP\IPreview | \PHPUnit\Framework\MockObject\MockObject
|
2016-07-26 14:15:12 +03:00
|
|
|
*/
|
|
|
|
private $previewManager;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2015-02-12 14:29:01 +03:00
|
|
|
parent::setUp();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->server = $this->getMockBuilder(Server::class)
|
2015-10-06 16:36:54 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->tree = $this->getMockBuilder(Tree::class)
|
2015-02-12 14:29:01 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2016-06-06 18:01:27 +03:00
|
|
|
$this->config->expects($this->any())->method('getSystemValue')
|
2016-04-18 12:18:50 +03:00
|
|
|
->with($this->equalTo('data-fingerprint'), $this->equalTo(''))
|
|
|
|
->willReturn('my_fingerprint');
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->request = $this->getMockBuilder(IRequest::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->previewManager = $this->getMockBuilder(IPreview::class)
|
2016-07-26 14:15:12 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-04-18 12:18:50 +03:00
|
|
|
|
2016-06-06 18:01:27 +03:00
|
|
|
$this->plugin = new FilesPlugin(
|
2016-04-18 12:18:50 +03:00
|
|
|
$this->tree,
|
2016-06-09 12:29:20 +03:00
|
|
|
$this->config,
|
2016-07-26 14:15:12 +03:00
|
|
|
$this->request,
|
|
|
|
$this->previewManager
|
2016-04-18 12:18:50 +03:00
|
|
|
);
|
2017-03-30 12:30:37 +03:00
|
|
|
|
|
|
|
$response = $this->getMockBuilder(ResponseInterface::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->server->httpResponse = $response;
|
2019-11-22 12:20:07 +03:00
|
|
|
$this->server->xml = new Service();
|
2017-03-30 12:30:37 +03:00
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
$this->plugin->initialize($this->server);
|
|
|
|
}
|
|
|
|
|
2015-11-20 18:42:34 +03:00
|
|
|
/**
|
|
|
|
* @param string $class
|
2020-08-11 22:32:18 +03:00
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject
|
2015-11-20 18:42:34 +03:00
|
|
|
*/
|
2015-12-16 19:35:53 +03:00
|
|
|
private function createTestNode($class, $path = '/dummypath') {
|
2015-02-12 14:29:01 +03:00
|
|
|
$node = $this->getMockBuilder($class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-04-08 16:03:17 +03:00
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
$node->expects($this->any())
|
|
|
|
->method('getId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(123);
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
$this->tree->expects($this->any())
|
|
|
|
->method('getNodeForPath')
|
2015-12-16 19:35:53 +03:00
|
|
|
->with($path)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($node);
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
$node->expects($this->any())
|
|
|
|
->method('getFileId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('00000123instanceid');
|
2015-11-18 13:41:04 +03:00
|
|
|
$node->expects($this->any())
|
|
|
|
->method('getInternalFileId')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('123');
|
2015-02-12 14:29:01 +03:00
|
|
|
$node->expects($this->any())
|
|
|
|
->method('getEtag')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('"abc"');
|
2015-02-12 14:29:01 +03:00
|
|
|
$node->expects($this->any())
|
|
|
|
->method('getDavPermissions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('DWCKMSR');
|
2017-02-24 13:56:29 +03:00
|
|
|
|
|
|
|
$fileInfo = $this->createMock(FileInfo::class);
|
|
|
|
$fileInfo->expects($this->any())
|
|
|
|
->method('isReadable')
|
|
|
|
->willReturn(true);
|
|
|
|
|
2016-07-26 14:15:12 +03:00
|
|
|
$node->expects($this->any())
|
|
|
|
->method('getFileInfo')
|
2017-02-24 13:56:29 +03:00
|
|
|
->willReturn($fileInfo);
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
return $node;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPropertiesForFile() {
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit\Framework\MockObject\MockObject $node */
|
2015-08-30 20:13:01 +03:00
|
|
|
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
|
2015-02-12 14:29:01 +03:00
|
|
|
|
2016-04-12 16:51:09 +03:00
|
|
|
$propFind = new PropFind(
|
2015-02-12 14:29:01 +03:00
|
|
|
'/dummyPath',
|
2020-03-26 11:30:18 +03:00
|
|
|
[
|
2015-02-12 14:29:01 +03:00
|
|
|
self::GETETAG_PROPERTYNAME,
|
|
|
|
self::FILEID_PROPERTYNAME,
|
2015-11-18 13:41:04 +03:00
|
|
|
self::INTERNAL_FILEID_PROPERTYNAME,
|
2015-02-12 14:29:01 +03:00
|
|
|
self::SIZE_PROPERTYNAME,
|
|
|
|
self::PERMISSIONS_PROPERTYNAME,
|
|
|
|
self::DOWNLOADURL_PROPERTYNAME,
|
2015-11-02 17:05:16 +03:00
|
|
|
self::OWNER_ID_PROPERTYNAME,
|
2016-04-18 12:18:50 +03:00
|
|
|
self::OWNER_DISPLAY_NAME_PROPERTYNAME,
|
|
|
|
self::DATA_FINGERPRINT_PROPERTYNAME,
|
2020-03-26 11:30:18 +03:00
|
|
|
],
|
2015-02-12 14:29:01 +03:00
|
|
|
0
|
|
|
|
);
|
|
|
|
|
2017-10-25 01:03:28 +03:00
|
|
|
$user = $this->getMockBuilder(User::class)
|
2015-11-02 17:05:16 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$user
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2015-11-02 17:05:16 +03:00
|
|
|
$user
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getDisplayName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('M. Foo');
|
2015-11-02 17:05:16 +03:00
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
$node->expects($this->once())
|
|
|
|
->method('getDirectDownload')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn(['url' => 'http://example.com/']);
|
2015-11-02 17:05:16 +03:00
|
|
|
$node->expects($this->exactly(2))
|
|
|
|
->method('getOwner')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
$this->plugin->handleGetProperties(
|
|
|
|
$propFind,
|
|
|
|
$node
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals('"abc"', $propFind->get(self::GETETAG_PROPERTYNAME));
|
2015-11-18 13:41:04 +03:00
|
|
|
$this->assertEquals('00000123instanceid', $propFind->get(self::FILEID_PROPERTYNAME));
|
|
|
|
$this->assertEquals('123', $propFind->get(self::INTERNAL_FILEID_PROPERTYNAME));
|
2015-02-12 14:29:01 +03:00
|
|
|
$this->assertEquals(null, $propFind->get(self::SIZE_PROPERTYNAME));
|
2015-07-13 15:20:35 +03:00
|
|
|
$this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
|
2015-02-12 14:29:01 +03:00
|
|
|
$this->assertEquals('http://example.com/', $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
|
2015-11-02 17:05:16 +03:00
|
|
|
$this->assertEquals('foo', $propFind->get(self::OWNER_ID_PROPERTYNAME));
|
|
|
|
$this->assertEquals('M. Foo', $propFind->get(self::OWNER_DISPLAY_NAME_PROPERTYNAME));
|
2016-08-13 18:03:54 +03:00
|
|
|
$this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
|
|
|
|
$this->assertEquals([self::SIZE_PROPERTYNAME], $propFind->get404Properties());
|
2015-02-12 14:29:01 +03:00
|
|
|
}
|
|
|
|
|
2015-12-09 19:31:14 +03:00
|
|
|
public function testGetPropertiesStorageNotAvailable() {
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit\Framework\MockObject\MockObject $node */
|
2015-12-09 19:31:14 +03:00
|
|
|
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
|
|
|
|
|
2016-04-12 16:51:09 +03:00
|
|
|
$propFind = new PropFind(
|
2015-12-09 19:31:14 +03:00
|
|
|
'/dummyPath',
|
2020-03-26 11:30:18 +03:00
|
|
|
[
|
2015-12-09 19:31:14 +03:00
|
|
|
self::DOWNLOADURL_PROPERTYNAME,
|
2020-03-26 11:30:18 +03:00
|
|
|
],
|
2015-12-09 19:31:14 +03:00
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
$node->expects($this->once())
|
|
|
|
->method('getDirectDownload')
|
|
|
|
->will($this->throwException(new StorageNotAvailableException()));
|
|
|
|
|
|
|
|
$this->plugin->handleGetProperties(
|
|
|
|
$propFind,
|
|
|
|
$node
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(null, $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:20:35 +03:00
|
|
|
public function testGetPublicPermissions() {
|
2016-06-06 18:01:27 +03:00
|
|
|
$this->plugin = new FilesPlugin(
|
2016-04-18 12:18:50 +03:00
|
|
|
$this->tree,
|
|
|
|
$this->config,
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->getMockBuilder(IRequest::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock(),
|
2016-07-26 14:15:12 +03:00
|
|
|
$this->previewManager,
|
2016-04-18 12:18:50 +03:00
|
|
|
true);
|
2015-07-13 15:20:35 +03:00
|
|
|
$this->plugin->initialize($this->server);
|
|
|
|
|
2016-04-12 16:51:09 +03:00
|
|
|
$propFind = new PropFind(
|
2015-07-13 15:20:35 +03:00
|
|
|
'/dummyPath',
|
|
|
|
[
|
|
|
|
self::PERMISSIONS_PROPERTYNAME,
|
|
|
|
],
|
|
|
|
0
|
|
|
|
);
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit\Framework\MockObject\MockObject $node */
|
2015-08-30 20:13:01 +03:00
|
|
|
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
|
2015-07-13 15:20:35 +03:00
|
|
|
$node->expects($this->any())
|
|
|
|
->method('getDavPermissions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('DWCKMSR');
|
2015-07-13 15:20:35 +03:00
|
|
|
|
|
|
|
$this->plugin->handleGetProperties(
|
|
|
|
$propFind,
|
|
|
|
$node
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals('DWCKR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
|
|
|
|
}
|
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
public function testGetPropertiesForDirectory() {
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit\Framework\MockObject\MockObject $node */
|
2015-08-30 20:13:01 +03:00
|
|
|
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
|
2015-02-12 14:29:01 +03:00
|
|
|
|
2016-04-12 16:51:09 +03:00
|
|
|
$propFind = new PropFind(
|
2015-02-12 14:29:01 +03:00
|
|
|
'/dummyPath',
|
2020-03-26 11:30:18 +03:00
|
|
|
[
|
2015-02-12 14:29:01 +03:00
|
|
|
self::GETETAG_PROPERTYNAME,
|
|
|
|
self::FILEID_PROPERTYNAME,
|
|
|
|
self::SIZE_PROPERTYNAME,
|
|
|
|
self::PERMISSIONS_PROPERTYNAME,
|
|
|
|
self::DOWNLOADURL_PROPERTYNAME,
|
2016-04-18 12:18:50 +03:00
|
|
|
self::DATA_FINGERPRINT_PROPERTYNAME,
|
2020-03-26 11:30:18 +03:00
|
|
|
],
|
2015-02-12 14:29:01 +03:00
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
$node->expects($this->once())
|
|
|
|
->method('getSize')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(1025);
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
$this->plugin->handleGetProperties(
|
|
|
|
$propFind,
|
|
|
|
$node
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals('"abc"', $propFind->get(self::GETETAG_PROPERTYNAME));
|
2015-11-18 13:41:04 +03:00
|
|
|
$this->assertEquals('00000123instanceid', $propFind->get(self::FILEID_PROPERTYNAME));
|
2015-02-12 14:29:01 +03:00
|
|
|
$this->assertEquals(1025, $propFind->get(self::SIZE_PROPERTYNAME));
|
2015-07-13 15:20:35 +03:00
|
|
|
$this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
|
2015-02-12 14:29:01 +03:00
|
|
|
$this->assertEquals(null, $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
|
2016-08-13 18:03:54 +03:00
|
|
|
$this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
|
|
|
|
$this->assertEquals([self::DOWNLOADURL_PROPERTYNAME], $propFind->get404Properties());
|
2016-04-18 12:18:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPropertiesForRootDirectory() {
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit\Framework\MockObject\MockObject $node */
|
2017-10-24 16:26:53 +03:00
|
|
|
$node = $this->getMockBuilder(Directory::class)
|
2016-04-18 12:18:50 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-06-06 18:01:27 +03:00
|
|
|
$node->expects($this->any())->method('getPath')->willReturn('/');
|
2016-04-18 12:18:50 +03:00
|
|
|
|
2017-02-24 13:56:29 +03:00
|
|
|
$fileInfo = $this->createMock(FileInfo::class);
|
|
|
|
$fileInfo->expects($this->any())
|
|
|
|
->method('isReadable')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$node->expects($this->any())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->willReturn($fileInfo);
|
|
|
|
|
2016-04-18 12:18:50 +03:00
|
|
|
$propFind = new PropFind(
|
|
|
|
'/',
|
|
|
|
[
|
|
|
|
self::DATA_FINGERPRINT_PROPERTYNAME,
|
|
|
|
],
|
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->plugin->handleGetProperties(
|
|
|
|
$propFind,
|
|
|
|
$node
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
|
2015-02-12 14:29:01 +03:00
|
|
|
}
|
|
|
|
|
2017-02-24 13:56:29 +03:00
|
|
|
public function testGetPropertiesWhenNoPermission() {
|
2017-06-07 12:24:00 +03:00
|
|
|
// No read permissions can be caused by files access control.
|
|
|
|
// But we still want to load the directory list, so this is okay for us.
|
|
|
|
// $this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit\Framework\MockObject\MockObject $node */
|
2017-10-24 16:26:53 +03:00
|
|
|
$node = $this->getMockBuilder(Directory::class)
|
2017-02-24 13:56:29 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$node->expects($this->any())->method('getPath')->willReturn('/');
|
|
|
|
|
|
|
|
$fileInfo = $this->createMock(FileInfo::class);
|
|
|
|
$fileInfo->expects($this->any())
|
|
|
|
->method('isReadable')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$node->expects($this->any())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->willReturn($fileInfo);
|
|
|
|
|
|
|
|
$propFind = new PropFind(
|
|
|
|
'/test',
|
|
|
|
[
|
|
|
|
self::DATA_FINGERPRINT_PROPERTYNAME,
|
|
|
|
],
|
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->plugin->handleGetProperties(
|
|
|
|
$propFind,
|
|
|
|
$node
|
|
|
|
);
|
2018-01-25 13:23:12 +03:00
|
|
|
|
|
|
|
$this->addToAssertionCount(1);
|
2017-02-24 13:56:29 +03:00
|
|
|
}
|
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
public function testUpdateProps() {
|
2015-08-30 20:13:01 +03:00
|
|
|
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
$testDate = 'Fri, 13 Feb 2015 00:01:02 GMT';
|
|
|
|
|
|
|
|
$node->expects($this->once())
|
|
|
|
->method('touch')
|
|
|
|
->with($testDate);
|
|
|
|
|
|
|
|
$node->expects($this->once())
|
|
|
|
->method('setEtag')
|
|
|
|
->with('newetag')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
// properties to set
|
2020-03-26 11:30:18 +03:00
|
|
|
$propPatch = new PropPatch([
|
2015-02-12 14:29:01 +03:00
|
|
|
self::GETETAG_PROPERTYNAME => 'newetag',
|
2015-10-13 13:51:21 +03:00
|
|
|
self::LASTMODIFIED_PROPERTYNAME => $testDate
|
2020-03-26 11:30:18 +03:00
|
|
|
]);
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
$this->plugin->handleUpdateProperties(
|
|
|
|
'/dummypath',
|
|
|
|
$propPatch
|
|
|
|
);
|
|
|
|
|
|
|
|
$propPatch->commit();
|
|
|
|
|
|
|
|
$this->assertEmpty($propPatch->getRemainingMutations());
|
|
|
|
|
|
|
|
$result = $propPatch->getResult();
|
2015-10-13 13:51:21 +03:00
|
|
|
$this->assertEquals(200, $result[self::LASTMODIFIED_PROPERTYNAME]);
|
2015-02-12 14:29:01 +03:00
|
|
|
$this->assertEquals(200, $result[self::GETETAG_PROPERTYNAME]);
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:05:16 +03:00
|
|
|
public function testUpdatePropsForbidden() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$propPatch = new PropPatch([
|
2015-11-02 17:05:16 +03:00
|
|
|
self::OWNER_ID_PROPERTYNAME => 'user2',
|
|
|
|
self::OWNER_DISPLAY_NAME_PROPERTYNAME => 'User Two',
|
|
|
|
self::FILEID_PROPERTYNAME => 12345,
|
|
|
|
self::PERMISSIONS_PROPERTYNAME => 'C',
|
|
|
|
self::SIZE_PROPERTYNAME => 123,
|
|
|
|
self::DOWNLOADURL_PROPERTYNAME => 'http://example.com/',
|
2020-03-26 11:30:18 +03:00
|
|
|
]);
|
2015-11-02 17:05:16 +03:00
|
|
|
|
|
|
|
$this->plugin->handleUpdateProperties(
|
|
|
|
'/dummypath',
|
|
|
|
$propPatch
|
|
|
|
);
|
|
|
|
|
|
|
|
$propPatch->commit();
|
|
|
|
|
|
|
|
$this->assertEmpty($propPatch->getRemainingMutations());
|
|
|
|
|
|
|
|
$result = $propPatch->getResult();
|
|
|
|
$this->assertEquals(403, $result[self::OWNER_ID_PROPERTYNAME]);
|
|
|
|
$this->assertEquals(403, $result[self::OWNER_DISPLAY_NAME_PROPERTYNAME]);
|
|
|
|
$this->assertEquals(403, $result[self::FILEID_PROPERTYNAME]);
|
|
|
|
$this->assertEquals(403, $result[self::PERMISSIONS_PROPERTYNAME]);
|
|
|
|
$this->assertEquals(403, $result[self::SIZE_PROPERTYNAME]);
|
|
|
|
$this->assertEquals(403, $result[self::DOWNLOADURL_PROPERTYNAME]);
|
|
|
|
}
|
|
|
|
|
2015-10-06 16:36:54 +03:00
|
|
|
/**
|
|
|
|
* Testcase from https://github.com/owncloud/core/issues/5251
|
|
|
|
*
|
|
|
|
* |-FolderA
|
|
|
|
* |-text.txt
|
|
|
|
* |-test.txt
|
|
|
|
*
|
2016-01-29 20:25:27 +03:00
|
|
|
* FolderA is an incoming shared folder and there are no delete permissions.
|
2015-10-06 16:36:54 +03:00
|
|
|
* Thus moving /FolderA/test.txt to /test.txt should fail already on that check
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function testMoveSrcNotDeletable() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
|
|
|
$this->expectExceptionMessage('FolderA/test.txt cannot be deleted');
|
|
|
|
|
2017-10-25 01:03:28 +03:00
|
|
|
$fileInfoFolderATestTXT = $this->getMockBuilder(FileInfo::class)
|
2015-10-06 16:36:54 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$fileInfoFolderATestTXT->expects($this->once())
|
|
|
|
->method('isDeletable')
|
|
|
|
->willReturn(false);
|
|
|
|
|
2017-10-25 01:03:28 +03:00
|
|
|
$node = $this->getMockBuilder(Node::class)
|
2016-06-06 18:01:27 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$node->expects($this->once())
|
2015-10-06 16:36:54 +03:00
|
|
|
->method('getFileInfo')
|
|
|
|
->willReturn($fileInfoFolderATestTXT);
|
|
|
|
|
2016-06-06 18:01:27 +03:00
|
|
|
$this->tree->expects($this->once())->method('getNodeForPath')
|
|
|
|
->willReturn($node);
|
|
|
|
|
2015-10-06 16:36:54 +03:00
|
|
|
$this->plugin->checkMove('FolderA/test.txt', 'test.txt');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMoveSrcDeletable() {
|
2017-10-25 01:03:28 +03:00
|
|
|
$fileInfoFolderATestTXT = $this->getMockBuilder(FileInfo::class)
|
2015-10-06 16:36:54 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$fileInfoFolderATestTXT->expects($this->once())
|
|
|
|
->method('isDeletable')
|
|
|
|
->willReturn(true);
|
|
|
|
|
2017-10-25 01:03:28 +03:00
|
|
|
$node = $this->getMockBuilder(Node::class)
|
2016-06-06 18:01:27 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$node->expects($this->once())
|
2015-10-06 16:36:54 +03:00
|
|
|
->method('getFileInfo')
|
|
|
|
->willReturn($fileInfoFolderATestTXT);
|
|
|
|
|
2016-06-06 18:01:27 +03:00
|
|
|
$this->tree->expects($this->once())->method('getNodeForPath')
|
|
|
|
->willReturn($node);
|
|
|
|
|
2015-10-06 16:36:54 +03:00
|
|
|
$this->plugin->checkMove('FolderA/test.txt', 'test.txt');
|
|
|
|
}
|
2015-10-27 11:14:28 +03:00
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2015-10-27 11:14:28 +03:00
|
|
|
public function testMoveSrcNotExist() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
|
|
|
$this->expectExceptionMessage('FolderA/test.txt does not exist');
|
|
|
|
|
2017-10-25 01:03:28 +03:00
|
|
|
$node = $this->getMockBuilder(Node::class)
|
2016-06-06 18:01:27 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$node->expects($this->once())
|
2015-10-27 11:14:28 +03:00
|
|
|
->method('getFileInfo')
|
2016-06-06 18:01:27 +03:00
|
|
|
->willReturn(null);
|
|
|
|
|
|
|
|
$this->tree->expects($this->once())->method('getNodeForPath')
|
|
|
|
->willReturn($node);
|
2015-10-27 11:14:28 +03:00
|
|
|
|
|
|
|
$this->plugin->checkMove('FolderA/test.txt', 'test.txt');
|
|
|
|
}
|
2016-06-09 12:29:20 +03:00
|
|
|
|
|
|
|
public function downloadHeadersProvider() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
false,
|
|
|
|
'attachment; filename*=UTF-8\'\'somefile.xml; filename="somefile.xml"'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
true,
|
|
|
|
'attachment; filename="somefile.xml"'
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider downloadHeadersProvider
|
|
|
|
*/
|
|
|
|
public function testDownloadHeaders($isClumsyAgent, $contentDispositionHeader) {
|
2016-10-13 13:15:10 +03:00
|
|
|
$request = $this->getMockBuilder(RequestInterface::class)
|
2016-06-09 12:29:20 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-10-13 13:15:10 +03:00
|
|
|
$response = $this->getMockBuilder(ResponseInterface::class)
|
2016-06-09 12:29:20 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getPath')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('test/somefile.xml');
|
2016-06-09 12:29:20 +03:00
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$node = $this->getMockBuilder(File::class)
|
2016-06-09 12:29:20 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$node
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('somefile.xml');
|
2016-06-09 12:29:20 +03:00
|
|
|
|
|
|
|
$this->tree
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getNodeForPath')
|
|
|
|
->with('test/somefile.xml')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($node);
|
2016-06-09 12:29:20 +03:00
|
|
|
|
|
|
|
$this->request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAgent')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($isClumsyAgent);
|
2016-06-09 12:29:20 +03:00
|
|
|
|
|
|
|
$response
|
2021-02-22 17:59:26 +03:00
|
|
|
->expects($this->exactly(2))
|
2016-06-09 12:29:20 +03:00
|
|
|
->method('addHeader')
|
2021-02-22 17:59:26 +03:00
|
|
|
->withConsecutive(
|
|
|
|
['Content-Disposition', $contentDispositionHeader],
|
|
|
|
['X-Accel-Buffering', 'no']
|
|
|
|
);
|
2016-06-09 12:29:20 +03:00
|
|
|
|
|
|
|
$this->plugin->httpGet($request, $response);
|
|
|
|
}
|
2016-07-26 14:15:12 +03:00
|
|
|
|
|
|
|
public function testHasPreview() {
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit\Framework\MockObject\MockObject $node */
|
2016-07-26 14:15:12 +03:00
|
|
|
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
|
|
|
|
|
|
|
|
$propFind = new PropFind(
|
|
|
|
'/dummyPath',
|
2020-03-26 11:30:18 +03:00
|
|
|
[
|
2016-07-26 14:15:12 +03:00
|
|
|
self::HAS_PREVIEW_PROPERTYNAME
|
2020-03-26 11:30:18 +03:00
|
|
|
],
|
2016-07-26 14:15:12 +03:00
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->previewManager->expects($this->once())
|
|
|
|
->method('isAvailable')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2016-07-26 14:15:12 +03:00
|
|
|
|
|
|
|
$this->plugin->handleGetProperties(
|
|
|
|
$propFind,
|
|
|
|
$node
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals("false", $propFind->get(self::HAS_PREVIEW_PROPERTYNAME));
|
|
|
|
}
|
2015-02-12 14:29:01 +03:00
|
|
|
}
|