Skip to content

Commit 78cbf94

Browse files
provokateurinbackportbot[bot]
authored andcommitted
fix(FilesDropPlugin): Fix request method and nickname header checks
Signed-off-by: provokateurin <[email protected]>
1 parent c24340f commit 78cbf94

File tree

4 files changed

+11
-64
lines changed

4 files changed

+11
-64
lines changed

apps/dav/lib/Files/Sharing/FilesDropPlugin.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,8 @@ public function beforeMethod(RequestInterface $request, ResponseInterface $respo
8383
return;
8484
}
8585

86-
// Retrieve the nickname from the request
87-
$nickname = $request->hasHeader('X-NC-Nickname')
88-
? trim(urldecode($request->getHeader('X-NC-Nickname')))
89-
: null;
90-
91-
if ($request->getMethod() !== 'PUT') {
92-
// If uploading subfolders we need to ensure they get created
93-
// within the nickname folder
94-
if ($request->getMethod() === 'MKCOL') {
95-
if (!$nickname) {
96-
throw new BadRequest('A nickname header is required when uploading subfolders');
97-
}
98-
} else {
99-
throw new MethodNotAllowed('Only PUT is allowed on files drop');
100-
}
86+
if ($request->getMethod() !== 'PUT' && $request->getMethod() !== 'MKCOL' && (!$isChunkedUpload || $request->getMethod() !== 'MOVE')) {
87+
throw new MethodNotAllowed('Only PUT, MKCOL and MOVE are allowed on files drop');
10188
}
10289

10390
// If this is a folder creation request
@@ -135,6 +122,11 @@ public function beforeMethod(RequestInterface $request, ResponseInterface $respo
135122
$isFileRequest = $attributes->getAttribute('fileRequest', 'enabled') === true;
136123
}
137124

125+
// Retrieve the nickname from the request
126+
$nickname = $request->hasHeader('X-NC-Nickname')
127+
? trim(urldecode($request->getHeader('X-NC-Nickname')))
128+
: null;
129+
138130
// We need a valid nickname for file requests
139131
if ($isFileRequest && !$nickname) {
140132
throw new BadRequest('A nickname header is required for file requests');

apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use OCP\Share\IAttributes;
1414
use OCP\Share\IShare;
1515
use PHPUnit\Framework\MockObject\MockObject;
16-
use Sabre\DAV\Exception\BadRequest;
1716
use Sabre\DAV\Server;
1817
use Sabre\HTTP\RequestInterface;
1918
use Sabre\HTTP\ResponseInterface;
@@ -105,32 +104,13 @@ public function testFileAlreadyExistsValid(): void {
105104
$this->plugin->beforeMethod($this->request, $this->response);
106105
}
107106

108-
public function testNoMKCOLWithoutNickname(): void {
107+
public function testMKCOL(): void {
109108
$this->plugin->enable();
110109
$this->plugin->setShare($this->share);
111110

112111
$this->request->method('getMethod')
113112
->willReturn('MKCOL');
114113

115-
$this->expectException(BadRequest::class);
116-
117-
$this->plugin->beforeMethod($this->request, $this->response);
118-
}
119-
120-
public function testMKCOLWithNickname(): void {
121-
$this->plugin->enable();
122-
$this->plugin->setShare($this->share);
123-
124-
$this->request->method('getMethod')
125-
->willReturn('MKCOL');
126-
127-
$this->request->method('hasHeader')
128-
->with('X-NC-Nickname')
129-
->willReturn(true);
130-
$this->request->method('getHeader')
131-
->with('X-NC-Nickname')
132-
->willReturn('nickname');
133-
134114
$this->expectNotToPerformAssertions();
135115

136116
$this->plugin->beforeMethod($this->request, $this->response);

build/integration/features/bootstrap/FilesDropContext.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function droppingFileWithAs($path, $content, $nickname) {
5757
/**
5858
* @When Creating folder :folder in drop
5959
*/
60-
public function creatingFolderInDrop($folder, $nickname = null) {
60+
public function creatingFolderInDrop($folder) {
6161
$client = new Client();
6262
$options = [];
6363
if (count($this->lastShareData->data->element) > 0) {
@@ -73,22 +73,10 @@ public function creatingFolderInDrop($folder, $nickname = null) {
7373
'X-REQUESTED-WITH' => 'XMLHttpRequest',
7474
];
7575

76-
if ($nickname) {
77-
$options['headers']['X-NC-NICKNAME'] = $nickname;
78-
}
79-
8076
try {
8177
$this->response = $client->request('MKCOL', $fullUrl, $options);
8278
} catch (\GuzzleHttp\Exception\ClientException $e) {
8379
$this->response = $e->getResponse();
8480
}
8581
}
86-
87-
88-
/**
89-
* @When Creating folder :folder in drop as :nickName
90-
*/
91-
public function creatingFolderInDropWithNickname($folder, $nickname) {
92-
return $this->creatingFolderInDrop($folder, $nickname);
93-
}
9482
}

build/integration/filesdrop_features/filesdrop.feature

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Feature: FilesDrop
4646
When Dropping file "/folder/a.txt" with "abc"
4747
Then the HTTP status code should be "400"
4848

49-
Scenario: Files drop forbid MKCOL without a nickname
49+
Scenario: Files drop allows MKCOL
5050
Given user "user0" exists
5151
And As an "user0"
5252
And user "user0" created a folder "/drop"
@@ -57,19 +57,6 @@ Feature: FilesDrop
5757
And Updating last share with
5858
| permissions | 4 |
5959
When Creating folder "folder" in drop
60-
Then the HTTP status code should be "400"
61-
62-
Scenario: Files drop allows MKCOL with a nickname
63-
Given user "user0" exists
64-
And As an "user0"
65-
And user "user0" created a folder "/drop"
66-
And as "user0" creating a share with
67-
| path | drop |
68-
| shareType | 3 |
69-
| publicUpload | true |
70-
And Updating last share with
71-
| permissions | 4 |
72-
When Creating folder "folder" in drop as "nickname"
7360
Then the HTTP status code should be "201"
7461

7562
Scenario: Files drop forbid subfolder creation without a nickname
@@ -139,7 +126,7 @@ Feature: FilesDrop
139126
When Downloading file "/drop/Alice/folder (2)"
140127
Then the HTTP status code should be "200"
141128
And Downloaded content should be "its a file"
142-
129+
143130
Scenario: Put file same file multiple times via files drop
144131
Given user "user0" exists
145132
And As an "user0"

0 commit comments

Comments
 (0)