Skip to content

Commit

Permalink
Add logic to store personal spaces of only user created by the scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
SwikritiT committed Aug 22, 2022
1 parent 05b6346 commit ee38488
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

22 changes: 11 additions & 11 deletions tests/acceptance/features/apiSpaces/shareOperations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 |
Expand All @@ -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"
Expand All @@ -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 |
Expand All @@ -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"
Expand Down Expand Up @@ -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 |
Expand All @@ -343,21 +343,21 @@ 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 |
| shareType | user |
| 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"
Expand All @@ -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

Expand Down
27 changes: 20 additions & 7 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down Expand Up @@ -416,6 +415,7 @@ public function setUpScenario(BeforeScenarioScope $scope): void {
$this->baseUrl,
$this->featureContext->getOcPath()
);
$this->availableSpaces = [];
}

/**
Expand All @@ -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 = [];
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand All @@ -1631,6 +1644,7 @@ public function updateSpaceQuota(
$spaceId
)
);
$res = $this->featureContext->getJsonDecodedResponse();
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ee38488

Please sign in to comment.