Skip to content

Commit

Permalink
add test to upload via TUS by federated user
Browse files Browse the repository at this point in the history
Signed-off-by: prashant-gurung899 <[email protected]>
  • Loading branch information
prashant-gurung899 committed Nov 13, 2024
1 parent 3998a9a commit 3ec2a4e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 43 deletions.
50 changes: 32 additions & 18 deletions tests/acceptance/bootstrap/SpacesTUSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\Assert;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
use TestHelpers\GraphHelper;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -89,11 +90,10 @@ public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(
}

/**
* @Given user :user has created a new TUS resource for the space :spaceName with content :content using the WebDAV API with these headers:
* @Given user :user has created a new TUS resource in the space :spaceName with the following headers:
*
* @param string $user
* @param string $spaceName
* @param string $content
* @param TableNode $headers
*
* @return void
Expand All @@ -104,11 +104,10 @@ public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(
public function userHasCreatedANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(
string $user,
string $spaceName,
string $content,
TableNode $headers
): void {
$spaceId = $this->spacesContext->getSpaceIdByName($user, $spaceName);
$response = $this->tusContext->createNewTUSResourceWithHeaders($user, $headers, $content, $spaceId);
$response = $this->tusContext->createNewTUSResourceWithHeaders($user, $headers, '', $spaceId);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201", $response);
}

Expand Down Expand Up @@ -148,19 +147,36 @@ public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseH
* @throws Exception|GuzzleException
*/
private function uploadFileViaTus(string $user, string $content, string $resource, string $spaceName): void {
$spaceId = $this->spacesContext->getSpaceIdByName($user, $spaceName);
$tmpFile = $this->tusContext->writeDataToTempFile($content);
try {
$this->tusContext->uploadFileUsingTus(
$user,
\basename($tmpFile),
$resource,
$spaceId
$server = $this->featureContext->getCurrentServer();

//check if it is REMOTE server and Shares space
if ($server === 'REMOTE' && $spaceName === 'Shares') {
$credentials = $this->featureContext->graphContext->getAdminOrUserCredentials($user);
$response = GraphHelper::getSharesSharedWithMe(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials['username'],
$credentials['password']
);
$this->featureContext->setLastUploadDeleteTime(\time());
} catch (Exception $e) {
Assert::assertStringContainsString('Unable to create resource', (string)$e);

$jsonBody = $this->featureContext->getJsonDecodedResponseBodyContent($response);

// trimming the resource 'FOLDER/file.txt' to get the destination path 'file.txt'
// as $spaceId below represents the remoteItem id
$resource = \ltrim($resource, "/");
$resource = preg_replace("#^[^/]+/#", "", $resource);
$spaceId = $jsonBody->value[0]->remoteItem->id;
} else {
$spaceId = $this->spacesContext->getSpaceIdByName($user, $spaceName);
}
$tmpFile = $this->tusContext->writeDataToTempFile($content);
$this->tusContext->uploadFileUsingTus(
$user,
\basename($tmpFile),
$resource,
$spaceId
);
$this->featureContext->setLastUploadDeleteTime(\time());
\unlink($tmpFile);
}

Expand Down Expand Up @@ -330,11 +346,10 @@ public function userSendsAChunkToTheLastCreatedTusLocationWithOffsetAndDataWithC
}

/**
* @When /^user "([^"]*)" sends a chunk to the last created TUS Location with data "([^"]*)" inside of the space "([^"]*)" with headers:$/
* @When /^user "([^"]*)" sends a chunk to the last created TUS Location with data "([^"]*)" with the following headers:$/
*
* @param string $user
* @param string $data
* @param string $spaceName
* @param TableNode $headers
*
* @return void
Expand All @@ -343,7 +358,6 @@ public function userSendsAChunkToTheLastCreatedTusLocationWithOffsetAndDataWithC
public function userSendsAChunkToTheLastCreatedTusLocationWithDataInsideOfTheSpaceWithHeaders(
string $user,
string $data,
string $spaceName,
TableNode $headers
): void {
$rows = $headers->getRowsHash();
Expand Down
16 changes: 6 additions & 10 deletions tests/acceptance/bootstrap/TUSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,12 @@ public function userUploadsAFileWithContentToUsingTus(
string $destination
): void {
$temporaryFileName = $this->writeDataToTempFile($content);
try {
$this->uploadFileUsingTus(
$user,
\basename($temporaryFileName),
$destination
);
$this->featureContext->setLastUploadDeleteTime(\time());
} catch (Exception $e) {
Assert::assertStringContainsString('TusPhp\Exception\FileException: Unable to create resource', (string)$e);
}
$this->uploadFileUsingTus(
$user,
\basename($temporaryFileName),
$destination
);
$this->featureContext->setLastUploadDeleteTime(\time());
\unlink($temporaryFileName);
}

Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ default:
- OcisConfigContext:
- NotificationContext:
- SettingsContext:
- SpacesTUSContext:

apiActivities:
paths:
Expand Down
10 changes: 5 additions & 5 deletions tests/acceptance/features/apiCors/cors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ Feature: CORS headers

@issue-8380
Scenario: CORS headers should be returned when uploading file using Tus and when CORS domain sending origin header in the Webdav api
Given user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
Given user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
| Tus-Resumable | 1.0.0 |
| Origin | https://aphno.badal |
When user "Alice" sends a chunk to the last created TUS Location with data "01234" inside of the space "Personal" with headers:
When user "Alice" sends a chunk to the last created TUS Location with data "01234" with the following headers:
| Origin | https://aphno.badal |
| Upload-Checksum | MD5 4100c4d44da9177247e44a5fc1546778 |
| Upload-Offset | 0 |
Expand All @@ -123,13 +123,13 @@ Feature: CORS headers

@issue-8380
Scenario: uploading file using Tus using different CORS headers
Given user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
Given user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
| Tus-Resumable | 1.0.0 |
| Origin | https://something.else |
When user "Alice" sends a chunk to the last created TUS Location with data "01234" inside of the space "Personal" with headers:
When user "Alice" sends a chunk to the last created TUS Location with data "01234" with the following headers:
| Origin | https://something.else |
| Upload-Checksum | MD5 4100c4d44da9177247e44a5fc1546778 |
| Upload-Offset | 0 |
Expand All @@ -139,7 +139,7 @@ Feature: CORS headers
# The Access-Control-Request-Headers need to be in lower-case and alphabetically order to comply with the rs/cors
# package see: https://github.com/rs/cors/commit/4c32059b2756926619f6bf70281b91be7b5dddb2#diff-bf80d8fbedf172fab9ba2604da7f7be972e48b2f78a8d0cd21619d5f93665895R367
Scenario Outline: CORS headers should be returned when an preflight request is sent to Tus upload
Given user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
Given user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
Expand Down
18 changes: 18 additions & 0 deletions tests/acceptance/features/apiOcm/share.feature
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,21 @@ Feature: an user shares resources using ScienceMesh application
}
}
"""

@issue-10285
Scenario: federated user upload file to a shared folder via TUS
Given using server "LOCAL"
And user "Alice" has created a folder "FOLDER" in space "Personal"
And "Alice" has created the federation share invitation
And using server "REMOTE"
And "Brian" has accepted invitation
And using server "LOCAL"
And user "Alice" has sent the following resource share invitation to federated user:
| resource | FOLDER |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permissionsRole | Editor |
And using server "REMOTE"
When user "Brian" uploads a file with content "uploaded content" to "FOLDER/file.txt" via TUS inside of the space "Shares" using the WebDAV API
# When user "Brian" uploads a file with content "lorem" to "textFile.txt" inside federated share "FOLDER" via TUS using the WebDAV API
18 changes: 9 additions & 9 deletions tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Feature: upload resources on share using TUS protocol
| shareType | user |
| permissionsRole | Editor |
And user "Brian" has a share "FOLDER" synced
And user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
And user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 5 |
# L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt
| Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= |
Expand All @@ -213,7 +213,7 @@ Feature: upload resources on share using TUS protocol
| shareType | user |
| permissionsRole | Editor |
And user "Brian" has a share "FOLDER" synced
And user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
And user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 5 |
# L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt
| Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= |
Expand All @@ -224,7 +224,7 @@ Feature: upload resources on share using TUS protocol


Scenario: sharer shares a file with correct checksum should return the checksum in the propfind for sharee
Given user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
Given user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
Expand All @@ -243,7 +243,7 @@ Feature: upload resources on share using TUS protocol


Scenario: sharer shares a file with correct checksum should return the checksum in the download header for sharee
Given user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
Given user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
Expand Down Expand Up @@ -309,7 +309,7 @@ Feature: upload resources on share using TUS protocol
| shareType | user |
| permissionsRole | Editor |
And user "Brian" has a share "FOLDER" synced
And user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
And user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 16 |
# L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt
| Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= |
Expand All @@ -323,7 +323,7 @@ Feature: upload resources on share using TUS protocol


Scenario: sharer uploads a chunked file with correct checksum and share it with sharee should work
Given user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
Given user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 10 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
Expand All @@ -345,7 +345,7 @@ Feature: upload resources on share using TUS protocol
| shareType | user |
| permissionsRole | Editor |
And user "Brian" has a share "FOLDER" synced
And user "Brian" has created a new TUS resource for the space "Shares" with content "" using the WebDAV API with these headers:
And user "Brian" has created a new TUS resource in the space "Shares" with the following headers:
| Upload-Length | 10 |
# L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt
| Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= |
Expand All @@ -359,7 +359,7 @@ Feature: upload resources on share using TUS protocol


Scenario: sharer uploads a file with checksum and as a sharee overwrites the shared file with new data and correct checksum
Given user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
Given user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 16 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
Expand All @@ -382,7 +382,7 @@ Feature: upload resources on share using TUS protocol

@issue-1755
Scenario: sharer uploads a file with checksum and as a sharee overwrites the shared file with new data and invalid checksum
Given user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
Given user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 16 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Feature: List upload sessions via CLI command
| POSTPROCESSING_DELAY | 10s |
And user "Alice" has uploaded file "filesForUpload/filesWithVirus/eicar.com" to "/virusFile.txt"
And user "Alice" has uploaded file with content "upload content" to "/file1.txt"
And user "Alice" has created a new TUS resource for the space "Personal" with content "" using the WebDAV API with these headers:
And user "Alice" has created a new TUS resource in the space "Personal" with the following headers:
| Upload-Length | 10 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
Expand Down

0 comments on commit 3ec2a4e

Please sign in to comment.