From ed81da84e7892b586dc4ec5454fb24d6f97eff65 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Tue, 25 Jan 2022 14:59:15 +0100 Subject: [PATCH 1/3] add tests remove objects. Add creating subfolder, showing object in folder --- ...ected-failures-localAPI-on-OCIS-storage.md | 6 + .../features/apiSpaces/removeSpaces.feature | 181 ++++++++++++++++++ .../features/apiSpaces/uploadSpaces.feature | 14 ++ .../features/bootstrap/SpacesContext.php | 99 +++++++++- 4 files changed, 291 insertions(+), 9 deletions(-) create mode 100644 tests/acceptance/features/apiSpaces/removeSpaces.feature diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 591c12dcf54..49ce60e0345 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -21,3 +21,9 @@ #### [Overwriting a file in the space within the allowed quota does not work](https://github.com/owncloud/ocis/issues/2829) - [apiSpaces/quota.feature:56](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/quota.feature#L56) +#### [Viewer has the possibility to delete the space](https://github.com/owncloud/ocis/issues/3031) +- [apiSpaces/removeSpaces.feature:130](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L130) +- [apiSpaces/removeSpaces.feature:140](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L140) +- [apiSpaces/removeSpaces.feature:150](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L150) +- [apiSpaces/removeSpaces.feature:160](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L160) +- [apiSpaces/removeSpaces.feature:171](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L171) diff --git a/tests/acceptance/features/apiSpaces/removeSpaces.feature b/tests/acceptance/features/apiSpaces/removeSpaces.feature new file mode 100644 index 00000000000..b9e4d39b621 --- /dev/null +++ b/tests/acceptance/features/apiSpaces/removeSpaces.feature @@ -0,0 +1,181 @@ +@api @skipOnOcV10 +Feature: Remove files, folder and spaces + As a user + I want to be able to remove files, folders and space itself + Users with the editor role can also remove objects + Users with the viewer role cannot remove objects + + Note - this feature is run in CI with ACCOUNTS_HASH_DIFFICULTY set to the default for production + See https://github.com/owncloud/ocis/issues/1542 and https://github.com/owncloud/ocis/pull/839 + + Background: + Given user "Alice" has been created with default attributes and without skeleton files + And user "Brian" has been created with default attributes and without skeleton files + And the administrator has given "Alice" the role "Admin" using the settings api + +# owner of space + + Scenario: A owner can delete a folder with some subfolders in a Space via the webDav API + Given user "Alice" has created a space "Owner deletes folder" of type "project" with quota "10" + And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Owner deletes folder" + When user "Alice" removes the object "folderForDeleting" from space "Owner deletes folder" + Then the HTTP status code should be "200" + And for user "Alice" the space "Owner deletes folder" should not contain these entries: + | folderForDeleting | + + + Scenario: A owner can delete a subfolder in a Space via the webDav API + Given user "Alice" has created a space "Owner deletes subfolder" of type "project" with quota "10" + And user "Alice" has created a subfolder "folder/subFolderForDeleting" in space "Owner deletes subfolder" + When user "Alice" removes the object "folder/subFolderForDeleting" from space "Owner deletes subfolder" + Then the HTTP status code should be "200" + And for user "Alice" the space "Owner deletes subfolder" should contain these entries: + | folder | + And for user "Alice" folder "folder/" of the space "Owner deletes subfolder" should not contain these entries: + | subFolderForDeleting | + + + Scenario: A owner can delete a file in a Space via the webDav API + Given user "Alice" has created a space "Owner deletes file" of type "project" with quota "20" + And user "Alice" has uploaded a file inside space "Owner deletes file" with content "some content" to "text.txt" + When user "Alice" removes the object "text.txt" from space "Owner deletes file" + Then the HTTP status code should be "200" + And for user "Alice" the space "Owner deletes file" should not contain these entries: + | text.txt | + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should contain a space "Owner deletes file" with these key and value pairs: + | key | value | + | name | Owner deletes file | + | quota@@@used | 0 | + + + Scenario: A owner can delete a empty Space via the webDav API + Given user "Alice" has created a space "Owner deletes empty space" of type "project" with quota "20" + When user "Alice" removes a space "Owner deletes empty space" + Then the HTTP status code should be "200" + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should not contain a space with name "Owner deletes empty space" + + + Scenario: A owner can delete a Space containing folders and files via the webDav API + Given user "Alice" has created a space "Owner deletes space" of type "project" with quota "20" + And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Owner deletes space" + And user "Alice" has uploaded a file inside space "Owner deletes space" with content "some content" to "folderForDeleting/sub1/sub2/text.txt" + When user "Alice" removes a space "Owner deletes space" + Then the HTTP status code should be "200" + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should not contain a space with name "Owner deletes space" + +# editor role + + Scenario: A editor can delete a folder with some subfolders in a Space via the webDav API + Given user "Alice" has created a space "Editor deletes folder" of type "project" with quota "10" + And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Editor deletes folder" + And user "Alice" has shared a space "Editor deletes folder" to user "Brian" with role "editor" + When user "Brian" removes the object "folderForDeleting" from space "Editor deletes folder" + Then the HTTP status code should be "200" + And for user "Brian" the space "Editor deletes folder" should not contain these entries: + | folderForDeleting | + + + Scenario: A editor can delete a subfolder in a Space via the webDav API + Given user "Alice" has created a space "Editor deletes subfolder" of type "project" with quota "10" + And user "Alice" has created a subfolder "folder/subFolderForDeleting" in space "Editor deletes subfolder" + And user "Alice" has shared a space "Editor deletes subfolder" to user "Brian" with role "editor" + When user "Brian" removes the object "folder/subFolderForDeleting" from space "Editor deletes subfolder" + Then the HTTP status code should be "200" + And for user "Brian" the space "Editor deletes subfolder" should contain these entries: + | folder | + And for user "Brian" folder "folder/" of the space "Editor deletes subfolder" should not contain these entries: + | subFolderForDeleting | + + + Scenario: A editor can delete a file in a Space via the webDav API + Given user "Alice" has created a space "Editor deletes file" of type "project" with quota "20" + And user "Alice" has uploaded a file inside space "Editor deletes file" with content "some content" to "text.txt" + And user "Alice" has shared a space "Editor deletes file" to user "Brian" with role "editor" + When user "Brian" removes the object "text.txt" from space "Editor deletes file" + Then the HTTP status code should be "200" + And for user "Brian" the space "Editor deletes file" should not contain these entries: + | text.txt | + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should contain a space "Editor deletes file" with these key and value pairs: + | key | value | + | name | Editor deletes file | + | quota@@@used | 0 | + + + Scenario: A editor can delete a empty Space via the webDav API + Given user "Alice" has created a space "Editor deletes empty space" of type "project" with quota "20" + And user "Alice" has shared a space "Editor deletes empty space" to user "Brian" with role "editor" + When user "Brian" removes a space "Editor deletes empty space" + Then the HTTP status code should be "200" + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should not contain a space with name "Editor deletes empty space" + + + Scenario: A editor can delete a Space containing folders and files via the webDav API + Given user "Alice" has created a space "Editor deletes space" of type "project" with quota "20" + And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Editor deletes space" + And user "Alice" has uploaded a file inside space "Editor deletes space" with content "some content" to "folderForDeleting/sub1/sub2/text.txt" + And user "Alice" has shared a space "Editor deletes space" to user "Brian" with role "editor" + When user "Brian" removes a space "Editor deletes space" + Then the HTTP status code should be "200" + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should not contain a space with name "Editor deletes space" + + +# viewer role + + Scenario: A viewer cannot delete a folder with some subfolders in a Space via the webDav API + Given user "Alice" has created a space "Viewer deletes folder" of type "project" with quota "10" + And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Viewer deletes folder" + And user "Alice" has shared a space "Viewer deletes folder" to user "Brian" with role "viewer" + When user "Brian" removes the object "folderForDeleting" from space "Viewer deletes folder" + Then the HTTP status code should be "403" + And for user "Brian" the space "Viewer deletes folder" should contain these entries: + | folderForDeleting | + + + Scenario: A viewer cannot delete a subfolder in a Space via the webDav API + Given user "Alice" has created a space "Viewer deletes subfolder" of type "project" with quota "10" + And user "Alice" has created a subfolder "folder/subFolderForDeleting" in space "Viewer deletes subfolder" + And user "Alice" has shared a space "Viewer deletes subfolder" to user "Brian" with role "viewer" + When user "Brian" removes the object "folder/subFolderForDeleting" from space "Viewer deletes subfolder" + Then the HTTP status code should be "403" + And for user "Brian" folder "folder/" of the space "Viewer deletes subfolder" should contain these entries: + | subFolderForDeleting | + + + Scenario: A viewer cannot delete a file in a Space via the webDav API + Given user "Alice" has created a space "Viewer deletes file" of type "project" with quota "20" + And user "Alice" has uploaded a file inside space "Viewer deletes file" with content "some content" to "text.txt" + And user "Alice" has shared a space "Viewer deletes file" to user "Brian" with role "viewer" + When user "Brian" removes the object "text.txt" from space "Viewer deletes file" + Then the HTTP status code should be "403" + And for user "Brian" the space "Viewer deletes file" should contain these entries: + | text.txt | + + + Scenario: A viewer cannot delete a empty Space via the webDav API + Given user "Alice" has created a space "Viewer deletes empty space" of type "project" with quota "20" + And user "Alice" has shared a space "Viewer deletes empty space" to user "Brian" with role "viewer" + When user "Brian" removes a space "Viewer deletes empty space" + Then the HTTP status code should be "403" + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should contain a space "Viewer deletes empty space" with these key and value pairs: + | key | value | + | name | Viewer deletes empty space | + + + Scenario: A viewer cannot delete a Space containing folders and files via the webDav API + Given user "Alice" has created a space "Viewer deletes space" of type "project" with quota "20" + And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Viewer deletes space" + And user "Alice" has uploaded a file inside space "Viewer deletes space" with content "some content" to "folderForDeleting/sub1/sub2/text.txt" + And user "Alice" has shared a space "Viewer deletes space" to user "Brian" with role "viewer" + When user "Brian" removes a space "Viewer deletes space" + Then the HTTP status code should be "403" + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should contain a space "Viewer deletes space" with these key and value pairs: + | key | value | + | name | Viewer deletes space | diff --git a/tests/acceptance/features/apiSpaces/uploadSpaces.feature b/tests/acceptance/features/apiSpaces/uploadSpaces.feature index 638866a5bfd..4e62cbb7546 100644 --- a/tests/acceptance/features/apiSpaces/uploadSpaces.feature +++ b/tests/acceptance/features/apiSpaces/uploadSpaces.feature @@ -11,6 +11,7 @@ Feature: Upload files into a space And user "Bob" has been created with default attributes and without skeleton files And the administrator has given "Alice" the role "Admin" using the settings api + Scenario: A user can create a folder in a Space via the Graph API Given user "Alice" has created a space "Project Ceres" of type "project" with quota "2000" When user "Alice" creates a folder "mainFolder" in space "Project Ceres" using the WebDav Api @@ -18,6 +19,16 @@ Feature: Upload files into a space And for user "Alice" the space "Project Ceres" should contain these entries: | mainFolder | + + Scenario: A user can create a subfolders in a Space via the Graph API + Given user "Alice" has created a space "Subfolders in Project" of type "project" with quota "2000" + When user "Alice" creates a subfolder "mainFolder/subFolder1/subFolder2" in space "Subfolders in Project" using the WebDav Api + Then the HTTP status code should be "201" + And for user "Alice" the space "Subfolders in Project" should contain these entries: + | mainFolder | + And for user "Alice" folder "mainFolder/subFolder1/" of the space "Subfolders in Project" should contain these entries: + | subFolder2 | + Scenario: A user cannot create a folder in a Space if they do not have permission Given user "Alice" has created a space "Project Merkur" of type "project" with quota "2000" And user "Bob" creates a folder "forAlice" in space "Project Merkur" owned by the user "Alice" using the WebDav Api @@ -25,6 +36,7 @@ Feature: Upload files into a space And for user "Alice" the space "Project Merkur" should not contain these entries: | forAlice | + Scenario: A user can create a folder and upload a file to a Space Given user "Alice" has created a space "Project Moon" of type "project" with quota "2000" When user "Alice" creates a folder "NewFolder" in space "Project Moon" using the WebDav Api @@ -42,6 +54,7 @@ Feature: Upload files into a space And for user "Alice" the space "Project Pluto" should not contain these entries: | test.txt | + Scenario: A user can upload a file in a Space and see the remaining quota When user "Alice" creates a space "Project Saturn" of type "project" with quota "2000" using the GraphApi And the json responded should contain a space "Project Saturn" with these key and value pairs: @@ -65,6 +78,7 @@ Feature: Upload files into a space | quota@@@remaining| 1996 | | quota@@@used | 4 | + Scenario: A user with role editor can create a folder in shared Space via the Graph API Given user "Alice" has created a space "Editor can create folder" of type "project" with quota "2000" And user "Alice" has shared a space "Editor can create folder" to user "Bob" with role "editor" diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 153310be200..3e1b6af248f 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -581,6 +581,7 @@ class SpacesContext implements Context { * * @param string $user * @param string $spaceName + * @param string $path * * @return void * @@ -588,7 +589,8 @@ class SpacesContext implements Context { */ public function theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi( string $user, - string $spaceName + string $spaceName, + string $foldersPath = '' ): void { $space = $this->getSpaceByName($user, $spaceName); Assert::assertIsArray($space); @@ -596,7 +598,7 @@ class SpacesContext implements Context { Assert::assertNotEmpty($spaceWebDavUrl = $space["root"]["webDavUrl"]); $this->featureContext->setResponse( $this->sendPropfindRequestToUrl( - $spaceWebDavUrl, + $spaceWebDavUrl . '/' . $foldersPath, $user, $this->featureContext->getPasswordForUser($user), "", @@ -677,9 +679,41 @@ class SpacesContext implements Context { $user, $spaceName ); + $this->propfindResultShouldContainEntries( + $shouldOrNot, + $expectedFiles + ); + } + + /** + * @Then /^for user "([^"]*)" folder "([^"]*)" of the space "([^"]*)" should (not|)\s?contain these (?:files|entries):$/ + * + * @param string $user + * @param string $folderPath + * @param string $spaceName + * @param string $shouldOrNot (not|) + * @param TableNode $expectedFiles + * + * @return void + * + * @throws Exception|GuzzleException + */ + public function folderOfTheSpaceShouldContainEntries( + string $user, + string $folderPath, + string $spaceName, + string $shouldOrNot, + TableNode $expectedFiles + ): void { + $this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi( + $user, + $spaceName, + $folderPath + ); $this->propfindResultShouldContainEntries( $shouldOrNot, $expectedFiles, + $folderPath ); } @@ -786,6 +820,7 @@ class SpacesContext implements Context { /** * @param string $shouldOrNot (not|) * @param TableNode $expectedFiles + * @param string $folderPath * * @return void * @@ -793,7 +828,8 @@ class SpacesContext implements Context { */ public function propfindResultShouldContainEntries( string $shouldOrNot, - TableNode $expectedFiles + TableNode $expectedFiles, + string $folderPath = '' ): void { $this->verifyTableNodeColumnsCount($expectedFiles, 1); $elementRows = $expectedFiles->getRows(); @@ -801,7 +837,8 @@ class SpacesContext implements Context { foreach ($elementRows as $expectedFile) { $fileFound = $this->findEntryFromPropfindResponse( - $expectedFile[0] + $expectedFile[0], + $folderPath ); if ($should) { Assert::assertNotEmpty( @@ -852,7 +889,8 @@ class SpacesContext implements Context { * boolean false if $entryNameToSearch is given and is not found */ public function findEntryFromPropfindResponse( - string $entryNameToSearch = null + string $entryNameToSearch = null, + string $folderPath = '' ): array { $spaceId = $this->getResponseSpaceId(); //if we are using that step the second time in a scenario e.g. 'But ... should not' @@ -870,7 +908,7 @@ class SpacesContext implements Context { // topWebDavPath should be something like /remote.php/webdav/ or // /remote.php/dav/files/alice/ - $topWebDavPath = "/" . "dav/spaces/" . $spaceId . "/"; + $topWebDavPath = "/" . "dav/spaces/" . $spaceId . "/" . $folderPath; Assert::assertIsArray( $this->responseXml, @@ -902,7 +940,7 @@ class SpacesContext implements Context { } /** - * @When /^user "([^"]*)" creates a folder "([^"]*)" in space "([^"]*)" using the WebDav Api$/ + * @When /^user "([^"]*)" creates a (?:folder|subfolder) "([^"]*)" in space "([^"]*)" using the WebDav Api$/ * * @param string $user * @param string $folder @@ -917,11 +955,16 @@ class SpacesContext implements Context { string $folder, string $spaceName ): void { - $this->theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi($user, $folder, $spaceName); + $exploded = explode('/', $folder); + $path = ''; + for ($i = 0; $i < count($exploded); $i++) { + $path = $path . $exploded[$i] . '/'; + $this->theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi($user, $path, $spaceName); + }; } /** - * @Given /^user "([^"]*)" has created a folder "([^"]*)" in space "([^"]*)"$/ + * @Given /^user "([^"]*)" has created a (?:folder|subfolder) "([^"]*)" in space "([^"]*)"$/ * * @param string $user * @param string $folder @@ -1331,4 +1374,42 @@ class SpacesContext implements Context { HttpRequestHelper::delete($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user)); } + + /** + * @When /^user "([^"]*)" removes the object "([^"]*)" from space "([^"]*)"$/ + * + * @param string $user + * @param string $object + * @param string $spaceName + * + * @return void + * @throws GuzzleException + */ + public function sendRemoveObjectFromSpaceRequest( + string $user, + string $object, + string $spaceName + ): void { + $space = $this->getSpaceByName($user, $spaceName); + $spaceWebDavUrl = $space["root"]["webDavUrl"] . '/' . $object; + HttpRequestHelper::delete($spaceWebDavUrl, "", $user, $this->featureContext->getPasswordForUser($user)); + } + + /** + * @When /^user "([^"]*)" removes a space "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * + * @return void + * @throws GuzzleException + */ + public function sendRemoveSpaceRequest( + string $user, + string $spaceName + ): void { + $space = $this->getSpaceByName($user, $spaceName); + $spaceWebDavUrl = $space["root"]["webDavUrl"]; + HttpRequestHelper::delete($spaceWebDavUrl, "", $user, $this->featureContext->getPasswordForUser($user)); + } } From 7a91fc00121e2e2dc81e4f7d53a5886791ec2f47 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Tue, 25 Jan 2022 20:57:02 +0100 Subject: [PATCH 2/3] typo corrections --- .../features/apiSpaces/removeSpaces.feature | 46 +++++++++---------- .../features/apiSpaces/uploadSpaces.feature | 4 +- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/tests/acceptance/features/apiSpaces/removeSpaces.feature b/tests/acceptance/features/apiSpaces/removeSpaces.feature index b9e4d39b621..71e65273e29 100644 --- a/tests/acceptance/features/apiSpaces/removeSpaces.feature +++ b/tests/acceptance/features/apiSpaces/removeSpaces.feature @@ -15,7 +15,7 @@ Feature: Remove files, folder and spaces # owner of space - Scenario: A owner can delete a folder with some subfolders in a Space via the webDav API + Scenario: An owner can delete a folder with some subfolders in a Space via the webDav API Given user "Alice" has created a space "Owner deletes folder" of type "project" with quota "10" And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Owner deletes folder" When user "Alice" removes the object "folderForDeleting" from space "Owner deletes folder" @@ -24,7 +24,7 @@ Feature: Remove files, folder and spaces | folderForDeleting | - Scenario: A owner can delete a subfolder in a Space via the webDav API + Scenario: An owner can delete a subfolder in a Space via the webDav API Given user "Alice" has created a space "Owner deletes subfolder" of type "project" with quota "10" And user "Alice" has created a subfolder "folder/subFolderForDeleting" in space "Owner deletes subfolder" When user "Alice" removes the object "folder/subFolderForDeleting" from space "Owner deletes subfolder" @@ -35,7 +35,7 @@ Feature: Remove files, folder and spaces | subFolderForDeleting | - Scenario: A owner can delete a file in a Space via the webDav API + Scenario: An owner can delete a file in a Space via the webDav API Given user "Alice" has created a space "Owner deletes file" of type "project" with quota "20" And user "Alice" has uploaded a file inside space "Owner deletes file" with content "some content" to "text.txt" When user "Alice" removes the object "text.txt" from space "Owner deletes file" @@ -49,15 +49,15 @@ Feature: Remove files, folder and spaces | quota@@@used | 0 | - Scenario: A owner can delete a empty Space via the webDav API - Given user "Alice" has created a space "Owner deletes empty space" of type "project" with quota "20" - When user "Alice" removes a space "Owner deletes empty space" + Scenario: An owner can delete an empty Space via the webDav API + Given user "Alice" has created a space "Owner deletes an empty space" of type "project" with quota "20" + When user "Alice" removes a space "Owner deletes an empty space" Then the HTTP status code should be "200" When user "Alice" lists all available spaces via the GraphApi - Then the json responded should not contain a space with name "Owner deletes empty space" + Then the json responded should not contain a space with name "Owner deletes an empty space" - Scenario: A owner can delete a Space containing folders and files via the webDav API + Scenario: An owner can delete a Space containing folders and files via the webDav API Given user "Alice" has created a space "Owner deletes space" of type "project" with quota "20" And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Owner deletes space" And user "Alice" has uploaded a file inside space "Owner deletes space" with content "some content" to "folderForDeleting/sub1/sub2/text.txt" @@ -68,7 +68,7 @@ Feature: Remove files, folder and spaces # editor role - Scenario: A editor can delete a folder with some subfolders in a Space via the webDav API + Scenario: An editor can delete a folder with some subfolders in a Space via the webDav API Given user "Alice" has created a space "Editor deletes folder" of type "project" with quota "10" And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Editor deletes folder" And user "Alice" has shared a space "Editor deletes folder" to user "Brian" with role "editor" @@ -78,7 +78,7 @@ Feature: Remove files, folder and spaces | folderForDeleting | - Scenario: A editor can delete a subfolder in a Space via the webDav API + Scenario: An editor can delete a subfolder in a Space via the webDav API Given user "Alice" has created a space "Editor deletes subfolder" of type "project" with quota "10" And user "Alice" has created a subfolder "folder/subFolderForDeleting" in space "Editor deletes subfolder" And user "Alice" has shared a space "Editor deletes subfolder" to user "Brian" with role "editor" @@ -90,7 +90,7 @@ Feature: Remove files, folder and spaces | subFolderForDeleting | - Scenario: A editor can delete a file in a Space via the webDav API + Scenario: An editor can delete a file in a Space via the webDav API Given user "Alice" has created a space "Editor deletes file" of type "project" with quota "20" And user "Alice" has uploaded a file inside space "Editor deletes file" with content "some content" to "text.txt" And user "Alice" has shared a space "Editor deletes file" to user "Brian" with role "editor" @@ -105,16 +105,16 @@ Feature: Remove files, folder and spaces | quota@@@used | 0 | - Scenario: A editor can delete a empty Space via the webDav API - Given user "Alice" has created a space "Editor deletes empty space" of type "project" with quota "20" - And user "Alice" has shared a space "Editor deletes empty space" to user "Brian" with role "editor" - When user "Brian" removes a space "Editor deletes empty space" + Scenario: An editor can delete an empty Space via the webDav API + Given user "Alice" has created a space "Editor deletes an empty space" of type "project" with quota "20" + And user "Alice" has shared a space "Editor deletes an empty space" to user "Brian" with role "editor" + When user "Brian" removes a space "Editor deletes an empty space" Then the HTTP status code should be "200" When user "Brian" lists all available spaces via the GraphApi - Then the json responded should not contain a space with name "Editor deletes empty space" + Then the json responded should not contain a space with name "Editor deletes an empty space" - Scenario: A editor can delete a Space containing folders and files via the webDav API + Scenario: An editor can delete a Space containing folders and files via the webDav API Given user "Alice" has created a space "Editor deletes space" of type "project" with quota "20" And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Editor deletes space" And user "Alice" has uploaded a file inside space "Editor deletes space" with content "some content" to "folderForDeleting/sub1/sub2/text.txt" @@ -157,15 +157,15 @@ Feature: Remove files, folder and spaces | text.txt | - Scenario: A viewer cannot delete a empty Space via the webDav API - Given user "Alice" has created a space "Viewer deletes empty space" of type "project" with quota "20" - And user "Alice" has shared a space "Viewer deletes empty space" to user "Brian" with role "viewer" - When user "Brian" removes a space "Viewer deletes empty space" + Scenario: A viewer cannot delete an empty Space via the webDav API + Given user "Alice" has created a space "Viewer deletes an empty space" of type "project" with quota "20" + And user "Alice" has shared a space "Viewer deletes an empty space" to user "Brian" with role "viewer" + When user "Brian" removes a space "Viewer deletes an empty space" Then the HTTP status code should be "403" When user "Brian" lists all available spaces via the GraphApi - Then the json responded should contain a space "Viewer deletes empty space" with these key and value pairs: + Then the json responded should contain a space "Viewer deletes an empty space" with these key and value pairs: | key | value | - | name | Viewer deletes empty space | + | name | Viewer deletes an empty space | Scenario: A viewer cannot delete a Space containing folders and files via the webDav API diff --git a/tests/acceptance/features/apiSpaces/uploadSpaces.feature b/tests/acceptance/features/apiSpaces/uploadSpaces.feature index 4e62cbb7546..769da807dee 100644 --- a/tests/acceptance/features/apiSpaces/uploadSpaces.feature +++ b/tests/acceptance/features/apiSpaces/uploadSpaces.feature @@ -20,7 +20,7 @@ Feature: Upload files into a space | mainFolder | - Scenario: A user can create a subfolders in a Space via the Graph API + Scenario: A user can create subfolders in a Space via the Graph API Given user "Alice" has created a space "Subfolders in Project" of type "project" with quota "2000" When user "Alice" creates a subfolder "mainFolder/subFolder1/subFolder2" in space "Subfolders in Project" using the WebDav Api Then the HTTP status code should be "201" @@ -29,6 +29,7 @@ Feature: Upload files into a space And for user "Alice" folder "mainFolder/subFolder1/" of the space "Subfolders in Project" should contain these entries: | subFolder2 | + Scenario: A user cannot create a folder in a Space if they do not have permission Given user "Alice" has created a space "Project Merkur" of type "project" with quota "2000" And user "Bob" creates a folder "forAlice" in space "Project Merkur" owned by the user "Alice" using the WebDav Api @@ -47,6 +48,7 @@ Feature: Upload files into a space | NewFolder | | test.txt | + Scenario: A user cannot upload a file in a Space if they do not have permission Given user "Alice" has created a space "Project Pluto" of type "project" with quota "2000" When user "Bob" uploads a file inside space "Project Pluto" owned by the user "Alice" with content "Test" to "test.txt" using the WebDAV API From 828d3eec96ec4f5354bcddc81dd502c641bede87 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Sun, 30 Jan 2022 20:50:41 +0100 Subject: [PATCH 3/3] change tests. add disabling/deleting space tests --- ...ected-failures-localAPI-on-OCIS-storage.md | 10 +-- .../features/apiSpaces/deleteSpaces.feature | 79 ++++++++++++++++ ...ces.feature => removeSpaceObjects.feature} | 89 ++++--------------- .../features/bootstrap/SpacesContext.php | 82 +++++++++++++++-- 4 files changed, 177 insertions(+), 83 deletions(-) create mode 100644 tests/acceptance/features/apiSpaces/deleteSpaces.feature rename tests/acceptance/features/apiSpaces/{removeSpaces.feature => removeSpaceObjects.feature} (61%) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 49ce60e0345..f26e00031ce 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -21,9 +21,7 @@ #### [Overwriting a file in the space within the allowed quota does not work](https://github.com/owncloud/ocis/issues/2829) - [apiSpaces/quota.feature:56](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/quota.feature#L56) -#### [Viewer has the possibility to delete the space](https://github.com/owncloud/ocis/issues/3031) -- [apiSpaces/removeSpaces.feature:130](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L130) -- [apiSpaces/removeSpaces.feature:140](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L140) -- [apiSpaces/removeSpaces.feature:150](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L150) -- [apiSpaces/removeSpaces.feature:160](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L160) -- [apiSpaces/removeSpaces.feature:171](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaces.feature#L171) +#### [Viewer and editor has the possibility to disable the space](https://github.com/owncloud/ocis/issues/3031) +- [apiSpaces/removeSpaceObjects.feature:121](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature#L121) +- [apiSpaces/deleteSpaces.feature:60](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/deleteSpaces.feature#L60) +- [apiSpaces/deleteSpaces.feature:71](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/deleteSpaces.feature#L60) diff --git a/tests/acceptance/features/apiSpaces/deleteSpaces.feature b/tests/acceptance/features/apiSpaces/deleteSpaces.feature new file mode 100644 index 00000000000..979bd840c08 --- /dev/null +++ b/tests/acceptance/features/apiSpaces/deleteSpaces.feature @@ -0,0 +1,79 @@ +@api @skipOnOcV10 +Feature: Disabling and deleting space + As a manager of space + I want to be able to disable the space first, then delete it. + I want to make sure that a disabled spaces isn't accessible by shared users. + + Note - this feature is run in CI with ACCOUNTS_HASH_DIFFICULTY set to the default for production + See https://github.com/owncloud/ocis/issues/1542 and https://github.com/owncloud/ocis/pull/839 + + Background: + Given user "Alice" has been created with default attributes and without skeleton files + And user "Brian" has been created with default attributes and without skeleton files + And the administrator has given "Alice" the role "Admin" using the settings api + + + Scenario: An owner can disable a Space via the Graph API + Given user "Alice" has created a space "disable a space" of type "project" with quota "10" + And user "Alice" has shared a space "disable a space" to user "Brian" with role "editor" + When user "Alice" disables a space "disable a space" + Then the HTTP status code should be "204" + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should contain a space "disable a space" with these key and value pairs: + | key | value | + | name | disable a space | + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should not contain a space with name "disable a space" + + + Scenario: An owner can delete a disabled Space via the webDav API + Given user "Alice" has created a space "delete a space" of type "project" with quota "10" + And user "Alice" has disabled a space "delete a space" + When user "Alice" deletes a space "delete a space" + Then the HTTP status code should be "204" + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should not contain a space with name "delete a space" + + + Scenario: An owner can disable and delete Space in which files and folders exist via the webDav API + Given user "Alice" has created a space "delete a space with content" of type "project" with quota "10" + And user "Alice" has uploaded a file inside space "delete a space with content" with content "test" to "test.txt" + And user "Alice" has created a folder "MainFolder" in space "delete a space with content" + When user "Alice" disables a space "delete a space with content" + Then the HTTP status code should be "204" + When user "Alice" deletes a space "delete a space with content" + Then the HTTP status code should be "204" + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should not contain a space with name "delete a space with content" + + + Scenario: An owner cannot delete a space via the webDav API without first disabling it + Given user "Alice" has created a space "delete without disabling" of type "project" with quota "10" + When user "Alice" deletes a space "delete without disabling" + Then the HTTP status code should be "400" + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should contain a space "delete without disabling" with these key and value pairs: + | key | value | + | name | delete without disabling | + + + Scenario: An user with editor role cannot disable a Space via the Graph API + Given user "Alice" has created a space "editor tries to disable a space" of type "project" with quota "10" + And user "Alice" has shared a space "editor tries to disable a space" to user "Brian" with role "editor" + When user "Brian" disables a space "editor tries to disable a space" + Then the HTTP status code should be "403" + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should contain a space "editor tries to disable a space" with these key and value pairs: + | key | value | + | name | editor tries to disable a space | + + + Scenario: An user with viewer role cannot disable a Space via the Graph API + Given user "Alice" has created a space "viewer tries to disable a space" of type "project" with quota "10" + And user "Alice" has shared a space "viewer tries to disable a space" to user "Brian" with role "viewer" + When user "Brian" disables a space "viewer tries to disable a space" + Then the HTTP status code should be "403" + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should contain a space "viewer tries to disable a space" with these key and value pairs: + | key | value | + | name | viewer tries to disable a space | diff --git a/tests/acceptance/features/apiSpaces/removeSpaces.feature b/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature similarity index 61% rename from tests/acceptance/features/apiSpaces/removeSpaces.feature rename to tests/acceptance/features/apiSpaces/removeSpaceObjects.feature index 71e65273e29..aa15aa89d79 100644 --- a/tests/acceptance/features/apiSpaces/removeSpaces.feature +++ b/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature @@ -1,7 +1,7 @@ @api @skipOnOcV10 -Feature: Remove files, folder and spaces +Feature: Remove files, folder As a user - I want to be able to remove files, folders and space itself + I want to be able to remove files, folders Users with the editor role can also remove objects Users with the viewer role cannot remove objects @@ -13,13 +13,13 @@ Feature: Remove files, folder and spaces And user "Brian" has been created with default attributes and without skeleton files And the administrator has given "Alice" the role "Admin" using the settings api -# owner of space +# owner of space (admin permissions) Scenario: An owner can delete a folder with some subfolders in a Space via the webDav API Given user "Alice" has created a space "Owner deletes folder" of type "project" with quota "10" And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Owner deletes folder" When user "Alice" removes the object "folderForDeleting" from space "Owner deletes folder" - Then the HTTP status code should be "200" + Then the HTTP status code should be "204" And for user "Alice" the space "Owner deletes folder" should not contain these entries: | folderForDeleting | @@ -28,7 +28,7 @@ Feature: Remove files, folder and spaces Given user "Alice" has created a space "Owner deletes subfolder" of type "project" with quota "10" And user "Alice" has created a subfolder "folder/subFolderForDeleting" in space "Owner deletes subfolder" When user "Alice" removes the object "folder/subFolderForDeleting" from space "Owner deletes subfolder" - Then the HTTP status code should be "200" + Then the HTTP status code should be "204" And for user "Alice" the space "Owner deletes subfolder" should contain these entries: | folder | And for user "Alice" folder "folder/" of the space "Owner deletes subfolder" should not contain these entries: @@ -39,7 +39,7 @@ Feature: Remove files, folder and spaces Given user "Alice" has created a space "Owner deletes file" of type "project" with quota "20" And user "Alice" has uploaded a file inside space "Owner deletes file" with content "some content" to "text.txt" When user "Alice" removes the object "text.txt" from space "Owner deletes file" - Then the HTTP status code should be "200" + Then the HTTP status code should be "204" And for user "Alice" the space "Owner deletes file" should not contain these entries: | text.txt | When user "Alice" lists all available spaces via the GraphApi @@ -48,24 +48,6 @@ Feature: Remove files, folder and spaces | name | Owner deletes file | | quota@@@used | 0 | - - Scenario: An owner can delete an empty Space via the webDav API - Given user "Alice" has created a space "Owner deletes an empty space" of type "project" with quota "20" - When user "Alice" removes a space "Owner deletes an empty space" - Then the HTTP status code should be "200" - When user "Alice" lists all available spaces via the GraphApi - Then the json responded should not contain a space with name "Owner deletes an empty space" - - - Scenario: An owner can delete a Space containing folders and files via the webDav API - Given user "Alice" has created a space "Owner deletes space" of type "project" with quota "20" - And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Owner deletes space" - And user "Alice" has uploaded a file inside space "Owner deletes space" with content "some content" to "folderForDeleting/sub1/sub2/text.txt" - When user "Alice" removes a space "Owner deletes space" - Then the HTTP status code should be "200" - When user "Alice" lists all available spaces via the GraphApi - Then the json responded should not contain a space with name "Owner deletes space" - # editor role Scenario: An editor can delete a folder with some subfolders in a Space via the webDav API @@ -73,7 +55,7 @@ Feature: Remove files, folder and spaces And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Editor deletes folder" And user "Alice" has shared a space "Editor deletes folder" to user "Brian" with role "editor" When user "Brian" removes the object "folderForDeleting" from space "Editor deletes folder" - Then the HTTP status code should be "200" + Then the HTTP status code should be "204" And for user "Brian" the space "Editor deletes folder" should not contain these entries: | folderForDeleting | @@ -83,7 +65,7 @@ Feature: Remove files, folder and spaces And user "Alice" has created a subfolder "folder/subFolderForDeleting" in space "Editor deletes subfolder" And user "Alice" has shared a space "Editor deletes subfolder" to user "Brian" with role "editor" When user "Brian" removes the object "folder/subFolderForDeleting" from space "Editor deletes subfolder" - Then the HTTP status code should be "200" + Then the HTTP status code should be "204" And for user "Brian" the space "Editor deletes subfolder" should contain these entries: | folder | And for user "Brian" folder "folder/" of the space "Editor deletes subfolder" should not contain these entries: @@ -95,7 +77,7 @@ Feature: Remove files, folder and spaces And user "Alice" has uploaded a file inside space "Editor deletes file" with content "some content" to "text.txt" And user "Alice" has shared a space "Editor deletes file" to user "Brian" with role "editor" When user "Brian" removes the object "text.txt" from space "Editor deletes file" - Then the HTTP status code should be "200" + Then the HTTP status code should be "204" And for user "Brian" the space "Editor deletes file" should not contain these entries: | text.txt | When user "Brian" lists all available spaces via the GraphApi @@ -104,27 +86,6 @@ Feature: Remove files, folder and spaces | name | Editor deletes file | | quota@@@used | 0 | - - Scenario: An editor can delete an empty Space via the webDav API - Given user "Alice" has created a space "Editor deletes an empty space" of type "project" with quota "20" - And user "Alice" has shared a space "Editor deletes an empty space" to user "Brian" with role "editor" - When user "Brian" removes a space "Editor deletes an empty space" - Then the HTTP status code should be "200" - When user "Brian" lists all available spaces via the GraphApi - Then the json responded should not contain a space with name "Editor deletes an empty space" - - - Scenario: An editor can delete a Space containing folders and files via the webDav API - Given user "Alice" has created a space "Editor deletes space" of type "project" with quota "20" - And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Editor deletes space" - And user "Alice" has uploaded a file inside space "Editor deletes space" with content "some content" to "folderForDeleting/sub1/sub2/text.txt" - And user "Alice" has shared a space "Editor deletes space" to user "Brian" with role "editor" - When user "Brian" removes a space "Editor deletes space" - Then the HTTP status code should be "200" - When user "Brian" lists all available spaces via the GraphApi - Then the json responded should not contain a space with name "Editor deletes space" - - # viewer role Scenario: A viewer cannot delete a folder with some subfolders in a Space via the webDav API @@ -156,26 +117,12 @@ Feature: Remove files, folder and spaces And for user "Brian" the space "Viewer deletes file" should contain these entries: | text.txt | - - Scenario: A viewer cannot delete an empty Space via the webDav API - Given user "Alice" has created a space "Viewer deletes an empty space" of type "project" with quota "20" - And user "Alice" has shared a space "Viewer deletes an empty space" to user "Brian" with role "viewer" - When user "Brian" removes a space "Viewer deletes an empty space" - Then the HTTP status code should be "403" - When user "Brian" lists all available spaces via the GraphApi - Then the json responded should contain a space "Viewer deletes an empty space" with these key and value pairs: - | key | value | - | name | Viewer deletes an empty space | - - - Scenario: A viewer cannot delete a Space containing folders and files via the webDav API - Given user "Alice" has created a space "Viewer deletes space" of type "project" with quota "20" - And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "Viewer deletes space" - And user "Alice" has uploaded a file inside space "Viewer deletes space" with content "some content" to "folderForDeleting/sub1/sub2/text.txt" - And user "Alice" has shared a space "Viewer deletes space" to user "Brian" with role "viewer" - When user "Brian" removes a space "Viewer deletes space" - Then the HTTP status code should be "403" - When user "Brian" lists all available spaces via the GraphApi - Then the json responded should contain a space "Viewer deletes space" with these key and value pairs: - | key | value | - | name | Viewer deletes space | + + Scenario: An user is unable to delete a Space via the webDav API + Given user "Alice" has created a space "user deletes a space" of type "project" with quota "20" + When user "Alice" removes the object "" from space "user deletes a space" + Then the HTTP status code should be "405" + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should contain a space "user deletes a space" with these key and value pairs: + | key | value | + | name | user deletes a space | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 3e1b6af248f..16d23b839f9 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -1372,7 +1372,14 @@ class SpacesContext implements Context { $space = $this->getSpaceByName($user, $spaceName); $fullUrl = $this->baseUrl . "/ocs/v2.php/apps/files_sharing/api/v1/shares/" . $space['id'] . "?shareWith=" . $userRecipient; - HttpRequestHelper::delete($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user)); + $this->featureContext->setResponse( + HttpRequestHelper::delete( + $fullUrl, + "", + $user, + $this->featureContext->getPasswordForUser($user) + ) + ); } /** @@ -1392,11 +1399,18 @@ class SpacesContext implements Context { ): void { $space = $this->getSpaceByName($user, $spaceName); $spaceWebDavUrl = $space["root"]["webDavUrl"] . '/' . $object; - HttpRequestHelper::delete($spaceWebDavUrl, "", $user, $this->featureContext->getPasswordForUser($user)); + $this->featureContext->setResponse( + HttpRequestHelper::delete( + $spaceWebDavUrl, + "", + $user, + $this->featureContext->getPasswordForUser($user) + ) + ); } /** - * @When /^user "([^"]*)" removes a space "([^"]*)"$/ + * @When /^user "([^"]*)" disables a space "([^"]*)"$/ * * @param string $user * @param string $spaceName @@ -1404,12 +1418,68 @@ class SpacesContext implements Context { * @return void * @throws GuzzleException */ - public function sendRemoveSpaceRequest( + public function sendDisableSpaceRequest( string $user, string $spaceName ): void { $space = $this->getSpaceByName($user, $spaceName); - $spaceWebDavUrl = $space["root"]["webDavUrl"]; - HttpRequestHelper::delete($spaceWebDavUrl, "", $user, $this->featureContext->getPasswordForUser($user)); + $fullUrl = $this->baseUrl . "/graph/v1.0/drives/" . $space["id"]; + $this->featureContext->setResponse( + HttpRequestHelper::delete( + $fullUrl, + "", + $user, + $this->featureContext->getPasswordForUser($user) + ) + ); + } + + /** + * @When /^user "([^"]*)" has disabled a space "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * + * @return void + * @throws GuzzleException + */ + public function sendUserHasDisabledSpaceRequest( + string $user, + string $spaceName + ): void { + $this->sendDisableSpaceRequest($user, $spaceName); + $expectedHTTPStatus = "204"; + $this->featureContext->theHTTPStatusCodeShouldBe( + $expectedHTTPStatus, + "Expected response status code should be $expectedHTTPStatus" + ); + } + + /** + * @When /^user "([^"]*)" deletes a space "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * + * @return void + * @throws GuzzleException + */ + public function sendDeleteSpaceRequest( + string $user, + string $spaceName + ): void { + $header = ["Purge" => "T"]; + $space = $this->getSpaceByName($user, $spaceName); + $fullUrl = $this->baseUrl . "/graph/v1.0/drives/" . $space["id"]; + + $this->featureContext->setResponse( + HttpRequestHelper::delete( + $fullUrl, + "", + $user, + $this->featureContext->getPasswordForUser($user), + $header + ) + ); } }