Skip to content

Commit

Permalink
add tests for uploading the zero-byte via tus and webdav api
Browse files Browse the repository at this point in the history
Signed-off-by: nabim777 <[email protected]>
  • Loading branch information
nabim777 committed Dec 9, 2024
1 parent 3f26e0f commit ac4f914
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 1 deletion.
19 changes: 19 additions & 0 deletions tests/acceptance/bootstrap/SpacesTUSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(
$this->featureContext->setLastUploadDeleteTime(\time());
}

/**
* @When the public uploads a file from :source to :destination via TUS inside last link shared folder with password :password using the WebDAV API
*
* @param string $source
* @param string $destination
* @param string $password
*
* @return void
* @throws Exception
*/
public function publicUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(
string $source,
string $destination,
string $password
): void {
$this->tusContext->publicUploadFileUsingTus($source,$destination,$password);
$this->featureContext->setLastUploadDeleteTime(\time());
}

/**
* @Given user :user has created a new TUS resource in the space :spaceName with the following headers:
*
Expand Down
38 changes: 38 additions & 0 deletions tests/acceptance/bootstrap/TUSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,44 @@ public function uploadFileUsingTus(
}
}

/**
* @param string $source
* @param string $destination
* @param string|null $password
*
* @return void
*/
public function publicUploadFileUsingTus(
string $source,
string $destination,
?string $password,
):void {
$password = $this->featureContext->getActualPassword($password);
if ($this->featureContext->isUsingSharingNG()) {
$token = $this->featureContext->shareNgGetLastCreatedLinkShareToken();
} else {
$token = $this->featureContext->getLastCreatedPublicShareToken();
}
$headers = [
'Authorization' => 'Basic ' . \base64_encode("public" . ':' . $password),
];
$sourceFile = $this->featureContext->acceptanceTestsDirLocation() . $source;
$davPath = WebdavHelper::getDavPath(WebDavHelper::DAV_VERSION_SPACES, $token, "public-files");
$url = $davPath;

$client = new Client(
$this->featureContext->getBaseUrl(),
[
'verify' => false,
'headers' => $headers
]
);

$client->setApiPath($url);
$client->setKey((string)rand())->file($sourceFile, $destination);
$client->file($sourceFile, $destination)->createWithUpload("", 0);
}

/**
* @When user :user uploads file with content :content to :destination using the TUS protocol on the WebDAV API
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2763,4 +2763,57 @@ Feature: Create a link share for a resource
| permissions-role |
| Space Viewer |
| Space Editor |
| Manager |
| Manager |

@issue-10649
Scenario: public uploads a zero byte file to a public share folder
Given using spaces DAV path
And using SharingNG
And user "Alice" has created folder "/uploadFolder"
And user "Alice" has created the following resource link share:
| resource | uploadFolder |
| space | Personal |
| permissionsRole | createOnly |
| password | %public% |
When the public uploads file "filesForUpload/zerobyte.txt" to "textfile.txt" inside last link shared folder with password "%public%" using the public WebDAV API
Then the HTTP status code should be "201"
And for user "Alice" folder "uploadFolder" of the space "Personal" should contain these files:
| textfile.txt |
And for user "Alice" folder "uploadFolder" of the space "Personal" should not contain these files:
| textfile (1).txt |

@issue-10649
Scenario: public uploads a zero byte file to a public share folder inside project space
Given using spaces DAV path
And using SharingNG
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And user "Alice" has created a space "Project" with the default quota using the Graph API
And user "Alice" has created a folder "/uploadFolder" in space "Project"
And user "Alice" has created the following resource link share:
| resource | uploadFolder |
| space | Project |
| permissionsRole | createOnly |
| password | %public% |
When the public uploads file "filesForUpload/zerobyte.txt" to "textfile.txt" inside last link shared folder with password "%public%" using the public WebDAV API
Then the HTTP status code should be "201"
And for user "Alice" folder "uploadFolder" of the space "Project" should contain these files:
| textfile.txt |
And for user "Alice" folder "uploadFolder" of the space "Project" should not contain these files:
| textfile (1).txt |

@issue-10649
Scenario: public uploads a zero byte file to a public share project space
Given using spaces DAV path
And using SharingNG
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And user "Alice" has created a space "Project" with the default quota using the Graph API
And user "Alice" has created the following space link share:
| space | Project |
| permissionsRole | createOnly |
| password | %public% |
When the public uploads file "filesForUpload/zerobyte.txt" to "textfile.txt" inside last link shared folder with password "%public%" using the public WebDAV API
Then the HTTP status code should be "201"
Then for user "Alice" the space "Project" should contain these files:
| textfile.txt |
And for user "Alice" the space "Project" should not contain these files:
| textfile (1).txt |
50 changes: 50 additions & 0 deletions tests/acceptance/features/apiSpaces/tusUpload.feature
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,53 @@ Feature: upload resources using TUS protocol
When user "Brian" uploads a file from "filesForUpload/zerobyte.txt" to "textfile.txt" via TUS inside of the space "new-space" using the WebDAV API
Then for user "Brian" the content of the file "textfile.txt" of the space "new-space" should be ""
And for user "Alice" the content of the file "textfile.txt" of the space "new-space" should be ""

@issue-10649
Scenario: public uploads a zero byte file to a public share folder
Given using spaces DAV path
And using SharingNG
And user "Alice" has created folder "/uploadFolder"
And user "Alice" has created the following resource link share:
| resource | uploadFolder |
| space | Personal |
| permissionsRole | createOnly |
| password | %public% |
When the public uploads a file from "filesForUpload/zerobyte.txt" to "textfile.txt" via TUS inside last link shared folder with password "%public%" using the WebDAV API
And for user "Alice" folder "uploadFolder" of the space "Personal" should contain these files:
| textfile.txt |
And for user "Alice" folder "uploadFolder" of the space "Personal" should not contain these files:
| textfile (1).txt |

@issue-10346
Scenario: public uploads a zero-byte file to a shared folder inside project space
Given using spaces DAV path
And using SharingNG
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And user "Alice" has created a space "Project" with the default quota using the Graph API
And user "Alice" has created a folder "/uploadFolder" in space "Project"
And user "Alice" has created the following resource link share:
| resource | uploadFolder |
| space | Project |
| permissionsRole | createOnly |
| password | %public% |
When the public uploads a file from "filesForUpload/zerobyte.txt" to "textfile.txt" via TUS inside last link shared folder with password "%public%" using the WebDAV API
And for user "Alice" folder "uploadFolder" of the space "Project" should contain these files:
| textfile.txt |
And for user "Alice" folder "uploadFolder" of the space "Project" should not contain these files:
| textfile (1).txt |

@issue-10649
Scenario: public uploads a zero-byte file to a public share project space
Given using spaces DAV path
And using SharingNG
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And user "Alice" has created a space "Project" with the default quota using the Graph API
And user "Alice" has created the following space link share:
| space | Project |
| permissionsRole | createOnly |
| password | %public% |
When the public uploads a file from "filesForUpload/zerobyte.txt" to "textfile.txt" via TUS inside last link shared folder with password "%public%" using the WebDAV API
Then for user "Alice" the space "Project" should contain these files:
| textfile.txt |
And for user "Alice" the space "Project" should not contain these files:
| textfile (1).txt |

0 comments on commit ac4f914

Please sign in to comment.