Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use existing node in SharesPlugin
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Apr 6, 2022
commit ae7205f550d12d713b0b079eb0889c8f3bafb42b
4 changes: 2 additions & 2 deletions apps/dav/lib/Connector/Sabre/SharesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function getShares(DavNode $sabreNode): array {
// if we already cached the folder this file is in we know there are no shares for this file
if (array_search($parentPath, $this->cachedFolders) === false) {
try {
$node = $this->userFolder->get($sabreNode->getPath());
$node = $sabreNode->getNode();
} catch (NotFoundException $e) {
return [];
}
Expand Down Expand Up @@ -202,7 +202,7 @@ public function handleGetProperties(
)
) {
try {
$folderNode = $this->userFolder->get($sabreNode->getPath());
$folderNode = $sabreNode->getNode();
} catch (NotFoundException $e) {
// If the folder can't be properly found just return
return;
Expand Down
36 changes: 22 additions & 14 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace OCA\DAV\Tests\Unit\Connector\Sabre;

use OC\Files\FileInfo;
use OC\Files\Node\Node;
use OC\Files\Storage\Wrapper\Quota;
use OCA\DAV\Connector\Sabre\Directory;
use OCP\Files\ForbiddenException;
Expand Down Expand Up @@ -82,9 +83,12 @@ protected function setUp(): void {

$this->view = $this->createMock('OC\Files\View');
$this->info = $this->createMock('OC\Files\FileInfo');
$this->info->expects($this->any())
->method('isReadable')
$this->info->method('isReadable')
->willReturn(true);
$this->info->method('getType')
->willReturn(Node::TYPE_FOLDER);
$this->info->method('getName')
->willReturn("folder");
}

private function getDir($path = '/') {
Expand Down Expand Up @@ -186,17 +190,17 @@ public function testGetChildren() {
$info2 = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()
->getMock();
$info1->expects($this->any())
->method('getName')
$info1->method('getName')
->willReturn('first');
$info1->expects($this->any())
->method('getEtag')
$info1->method('getPath')
->willReturn('folder/first');
$info1->method('getEtag')
->willReturn('abc');
$info2->expects($this->any())
->method('getName')
$info2->method('getName')
->willReturn('second');
$info2->expects($this->any())
->method('getEtag')
$info2->method('getPath')
->willReturn('folder/second');
$info2->method('getEtag')
->willReturn('def');

$this->view->expects($this->once())
Expand Down Expand Up @@ -403,8 +407,12 @@ public function moveSuccessProvider() {
private function moveTest($source, $destination, $updatables, $deletables) {
$view = new TestViewDirectory($updatables, $deletables);

$sourceInfo = new FileInfo($source, null, null, [], null);
$targetInfo = new FileInfo(dirname($destination), null, null, [], null);
$sourceInfo = new FileInfo($source, null, null, [
'type' => FileInfo::TYPE_FOLDER,
], null);
$targetInfo = new FileInfo(dirname($destination), null, null, [
'type' => FileInfo::TYPE_FOLDER,
], null);

$sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class)
Expand All @@ -429,8 +437,8 @@ public function testFailingMove() {

$view = new TestViewDirectory($updatables, $deletables);

$sourceInfo = new FileInfo($source, null, null, [], null);
$targetInfo = new FileInfo(dirname($destination), null, null, [], null);
$sourceInfo = new FileInfo($source, null, null, ['type' => FileInfo::TYPE_FOLDER], null);
$targetInfo = new FileInfo(dirname($destination), null, null, ['type' => FileInfo::TYPE_FOLDER], null);

$sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class)
Expand Down
67 changes: 47 additions & 20 deletions apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OC\Files\View;
use OCA\DAV\Connector\Sabre\File;
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\ForbiddenException;
use OCP\Files\Storage;
use OCP\IConfig;
Expand Down Expand Up @@ -211,7 +212,8 @@ function ($path) use ($storage) {
->willReturnArgument(0);

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand Down Expand Up @@ -272,7 +274,8 @@ function ($path) use ($storage) {
$_SERVER['HTTP_OC_CHUNKED'] = true;

$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);

Expand All @@ -282,7 +285,8 @@ function ($path) use ($storage) {
$file->releaseLock(ILockingProvider::LOCK_SHARED);

$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);

Expand Down Expand Up @@ -326,7 +330,10 @@ private function doPut($path, $viewRoot = null, Request $request = null) {
$viewRoot . '/' . ltrim($path, '/'),
$this->getMockStorage(),
null,
['permissions' => \OCP\Constants::PERMISSION_ALL],
[
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
],
null
);

Expand Down Expand Up @@ -690,7 +697,8 @@ public function testSimplePutFailsSizeCheck() {
$_SERVER['REQUEST_METHOD'] = 'PUT';

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand Down Expand Up @@ -723,7 +731,8 @@ public function testSimplePutFailsMoveFromStorage() {
$view->lockFile('/test.txt', ILockingProvider::LOCK_EXCLUSIVE);

$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand Down Expand Up @@ -758,15 +767,17 @@ public function testChunkedPutFailsFinalRename() {
$_SERVER['HTTP_OC_CHUNKED'] = true;

$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
$file->acquireLock(ILockingProvider::LOCK_SHARED);
$this->assertNull($file->put('test data one'));
$file->releaseLock(ILockingProvider::LOCK_SHARED);

$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);

Expand Down Expand Up @@ -797,7 +808,8 @@ public function testSimplePutInvalidChars() {
->willReturnArgument(0);

$info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);

Expand Down Expand Up @@ -836,7 +848,8 @@ public function testSetNameInvalidChars() {
->willReturnArgument(0);

$info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
$file->setName('/super*star.txt');
Expand All @@ -863,7 +876,8 @@ public function testUploadAbort() {
$_SERVER['REQUEST_METHOD'] = 'PUT';

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand Down Expand Up @@ -897,7 +911,8 @@ public function testDeleteWhenAllowed() {
->willReturn(true);

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand All @@ -915,7 +930,8 @@ public function testDeleteThrowsWhenDeletionNotAllowed() {
->getMock();

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => 0
'permissions' => 0,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand All @@ -938,7 +954,8 @@ public function testDeleteThrowsWhenDeletionFailed() {
->willReturn(false);

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand All @@ -961,7 +978,8 @@ public function testDeleteThrowsWhenDeletionThrows() {
->willThrowException(new ForbiddenException('', true));

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand Down Expand Up @@ -997,7 +1015,10 @@ public function testPutLocking() {
'/' . $this->user . '/files/' . $path,
$this->getMockStorage(),
null,
['permissions' => \OCP\Constants::PERMISSION_ALL],
[
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
],
null
);

Expand Down Expand Up @@ -1129,7 +1150,8 @@ public function testGetFopenFails() {
->willReturn(false);

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand All @@ -1149,7 +1171,8 @@ public function testGetFopenThrows() {
->willThrowException(new ForbiddenException('', true));

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand All @@ -1168,7 +1191,8 @@ public function testGetThrowsIfNoPermission() {
->method('fopen');

$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_CREATE // no read perm
'permissions' => \OCP\Constants::PERMISSION_CREATE, // no read perm
'type' => FileInfo::TYPE_FOLDER,
], null);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
Expand Down Expand Up @@ -1215,7 +1239,10 @@ public function testPutLockExpired() {
'/' . $this->user . '/files/' . $path,
$this->getMockStorage(),
null,
['permissions' => \OCP\Constants::PERMISSION_ALL],
[
'permissions' => \OCP\Constants::PERMISSION_ALL,
'type' => FileInfo::TYPE_FOLDER,
],
null
);

Expand Down
9 changes: 3 additions & 6 deletions apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,14 @@ public function testGetNodeForPath(
$fileInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()
->getMock();
$fileInfo->expects($this->once())
->method('getType')
$fileInfo->method('getType')
->willReturn($type);
$fileInfo->expects($this->once())
->method('getName')
$fileInfo->method('getName')
->willReturn($outputFileName);
$fileInfo->method('getStorage')
->willReturn($this->createMock(\OC\Files\Storage\Common::class));

$view->expects($this->once())
->method('getFileInfo')
$view->method('getFileInfo')
->with($fileInfoQueryPath)
->willReturn($fileInfo);

Expand Down
15 changes: 8 additions & 7 deletions apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ public function testGetProperties($shareTypes) {
->disableOriginalConstructor()
->getMock();

$this->userFolder->expects($this->once())
->method('get')
->with('/subdir')
$sabreNode->method('getNode')
->willReturn($node);

$this->shareManager->expects($this->any())
Expand Down Expand Up @@ -180,16 +178,19 @@ public function testPreloadThenGetProperties($shareTypes) {
$node = $this->createMock(Folder::class);
$node->method('getId')
->willReturn(123);
$node1 = $this->createMock(File::class);
$node1 = $this->createMock(\OC\Files\Node\File::class);
$node1->method('getId')
->willReturn(111);
$node2 = $this->createMock(File::class);
$node2 = $this->createMock(\OC\Files\Node\File::class);
$node2->method('getId')
->willReturn(222);

$this->userFolder->method('get')
->with('/subdir')
$sabreNode->method('getNode')
->willReturn($node);
$sabreNode1->method('getNode')
->willReturn($node1);
$sabreNode2->method('getNode')
->willReturn($node2);

$dummyShares = array_map(function ($type) {
$share = $this->getMockBuilder(IShare::class)->getMock();
Expand Down