From e13fe986cd3f3e869e90abcf4bb72ea662887ff9 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Mon, 26 Aug 2024 19:39:57 +0200 Subject: [PATCH] feat: Own the handling of the is-encrypted DAV property Signed-off-by: Louis Chemineau --- lib/Connector/Sabre/PropFindPlugin.php | 12 ++++++++++++ tests/Unit/Connector/Sabre/PropFindPluginTest.php | 1 + tests/stub.phpstub | 1 + 3 files changed, 14 insertions(+) diff --git a/lib/Connector/Sabre/PropFindPlugin.php b/lib/Connector/Sabre/PropFindPlugin.php index b327aaf0..24b800ac 100644 --- a/lib/Connector/Sabre/PropFindPlugin.php +++ b/lib/Connector/Sabre/PropFindPlugin.php @@ -37,6 +37,8 @@ use Sabre\HTTP\RequestInterface; class PropFindPlugin extends APlugin { + public const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; + private UserAgentManager $userAgentManager; private IRequest $request; protected ?Server $server = null; @@ -59,9 +61,19 @@ public function initialize(Server $server) { $this->server = $server; $this->server->on('afterMethod:PROPFIND', [$this, 'checkAccess'], 50); + $this->server->on('propFind', [$this, 'setEncryptedProperty'], 104); $this->server->on('propFind', [$this, 'updateProperty'], 105); } + public function setEncryptedProperty(PropFind $propFind, \Sabre\DAV\INode $node) { + // Only folders can be e2e encrypted, so we only respond for directories. + if ($node instanceof Directory) { + $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) { + return $node->getFileInfo()->isEncrypted() ? '1' : '0'; + }); + } + } + /** * Remove permissions of end-to-end encrypted files for unsupported clients * diff --git a/tests/Unit/Connector/Sabre/PropFindPluginTest.php b/tests/Unit/Connector/Sabre/PropFindPluginTest.php index 343768e2..38a8b956 100644 --- a/tests/Unit/Connector/Sabre/PropFindPluginTest.php +++ b/tests/Unit/Connector/Sabre/PropFindPluginTest.php @@ -86,6 +86,7 @@ public function testInitialize(): void { ->method('on') ->withConsecutive( ['afterMethod:PROPFIND', [$this->plugin, 'checkAccess'], 50], + ['propFind', [$this->plugin, 'setEncryptedProperty'], 104], ['propFind', [$this->plugin, 'updateProperty'], 105], ); diff --git a/tests/stub.phpstub b/tests/stub.phpstub index 1624ecd8..5e7d4929 100644 --- a/tests/stub.phpstub +++ b/tests/stub.phpstub @@ -65,6 +65,7 @@ namespace Sabre\DAV { public function set(string $key, string $value, int $stuff) {} public function getPath(): string {} public function setPath(string $string): void {} + public function handle($propertyName, $valueOrCallBack) } class Server {