From 6d6dfb63eef733f547ae0c9e362c9881cecdf0cf Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Mon, 20 Apr 2020 21:30:50 +0200 Subject: [PATCH] Ignore sharees and share-types property for chunks inside uploads/ Signed-off-by: Daniel Kesselberg --- apps/dav/lib/Connector/Sabre/SharesPlugin.php | 4 ++ .../unit/Connector/Sabre/SharesPluginTest.php | 61 ++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php index 63c204fda4efc..c950046aa4b9f 100644 --- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php @@ -179,6 +179,10 @@ public function handleGetProperties( return; } + if (strpos($sabreNode->getFileInfo()->getInternalPath(), 'uploads/') === 0) { + return; + } + // need prefetch ? if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory && $propFind->getDepth() !== 0 diff --git a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php index 153bc0cd93bb0..145ffd39dbe63 100644 --- a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php @@ -32,6 +32,8 @@ use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\File; use OCA\DAV\Connector\Sabre\Node; +use OCA\DAV\Connector\Sabre\SharesPlugin; +use OCP\Files\FileInfo; use OCP\Files\Folder; use OCP\IUser; use OCP\IUserSession; @@ -95,9 +97,16 @@ protected function setUp(): void { * @dataProvider sharesGetPropertiesDataProvider */ public function testGetProperties($shareTypes) { + $nodeInfo = $this->getMockBuilder(FileInfo::class) + ->disableOriginalConstructor() + ->getMock(); + $nodeInfo->method('getInternalPath') + ->willReturn('files/subdir'); $sabreNode = $this->getMockBuilder(Node::class) ->disableOriginalConstructor() ->getMock(); + $sabreNode->method('getFileInfo') + ->willReturn($nodeInfo); $sabreNode->expects($this->any()) ->method('getId') ->willReturn(123); @@ -156,16 +165,38 @@ public function testGetProperties($shareTypes) { * @dataProvider sharesGetPropertiesDataProvider */ public function testPreloadThenGetProperties($shareTypes) { + $nodeInfo1 = $this->getMockBuilder(FileInfo::class) + ->disableOriginalConstructor() + ->getMock(); + $nodeInfo1->method('getInternalPath') + ->willReturn('files/subdir/foo'); $sabreNode1 = $this->createMock(File::class); + $sabreNode1->method('getFileInfo') + ->willReturn($nodeInfo1); $sabreNode1->method('getId') ->willReturn(111); + + $nodeInfo2= $this->getMockBuilder(FileInfo::class) + ->disableOriginalConstructor() + ->getMock(); + $nodeInfo2->method('getInternalPath') + ->willReturn('files/subdir/foo'); $sabreNode2 = $this->createMock(File::class); + $sabreNode2->method('getFileInfo') + ->willReturn($nodeInfo2); $sabreNode2->method('getId') ->willReturn(222); $sabreNode2->method('getPath') ->willReturn('/subdir/foo'); + $nodeInfo= $this->getMockBuilder(FileInfo::class) + ->disableOriginalConstructor() + ->getMock(); + $nodeInfo->method('getInternalPath') + ->willReturn('files/subdir'); $sabreNode = $this->createMock(Directory::class); + $sabreNode->method('getFileInfo') + ->willReturn($nodeInfo); $sabreNode->method('getId') ->willReturn(123); // never, because we use getDirectoryListing from the Node API instead @@ -189,7 +220,7 @@ public function testPreloadThenGetProperties($shareTypes) { $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 +313,32 @@ public function sharesGetPropertiesDataProvider() { [[\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_REMOTE]], ]; } + + public function testGetPropertiesSkipChunks(): void { + $nodeInfo = $this->getMockBuilder(FileInfo::class) + ->disableOriginalConstructor() + ->getMock(); + $nodeInfo->method('getInternalPath') + ->willReturn('uploads/a-chunk-file'); + + $sabreNode = $this->getMockBuilder(Node::class) + ->disableOriginalConstructor() + ->getMock(); + $sabreNode->method('getFileInfo') + ->willReturn($nodeInfo); + + $propFind = new \Sabre\DAV\PropFind( + '/dummyPath', + [SharesPlugin::SHARETYPES_PROPERTYNAME], + 0 + ); + + $this->plugin->handleGetProperties( + $propFind, + $sabreNode + ); + + $result = $propFind->getResultForMultiStatus(); + $this->assertCount(1, $result[404]); + } }