Skip to content

Commit c0f3fcd

Browse files
authored
Merge pull request #28152 from nextcloud/backport/28084/stable22
[stable22] Make sure that the dav propfind plugins always use the proper user id
2 parents 4c47cef + eae6ab2 commit c0f3fcd

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use OCP\IConfig;
4141
use OCP\IPreview;
4242
use OCP\IRequest;
43+
use OCP\IUserSession;
4344
use Sabre\DAV\Exception\Forbidden;
4445
use Sabre\DAV\Exception\NotFound;
4546
use Sabre\DAV\IFile;
@@ -88,6 +89,11 @@ class FilesPlugin extends ServerPlugin {
8889
*/
8990
private $tree;
9091

92+
/**
93+
* @var IUserSession
94+
*/
95+
private $userSession;
96+
9197
/**
9298
* Whether this is public webdav.
9399
* If true, some returned information will be stripped off.
@@ -128,11 +134,13 @@ public function __construct(Tree $tree,
128134
IConfig $config,
129135
IRequest $request,
130136
IPreview $previewManager,
137+
IUserSession $userSession,
131138
$isPublic = false,
132139
$downloadAttachment = true) {
133140
$this->tree = $tree;
134141
$this->config = $config;
135142
$this->request = $request;
143+
$this->userSession = $userSession;
136144
$this->isPublic = $isPublic;
137145
$this->downloadAttachment = $downloadAttachment;
138146
$this->previewManager = $previewManager;
@@ -322,14 +330,22 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
322330
});
323331

324332
$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) {
333+
$user = $this->userSession->getUser();
334+
if ($user === null) {
335+
return null;
336+
}
325337
return $node->getSharePermissions(
326-
$httpRequest->getRawServerValue('PHP_AUTH_USER')
338+
$user->getUID()
327339
);
328340
});
329341

330342
$propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) {
343+
$user = $this->userSession->getUser();
344+
if ($user === null) {
345+
return null;
346+
}
331347
$ncPermissions = $node->getSharePermissions(
332-
$httpRequest->getRawServerValue('PHP_AUTH_USER')
348+
$user->getUID()
333349
);
334350
$ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
335351
return json_encode($ocmPermissions);
@@ -367,8 +383,12 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
367383
});
368384

369385
$propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest) {
386+
$user = $this->userSession->getUser();
387+
if ($user === null) {
388+
return null;
389+
}
370390
return $node->getNoteFromShare(
371-
$httpRequest->getRawServerValue('PHP_AUTH_USER')
391+
$user->getUID()
372392
);
373393
});
374394
}

apps/dav/lib/Connector/Sabre/ServerFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public function createServer($baseUri,
171171
$this->config,
172172
$this->request,
173173
$this->previewManager,
174+
$this->userSession,
174175
false,
175176
!$this->config->getSystemValue('debug', false)
176177
)

apps/dav/lib/Server.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public function __construct(IRequest $request, $baseUri) {
238238
\OC::$server->getConfig(),
239239
$this->request,
240240
\OC::$server->getPreviewManager(),
241+
\OC::$server->getUserSession(),
241242
false,
242243
!\OC::$server->getConfig()->getSystemValue('debug', false)
243244
)

apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
use OCP\IConfig;
4242
use OCP\IPreview;
4343
use OCP\IRequest;
44+
use OCP\IUserSession;
45+
use PHPUnit\Framework\MockObject\MockObject;
4446
use Sabre\DAV\PropFind;
4547
use Sabre\DAV\PropPatch;
4648
use Sabre\DAV\Server;
@@ -99,30 +101,27 @@ class FilesPluginTest extends TestCase {
99101
*/
100102
private $previewManager;
101103

104+
/** @var IUserSession|MockObject */
105+
private $userSession;
106+
102107
protected function setUp(): void {
103108
parent::setUp();
104-
$this->server = $this->getMockBuilder(Server::class)
105-
->disableOriginalConstructor()
106-
->getMock();
107-
$this->tree = $this->getMockBuilder(Tree::class)
108-
->disableOriginalConstructor()
109-
->getMock();
109+
$this->server = $this->createMock(Server::class);
110+
$this->tree = $this->createMock(Tree::class);
110111
$this->config = $this->createMock(IConfig::class);
111112
$this->config->expects($this->any())->method('getSystemValue')
112113
->with($this->equalTo('data-fingerprint'), $this->equalTo(''))
113114
->willReturn('my_fingerprint');
114-
$this->request = $this->getMockBuilder(IRequest::class)
115-
->disableOriginalConstructor()
116-
->getMock();
117-
$this->previewManager = $this->getMockBuilder(IPreview::class)
118-
->disableOriginalConstructor()
119-
->getMock();
115+
$this->request = $this->createMock(IRequest::class);
116+
$this->previewManager = $this->createMock(IPreview::class);
117+
$this->userSession = $this->createMock(IUserSession::class);
120118

121119
$this->plugin = new FilesPlugin(
122120
$this->tree,
123121
$this->config,
124122
$this->request,
125-
$this->previewManager
123+
$this->previewManager,
124+
$this->userSession
126125
);
127126

128127
$response = $this->getMockBuilder(ResponseInterface::class)
@@ -264,6 +263,7 @@ public function testGetPublicPermissions() {
264263
->disableOriginalConstructor()
265264
->getMock(),
266265
$this->previewManager,
266+
$this->userSession,
267267
true);
268268
$this->plugin->initialize($this->server);
269269

apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,9 @@ public function testPrepareResponses() {
406406
new \OCA\DAV\Connector\Sabre\FilesPlugin(
407407
$this->tree,
408408
$config,
409-
$this->getMockBuilder(IRequest::class)
410-
->disableOriginalConstructor()
411-
->getMock(),
412-
$this->previewManager
409+
$this->createMock(IRequest::class),
410+
$this->previewManager,
411+
$this->createMock(IUserSession::class)
413412
)
414413
);
415414
$this->plugin->initialize($this->server);

0 commit comments

Comments
 (0)