Merge pull request #20570 from nextcloud/fix/20235/use_uploadfile

Use a proper upload file so propfinds return 404
This commit is contained in:
Roeland Jago Douma 2020-04-24 16:31:38 +02:00 committed by GitHub
commit 768b012000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 129 additions and 3 deletions

View File

@ -223,6 +223,7 @@ return array(
'OCA\\DAV\\Upload\\CleanupService' => $baseDir . '/../lib/Upload/CleanupService.php',
'OCA\\DAV\\Upload\\FutureFile' => $baseDir . '/../lib/Upload/FutureFile.php',
'OCA\\DAV\\Upload\\RootCollection' => $baseDir . '/../lib/Upload/RootCollection.php',
'OCA\\DAV\\Upload\\UploadFile' => $baseDir . '/../lib/Upload/UploadFile.php',
'OCA\\DAV\\Upload\\UploadFolder' => $baseDir . '/../lib/Upload/UploadFolder.php',
'OCA\\DAV\\Upload\\UploadHome' => $baseDir . '/../lib/Upload/UploadHome.php',
);

View File

@ -238,6 +238,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Upload\\CleanupService' => __DIR__ . '/..' . '/../lib/Upload/CleanupService.php',
'OCA\\DAV\\Upload\\FutureFile' => __DIR__ . '/..' . '/../lib/Upload/FutureFile.php',
'OCA\\DAV\\Upload\\RootCollection' => __DIR__ . '/..' . '/../lib/Upload/RootCollection.php',
'OCA\\DAV\\Upload\\UploadFile' => __DIR__ . '/..' . '/../lib/Upload/UploadFile.php',
'OCA\\DAV\\Upload\\UploadFolder' => __DIR__ . '/..' . '/../lib/Upload/UploadFolder.php',
'OCA\\DAV\\Upload\\UploadHome' => __DIR__ . '/..' . '/../lib/Upload/UploadHome.php',
);

View File

@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\Upload;
use OCA\DAV\Connector\Sabre\File;
use Sabre\DAV\IFile;
class UploadFile implements IFile {
/** @var File */
private $file;
public function __construct(File $file) {
$this->file = $file;
}
public function put($data) {
return $this->file->put($data);
}
public function get() {
return $this->file->get();
}
public function getContentType() {
return $this->file->getContentType();
}
public function getETag() {
return $this->file->getETag();
}
public function getSize() {
return $this->file->getSize();
}
public function delete() {
$this->file->delete();
}
public function getName() {
return $this->file->getName();
}
public function setName($name) {
$this->file->setName($name);
}
public function getLastModified() {
return $this->file->getLastModified();
}
}

View File

@ -53,12 +53,19 @@ class UploadFolder implements ICollection {
if ($name === '.file') {
return new FutureFile($this->node, '.file');
}
return $this->node->getChild($name);
return new UploadFile($this->node->getChild($name));
}
public function getChildren() {
$children = $this->node->getChildren();
$tmpChildren = $this->node->getChildren();
$children = [];
$children[] = new FutureFile($this->node, '.file');
foreach ($tmpChildren as $child) {
$children[] = new UploadFile($child);
}
return $children;
}

View File

@ -32,6 +32,7 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\File;
use OCA\DAV\Connector\Sabre\Node;
use OCA\DAV\Upload\UploadFile;
use OCP\Files\Folder;
use OCP\IUser;
use OCP\IUserSession;
@ -189,7 +190,7 @@ class SharesPluginTest extends \Test\TestCase {
$this->userFolder->method('get')
->with('/subdir')
->willReturn($node);
$dummyShares = array_map(function ($type) {
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->expects($this->any())
@ -282,4 +283,24 @@ class SharesPluginTest extends \Test\TestCase {
[[\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_REMOTE]],
];
}
public function testGetPropertiesSkipChunks(): void {
$sabreNode = $this->getMockBuilder(UploadFile::class)
->disableOriginalConstructor()
->getMock();
$propFind = new \Sabre\DAV\PropFind(
'/dummyPath',
[self::SHARETYPES_PROPERTYNAME],
0
);
$this->plugin->handleGetProperties(
$propFind,
$sabreNode
);
$result = $propFind->getResultForMultiStatus();
$this->assertCount(1, $result[404]);
}
}

View File

@ -30,6 +30,7 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\File;
use OCA\DAV\Connector\Sabre\Node;
use OCA\DAV\Upload\UploadFile;
use OCP\ITagManager;
use OCP\ITags;
use Sabre\DAV\Tree;
@ -266,6 +267,26 @@ class TagsPluginTest extends \Test\TestCase {
];
}
public function testGetPropertiesSkipChunks(): void {
$sabreNode = $this->getMockBuilder(UploadFile::class)
->disableOriginalConstructor()
->getMock();
$propFind = new \Sabre\DAV\PropFind(
'/dummyPath',
[self::TAGS_PROPERTYNAME, self::TAG_FAVORITE],
0
);
$this->plugin->handleGetProperties(
$propFind,
$sabreNode
);
$result = $propFind->getResultForMultiStatus();
$this->assertCount(2, $result[404]);
}
public function testUpdateTags() {
// this test will replace the existing tags "tagremove" with "tag1" and "tag2"
// and keep "tagkeep"