From 7fb7a8b6e16c6afc042e3e7a60e0ed26406165ca Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Mon, 17 Oct 2022 13:46:07 +0200 Subject: [PATCH] [test-only] Apitest. Add checking parentId (#4763) * add checking parentId * add case where parent is space * php style fix --- .../features/apiSpaces/search.feature | 64 +++++++++++++------ .../features/bootstrap/SpacesContext.php | 49 ++++++++++++++ 2 files changed, 95 insertions(+), 18 deletions(-) diff --git a/tests/acceptance/features/apiSpaces/search.feature b/tests/acceptance/features/apiSpaces/search.feature index 8fcd40f5c..3a6367bf3 100644 --- a/tests/acceptance/features/apiSpaces/search.feature +++ b/tests/acceptance/features/apiSpaces/search.feature @@ -13,8 +13,8 @@ Feature: Search And using spaces DAV path And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "find data" with the default quota using the GraphApi - And user "Alice" has created a folder "folder/SubFolder1/subFOLDER2" in space "find data" - And user "Alice" has uploaded a file inside space "find data" with content "some content" to "folder/SubFolder1/subFOLDER2/insideTheFolder.txt" + And user "Alice" has created a folder "folderMain/SubFolder1/subFOLDER2" in space "find data" + And user "Alice" has uploaded a file inside space "find data" with content "some content" to "folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt" And using new DAV path Scenario: Alice can find data from the project space @@ -22,10 +22,10 @@ Feature: Search Then the HTTP status code should be "207" And the search result should contain "4" entries And the search result of user "Alice" should contain these entries: - | /folder | - | /folder/SubFolder1 | - | /folder/SubFolder1/subFOLDER2 | - | /folder/SubFolder1/subFOLDER2/insideTheFolder.txt | + | /folderMain | + | /folderMain/SubFolder1 | + | /folderMain/SubFolder1/subFOLDER2 | + | /folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt | Scenario: Alice can find data from the project space @@ -33,16 +33,16 @@ Feature: Search Then the HTTP status code should be "207" And the search result should contain "2" entries And the search result of user "Alice" should contain these entries: - | /folder/SubFolder1 | - | /folder/SubFolder1/subFOLDER2 | + | /folderMain/SubFolder1 | + | /folderMain/SubFolder1/subFOLDER2 | But the search result of user "Alice" should not contain these entries: - | /folder | - | /folder/SubFolder1/subFOLDER2/insideTheFolder.txt | + | /folderMain | + | /folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt | Scenario: Brian can find data from the shares jail - Given user "Alice" shares the following entity "folder" inside of space "find data" with user "Brian" with role "viewer" - And user "Brian" has accepted share "/folder" offered by user "Alice" + Given user "Alice" shares the following entity "folderMain" inside of space "find data" with user "Brian" with role "viewer" + And user "Brian" has accepted share "/folderMain" offered by user "Alice" When user "Brian" searches for "folder" using the WebDAV API Then the HTTP status code should be "207" And the search result should contain "4" entries @@ -50,7 +50,7 @@ Feature: Search | /SubFolder1 | | /SubFolder1/subFOLDER2 | | /SubFolder1/subFOLDER2/insideTheFolder.txt | - And for user "Brian" the search result should contain space "mountpoint/folder" + And for user "Brian" the search result should contain space "mountpoint/folderMain" Scenario: User can find hidden file @@ -63,7 +63,7 @@ Feature: Search Scenario: User cannot find pending folder - Given user "Alice" shares the following entity "folder" inside of space "find data" with user "Brian" with role "viewer" + Given user "Alice" shares the following entity "folderMain" inside of space "find data" with user "Brian" with role "viewer" When user "Brian" searches for "folder" using the WebDAV API Then the HTTP status code should be "207" And the search result should contain "0" entries @@ -74,8 +74,8 @@ Feature: Search Scenario: User cannot find declined folder - Given user "Alice" shares the following entity "folder" inside of space "find data" with user "Brian" with role "viewer" - And user "Brian" has declined share "/folder" offered by user "Alice" + Given user "Alice" shares the following entity "folderMain" inside of space "find data" with user "Brian" with role "viewer" + And user "Brian" has declined share "/folderMain" offered by user "Alice" When user "Brian" searches for "folder" using the WebDAV API Then the HTTP status code should be "207" And the search result should contain "0" entries @@ -86,8 +86,8 @@ Feature: Search Scenario: User cannot find deleted folder - Given user "Alice" has removed the folder "folder" from space "find data" - When user "Alice" searches for "folder" using the WebDAV API + Given user "Alice" has removed the folder "folderMain" from space "find data" + When user "Alice" searches for "folderMain" using the WebDAV API Then the HTTP status code should be "207" And the search result should contain "0" entries @@ -98,3 +98,31 @@ Feature: Search And the search result should contain "1" entries And for user "Alice" the search result should contain space "find data" + + Scenario Outline: search result for project space contains resource parentID + When user "Alice" searches for "" using the WebDAV API + Then the HTTP status code should be "207" + And the search result should contain "1" entries + And the search result of user "Alice" should contain these entries: + | / | + And for user "Alice" the response should contains the parent "" from space "find data" + Examples: + | searchObject | parentFolder | + | SubFolder1 | folderMain | + | insideTheFolder.txt | folderMain/SubFolder1/subFOLDER2 | + | folderMain | find data | + + + Scenario Outline: search result for shares jail contains resource parentID + Given user "Alice" shares the following entity "folderMain" inside of space "find data" with user "Brian" with role "viewer" + And user "Brian" has accepted share "/folderMain" offered by user "Alice" + When user "Brian" searches for "" using the WebDAV API + Then the HTTP status code should be "207" + And the search result should contain "1" entries + And the search result of user "Brian" should contain these entries: + | / | + And for user "Brian" the response should contains the parent "" from mountpoint "folderMain" + Examples: + | searchObject | parentFolder | + | insideTheFolder.txt | SubFolder1/subFOLDER2 | + | SubFolder1 | folderMain | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index f3225ef2d..331e5c5ab 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -332,6 +332,38 @@ class SpacesContext implements Context { return $fileData["Oc-Fileid"][0]; } + /** + * The method returns folderId + * + * @param string $user + * @param string $spaceName + * @param string $folderName + * + * @return string + * @throws GuzzleException + */ + public function getFolderId(string $user, string $spaceName, string $folderName): string { + $space = $this->getSpaceByName($user, $spaceName); + // For a level 1 folder, the parent is space so $folderName = '' + if ($folderName === $space["name"]) { + $folderName = ''; + } + $fullUrl = $this->baseUrl . $this->davSpacesUrl . $space["id"] . "/" . $folderName; + $this->featureContext->setResponse( + HttpRequestHelper::sendRequest( + $fullUrl, + $this->featureContext->getStepLineRef(), + 'PROPFIND', + $user, + $this->featureContext->getPasswordForUser($user), + ['Depth' => '0'], + ) + ); + $responseArray = json_decode(json_encode($this->featureContext->getResponseXml()->xpath("//d:response/d:propstat/d:prop/oc:fileid")), true, 512, JSON_THROW_ON_ERROR); + Assert::assertNotEmpty($responseArray, "the PROPFIND response for $folderName is empty"); + return $responseArray[0][0]; + } + /** * The method returns eTag * @@ -2961,4 +2993,21 @@ class SpacesContext implements Context { } Assert::assertTrue($spaceFound, "response does not contain the space '$spaceName'"); } + + /** + * @Then /^for user "([^"]*)" the response should contains the parent "([^"]*)" from (?:space|mountpoint) "([^"]*)"$/ + * + * @param string $user + * @param string $parent + * @param string $space + * + * @return void + * @throws GuzzleException + */ + public function responseShouldContainParent(string $user, string $parent, string $space): void { + // get a response after a Report request (called in the core) + $responseArray = json_decode(json_encode($this->featureContext->getResponseXml()->xpath("//d:response/d:propstat/d:prop/oc:file-parent")), true, 512, JSON_THROW_ON_ERROR); + Assert::assertNotEmpty($responseArray, "search result is empty"); + Assert::assertEquals($this->getFolderId($user, $space, $parent), $responseArray[0][0], 'wrong file-parentId'); + } }