diff --git a/tests/acceptance/TestHelpers/CollaborationHelper.php b/tests/acceptance/TestHelpers/CollaborationHelper.php index a0b6b9b9b..758666e8e 100644 --- a/tests/acceptance/TestHelpers/CollaborationHelper.php +++ b/tests/acceptance/TestHelpers/CollaborationHelper.php @@ -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 + ); + } } diff --git a/tests/acceptance/bootstrap/CollaborationContext.php b/tests/acceptance/bootstrap/CollaborationContext.php index 871083d8e..1010dbf40 100644 --- a/tests/acceptance/bootstrap/CollaborationContext.php +++ b/tests/acceptance/bootstrap/CollaborationContext.php @@ -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 ) ); } diff --git a/tests/acceptance/features/apiCollaboration/wopi.feature b/tests/acceptance/features/apiCollaboration/wopi.feature index d2d5b916b..7cda11ce7 100644 --- a/tests/acceptance/features/apiCollaboration/wopi.feature +++ b/tests/acceptance/features/apiCollaboration/wopi.feature @@ -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 | | + | 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