From ee38488c40f6d7ddb3231b082b0b7f76a63c0a51 Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Mon, 22 Aug 2022 11:58:36 +0545 Subject: [PATCH] Add logic to store personal spaces of only user created by the scenario --- ...ected-failures-localAPI-on-OCIS-storage.md | 4 --- .../apiSpaces/shareOperations.feature | 22 +++++++-------- .../features/bootstrap/SpacesContext.php | 27 ++++++++++++++----- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 0170f03fe79..a636c8ba43b 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -21,7 +21,3 @@ The expected failures in this file are from features in the owncloud/ocis repo. ### [Search by shares jail works incorrect](https://github.com/owncloud/ocis/issues/4014) - [apiSpaces/search.feature:43](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/search.feature#L43) - -### [Changing personal drive quota on another user as admin is not possible](https://github.com/owncloud/ocis/issues/4325) -- [apiSpaces/changeSpaces.feature:221](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changeSpaces.feature#L221) - diff --git a/tests/acceptance/features/apiSpaces/shareOperations.feature b/tests/acceptance/features/apiSpaces/shareOperations.feature index c322fc0c60a..85920f5c5ef 100644 --- a/tests/acceptance/features/apiSpaces/shareOperations.feature +++ b/tests/acceptance/features/apiSpaces/shareOperations.feature @@ -227,7 +227,7 @@ Feature: sharing And the single response should contain a property "ocs:share-permissions" with value "15" - Scenario: Uploading a file to a group read-only share folder does not work + Scenario: Uploading a file to a folder received as a read-only group share Given group "grp1" has been created And user "Brian" has been added to group "grp1" And user "Alice" has created folder "FOLDER" @@ -242,7 +242,7 @@ Feature: sharing And as "Alice" file "/FOLDER/textfile.txt" should not exist - Scenario: Uploading file to a user upload-only share folder works + Scenario: Uploading a file to a folder received as a upload-only user share Given user "Alice" has created folder "FOLDER" And user "Alice" has created a share with settings | path | FOLDER | @@ -260,7 +260,7 @@ Feature: sharing """ - Scenario: Uploading file to a group upload-only share folder works + Scenario: Uploading a file to a folder received as a upload-only group share Given group "grp1" has been created And user "Brian" has been added to group "grp1" And user "Alice" has created folder "FOLDER" @@ -280,7 +280,7 @@ Feature: sharing """ - Scenario: Uploading file to a user read/write share folder works + Scenario: Uploading a file to a folder received as a read/write user share Given user "Alice" has created folder "FOLDER" And user "Alice" has created a share with settings | path | FOLDER | @@ -296,7 +296,7 @@ Feature: sharing """ - Scenario: Uploading file to a group read/write share folder works + Scenario: Uploading a file to a folder received as a read/write group share Given group "grp1" has been created And user "Brian" has been added to group "grp1" And user "Alice" has created folder "FOLDER" @@ -329,7 +329,7 @@ Feature: sharing """ - Scenario: Uploading to a user shared folder with read/write permission when the sharer has insufficient quota does not work + Scenario: Uploading to a user shared folder with read/write permission when the sharer has insufficient quota Given user "Alice" has created folder "FOLDER" And user "Alice" has created a share with settings | path | FOLDER | @@ -343,7 +343,7 @@ Feature: sharing And as "Alice" file "/FOLDER/textfile.txt" should not exist - Scenario: Uploading to a user shared folder with upload-only permission when the sharer has insufficient quota does not work + Scenario: Uploading to a user shared folder with upload-only permission when the sharer has insufficient quota Given user "Alice" has created folder "FOLDER" And user "Alice" has created a share with settings | path | FOLDER | @@ -351,13 +351,13 @@ Feature: sharing | permissions | create | | shareWith | Brian | And user "Brian" has accepted share "/FOLDER" offered by user "Alice" - And user "Admin" has changed the quota of the "Alice Hansen" space to "1" + And user "Admin" has changed the quota of the "Alice Hansen" space to "1" When user "Brian" uploads a file inside space "Shares Jail" with content "new description" to "/FOLDER/textfile.txt" using the WebDAV API Then the HTTP status code should be "507" And as "Alice" file "/FOLDER/textfile.txt" should not exist - Scenario: Uploading a file to a group shared folder with upload-only permission when the sharer has insufficient quota does not work + Scenario: Uploading a file to a group shared folder with upload-only permission when the sharer has insufficient quota Given group "grp1" has been created And user "Brian" has been added to group "grp1" And user "Alice" has created folder "FOLDER" @@ -367,8 +367,8 @@ Feature: sharing | permissions | create | | shareWith | grp1 | And user "Brian" has accepted share "/FOLDER" offered by user "Alice" - And user "Admin" has changed the quota of the "Alice Hansen" space to "1" - When user "Brian" uploads a file inside space "Shares Jail" with content "new description" to "/FOLDER/textfile.txt" using the WebDAV API + And user "Admin" has changed the quota of the "Alice Hansen" space to "10" + When user "Brian" uploads a file inside space "Shares Jail" with content "new descriptionfgshsywhhh" to "/FOLDER/textfile.txt" using the WebDAV API Then the HTTP status code should be "507" And as "Alice" file "/FOLDER/textfile.txt" should not exist diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 0965e75c82e..4cb83926f5c 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -260,7 +260,6 @@ public function getSpaceByName(string $user, string $spaceName): array { $spaces = $this->getAvailableSpaces(); Assert::assertIsArray($spaces[$spaceName], "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]; } @@ -416,6 +415,7 @@ public function setUpScenario(BeforeScenarioScope $scope): void { $this->baseUrl, $this->featureContext->getOcPath() ); + $this->availableSpaces = []; } /** @@ -429,6 +429,7 @@ public function cleanDataAfterTests(): void { // TODO enable when admin can disable and delete spaces // $this->deleteAllSpacesOfTheType('project'); // $this->deleteAllSpacesOfTheType('personal'); + $this->availableSpaces = []; } /** @@ -513,7 +514,6 @@ public function listAllSpacesRequest( array $headers = [] ): ResponseInterface { $fullUrl = $this->baseUrl . "/graph/v1.0/drives/" . $urlArguments; - return HttpRequestHelper::get($fullUrl, $xRequestId, $user, $password, $headers, $body); } @@ -566,7 +566,6 @@ public function sendCreateSpaceRequest( array $headers = [] ): ResponseInterface { $fullUrl = $this->baseUrl . "/graph/v1.0/drives/"; - return HttpRequestHelper::post($fullUrl, $xRequestId, $user, $password, $headers, $body); } @@ -875,16 +874,31 @@ public function theAdministratorGivesUserTheRole(string $user, string $role): vo * @throws Exception */ public function rememberTheAvailableSpaces(): void { + $this->availableSpaces = []; $rawBody = $this->featureContext->getResponse()->getBody()->getContents(); $drives = json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR); if (isset($drives["value"])) { $drives = $drives["value"]; } - Assert::assertArrayHasKey(0, $drives, "No drives were found on that endpoint"); $spaces = []; + $createdUsers = $this->featureContext->getCreatedUsers(); + $createdUsersId = array_column($createdUsers, 'id'); foreach ($drives as $drive) { - $spaces[$drive["name"]] = $drive; + // when the user gets deleted the spaces related to user isn't deleted so we add only the spaces + // of users created by a paticular scenario to the array + // this work around can be removed after the fix of https://github.com/owncloud/ocis/issues/4195 + if ($drive["name"] === 'Admin') { + $spaces[$drive["name"]] = $drive; + } elseif ($drive["driveType"] === 'personal') { + // get the user id of all the personal spaces availabe till now + $userId = $drive["owner"]["user"]["id"]; + if (\in_array($userId, $createdUsersId)) { + $spaces[$drive["name"]] = $drive; + } + } elseif ($drive["driveType"] !== 'personal') { + $spaces[$drive["name"]] = $drive; + } } $this->setAvailableSpaces($spaces); Assert::assertNotEmpty($spaces, "No spaces have been found"); @@ -1619,7 +1633,6 @@ public function updateSpaceQuota( ): void { $space = $this->getSpaceByName($user, $spaceName); $spaceId = $space["id"]; - $bodyData = ["quota" => ["total" => $newQuota]]; $body = json_encode($bodyData, JSON_THROW_ON_ERROR); @@ -1631,6 +1644,7 @@ public function updateSpaceQuota( $spaceId ) ); + $res = $this->featureContext->getJsonDecodedResponse(); } /** @@ -1746,7 +1760,6 @@ public function sendUpdateSpaceRequest( ): ResponseInterface { $fullUrl = $this->baseUrl . "/graph/v1.0/drives/$spaceId"; $method = 'PATCH'; - return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers, $body); }