diff --git a/composer.json b/composer.json index f75ab59e..e9075cfd 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", "psalm": "psalm.phar --threads=1", - "psalm:update-baseline": "psalm.phar --threads=1 --update-baseline --set-baseline=tests/psalm-baseline.xml", + "psalm:update-baseline": "psalm.phar --threads=1 --update-baseline", "psalm:clear": "psalm.phar --clear-cache && psalm --clear-global-cache", "psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType", "test": "phpunit --configuration phpunit.xml --fail-on-warning", diff --git a/composer.lock b/composer.lock index 8836c82b..6c562479 100644 --- a/composer.lock +++ b/composer.lock @@ -13,17 +13,17 @@ "source": { "type": "git", "url": "https://github.com/ChristophWurst/nextcloud_composer.git", - "reference": "19c58278e072ef28bcce2370995b785aca350149" + "reference": "9f9f727cf66a75ece93cee24c01074a477e1615e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/19c58278e072ef28bcce2370995b785aca350149", - "reference": "19c58278e072ef28bcce2370995b785aca350149", + "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/9f9f727cf66a75ece93cee24c01074a477e1615e", + "reference": "9f9f727cf66a75ece93cee24c01074a477e1615e", "shasum": "" }, "require": { "php": "^7.4 || ~8.0 || ~8.1", - "psr/container": "^1.0", + "psr/container": "^1.1.1", "psr/event-dispatcher": "^1.0", "psr/log": "^1.1" }, @@ -31,7 +31,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "24.0.0-dev" + "dev-master": "25.0.0-dev" } }, "notification-url": "https://packagist.org/downloads/", @@ -49,7 +49,7 @@ "issues": "https://github.com/ChristophWurst/nextcloud_composer/issues", "source": "https://github.com/ChristophWurst/nextcloud_composer/tree/master" }, - "time": "2022-04-07T01:42:11+00:00" + "time": "2022-08-18T02:33:31+00:00" }, { "name": "composer/pcre", @@ -4250,5 +4250,5 @@ "platform-overrides": { "php": "7.4" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/lib/Connector/Sabre/APlugin.php b/lib/Connector/Sabre/APlugin.php index 20b71fb3..1b107f74 100644 --- a/lib/Connector/Sabre/APlugin.php +++ b/lib/Connector/Sabre/APlugin.php @@ -22,9 +22,7 @@ */ namespace OCA\EndToEndEncryption\Connector\Sabre; -use OCP\AppFramework\Http; use OCA\DAV\Connector\Sabre\Directory; -use OCA\DAV\Connector\Sabre\Exception\Forbidden; use OCA\DAV\Connector\Sabre\File; use OCA\EndToEndEncryption\E2EEnabledPathCache; use OCP\Files\IRootFolder; @@ -99,29 +97,11 @@ protected function getNodeForPath(string $path): INode { throw new Conflict(); } - /** - * Get file system node of requested file - * @throws NotFound - */ - protected function getFileNode(string $path): Node { - $user = $this->userSession->getUser(); - if ($user === null) { - throw new Forbidden('No user session found'); - } - $uid = $user->getUID(); - return $this->pathCache->getFileNode($uid, $path, $this->rootFolder); - } - /** * Checks if the path is an E2E folder or inside an E2E folder */ - protected function isE2EEnabledPath(string $path): bool { - try { - $node = $this->getFileNode($path); - } catch (NotFound $e) { - return false; - } - return $this->pathCache->isE2EEnabledPath($node, $path); + protected function isE2EEnabledPath(\OCA\DAV\Connector\Sabre\Node $node): bool { + return $this->pathCache->isE2EEnabledPath($node->getNode()); } /** diff --git a/lib/Connector/Sabre/LockPlugin.php b/lib/Connector/Sabre/LockPlugin.php index a84f7f92..b1e1ea1a 100644 --- a/lib/Connector/Sabre/LockPlugin.php +++ b/lib/Connector/Sabre/LockPlugin.php @@ -98,21 +98,21 @@ public function checkLock(RequestInterface $request): void { $destNode = $this->getNode($destInfo['destination'], $method); if ($node instanceof FutureFile) { - if ($this->isE2EEnabledPath($destNode->getPath()) === false) { + if ($this->isE2EEnabledPath($destNode) === false) { return; } } else { // If neither is an end to end encrypted folders, we don't care - if (!$this->isE2EEnabledPath($node->getPath()) && !$this->isE2EEnabledPath($destNode->getPath())) { + if (!$this->isE2EEnabledPath($node) && !$this->isE2EEnabledPath($destNode)) { return; } // Prevent moving or copying stuff from non-encrypted to encrypted folders - if ($this->isE2EEnabledPath($node->getPath()) xor $this->isE2EEnabledPath($destNode->getPath())) { + if ($this->isE2EEnabledPath($node) xor $this->isE2EEnabledPath($destNode)) { throw new Forbidden('Cannot copy or move files from non-encrypted folders to end to end encrypted folders or vice versa.'); } } - } elseif (!$this->isE2EEnabledPath($node->getPath())) { + } elseif (!$this->isE2EEnabledPath($node)) { return; } diff --git a/lib/Connector/Sabre/RedirectRequestPlugin.php b/lib/Connector/Sabre/RedirectRequestPlugin.php index e9e8d9cc..db9a8d52 100644 --- a/lib/Connector/Sabre/RedirectRequestPlugin.php +++ b/lib/Connector/Sabre/RedirectRequestPlugin.php @@ -92,7 +92,7 @@ public function httpCopyMove(RequestInterface $request): void { return; } /** @var File|Directory $node */ - if (!$this->isE2EEnabledPath($node->getPath())) { + if (!$this->isE2EEnabledPath($node)) { return; } @@ -114,7 +114,7 @@ public function httpDelete(RequestInterface $request, ResponseInterface $respons return true; } /** @var File|Directory $node */ - if (!$this->isE2EEnabledPath($node->getPath())) { + if (!$this->isE2EEnabledPath($node)) { // If this is no e2e-enabled path, return true to continue up in the event chain return true; } @@ -149,7 +149,7 @@ public function httpMkColPut(RequestInterface $request): void { return; } /** @var File|Directory $node */ - if (!$this->isE2EEnabledPath($node->getPath())) { + if (!$this->isE2EEnabledPath($node)) { return; } @@ -184,7 +184,7 @@ public function propFind(PropFind $propFind, INode $node): bool { } /** @var File|Directory $node */ - if (!$this->isE2EEnabledPath($node->getPath())) { + if (!$this->isE2EEnabledPath($node)) { return true; } diff --git a/lib/E2EEnabledPathCache.php b/lib/E2EEnabledPathCache.php index 4408628a..291766f5 100644 --- a/lib/E2EEnabledPathCache.php +++ b/lib/E2EEnabledPathCache.php @@ -24,68 +24,37 @@ namespace OCA\EndToEndEncryption; -use Sabre\DAV\INode; use OCP\Files\Node; use OCP\Files\Storage\IStorage; use OCP\Files\IHomeStorage; use OCP\Files\Cache\ICache; use OCP\Cache\CappedMemoryCache; -use Sabre\DAV\Exception\NotFound; class E2EEnabledPathCache { /** * @psalm-type EncryptedState=bool * - * @psalm-type Path=string - * - * @psalm-type StorageId=string|int + * @psalm-type FileId=int */ - /** @var CappedMemoryCache> */ private CappedMemoryCache $perStorageEncryptedStateCache; public function __construct() { $this->perStorageEncryptedStateCache = new CappedMemoryCache(); - $this->nodeCache = []; } /** * Checks if the path is an E2E folder or inside an E2E folder - * - * @param INode&Node $node */ - public function isE2EEnabledPath($node): bool { + public function isE2EEnabledPath(Node $node): bool { + if ($node->isEncrypted()) { + return true; + } $storage = $node->getStorage(); $cache = $storage->getCache(); return $this->getEncryptedStates($cache, $node, $storage); } - /** - * Get file system node of requested file - * @throws NotFound - */ - public function getFileNode($uid, string $path, $rootFolder): Node { - if (!isset($this->nodeCache[$uid])) { - $this->nodeCache[$uid] = []; - } else if (isset($this->nodeCache[$uid][$path])) { - $node = $this->nodeCache[$uid][$path]; - if ($node instanceof \Exception) { - throw new NotFound('file not found', Http::STATUS_NOT_FOUND, $node); - } - return $node; - } - try { - $node = $rootFolder - ->getUserFolder($uid) - ->get($path); - $this->nodeCache[$uid][$path] = $node; - return $node; - } catch (Exception $e) { - $this->nodeCache[$uid][$path] = $e; - throw new NotFound('file not found', Http::STATUS_NOT_FOUND, $e); - } - } - /** * Get the encryption state for the path */ @@ -94,43 +63,36 @@ protected function getEncryptedStates(ICache $cache, $node, IStorage $storage): return false; } - $storageId = $cache->getNumericStorageId(); - if (isset($this->perStorageEncryptedStateCache[$storageId][$node->getPath()])) { - return $this->perStorageEncryptedStateCache[$storageId][$node->getPath()]; + $storageId = (string)$cache->getNumericStorageId(); + if (!isset($this->perStorageEncryptedStateCache[$storageId])) { + $this->perStorageEncryptedStateCache[$storageId] = []; + } + if (isset($this->perStorageEncryptedStateCache[$storageId][$node->getId()])) { + return $this->perStorageEncryptedStateCache[$storageId][$node->getId()]; } $parentIds = []; - if ($node->getPath() === '/' || $node->getPath() === '') { + if ($node->getPath() === '/') { // root is never encrypted - $this->perStorageEncryptedStateCache[$storageId][$node->getPath()] = false; + $this->perStorageEncryptedStateCache[$storageId][$node->getId()] = false; return false; } if ($node->isEncrypted()) { // no need to go further down in the tree - $this->perStorageEncryptedStateCache[$storageId][$node->getPath()] = true; + $this->perStorageEncryptedStateCache[$storageId][$node->getId()] = true; return true; } // go down more, but try first just with the parent path to spare a lot of // queries if already cached - $parentPath = $this->dirname($node->getPath()); - if (isset($this->perStorageEncryptedStateCache[$storageId][$parentPath])) { - return $this->perStorageEncryptedStateCache[$storageId][$parentPath]; - } - - if ($parentPath === '/' || $parentPath === '.') { - $this->perStorageEncryptedStateCache[$storageId][$node->getPath()] = false; - return false; + $parentId = $node->getFileInfo()['parent']; + if (isset($this->perStorageEncryptedStateCache[$storageId][$parentId])) { + return $this->perStorageEncryptedStateCache[$storageId][$parentId]; } $encrypted = $this->getEncryptedStates($cache, $node->getParent(), $storage); - $this->perStorageEncryptedStateCache[$storageId][$node->getPath()] = $encrypted; + $this->perStorageEncryptedStateCache[$storageId][$node->getId()] = $encrypted; return $encrypted; } - - protected function dirname(string $path): string { - $dir = dirname($path); - return $dir === '.' ? '' : $dir; - } } diff --git a/tests/Unit/Connector/Sabre/LockPluginTest.php b/tests/Unit/Connector/Sabre/LockPluginTest.php index 4e666a7b..998f33f1 100644 --- a/tests/Unit/Connector/Sabre/LockPluginTest.php +++ b/tests/Unit/Connector/Sabre/LockPluginTest.php @@ -34,10 +34,11 @@ use OCA\EndToEndEncryption\E2EEnabledPathCache; use OCP\Files\FileInfo; use OCP\Files\IRootFolder; -use OCP\Files\Storage\IStorage; use OCP\Files\IHomeStorage; -use OCP\Files\Node; +use OC\Files\Node\Node; use OCP\IUserSession; +use OCP\Files\Cache\ICache; +use OCP\Files\Storage\IStorage; use Sabre\CalDAV\ICalendar; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\INode; @@ -161,9 +162,6 @@ public function testCheckLockNonCopyMoveNoE2EPath(string $method):void { $path = '/path/123'; $url = 'url://path/123'; $node = $this->createMock(File::class); - $node->expects($this->once()) - ->method('getPath') - ->willReturn('/node/path/123'); $plugin->expects($this->once()) ->method('isFile') @@ -177,7 +175,7 @@ public function testCheckLockNonCopyMoveNoE2EPath(string $method):void { $plugin->expects($this->once()) ->method('isE2EEnabledPath') - ->with('/node/path/123') + ->with($node) ->willReturn(false); $request = $this->createMock(RequestInterface::class); @@ -216,9 +214,6 @@ public function testCheckLockBlockUnsupportedClients(string $method): void { $url = 'url://path/123'; $node = $this->createMock(File::class); $userAgentString = 'User-Agent-String'; - $node->expects($this->once()) - ->method('getPath') - ->willReturn('/node/path/123'); $plugin->expects($this->once()) ->method('isFile') @@ -232,7 +227,7 @@ public function testCheckLockBlockUnsupportedClients(string $method): void { $plugin->expects($this->once()) ->method('isE2EEnabledPath') - ->with('/node/path/123') + ->with($node) ->willReturn(true); $plugin->expects($this->once()) @@ -303,9 +298,6 @@ public function testCheckLockForWrite(string $method, $url = 'url://path/123'; $node = $this->createMock(File::class); $userAgentString = 'User-Agent-String'; - $node->expects($this->once()) - ->method('getPath') - ->willReturn('/node/path/123'); if ($expectsForbidden) { $node->expects($this->never()) @@ -328,7 +320,7 @@ public function testCheckLockForWrite(string $method, $plugin->expects($this->once()) ->method('isE2EEnabledPath') - ->with('/node/path/123') + ->with($node) ->willReturn(true); $plugin->expects($this->once()) @@ -435,11 +427,9 @@ public function testCheckLockForWriteCopyMove(string $method, $srcNode = $this->createMock(FutureFile::class); } else { $srcNode = $this->createMock(File::class); - $srcNode->method('getPath')->willReturn('/path/src/'); $srcNode->method('getId')->willReturn(42); } $destNode = $this->createMock(File::class); - $destNode->method('getPath')->willReturn('/path/dest/'); $destNode->method('getId')->willReturn(1337); $path = '/path/123'; @@ -478,8 +468,8 @@ public function testCheckLockForWriteCopyMove(string $method, $plugin->method('isE2EEnabledPath') ->willReturnMap([ - ['/path/src/', $isSrcE2E], - ['/path/dest/', $isDestE2E], + [$srcNode, $isSrcE2E], + [$destNode, $isDestE2E], ]); $plugin->method('isE2EEnabledUserAgent') @@ -571,30 +561,8 @@ public function testIsFileDirectory(): void { $this->assertTrue($actual); } - public function testIsE2EEnabledPathNotFound():void { - $plugin = $this->getMockBuilder(LockPlugin::class) - ->setMethods(['getFileNode']) - ->setConstructorArgs([ - $this->rootFolder, - $this->userSession, - $this->lockManager, - $this->userAgentManager, - $this->pathCache, - ]) - ->getMock(); - - $plugin->expects($this->once()) - ->method('getFileNode') - ->with('path-123') - ->willThrowException(new NotFound()); - - $actual = self::invokePrivate($plugin, 'isE2EEnabledPath', ['path-123']); - $this->assertFalse($actual); - } - public function testIsE2EEnabledPathEncryptedFolder():void { $plugin = $this->getMockBuilder(LockPlugin::class) - ->setMethods(['getFileNode']) ->setConstructorArgs([ $this->rootFolder, $this->userSession, @@ -604,47 +572,26 @@ public function testIsE2EEnabledPathEncryptedFolder():void { ]) ->getMock(); - $cache = $this->createMock(\OCP\Files\Storage\IStorage::class); - $cache->expects($this->any()) - ->method('getNumericStorageId') - ->willReturn(42); - - $storage = $this->createMock(\OCP\Files\Storage\IStorage::class); - $storage->expects($this->once()) - ->method('getCache') - ->willReturn($cache); - $storage->expects($this->any()) - ->method('instanceOfStorage') - ->with(IHomeStorage::class) - ->willReturn(true); - $node = $this->createMock(Node::class); $node->expects($this->once()) ->method('isEncrypted') ->willReturn(true); - $node->expects($this->once()) - ->method('getStorage') - ->willReturn($storage); - - $plugin->expects($this->once()) - ->method('getFileNode') - ->with('path-123') - ->willReturn($node); + $davNode = $this->createMock(\OCA\DAV\Connector\Sabre\Node::class); + $davNode->method('getNode')->willReturn($node); - $actual = self::invokePrivate($plugin, 'isE2EEnabledPath', ['path-123']); + $actual = self::invokePrivate($plugin, 'isE2EEnabledPath', [$davNode]); $this->assertTrue($actual); } public function testIsE2EEnabledPathParentEncrypted():void { $plugin = $this->getMockBuilder(LockPlugin::class) - ->setMethods(['getFileNode']) ->setConstructorArgs([ $this->rootFolder, $this->userSession, $this->lockManager, $this->userAgentManager, - $this->pathCache, + new E2EEnabledPathCache(), ]) ->getMock(); @@ -652,38 +599,50 @@ public function testIsE2EEnabledPathParentEncrypted():void { $encryptedParentParentNode->expects($this->once()) ->method('isEncrypted') ->willReturn(true); - $encryptedParentParentNode->expects($this->once()) - ->method('getType') - ->willReturn(FileInfo::TYPE_FOLDER); - $encryptedParentParentNode->expects($this->once()) - ->method('getPath') - ->willReturn('/sub1/sub2/'); + $encryptedParentParentNode->method('getId') + ->willReturn(1); + $encryptedParentParentNode->method('getFileInfo') + ->willReturn(['parent' => 0]); $parentNode = $this->createMock(Node::class); $parentNode->expects($this->once()) ->method('isEncrypted') ->willReturn(false); - $parentNode->expects($this->once()) - ->method('getPath') - ->willReturn('/sub1/sub2/sub3/'); $parentNode->expects($this->once()) ->method('getParent') ->willReturn($encryptedParentParentNode); + $parentNode->method('getId') + ->willReturn(2); + $parentNode->method('getFileInfo') + ->willReturn(['parent' => 1]); $fileNode = $this->createMock(Node::class); - $fileNode->expects($this->once()) + $fileNode->expects($this->atLeastOnce()) ->method('isEncrypted') ->willReturn(false); + $cache = $this->createMock(ICache::class); + $cache->method('getNumericStorageId') + ->willReturn(1); + $storage = $this->createMock(IStorage::class); + $storage->method('instanceOfStorage') + ->willReturn(true); + $storage->method('getCache') + ->willReturn($cache); + $fileNode->expects($this->once()) + ->method('getStorage') + ->willReturn($storage); $fileNode->expects($this->once()) ->method('getParent') ->willReturn($parentNode); + $fileNode->method('getId') + ->willReturn(3); + $fileNode->method('getFileInfo') + ->willReturn(['parent' => 2]); - $plugin->expects($this->once()) - ->method('getFileNode') - ->with('path-123') - ->willReturn($fileNode); + $davNode = $this->createMock(\OCA\DAV\Connector\Sabre\Node::class); + $davNode->method('getNode')->willReturn($fileNode); - $actual = self::invokePrivate($plugin, 'isE2EEnabledPath', ['path-123']); + $actual = self::invokePrivate($plugin, 'isE2EEnabledPath', [$davNode]); $this->assertTrue($actual); } @@ -695,11 +654,15 @@ public function testIsE2EEnabledPathNonEncrypted():void { $this->userSession, $this->lockManager, $this->userAgentManager, - $this->pathCache, + new E2EEnabledPathCache(), ]) ->getMock(); $encryptedParentParentNode = $this->createMock(Node::class); + $encryptedParentParentNode->method('getId') + ->willReturn(1); + $encryptedParentParentNode->method('getFileInfo') + ->willReturn(['parent' => 0]); $encryptedParentParentNode->expects($this->once()) ->method('getPath') ->willReturn('/'); @@ -708,27 +671,44 @@ public function testIsE2EEnabledPathNonEncrypted():void { $parentNode->expects($this->once()) ->method('isEncrypted') ->willReturn(false); - $parentNode->expects($this->once()) - ->method('getPath') - ->willReturn('/sub1/'); $parentNode->expects($this->once()) ->method('getParent') ->willReturn($encryptedParentParentNode); + $parentNode->method('getId') + ->willReturn(2); + $parentNode->method('getFileInfo') + ->willReturn(['parent' => 1]); + + $cache = $this->createMock(ICache::class); + $cache->method('getNumericStorageId') + ->willReturn(1); + $storage = $this->createMock(IStorage::class); + $storage->method('instanceOfStorage') + ->willReturn(true); + $storage->method('getCache') + ->willReturn($cache); $fileNode = $this->createMock(Node::class); - $fileNode->expects($this->once()) + $fileNode->expects($this->atLeastOnce()) ->method('isEncrypted') ->willReturn(false); $fileNode->expects($this->once()) ->method('getParent') ->willReturn($parentNode); + $fileNode->expects($this->once()) + ->method('getPath') + ->willReturn('/data/rere/re'); + $fileNode->method('getId') + ->willReturn(3); + $fileNode->method('getFileInfo') + ->willReturn(['parent' => 2]); + $fileNode->method('getStorage') + ->willReturn($storage); - $plugin->expects($this->once()) - ->method('getFileNode') - ->with('path-123') - ->willReturn($fileNode); + $davNode = $this->createMock(\OCA\DAV\Connector\Sabre\Node::class); + $davNode->method('getNode')->willReturn($fileNode); - $actual = self::invokePrivate($plugin, 'isE2EEnabledPath', ['path-123']); + $actual = self::invokePrivate($plugin, 'isE2EEnabledPath', [$davNode]); $this->assertFalse($actual); } diff --git a/tests/Unit/Connector/Sabre/PropFindPluginTest.php b/tests/Unit/Connector/Sabre/PropFindPluginTest.php index e3264c0f..943bf68b 100644 --- a/tests/Unit/Connector/Sabre/PropFindPluginTest.php +++ b/tests/Unit/Connector/Sabre/PropFindPluginTest.php @@ -79,13 +79,12 @@ protected function setUp(): void { public function testInitialize(): void { $server = $this->createMock(Server::class); - $server->expects($this->at(0)) - ->method('on') - ->with('afterMethod:PROPFIND', [$this->plugin, 'checkAccess'], 50); - - $server->expects($this->at(1)) - ->method('on') - ->with('propFind', [$this->plugin, 'updateProperty'], 105); + $server->expects($this->atLeast(2)) + ->method('on') + ->withConsecutive( + ['afterMethod:PROPFIND', [$this->plugin, 'checkAccess'], 50], + ['propFind', [$this->plugin, 'updateProperty'], 105], + ); $this->plugin->initialize($server); } @@ -125,24 +124,24 @@ public function testUpdateProperty(bool $supportedUserAgent, bool $fileEncrypted $this->plugin->initialize($server); - $this->request->expects($this->at(0)) + $this->request->expects($this->once()) ->method('getHeader') ->with('USER_AGENT') ->willReturn('User-Agent-String'); - $this->userAgentManager->expects($this->at(0)) + $this->userAgentManager->expects($this->once()) ->method('supportsEndToEndEncryption') ->with('User-Agent-String') ->willReturn($supportedUserAgent); if (!$supportedUserAgent) { - $propFind->expects($this->at(0)) + $propFind->expects($this->once()) ->method('get') ->with('{http://nextcloud.org/ns}is-encrypted') ->willReturn($fileEncrypted ? '1' : '0'); if ($fileEncrypted) { - $propFind->expects($this->at(1)) + $propFind->expects($this->once()) ->method('set') ->with('{http://owncloud.org/ns}permissions', '', 200); } else { diff --git a/tests/Unit/Connector/Sabre/RedirectRequestPluginTest.php b/tests/Unit/Connector/Sabre/RedirectRequestPluginTest.php index 854fbee2..c7f55c17 100644 --- a/tests/Unit/Connector/Sabre/RedirectRequestPluginTest.php +++ b/tests/Unit/Connector/Sabre/RedirectRequestPluginTest.php @@ -117,9 +117,6 @@ public function testHttpCopyMoveInsideE2E(): void { ->with('Destination', '/foo/bar/DestinationPath123.e2e-to-save'); $node = $this->createMock(File::class); - $node->expects($this->once()) - ->method('getPath') - ->willReturn('/random/path/'); $plugin->expects($this->once()) ->method('getNode') @@ -127,7 +124,7 @@ public function testHttpCopyMoveInsideE2E(): void { ->willReturn($node); $plugin->expects($this->once()) ->method('isE2EEnabledPath') - ->with('/random/path/') + ->with($node) ->willReturn(true); $plugin->expects($this->once()) ->method('isFile') @@ -167,9 +164,6 @@ public function testHttpCopyMoveInsideE2EOriginalMethodDelete(): void { ->method('setHeader'); $node = $this->createMock(File::class); - $node->expects($this->once()) - ->method('getPath') - ->willReturn('/random/path/'); $plugin->expects($this->once()) ->method('getNode') @@ -177,7 +171,7 @@ public function testHttpCopyMoveInsideE2EOriginalMethodDelete(): void { ->willReturn($node); $plugin->expects($this->once()) ->method('isE2EEnabledPath') - ->with('/random/path/') + ->with($node) ->willReturn(true); $plugin->expects($this->once()) ->method('isFile') @@ -242,9 +236,6 @@ public function testHttpCopyMoveOutsideE2E(): void { ->method('setHeader'); $node = $this->createMock(File::class); - $node->expects($this->once()) - ->method('getPath') - ->willReturn('/random/path/'); $plugin->expects($this->once()) ->method('getNode') @@ -252,7 +243,7 @@ public function testHttpCopyMoveOutsideE2E(): void { ->willReturn($node); $plugin->expects($this->once()) ->method('isE2EEnabledPath') - ->with('/random/path/') + ->with($node) ->willReturn(false); $plugin->expects($this->once()) ->method('isFile') @@ -288,9 +279,6 @@ public function testHttpMkColPutInsideE2E(): void { ->with('http://username:password@hostname:9090/path/123/foo.e2e-to-save?arg=value#anchor'); $node = $this->createMock(File::class); - $node->expects($this->once()) - ->method('getPath') - ->willReturn('/random/path/'); $plugin->expects($this->once()) ->method('getNode') @@ -298,7 +286,7 @@ public function testHttpMkColPutInsideE2E(): void { ->willReturn($node); $plugin->expects($this->once()) ->method('isE2EEnabledPath') - ->with('/random/path/') + ->with($node) ->willReturn(true); $plugin->expects($this->once()) ->method('isFile') @@ -363,9 +351,6 @@ public function testHttpMkColPutOutsideE2E(): void { ->method('setUrl'); $node = $this->createMock(File::class); - $node->expects($this->once()) - ->method('getPath') - ->willReturn('/random/path/'); $plugin->expects($this->once()) ->method('getNode') @@ -377,7 +362,7 @@ public function testHttpMkColPutOutsideE2E(): void { ->willReturn(true); $plugin->expects($this->once()) ->method('isE2EEnabledPath') - ->with('/random/path/') + ->with($node) ->willReturn(false); $plugin->httpMkColPut($request); diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 5e623b62..d553aba7 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -7,9 +7,6 @@ - - $node - $this->server->tree @@ -34,16 +31,4 @@ $this->server->tree - - - CappedMemoryCache - - - $this->perStorageEncryptedStateCache - $this->perStorageEncryptedStateCache - $this->perStorageEncryptedStateCache - $this->perStorageEncryptedStateCache - CappedMemoryCache - - diff --git a/tests/stub.phpstub b/tests/stub.phpstub index 3d1ab8cb..df0a2581 100644 --- a/tests/stub.phpstub +++ b/tests/stub.phpstub @@ -76,8 +76,13 @@ namespace Sabre\Dav { } namespace OCA\DAV\Connector\Sabre { - class File extends \Sabre\Dav\INode {} - class Directory extends \Sabre\Dav\INode {} + class Node extends \Sabre\Dav\INode { + public function getNode(): \OCP\Files\Node { + + } + } + class File extends Node {} + class Directory extends Node {} } namespace OCA\DAV\Connector\Sabre\Exception {