Merge pull request #9978 from owncloud/create-file-in-public-folder

[tests-only][full-ci] added test for public user to create .odt file inside public folder
This commit is contained in:
Prajwol Amatya
2024-09-18 09:53:10 +05:45
committed by GitHub
3 changed files with 143 additions and 4 deletions

View File

@@ -64,4 +64,35 @@ class CollaborationHelper {
['Content-Type' => 'application/json']
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $parentContainerId
* @param string $file
* @param array|null $headers
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function createFile(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $parentContainerId,
string $file,
?array $headers = null
): ResponseInterface {
$url = $baseUrl . "/app/new?parent_container_id=$parentContainerId&filename=$file";
return HttpRequestHelper::post(
$url,
$xRequestId,
$user,
$password,
$headers
);
}
}

View File

@@ -105,15 +105,61 @@ class CollaborationContext implements Context {
* @param string $space
*
* @return void
* @throws GuzzleException
*/
public function userCreatesFileInsideFolderInSpaceUsingWopiEndpoint(string $user, string $file, string $folder, string $space): void {
$parent_container_id = $this->spacesContext->getResourceId($user, $space, $folder);
$parentContainerId = $this->spacesContext->getResourceId($user, $space, $folder);
$this->featureContext->setResponse(
HttpRequestHelper::post(
$this->featureContext->getBaseUrl() . "/app/new?parent_container_id=$parent_container_id&filename=$file",
CollaborationHelper::createFile(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user)
$this->featureContext->getPasswordForUser($user),
$parentContainerId,
$file
)
);
}
/**
* @When the public creates a file :file inside the last shared public link folder with password :password using wopi endpoint
* @When the public tries to create a file :file inside the last shared public link folder with password :password using wopi endpoint
*
* @param string $file
* @param string $password
*
* @return void
* @throws GuzzleException
*/
public function thePublicCreatesAFileInsideTheLastSharedPublicLinkFolderWithPasswordUsingWopiEndpoint(string $file, string $password): void {
$token = $this->featureContext->shareNgGetLastCreatedLinkShareToken();
$davPath = WebDavHelper::getDavPath($token, null, "public-files-new");
$response = HttpRequestHelper::sendRequest(
$this->featureContext->getBaseUrl() . "/$davPath",
$this->featureContext->getStepLineRef(),
"PROPFIND",
"public",
$this->featureContext->getActualPassword($password)
);
$responseXml = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
$xmlPart = $responseXml->xpath("//d:prop/oc:fileid");
$parentContainerId = (string) $xmlPart[0];
$headers = [
"Public-Token" => $token
];
$this->featureContext->setResponse(
CollaborationHelper::createFile(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
"public",
$this->featureContext->getActualPassword($password),
$parentContainerId,
$file,
$headers
)
);
}

View File

@@ -924,3 +924,65 @@ Feature: collaboration (wopi)
"""
And as "Alice" file "testFolder/simple.odt" should not exist
And as "Brian" file "Shares/testFolder/simple.odt" should not exist
Scenario Outline: public user with permission edit/upload/createOnly creates odt file inside public folder using wopi endpoint
Given user "Alice" has created folder "publicFolder"
And user "Alice" has created the following resource link share:
| resource | publicFolder |
| space | Personal |
| permissionsRole | <permissions-role> |
| password | %public% |
When the public creates a file "simple.odt" inside the last shared public link folder with password "%public%" using wopi endpoint
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
{
"type": "object",
"required": [
"file_id"
],
"properties": {
"file_id": {
"type": "string",
"pattern": "^%file_id_pattern%$"
}
}
}
"""
And as "Alice" file "publicFolder/simple.odt" should exist
Examples:
| permissions-role |
| edit |
| upload |
| createOnly |
Scenario: public user with permission view tries to creates odt file inside public folder using wopi endpoint
Given user "Alice" has created folder "publicFolder"
And user "Alice" has created the following resource link share:
| resource | publicFolder |
| space | Personal |
| permissionsRole | view |
| password | %public% |
When the public tries to create a file "simple.odt" inside the last shared public link folder with password "%public%" using wopi endpoint
Then the HTTP status code should be "500"
And the JSON data of the response should match
"""
{
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"const": "SERVER_ERROR"
},
"message": {
"const": "error calling InitiateFileUpload"
}
}
}
"""
And as "Alice" file "publicFolder/simple.odt" should not exist