Skip to content

Commit

Permalink
chore(integration): add file request tests
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Jul 18, 2024
1 parent 481551e commit dde63a3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
10 changes: 4 additions & 6 deletions apps/dav/lib/Files/Sharing/FilesDropPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ public function beforeMethod(RequestInterface $request, ResponseInterface $respo
$path = array_pop($path);

// Extract the attributes for the file request
$isFileRequest = false;
$attributes = $this->share->getAttributes();
if ($attributes === null) {
return;
}

// Prepare file request
$nickName = $request->getHeader('X-NC-Nickname');
$isFileRequest = $attributes->getAttribute('fileRequest', 'enabled') === true;
if ($attributes !== null) {
$isFileRequest = $attributes->getAttribute('fileRequest', 'enabled') === true;
}

// We need a valid nickname for file requests
if ($isFileRequest && ($nickName == null || trim($nickName) === '')) {
Expand Down
20 changes: 17 additions & 3 deletions build/integration/features/bootstrap/FilesDropContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FilesDropContext implements Context, SnippetAcceptingContext {
/**
* @When Dropping file :path with :content
*/
public function droppingFileWith($path, $content) {
public function droppingFileWith($path, $content, $nickName = null) {
$client = new Client();
$options = [];
if (count($this->lastShareData->data->element) > 0) {
Expand All @@ -25,11 +25,16 @@ public function droppingFileWith($path, $content) {
}

$base = substr($this->baseUrl, 0, -4);
$fullUrl = $base . "/public.php/dav/files/$token/$path";
$fullUrl = str_replace('//', '/', $base . "/public.php/dav/files/$token/$path");

$options['headers'] = [
'X-REQUESTED-WITH' => 'XMLHttpRequest'
];

if ($nickName) {
$options['headers']['X-NC-NICKNAME'] = $nickName;
}

$options['body'] = \GuzzleHttp\Psr7\Utils::streamFor($content);

try {
Expand All @@ -38,6 +43,15 @@ public function droppingFileWith($path, $content) {
$this->response = $e->getResponse();
}
}


/**
* @When Dropping file :path with :content as :nickName
*/
public function droppingFileWithAs($path, $content, $nickName) {
$this->droppingFileWith($path, $content, $nickName);
}


/**
* @When Creating folder :folder in drop
Expand All @@ -52,7 +66,7 @@ public function creatingFolderInDrop($folder) {
}

$base = substr($this->baseUrl, 0, -4);
$fullUrl = $base . "/public.php/dav/files/$token/$folder";
$fullUrl = str_replace('//', '/', $base . "/public.php/dav/files/$token/$folder");

$options['headers'] = [
'X-REQUESTED-WITH' => 'XMLHttpRequest'
Expand Down
31 changes: 31 additions & 0 deletions build/integration/filesdrop_features/filesdrop.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,34 @@ Feature: FilesDrop
| permissions | 4 |
When Creating folder "folder" in drop
Then the HTTP status code should be "405"

Scenario: Files request drop
Given user "user0" exists
And As an "user0"
And user "user0" created a folder "/drop"
And as "user0" creating a share with
| path | drop |
| shareType | 4 |
| permissions | 4 |
| attributes | [{"scope":"fileRequest","key":"enabled","value":true}] |
| shareWith | |
When Dropping file "/folder/a.txt" with "abc" as "Alice"
And Downloading file "/drop/Alice/a.txt"
Then Downloaded content should be "abc"

Scenario: Put file same file multiple times via files drop
Given user "user0" exists
And As an "user0"
And user "user0" created a folder "/drop"
And as "user0" creating a share with
| path | drop |
| shareType | 4 |
| permissions | 4 |
| attributes | [{"scope":"fileRequest","key":"enabled","value":true}] |
| shareWith | |
When Dropping file "/folder/a.txt" with "abc" as "Mallory"
And Dropping file "/folder/a.txt" with "def" as "Mallory"
And Downloading file "/drop/Mallory/a.txt"
Then Downloaded content should be "abc"
And Downloading file "/drop/Mallory/a (2).txt"
Then Downloaded content should be "def"

0 comments on commit dde63a3

Please sign in to comment.