Skip to content

Commit

Permalink
[test-only][full-ci]ApiTests. purge trash bin tests (#6699)
Browse files Browse the repository at this point in the history
* purge trash bin tests

* fix
  • Loading branch information
ScharfViktor authored Jul 4, 2023
1 parent 941ef59 commit 873732f
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 12 deletions.
10 changes: 10 additions & 0 deletions tests/acceptance/features/apiSpaces/quota.feature
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,13 @@ Feature: State of the quota
When user "Brian" tries to create a space "new space" of type "project" with quota "51" using the Graph API
Then the HTTP status code should be "400"
And the user "Brian" should not have a space called "new space"


Scenario: user can restore a file version even if there is not enough quota to do so
Given user "Admin" has changed the quota of the "Alice Hansen" space to "30"
And user "Alice" has uploaded file with content "file is less than 30 bytes" to "/file.txt"
And user "Alice" has uploaded file with content "reduceContent" to "/file.txt"
And user "Alice" has uploaded file with content "some content" to "newFile.txt"
When user "Alice" restores version index "1" of file "/file.txt" using the WebDAV API
Then the HTTP status code should be "204"
And the content of file "/file.txt" for user "Alice" should be "file is less than 30 bytes"
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Feature: Restore files, folder
| username |
| Alice |
| Brian |
| Bob |
| Carol |
And using spaces DAV path
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And user "Alice" has created a space "restore objects" with the default quota using the GraphApi
Expand Down Expand Up @@ -74,11 +72,44 @@ Feature: Restore files, folder
| Brian | viewer | 403 | should not | should |


Scenario: user can restore a file even if there is not enough quota to do so
Given user "Admin" has changed the quota of the "Brian Murphy" space to "30"
And user "Brian" has uploaded file with content "file is less than 30 bytes" to "/file.txt"
And user "Brian" has uploaded file with content "reduceContent" to "/file.txt"
And user "Brian" has uploaded file with content "some content" to "newFile.txt"
When user "Brian" restores version index "1" of file "/file.txt" using the WebDAV API
Then the HTTP status code should be "204"
And the content of file "/file.txt" for user "Brian" should be "file is less than 30 bytes"
Scenario Outline: only space manager can purge the trash via the webDav API
Given user "Alice" has shared a space "restore objects" with settings:
| shareWith | Brian |
| role | <role> |
And the administrator has assigned the role "Space Admin" to user "Brian" using the Graph API
And user "Alice" has removed the file "newFolder/file.txt" from space "restore objects"
When user "Brian" deletes the file "file.txt" from the trash of the space "restore objects"
Then the HTTP status code should be "<code>"
And as "Brian" file "file.txt" <shouldOrNotBeInTrash> exist in the trashbin of the space "restore objects"
Examples:
| role | code | shouldOrNotBeInTrash |
| manager | 204 | should not |
| editor | 403 | should |
| viewer | 403 | should |


Scenario Outline: admin user who is not a member of space cannot see its trash bin
Given user "Alice" has removed the file "newFolder/file.txt" from space "restore objects"
And the administrator has assigned the role "<role>" to user "Brian" using the Graph API
When user "Brian" with admin permission lists all deleted files in the trash bin of the space "restore objects"
Then the HTTP status code should be "404"
Examples:
| role |
| Space Admin |
| Admin |


Scenario Outline: admin user without space-manager role cannot purge the trash
Given user "Alice" has shared a space "restore objects" with settings:
| shareWith | Brian |
| role | editor |
And the administrator has assigned the role "<role>" to user "Brian" using the Graph API
And user "Alice" has removed the file "newFolder/file.txt" from space "restore objects"
When user "Brian" tries to delete the file "file.txt" from the trash of the space "restore objects"
Then the HTTP status code should be "403"
And as "Alice" file "file.txt" should exist in the trashbin of the space "restore objects"
Examples:
| role |
| Space Admin |
| Admin |

68 changes: 66 additions & 2 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function getSpaceByName(string $user, string $spaceName): array {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
}
$spaces = $this->getAvailableSpaces();
Assert::assertIsArray($spaces[$spaceName], "Space with name $spaceName for user $user not found");
Assert::assertArrayHasKey($spaceName, $spaces, "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 @@ -2365,6 +2365,26 @@ public function userListAllDeletedFilesInTrash(
);
}

/**
* @When /^user "([^"]*)" with admin permission lists all deleted files in the trash bin of the space "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function adminListAllDeletedFilesInTrash(
string $user,
string $spaceName
): void {
$space = $this->getSpaceByNameManager($user, $spaceName);
$fullUrl = $this->baseUrl . $this->davSpacesUrl . "trash-bin/" . $space["id"];
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest($fullUrl, '', 'PROPFIND', $user, $this->featureContext->getPasswordForUser($user))
);
}

/**
* User get all objects in the trash of project space
*
Expand Down Expand Up @@ -2460,7 +2480,7 @@ public function userRestoresSpaceObjectsFromTrashRequest(
}

if ($pathToDeletedObject === "") {
throw new Exception(__METHOD__ . " Object '$object' was not found in the trashbin of user '$user' space '$spaceName'");
throw new Exception(__METHOD__ . " Object '$object' was not found in the trashbin of space '$spaceName' by user '$user'");
}

$destination = $this->baseUrl . $this->davSpacesUrl . $space["id"] . $destination;
Expand All @@ -2480,6 +2500,50 @@ public function userRestoresSpaceObjectsFromTrashRequest(
);
}

/**
* @When user :user deletes the file/folder :resource from the trash of the space :spaceName
* @When user :user tries to delete the file/folder :resource from the trash of the space :spaceName
*
* @param string $user
* @param string $object
* @param string $spaceName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userDeletesObjectsFromTrashRequest(
string $user,
string $object,
string $spaceName
): void {
// find object in trash
$objectsInTrash = $this->getObjectsInTrashbin($user, $spaceName);
$pathToDeletedObject = "";
foreach ($objectsInTrash as $objectInTrash) {
if ($objectInTrash["name"] === $object) {
$pathToDeletedObject = $objectInTrash["href"];
}
}

if ($pathToDeletedObject === "") {
throw new Exception(__METHOD__ . " Object '$object' was not found in the trashbin of space '$spaceName' by user '$user'");
}

$fullUrl = $this->baseUrl . $pathToDeletedObject;
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
"",
'DELETE',
$user,
$this->featureContext->getPasswordForUser($user),
[],
""
)
);
}

/**
* User downloads a preview of the file inside the project space
*
Expand Down

0 comments on commit 873732f

Please sign in to comment.