From 5a101b7c4e62c3df866f0c118aed917c62227ccc Mon Sep 17 00:00:00 2001 From: prajwol Date: Tue, 8 Aug 2023 16:57:36 +0545 Subject: [PATCH 1/2] added test to update file using file id --- .../updateFileByFileId.feature | 112 ++++++++++++++++++ .../features/bootstrap/FeatureContext.php | 29 ++++- 2 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 tests/acceptance/features/apiSpacesDavOperation/updateFileByFileId.feature diff --git a/tests/acceptance/features/apiSpacesDavOperation/updateFileByFileId.feature b/tests/acceptance/features/apiSpacesDavOperation/updateFileByFileId.feature new file mode 100644 index 00000000000..d4cf9a2831d --- /dev/null +++ b/tests/acceptance/features/apiSpacesDavOperation/updateFileByFileId.feature @@ -0,0 +1,112 @@ +Feature: update files using file id + As a user + I want to update the files using file id + So that I can make changes on the content of a file + + Background: + Given using spaces DAV path + And user "Alice" has been created with default attributes and without skeleton files + + + Scenario Outline: update content of a file + Given user "Alice" has uploaded file with content "some data" to "/textfile.txt" + And we save it into "FILEID" + When user "Alice" sends HTTP method "PUT" to URL "" with content "updated content" + Then the HTTP status code should be "204" + And for user "Alice" the content of the file "/textfile.txt" of the space "Personal" should be "updated content" + Examples: + | dav-path | + | /remote.php/dav/spaces/<> | + | /dav/spaces/<> | + + + Scenario Outline: update content of a file inside a folder + Given user "Alice" has created folder "uploadFolder" + And user "Alice" has uploaded file with content "some data" to "uploadFolder/textfile.txt" + And we save it into "FILEID" + When user "Alice" sends HTTP method "PUT" to URL "" with content "updated content" + Then the HTTP status code should be "204" + And for user "Alice" the content of the file "/uploadFolder/textfile.txt" of the space "Personal" should be "updated content" + Examples: + | dav-path | + | /remote.php/dav/spaces/<> | + | /dav/spaces/<> | + + + Scenario Outline: update content of a file inside a project space + Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "new-space" with the default quota using the GraphApi + And user "Alice" has uploaded a file inside space "new-space" with content "some data" to "/textfile.txt" + And we save it into "FILEID" + When user "Alice" sends HTTP method "PUT" to URL "" with content "updated content" + Then the HTTP status code should be "204" + And for user "Alice" the content of the file "/textfile.txt" of the space "new-space" should be "updated content" + Examples: + | dav-path | + | /remote.php/dav/spaces/<> | + | /dav/spaces/<> | + + + Scenario Outline: sharee updates content of a shared file + Given user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has uploaded file with content "some data" to "/textfile.txt" + And we save it into "FILEID" + And user "Alice" has shared file "/textfile.txt" with user "Brian" + And user "Brian" has accepted share "/textfile.txt" offered by user "Alice" + When user "Brian" sends HTTP method "PUT" to URL "" with content "updated content" + Then the HTTP status code should be "204" + And for user "Alice" the content of the file "/textfile.txt" of the space "Personal" should be "updated content" + And for user "Brian" the content of the file "textfile.txt" of the space "Shares" should be "updated content" + Examples: + | dav-path | + | /remote.php/dav/spaces/<> | + | /dav/spaces/<> | + + + Scenario Outline: sharee updates content of a file inside a shared folder + Given user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has created folder "uploadFolder" + And user "Alice" has uploaded file with content "some data" to "uploadFolder/textfile.txt" + And we save it into "FILEID" + And user "Alice" has shared folder "/uploadFolder" with user "Brian" + And user "Brian" has accepted share "/uploadFolder" offered by user "Alice" + When user "Brian" sends HTTP method "PUT" to URL "" with content "updated content" + Then the HTTP status code should be "204" + And for user "Alice" the content of the file "uploadFolder/textfile.txt" of the space "Personal" should be "updated content" + And for user "Brian" the content of the file "uploadFolder/textfile.txt" of the space "Shares" should be "updated content" + Examples: + | dav-path | + | /remote.php/dav/spaces/<> | + | /dav/spaces/<> | + + + Scenario Outline: sharee with different role tries to update content of a file inside a shared space + Given user "Brian" has been created with default attributes and without skeleton files + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "new-space" with the default quota using the GraphApi + And user "Alice" has uploaded a file inside space "new-space" with content "some data" to "/textfile.txt" + And we save it into "FILEID" + And user "Alice" has shared a space "new-space" with settings: + | shareWith | Brian | + | role | | + When user "Brian" sends HTTP method "PUT" to URL "" with content "updated content" + Then the HTTP status code should be "" + And for user "Alice" the content of the file "/textfile.txt" of the space "new-space" should be "" + And for user "Brian" the content of the file "/textfile.txt" of the space "new-space" should be "" + Examples: + | dav-path | role | http_status_code | file-content | + | /remote.php/dav/spaces/<> | viewer | 403 | some data | + | /dav/spaces/<> | editor | 204 | updated content | + + + Scenario Outline: user tries to update content of a file owned by others + Given user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has uploaded file with content "some data" to "/textfile.txt" + And we save it into "FILEID" + When user "Brian" sends HTTP method "PUT" to URL "" with content "updated content" + Then the HTTP status code should be "404" + And for user "Alice" the content of the file "/textfile.txt" of the space "Personal" should be "some data" + Examples: + | dav-path | + | /remote.php/dav/spaces/<> | + | /dav/spcaes/<> | diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 0f263e66b39..52ff7a7314a 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -1156,7 +1156,7 @@ function ($subArray) { */ public function userSendsHTTPMethodToUrl(string $user, string $verb, string $url): void { $user = $this->getActualUsername($user); - $this->sendingToWithDirectUrl($user, $verb, $url, null); + $this->setResponse($this->sendingToWithDirectUrl($user, $verb, $url, null)); } /** @@ -1173,6 +1173,20 @@ public function userHasSentHTTPMethodToUrl(string $user, string $verb, string $u $this->theHTTPStatusCodeShouldBeSuccess(); } + /** + * @When user :user sends HTTP method :method to URL :davPath with content :content + * + * @param string $user + * @param string $method + * @param string $davPath + * @param string $content + * + * @return void + */ + public function userSendsHttpMethodToUrlWithContent(string $user, string $method, string $davPath, string $content): void { + $this->setResponse($this->sendingToWithDirectUrl($user, $method, $davPath, $content)); + } + /** * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to URL "([^"]*)" with password "([^"]*)"$/ * @@ -1184,7 +1198,7 @@ public function userHasSentHTTPMethodToUrl(string $user, string $verb, string $u * @return void */ public function userSendsHTTPMethodToUrlWithPassword(string $user, string $verb, string $url, string $password): void { - $this->sendingToWithDirectUrl($user, $verb, $url, null, $password); + $this->setResponse($this->sendingToWithDirectUrl($user, $verb, $url, null, $password)); } /** @@ -1206,13 +1220,13 @@ public function userHasSentHTTPMethodToUrlWithPassword(string $user, string $ver * @param string|null $user * @param string|null $verb * @param string|null $url - * @param TableNode|null $body + * @param TableNode|string|null $body * @param string|null $password * - * @return void + * @return ResponseInterface * @throws GuzzleException */ - public function sendingToWithDirectUrl(?string $user, ?string $verb, ?string $url, ?TableNode $body, ?string $password = null): void { + public function sendingToWithDirectUrl(?string $user, ?string $verb, ?string $url, $body = null, ?string $password = null): ResponseInterface { $fullUrl = $this->getBaseUrl() . $url; if ($password === null) { @@ -1239,12 +1253,15 @@ public function sendingToWithDirectUrl(?string $user, ?string $verb, ?string $ur if ($body instanceof TableNode) { $bodyRows = $body->getRowsHash(); } + if (\is_string($body)) { + $bodyRows = $body; + } if (isset($this->requestToken)) { $headers['requesttoken'] = $this->requestToken; } - $this->response = HttpRequestHelper::sendRequest( + return HttpRequestHelper::sendRequest( $fullUrl, $this->getStepLineRef(), $verb, From 233d9fa3c78db81b3332986c9fc2477a1df7c6bd Mon Sep 17 00:00:00 2001 From: prajwol Date: Thu, 24 Aug 2023 09:10:56 +0545 Subject: [PATCH 2/2] changed the datatype of body from Tablenode to string --- .../features/bootstrap/FeatureContext.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 52ff7a7314a..dabef111936 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -1220,13 +1220,13 @@ public function userHasSentHTTPMethodToUrlWithPassword(string $user, string $ver * @param string|null $user * @param string|null $verb * @param string|null $url - * @param TableNode|string|null $body + * @param string|null $body * @param string|null $password * * @return ResponseInterface * @throws GuzzleException */ - public function sendingToWithDirectUrl(?string $user, ?string $verb, ?string $url, $body = null, ?string $password = null): ResponseInterface { + public function sendingToWithDirectUrl(?string $user, ?string $verb, ?string $url, string $body = null, ?string $password = null): ResponseInterface { $fullUrl = $this->getBaseUrl() . $url; if ($password === null) { @@ -1249,14 +1249,6 @@ public function sendingToWithDirectUrl(?string $user, ?string $verb, ?string $ur $cookies = $this->cookieJar; } - $bodyRows = null; - if ($body instanceof TableNode) { - $bodyRows = $body->getRowsHash(); - } - if (\is_string($body)) { - $bodyRows = $body; - } - if (isset($this->requestToken)) { $headers['requesttoken'] = $this->requestToken; } @@ -1268,7 +1260,7 @@ public function sendingToWithDirectUrl(?string $user, ?string $verb, ?string $ur $user, $password, $headers, - $bodyRows, + $body, $config, $cookies );