From 84f8f797c995318ddf0864700bc5416b93778e7c Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Thu, 18 Aug 2022 11:23:57 +0200 Subject: [PATCH] [test-only]Api test. check that link or share exist for space members (#4348) Co-authored-by: Saw-jan --- .vscode/launch.json | 5 ++ .../apiSpaces/editPublicLinkOfSpace.feature | 12 ++-- .../apiSpaces/shareSubItemOfSpace.feature | 12 ++++ .../shareSubItemOfSpaceViaPublicLink.feature | 14 ++++ .../features/bootstrap/SpacesContext.php | 69 ++++++++++++++++--- 5 files changed, 95 insertions(+), 17 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0ecba45fa..7eae32421 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,6 +1,11 @@ { "version": "0.2.0", "configurations": [ + { + "name": "Listen for Xdebug", + "type": "php", + "request": "launch" + }, { "name": "oCIS server", "type": "go", diff --git a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature index 764d0f63e..29e4a96f9 100644 --- a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature +++ b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature @@ -52,18 +52,18 @@ Feature: A manager of the space can edit public link | 15 | read,update,create,delete | | newName | 2042-03-25T23:59:59+0100 | - Scenario Outline: Only users with manager role can see a created public link + Scenario Outline: All members can see a created public link Given using OCS API version "2" When user "Alice" shares a space "edit space" to user "Brian" with role "" Then the HTTP status code should be "200" And the OCS status code should be "200" And for user "Alice" the space "edit space" should contain the last created public link - And for user "Brian" the space "edit space" contain the last created public link + And for user "Brian" the space "edit space" should contain the last created public link Examples: - | role | shouldOrNot | - | manager | should | - | editor | should | - | viewer | should | + | role | + | manager | + | editor | + | viewer | Scenario Outline: Members of the space try to edit a public link diff --git a/tests/acceptance/features/apiSpaces/shareSubItemOfSpace.feature b/tests/acceptance/features/apiSpaces/shareSubItemOfSpace.feature index 4a22178e1..184fae7da 100644 --- a/tests/acceptance/features/apiSpaces/shareSubItemOfSpace.feature +++ b/tests/acceptance/features/apiSpaces/shareSubItemOfSpace.feature @@ -62,3 +62,15 @@ Feature: Share a file or folder that is inside a space | file.txt | editor | 404 | No share permission | | file.txt | viewer | 404 | No share permission | | folder | viewer | 404 | No share permission | + + + Scenario Outline: An user participant of the project space can see the created resources share + Given user "Alice" has shared a space "share sub-item" to user "Brian" with role "" + When user "Alice" shares the following entity "file.txt" inside of space "share sub-item" with user "Bob" with role "editor" + Then for user "Alice" the space "share sub-item" should contain the last created share of the file "file.txt" + And for user "Brian" the space "share sub-item" should contain the last created share of the file "file.txt" + Examples: + | spaceRole | + | editor | + | viewer | + | manager | diff --git a/tests/acceptance/features/apiSpaces/shareSubItemOfSpaceViaPublicLink.feature b/tests/acceptance/features/apiSpaces/shareSubItemOfSpaceViaPublicLink.feature index 017ef55b9..e9bb47d8a 100644 --- a/tests/acceptance/features/apiSpaces/shareSubItemOfSpaceViaPublicLink.feature +++ b/tests/acceptance/features/apiSpaces/shareSubItemOfSpaceViaPublicLink.feature @@ -117,3 +117,17 @@ Feature: Share a file or folder that is inside a space via public link | ocs_api_version | ocs_status_code | | 1 | 100 | | 2 | 200 | + + + Scenario Outline: An user participant of the project space can see the created public resources link + Given user "Alice" has shared a space "share sub-item" to user "Brian" with role "" + When user "Alice" creates a public link share inside of space "share sub-item" with settings: + | path | folder/file.txt | + | shareType | 3 | + | permissions | 1 | + Then for user "Brian" the space "share sub-item" should contain the last created public link of the file "folder/file.txt" + Examples: + | spaceRole | + | editor | + | viewer | + | manager | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 6d0f3c885..470a9d0fd 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -376,6 +376,20 @@ class SpacesContext implements Context { throw new Exception(__METHOD__ . " user with name $userName not found"); } + /** + * using method from core to set share data + * + * @return void + */ + public function setLastShareData(): void { + // set last response as PublicShareData + $this->featureContext->setLastPublicShareData($this->featureContext->getResponseXml(null, __METHOD__)); + // set last shareId if ShareData exists + if (isset($this->featureContext->getLastPublicShareData()->data)) { + $this->featureContext->setLastPublicLinkShareId((string) $this->featureContext->getLastPublicShareData()->data[0]->id); + } + } + /** * @BeforeScenario * @@ -2055,6 +2069,7 @@ class SpacesContext implements Context { $body ) ); + $this->setLastShareData(); } /** @@ -2062,7 +2077,7 @@ class SpacesContext implements Context { * * @param string $user * @param string $spaceName - * @param TableNode|null $table + * @param TableNode $table * * @return void * @throws GuzzleException @@ -2070,7 +2085,7 @@ class SpacesContext implements Context { public function createPublicLinkToEntityInsideOfSpaceRequest( string $user, string $spaceName, - ?TableNode $table + TableNode $table ): void { $space = $this->getSpaceByName($user, $spaceName); $rows = $table->getRowsHash(); @@ -2101,6 +2116,32 @@ class SpacesContext implements Context { $body ) ); + + $this->setLastShareData(); + } + + /** + * @Given /^user "([^"]*)" has created a public link share inside of space "([^"]*)" with settings:$/ + * + * @param string $user + * @param string $spaceName + * @param TableNode $table + * + * @return void + * @throws GuzzleException + */ + public function userHasCreatedPublicLinkToEntityInsideOfSpaceRequest( + string $user, + string $spaceName, + TableNode $table + ): void { + $this->createPublicLinkToEntityInsideOfSpaceRequest($user, $spaceName, $table); + + $expectedHTTPStatus = "200"; + $this->featureContext->theHTTPStatusCodeShouldBe( + $expectedHTTPStatus, + "Expected response status code should be $expectedHTTPStatus" + ); } /** @@ -2917,12 +2958,7 @@ class SpacesContext implements Context { ) ); - // set last response as PublicShareData. using method from core - $this->featureContext->setLastPublicShareData($this->featureContext->getResponseXml(null, __METHOD__)); - // set last shareId if ShareData exists. using method from core - if (isset($this->featureContext->getLastPublicShareData()->data)) { - $this->featureContext->setLastPublicLinkShareId((string) $this->featureContext->getLastPublicShareData()->data[0]->id); - } + $this->setLastShareData(); } /** @@ -2952,10 +2988,13 @@ class SpacesContext implements Context { /** * @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain the last created public link$/ + * @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain the last created public link of the file "([^"]*)"$/ + * @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain the last created share of the file "([^"]*)"$/ * * @param string $user * @param string $spaceName * @param string $shouldOrNot (not|) + * @param string $fileName * * @return void * @@ -2964,10 +3003,18 @@ class SpacesContext implements Context { public function forUserSpaceShouldContainLinks( string $user, string $spaceName, - string $shouldOrNot + string $shouldOrNot, + string $fileName = '' ): void { - $space = $this->getSpaceByName($user, $spaceName); - $url = "/apps/files_sharing/api/v1/shares?reshares=true&space_ref=" . $space['id']; + $body = ''; + if (!empty ($fileName)) { + $body = $this->getFileId($user, $spaceName, $fileName); + } else { + $space = $this->getSpaceByName($user, $spaceName); + $body = $space['id']; + } + + $url = "/apps/files_sharing/api/v1/shares?reshares=true&space_ref=" . $body; $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user,