From 873732fbb14c2ed1b46c471b0548d785b8f0cb0b Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Tue, 4 Jul 2023 14:43:00 +0200 Subject: [PATCH] [test-only][full-ci]ApiTests. purge trash bin tests (#6699) * purge trash bin tests * fix --- .../features/apiSpaces/quota.feature | 10 +++ ...eSpaceObjects.feature => trashBin.feature} | 51 +++++++++++--- .../features/bootstrap/SpacesContext.php | 68 ++++++++++++++++++- 3 files changed, 117 insertions(+), 12 deletions(-) rename tests/acceptance/features/apiSpaces/{restoreSpaceObjects.feature => trashBin.feature} (65%) diff --git a/tests/acceptance/features/apiSpaces/quota.feature b/tests/acceptance/features/apiSpaces/quota.feature index d31e23198e6..e784ba48de3 100644 --- a/tests/acceptance/features/apiSpaces/quota.feature +++ b/tests/acceptance/features/apiSpaces/quota.feature @@ -139,3 +139,13 @@ Feature: State of the quota When user "Brian" tries to create a space "new space" of type "project" with quota "51" using the Graph API Then the HTTP status code should be "400" And the user "Brian" should not have a space called "new space" + + + Scenario: user can restore a file version even if there is not enough quota to do so + Given user "Admin" has changed the quota of the "Alice Hansen" space to "30" + And user "Alice" has uploaded file with content "file is less than 30 bytes" to "/file.txt" + And user "Alice" has uploaded file with content "reduceContent" to "/file.txt" + And user "Alice" has uploaded file with content "some content" to "newFile.txt" + When user "Alice" restores version index "1" of file "/file.txt" using the WebDAV API + Then the HTTP status code should be "204" + And the content of file "/file.txt" for user "Alice" should be "file is less than 30 bytes" diff --git a/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature b/tests/acceptance/features/apiSpaces/trashBin.feature similarity index 65% rename from tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature rename to tests/acceptance/features/apiSpaces/trashBin.feature index 7bc737b0263..701a383b97c 100644 --- a/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature +++ b/tests/acceptance/features/apiSpaces/trashBin.feature @@ -12,8 +12,6 @@ Feature: Restore files, folder | username | | Alice | | Brian | - | Bob | - | Carol | And using spaces DAV path And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API And user "Alice" has created a space "restore objects" with the default quota using the GraphApi @@ -74,11 +72,44 @@ Feature: Restore files, folder | Brian | viewer | 403 | should not | should | - Scenario: user can restore a file even if there is not enough quota to do so - Given user "Admin" has changed the quota of the "Brian Murphy" space to "30" - And user "Brian" has uploaded file with content "file is less than 30 bytes" to "/file.txt" - And user "Brian" has uploaded file with content "reduceContent" to "/file.txt" - And user "Brian" has uploaded file with content "some content" to "newFile.txt" - When user "Brian" restores version index "1" of file "/file.txt" using the WebDAV API - Then the HTTP status code should be "204" - And the content of file "/file.txt" for user "Brian" should be "file is less than 30 bytes" + Scenario Outline: only space manager can purge the trash via the webDav API + Given user "Alice" has shared a space "restore objects" with settings: + | shareWith | Brian | + | role | | + And the administrator has assigned the role "Space Admin" to user "Brian" using the Graph API + And user "Alice" has removed the file "newFolder/file.txt" from space "restore objects" + When user "Brian" deletes the file "file.txt" from the trash of the space "restore objects" + Then the HTTP status code should be "" + And as "Brian" file "file.txt" exist in the trashbin of the space "restore objects" + Examples: + | role | code | shouldOrNotBeInTrash | + | manager | 204 | should not | + | editor | 403 | should | + | viewer | 403 | should | + + + Scenario Outline: admin user who is not a member of space cannot see its trash bin + Given user "Alice" has removed the file "newFolder/file.txt" from space "restore objects" + And the administrator has assigned the role "" to user "Brian" using the Graph API + When user "Brian" with admin permission lists all deleted files in the trash bin of the space "restore objects" + Then the HTTP status code should be "404" + Examples: + | role | + | Space Admin | + | Admin | + + + Scenario Outline: admin user without space-manager role cannot purge the trash + Given user "Alice" has shared a space "restore objects" with settings: + | shareWith | Brian | + | role | editor | + And the administrator has assigned the role "" to user "Brian" using the Graph API + And user "Alice" has removed the file "newFolder/file.txt" from space "restore objects" + When user "Brian" tries to delete the file "file.txt" from the trash of the space "restore objects" + Then the HTTP status code should be "403" + And as "Alice" file "file.txt" should exist in the trashbin of the space "restore objects" + Examples: + | role | + | Space Admin | + | Admin | + diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 732dda64647..e7242abe665 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -199,7 +199,7 @@ public function getSpaceByName(string $user, string $spaceName): array { $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); } $spaces = $this->getAvailableSpaces(); - Assert::assertIsArray($spaces[$spaceName], "Space with name $spaceName for user $user not found"); + Assert::assertArrayHasKey($spaceName, $spaces, "Space with name $spaceName for user $user not found"); Assert::assertNotEmpty($spaces[$spaceName]["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName for user $user not found"); return $spaces[$spaceName]; } @@ -2365,6 +2365,26 @@ public function userListAllDeletedFilesInTrash( ); } + /** + * @When /^user "([^"]*)" with admin permission lists all deleted files in the trash bin of the space "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * + * @return void + * @throws GuzzleException + */ + public function adminListAllDeletedFilesInTrash( + string $user, + string $spaceName + ): void { + $space = $this->getSpaceByNameManager($user, $spaceName); + $fullUrl = $this->baseUrl . $this->davSpacesUrl . "trash-bin/" . $space["id"]; + $this->featureContext->setResponse( + HttpRequestHelper::sendRequest($fullUrl, '', 'PROPFIND', $user, $this->featureContext->getPasswordForUser($user)) + ); + } + /** * User get all objects in the trash of project space * @@ -2460,7 +2480,7 @@ public function userRestoresSpaceObjectsFromTrashRequest( } if ($pathToDeletedObject === "") { - throw new Exception(__METHOD__ . " Object '$object' was not found in the trashbin of user '$user' space '$spaceName'"); + throw new Exception(__METHOD__ . " Object '$object' was not found in the trashbin of space '$spaceName' by user '$user'"); } $destination = $this->baseUrl . $this->davSpacesUrl . $space["id"] . $destination; @@ -2480,6 +2500,50 @@ public function userRestoresSpaceObjectsFromTrashRequest( ); } + /** + * @When user :user deletes the file/folder :resource from the trash of the space :spaceName + * @When user :user tries to delete the file/folder :resource from the trash of the space :spaceName + * + * @param string $user + * @param string $object + * @param string $spaceName + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function userDeletesObjectsFromTrashRequest( + string $user, + string $object, + string $spaceName + ): void { + // find object in trash + $objectsInTrash = $this->getObjectsInTrashbin($user, $spaceName); + $pathToDeletedObject = ""; + foreach ($objectsInTrash as $objectInTrash) { + if ($objectInTrash["name"] === $object) { + $pathToDeletedObject = $objectInTrash["href"]; + } + } + + if ($pathToDeletedObject === "") { + throw new Exception(__METHOD__ . " Object '$object' was not found in the trashbin of space '$spaceName' by user '$user'"); + } + + $fullUrl = $this->baseUrl . $pathToDeletedObject; + $this->featureContext->setResponse( + HttpRequestHelper::sendRequest( + $fullUrl, + "", + 'DELETE', + $user, + $this->featureContext->getPasswordForUser($user), + [], + "" + ) + ); + } + /** * User downloads a preview of the file inside the project space *