add test to upload via TUS by federated user

Signed-off-by: prashant-gurung899 <prasantgrg777@gmail.com>
This commit is contained in:
prashant-gurung899
2024-11-22 09:47:08 +05:45
parent 271455703b
commit e40015c2e2
7 changed files with 150 additions and 26 deletions
+66 -3
View File
@@ -254,6 +254,38 @@ class SpacesContext implements Context {
return $space["id"]; return $space["id"];
} }
/**
* @param string $user
* @param string $share
*
* @return string
*
* @throws Exception|GuzzleException
*/
public function getSharesRemoteItemId(string $user, string $share): string {
$credentials = $this->featureContext->graphContext->getAdminOrUserCredentials($user);
$response = GraphHelper::getSharesSharedWithMe(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials['username'],
$credentials['password']
);
$jsonBody = $this->featureContext->getJsonDecodedResponseBodyContent($response);
// Search remoteItem ID of a given share
foreach ($jsonBody->value as $item) {
if (isset($item->name) && $item->name === $share) {
if (isset($item->remoteItem->id)) {
return $item->remoteItem->id;
}
throw new Exception("Failed to find remoteItem ID for share: $share");
}
}
throw new Exception("Cannot find share: $share");
}
/** /**
* The method finds file by fileName and spaceName and returns data of file which contains in responseHeader * The method finds file by fileName and spaceName and returns data of file which contains in responseHeader
* fileName contains the path, if the file is in the folder * fileName contains the path, if the file is in the folder
@@ -261,14 +293,23 @@ class SpacesContext implements Context {
* @param string $user * @param string $user
* @param string $spaceName * @param string $spaceName
* @param string $fileName * @param string $fileName
* @param bool $federatedShare
* *
* @return ResponseInterface * @return ResponseInterface
* @throws GuzzleException * @throws GuzzleException
*/ */
public function getFileData(string $user, string $spaceName, string $fileName): ResponseInterface { public function getFileData(string $user, string $spaceName, string $fileName, bool $federatedShare = false): ResponseInterface {
$space = $this->getSpaceByName($user, $spaceName);
$baseUrl = $this->featureContext->getBaseUrl(); $baseUrl = $this->featureContext->getBaseUrl();
$davPath = WebdavHelper::getDavPath(WebDavHelper::DAV_VERSION_SPACES, $space["id"]);
if ($federatedShare) {
$remoteItemId = $this->getSharesRemoteItemId($user, $spaceName);
$spaceId = \rawurlencode($remoteItemId);
} else {
$space = $this->getSpaceByName($user, $spaceName);
$spaceId = $space["id"];
}
$davPath = WebdavHelper::getDavPath(WebDavHelper::DAV_VERSION_SPACES, $spaceId);
$fullUrl = "$baseUrl/$davPath/$fileName"; $fullUrl = "$baseUrl/$davPath/$fileName";
return HttpRequestHelper::get( return HttpRequestHelper::get(
@@ -874,6 +915,28 @@ class SpacesContext implements Context {
Assert::assertEquals($fileContent, $actualFileContent, "$file does not contain $fileContent"); Assert::assertEquals($fileContent, $actualFileContent, "$file does not contain $fileContent");
} }
/**
* @Then /^for user "([^"]*)" the content of file "([^"]*)" of federated share "([^"]*)" should be "([^"]*)"$/
*
* @param string $user
* @param string $file
* @param string $share
* @param string $fileContent
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function forUserTheContentOfFileOfFederatedShareShouldBe(
string $user,
string $file,
string $share,
string $fileContent
): void {
$actualFileContent = $this->getFileData($user, $share, $file, true)->getBody()->getContents();
Assert::assertEquals($fileContent, $actualFileContent, "File content did not match");
}
/** /**
* @Then /^the JSON response should contain space called "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )(?:|(?:with description file|with space image) "([^"]*)" )and match$/ * @Then /^the JSON response should contain space called "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )(?:|(?:with description file|with space image) "([^"]*)" )and match$/
* *
@@ -16,6 +16,8 @@ use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use TestHelpers\WebDavHelper; use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper; use TestHelpers\BehatHelper;
use TestHelpers\GraphHelper;
use TestHelpers\HttpRequestHelper;
require_once 'bootstrap.php'; require_once 'bootstrap.php';
@@ -89,11 +91,10 @@ class SpacesTUSContext implements Context {
} }
/** /**
* @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 $user
* @param string $spaceName * @param string $spaceName
* @param string $content
* @param TableNode $headers * @param TableNode $headers
* *
* @return void * @return void
@@ -104,11 +105,10 @@ class SpacesTUSContext implements Context {
public function userHasCreatedANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders( public function userHasCreatedANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(
string $user, string $user,
string $spaceName, string $spaceName,
string $content,
TableNode $headers TableNode $headers
): void { ): void {
$spaceId = $this->spacesContext->getSpaceIdByName($user, $spaceName); $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); $this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201", $response);
} }
@@ -164,6 +164,31 @@ class SpacesTUSContext implements Context {
\unlink($tmpFile); \unlink($tmpFile);
} }
/**
* @When /^user "([^"]*)" uploads a file with content "([^"]*)" to "([^"]*)" inside federated share "([^"]*)" via TUS using the WebDAV API$/
*
* @param string $user
* @param string $content
* @param string $file
* @param string $destination
*
* @return void
* @throws Exception|GuzzleException
*/
public function userUploadsAFileWithContentToInsideFederatedShareViaTusUsingTheWebdavApi(string $user, string $content, string $file, string $destination): void {
$remoteItemId = $this->spacesContext->getSharesRemoteItemId($user, $destination);
$remoteItemId = \rawurlencode($remoteItemId);
$tmpFile = $this->tusContext->writeDataToTempFile($content);
$this->tusContext->uploadFileUsingTus(
$user,
\basename($tmpFile),
$file,
$remoteItemId
);
$this->featureContext->setLastUploadDeleteTime(\time());
\unlink($tmpFile);
}
/** /**
* @When /^user "([^"]*)" uploads a file with content "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/ * @When /^user "([^"]*)" uploads a file with content "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
* *
@@ -330,11 +355,10 @@ class SpacesTUSContext implements Context {
} }
/** /**
* @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 $user
* @param string $data * @param string $data
* @param string $spaceName
* @param TableNode $headers * @param TableNode $headers
* *
* @return void * @return void
@@ -343,7 +367,6 @@ class SpacesTUSContext implements Context {
public function userSendsAChunkToTheLastCreatedTusLocationWithDataInsideOfTheSpaceWithHeaders( public function userSendsAChunkToTheLastCreatedTusLocationWithDataInsideOfTheSpaceWithHeaders(
string $user, string $user,
string $data, string $data,
string $spaceName,
TableNode $headers TableNode $headers
): void { ): void {
$rows = $headers->getRowsHash(); $rows = $headers->getRowsHash();
+1
View File
@@ -394,6 +394,7 @@ default:
- OcisConfigContext: - OcisConfigContext:
- NotificationContext: - NotificationContext:
- SettingsContext: - SettingsContext:
- SpacesTUSContext:
apiActivities: apiActivities:
paths: paths:
@@ -110,13 +110,13 @@ Feature: CORS headers
@issue-8380 @issue-8380
Scenario: CORS headers should be returned when uploading file using Tus and when CORS domain sending origin header in the Webdav api 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 | | Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt # dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 | | Upload-Metadata | filename dGV4dEZpbGUudHh0 |
| Tus-Resumable | 1.0.0 | | Tus-Resumable | 1.0.0 |
| Origin | https://aphno.badal | | 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 | | Origin | https://aphno.badal |
| Upload-Checksum | MD5 4100c4d44da9177247e44a5fc1546778 | | Upload-Checksum | MD5 4100c4d44da9177247e44a5fc1546778 |
| Upload-Offset | 0 | | Upload-Offset | 0 |
@@ -128,13 +128,13 @@ Feature: CORS headers
@issue-8380 @issue-8380
Scenario: uploading file using Tus using different CORS headers 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 | | Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt # dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 | | Upload-Metadata | filename dGV4dEZpbGUudHh0 |
| Tus-Resumable | 1.0.0 | | Tus-Resumable | 1.0.0 |
| Origin | https://something.else | | 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 | | Origin | https://something.else |
| Upload-Checksum | MD5 4100c4d44da9177247e44a5fc1546778 | | Upload-Checksum | MD5 4100c4d44da9177247e44a5fc1546778 |
| Upload-Offset | 0 | | Upload-Offset | 0 |
@@ -144,7 +144,7 @@ Feature: CORS headers
# The Access-Control-Request-Headers need to be in lower-case and alphabetically order to comply with the rs/cors # 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 # 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 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 | | Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt # dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 | | Upload-Metadata | filename dGV4dEZpbGUudHh0 |
+38 -1
View File
@@ -695,4 +695,41 @@ Feature: an user shares resources using ScienceMesh application
} }
} }
} }
""" """
@issue-10285 @issue-10536
Scenario: federation user uploads file to a federated shared folder via TUS
Given using spaces DAV path
And using server "LOCAL"
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 created a folder "FOLDER" in space "Personal"
And user "Alice" has sent the following resource share invitation to federated user:
| resource | FOLDER |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permissionsRole | Editor |
When using server "REMOTE"
And user "Brian" uploads a file with content "lorem" to "file.txt" inside federated share "FOLDER" via TUS using the WebDAV API
Then for user "Brian" the content of file "file.txt" of federated share "FOLDER" should be "lorem"
@issue-10285 @issue-10536
Scenario: local user uploads file to a federated shared folder via TUS
Given using spaces DAV path
And using server "LOCAL"
And "Alice" has created the federation share invitation
And using server "REMOTE"
And "Brian" has accepted invitation
And user "Brian" has created a folder "FOLDER" in space "Personal"
And user "Brian" has sent the following resource share invitation to federated user:
| resource | FOLDER |
| space | Personal |
| sharee | Alice |
| shareType | user |
| permissionsRole | Editor |
When using server "LOCAL"
And user "Alice" uploads a file with content "lorem" to "file.txt" inside federated share "FOLDER" via TUS using the WebDAV API
Then for user "Alice" the content of file "file.txt" of federated share "FOLDER" should be "lorem"
@@ -193,7 +193,7 @@ Feature: upload resources on share using TUS protocol
| shareType | user | | shareType | user |
| permissionsRole | Editor | | permissionsRole | Editor |
And user "Brian" has a share "FOLDER" synced 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 | | Upload-Length | 5 |
# L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt # L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt
| Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= | | Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= |
@@ -213,7 +213,7 @@ Feature: upload resources on share using TUS protocol
| shareType | user | | shareType | user |
| permissionsRole | Editor | | permissionsRole | Editor |
And user "Brian" has a share "FOLDER" synced 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 | | Upload-Length | 5 |
# L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt # L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt
| Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= | | Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= |
@@ -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 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 | | Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt # dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 | | Upload-Metadata | filename dGV4dEZpbGUudHh0 |
@@ -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 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 | | Upload-Length | 5 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt # dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 | | Upload-Metadata | filename dGV4dEZpbGUudHh0 |
@@ -309,7 +309,7 @@ Feature: upload resources on share using TUS protocol
| shareType | user | | shareType | user |
| permissionsRole | Editor | | permissionsRole | Editor |
And user "Brian" has a share "FOLDER" synced 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 | | Upload-Length | 16 |
# L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt # L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt
| Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= | | Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= |
@@ -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 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 | | Upload-Length | 10 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt # dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 | | Upload-Metadata | filename dGV4dEZpbGUudHh0 |
@@ -345,7 +345,7 @@ Feature: upload resources on share using TUS protocol
| shareType | user | | shareType | user |
| permissionsRole | Editor | | permissionsRole | Editor |
And user "Brian" has a share "FOLDER" synced 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 | | Upload-Length | 10 |
# L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt # L0ZPTERFUi90ZXh0RmlsZS50eHQ= is the base64 encode of /FOLDER/textFile.txt
| Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= | | Upload-Metadata | filename L0ZPTERFUi90ZXh0RmlsZS50eHQ= |
@@ -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 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 | | Upload-Length | 16 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt # dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 | | Upload-Metadata | filename dGV4dEZpbGUudHh0 |
@@ -382,7 +382,7 @@ Feature: upload resources on share using TUS protocol
@issue-1755 @issue-1755
Scenario: sharer uploads a file with checksum and as a sharee overwrites the shared file with new data and invalid checksum 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 | | Upload-Length | 16 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt # dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 | | Upload-Metadata | filename dGV4dEZpbGUudHh0 |
@@ -135,7 +135,7 @@ Feature: List upload sessions via CLI command
| POSTPROCESSING_DELAY | 10s | | POSTPROCESSING_DELAY | 10s |
And user "Alice" has uploaded file "filesForUpload/filesWithVirus/eicar.com" to "/virusFile.txt" 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 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 | | Upload-Length | 10 |
# dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt # dGV4dEZpbGUudHh0 is the base64 encode of textFile.txt
| Upload-Metadata | filename dGV4dEZpbGUudHh0 | | Upload-Metadata | filename dGV4dEZpbGUudHh0 |