diff --git a/tests/acceptance/features/apiSpaces/changeSpaces.feature b/tests/acceptance/features/apiSpaces/changeSpaces.feature index 1397ace3f9b..5f4860310ec 100644 --- a/tests/acceptance/features/apiSpaces/changeSpaces.feature +++ b/tests/acceptance/features/apiSpaces/changeSpaces.feature @@ -10,7 +10,7 @@ Feature: Change data of space Given user "Alice" has been created with default attributes and without skeleton files And the administrator has given "Alice" the role "Admin" using the settings api - Scenario: Alice changes a name of the space via the Graph api, she expects a 204 code and checks that the space name has changed + Scenario: Alice changes a name of the space via the Graph api, she expects a 200 code and checks that the space name has changed Given user "Alice" has created a space "Project Jupiter" of type "project" with quota "20" When user "Alice" changes the name of the "Project Jupiter" space to "Project Death Star" Then the HTTP status code should be "200" @@ -22,7 +22,7 @@ Feature: Change data of space | quota@@@total | 20 | | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - Scenario: Alice increases quota of the space via the Graph api, she expects a 204 code and checks that the quota has changed + Scenario: Alice increases quota of the space via the Graph api, she expects a 200 code and checks that the quota has changed Given user "Alice" has created a space "Project Earth" of type "project" with quota "20" When user "Alice" changes the quota of the "Project Earth" space to "100" Then the HTTP status code should be "200" diff --git a/tests/acceptance/features/apiSpaces/shareSpaces.feature b/tests/acceptance/features/apiSpaces/shareSpaces.feature new file mode 100644 index 00000000000..737eedf6ff9 --- /dev/null +++ b/tests/acceptance/features/apiSpaces/shareSpaces.feature @@ -0,0 +1,63 @@ +@api @skipOnOcV10 +Feature: Share spaces + As the owner of a space + I want to be able to add members to a space, and to remove access for them + + 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: Alice shares space to Brian, she expects a 200 response code + Given user "Alice" has created a space "Space to share" of type "project" with quota "10" + When user "Alice" shares a space "Space to share" to user "Brian" + Then the HTTP status code should be "200" + + + Scenario: Brian checks that a shared space is available + Given user "Alice" has created a space "Share space to Brian" of type "project" with quota "10" + And user "Alice" has shared a space "Share space to Brian" to user "Brian" + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should contain a space "Share space to Brian" with these key and value pairs: + | key | value | + | driveType | share | + | id | %space_id% | + | name | Share space to Brian | + | quota@@@state | normal | + | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | + + + Scenario: Brian can see files in shared space + Given user "Alice" has created a space "Share space with file" of type "project" with quota "10" + And user "Alice" has uploaded a file inside space "Share space with file" with content "Test" to "test.txt" + When user "Alice" has shared a space "Share space with file" to user "Brian" + Then for user "Brian" the space "Share space with file" should contain these entries: + | test.txt | + + + Scenario: Brian can see folder in shared space + Given user "Alice" has created a space "Share space with folder" of type "project" with quota "10" + And user "Alice" has created a folder "Folder Main" in space "Share space with folder" + When user "Alice" has shared a space "Share space with folder" to user "Brian" + Then for user "Brian" the space "Share space with folder" should contain these entries: + | Folder Main | + + + Scenario: When Alice unshares space, the space becomes unavailable to Brian + Given user "Alice" has created a space "Unshare space" of type "project" with quota "10" + And user "Alice" has shared a space "Unshare space" to user "Brian" + When user "Brian" lists all available spaces via the GraphApi + Then the json responded should contain a space "Unshare space" with these key and value pairs: + | key | value | + | driveType | share | + | id | %space_id% | + | name | Unshare space | + When user "Alice" unshares a space "Unshare space" to user "Brian" + Then the HTTP status code should be "200" + And user "Brian" lists all available spaces via the GraphApi + And the json responded should not contain a space "Unshare space" + \ No newline at end of file diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 5dec1726a20..e1f251dac21 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -667,6 +667,20 @@ public function jsonRespondedShouldContain( } } + /** + * @Then /^the json responded should not contain a space "([^"]*)"$/ + * + * @param string $spaceName + * + * @return void + * @throws Exception + */ + public function jsonRespondedShouldNotContain( + string $spaceName + ): void { + Assert::assertEmpty($this->getSpaceByNameFromResponse($spaceName), "space $spaceName should not be available for a user"); + } + /** * @param string $shouldOrNot (not|) * @param TableNode $expectedFiles @@ -819,6 +833,44 @@ public function theUserCreatesAFolderUsingTheGraphApi( ); } + /** + * @Given /^user "([^"]*)" has created a folder "([^"]*)" in space "([^"]*)"$/ + * + * @param string $user + * @param string $folder + * @param string $spaceName + * + * @return void + * + * @throws GuzzleException + */ + public function theUserHasCreateAFolderUsingTheGraphApi( + string $user, + string $folder, + string $spaceName + ): void { + $space = $this->getSpaceByName($user, $spaceName); + + $baseUrl = $this->featureContext->getBaseUrl(); + if (!str_ends_with($baseUrl, '/')) { + $baseUrl .= '/'; + } + $fullUrl = $baseUrl . "dav/spaces/" . $space['id'] . '/' . $folder; + + $this->featureContext->setResponse( + $this->sendCreateFolderRequest( + $fullUrl, + "MKCOL", + $user, + $this->featureContext->getPasswordForUser($user) + ) + ); + $this->featureContext->theHTTPStatusCodeShouldBe( + 201, + "Expected response status code should be 201" + ); + } + /** * @When /^user "([^"]*)" creates a folder "([^"]*)" in space "([^"]*)" owned by the user "([^"]*)" using the WebDav Api$/ * @@ -1108,4 +1160,86 @@ public function userHasUploadedFile(string $user, string $spaceName, string $fil $this->featureContext->theHTTPStatusCodeShouldBeOr(201, 204); } + + /** + * @When /^user "([^"]*)" shares a space "([^"]*)" to user "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * @param string $userRecipient + * + * @throws GuzzleException + */ + public function sendShareSpaceRequest( + string $user, + string $spaceName, + string $userRecipient + ): ResponseInterface { + $space = $this->getSpaceByName($user, $spaceName); + $body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient]; + + $baseUrl = $this->featureContext->getBaseUrl(); + if (!str_ends_with($baseUrl, '/')) { + $baseUrl .= '/'; + } + $fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares"; + + return HttpRequestHelper::post($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user), [], $body); + } + + /** + * @Given /^user "([^"]*)" has shared a space "([^"]*)" to user "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * @param string $userRecipient + * + * @throws GuzzleException + */ + public function userHasSharedSpace( + string $user, + string $spaceName, + string $userRecipient + ): ResponseInterface { + $space = $this->getSpaceByName($user, $spaceName); + $body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient]; + + $baseUrl = $this->featureContext->getBaseUrl(); + if (!str_ends_with($baseUrl, '/')) { + $baseUrl .= '/'; + } + $fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares"; + + return HttpRequestHelper::post($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user), [], $body); + + $this->featureContext->theHTTPStatusCodeShouldBe( + 200, + "Expected response status code should be 200" + ); + $this->OCSContext->theOCSStatusCodeShouldBe(400, "Expected OCS response status code should be 200"); + } + + /** + * @When /^user "([^"]*)" unshares a space "([^"]*)" to user "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * @param string $userRecipient + * + * @throws GuzzleException + */ + public function sendUnshareSpaceRequest( + string $user, + string $spaceName, + string $userRecipient + ): ResponseInterface { + $space = $this->getSpaceByName($user, $spaceName); + $baseUrl = $this->featureContext->getBaseUrl(); + if (!str_ends_with($baseUrl, '/')) { + $baseUrl .= '/'; + } + $fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares/" . $space['id'] . "?shareWith=" . $userRecipient; + + return HttpRequestHelper::delete($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user)); + } }