Skip to content

Commit

Permalink
purge trash bin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ScharfViktor committed Jul 4, 2023
1 parent f15ed6b commit 87ddacd
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 20 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
@@ -1,4 +1,4 @@
@api
@api
Feature: Restore files, folder
As a user with manager and editor role
I want to be able to restore files, folders
Expand All @@ -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 All @@ -27,15 +25,15 @@ Feature: Restore files, folder
| role | <role> |
And user "Alice" has removed the file "newFolder/file.txt" from space "restore objects"
And user "Alice" has removed the folder "newFolder" from space "restore objects"
When user "<user>" lists all deleted files in the trash bin of the space "restore objects"
When user "Brian" lists all deleted files in the trash bin of the space "restore objects"
Then the HTTP status code should be "207"
And as "<user>" folder "newFolder" should exist in the trashbin of the space "restore objects"
And as "<user>" file "file.txt" should exist in the trashbin of the space "restore objects"
And as "Brian" folder "newFolder" should exist in the trashbin of the space "restore objects"
And as "Brian" file "file.txt" should exist in the trashbin of the space "restore objects"
Examples:
| user | role |
| Brian | manager |
| Brian | editor |
| Brian | viewer |
| role |
| manager |
| editor |
| viewer |


Scenario Outline: user can restore a folder with some objects from the trash via the webDav API
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 "<user>" deletes the file "file.txt" from the trash of the space "restore objects"
Then the HTTP status code should be "<code>"
And as "<user>" file "file.txt" <shouldOrNotBeInTrash> exist in the trashbin of the space "restore objects"
Examples:
| user | role | code | shouldOrNotBeInTrash |
| Brian | manager | 204 | should not |
| Brian | editor | 403 | should |
| Brian | 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 87ddacd

Please sign in to comment.