add tests changing quota

This commit is contained in:
Viktor Scharf
2022-08-04 13:11:51 +02:00
parent 8d97b7e1a2
commit d7c406edde
3 changed files with 161 additions and 82 deletions

View File

@@ -38,3 +38,9 @@ The expected failures in this file are from features in the owncloud/ocis repo.
- [apiSpaces/moveSpaces.feature:185](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/moveSpaces.feature#L185)
- [apiSpaces/moveSpaces.feature:186](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/moveSpaces.feature#L186)
- [apiSpaces/moveSpaces.feature:189](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/moveSpaces.feature#L189)
### [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)
- [apiSpaces/changeSpaces.feature:222](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changeSpaces.feature#L222)
- [apiSpaces/changeSpaces.feature:223](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changeSpaces.feature#L223)
- [apiSpaces/changeSpaces.feature:224](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changeSpaces.feature#L224)

View File

@@ -183,7 +183,7 @@ Feature: Change data of space
When user "<user>" has uploaded a file inside space "Project Jupiter" with content "" to ".space/newSpaceImage.png"
And user "<user>" sets the file ".space/newSpaceImage.png" as a space image in a special section of the "Project Jupiter" space
Then the HTTP status code should be "200"
And the user "<user>" should have a space called "Project Jupiter" owned by "Alice" with space image ".space/newSpaceImage.png" with these key and value pairs:
And the user "<user>" should have a space called "Project Jupiter" owned by "Alice" with space image ".space/newSpaceImage.png" with these key and value pairs:
| key | value |
| name | Project Jupiter |
| special@@@0@@@size | 0 |
@@ -195,4 +195,30 @@ Feature: Change data of space
Examples:
| user |
| Alice |
| Brian |
| Brian |
Scenario Outline: An admin user set own quota of a personal space via the Graph API
When user "Admin" changes the quota of the "Admin" space to "<quotaValue>"
Then the HTTP status code should be "200"
When user "Admin" uploads a file inside space "Admin" with content "file is more than 15 bytes" to "file.txt" using the WebDAV API
Then the HTTP status code should be <code>
Examples:
| quotaValue | code |
| 15 | "507" |
| 10000 | between "201" and "204" |
| 0 | between "201" and "204" |
| -1 | between "201" and "204" |
Scenario Outline: An admin user set an user personal space quota of via the Graph API
When user "Admin" changes the quota of the "Brian Murphy" space to "<quotaValue>"
Then the HTTP status code should be "200"
When user "Brian" uploads a file inside space "Brian Murphy" with content "file is more than 15 bytes" to "file.txt" using the WebDAV API
Then the HTTP status code should be <code>
Examples:
| quotaValue | code |
| 15 | "507" |
| 10000 | between "201" and "204" |
| 0 | between "201" and "204" |
| -1 | between "201" and "204" |

View File

@@ -91,11 +91,11 @@ class SpacesContext implements Context {
*/
private $storedEtags = [];
private $etagPropfindBody = '<?xml version="1.0"?>'
. '<d:propfind xmlns:d="DAV:" '
. 'xmlns:oc="http://owncloud.org/ns" '
. 'xmlns:ocs="http://open-collaboration-services.org/ns">'
.'<d:prop><d:getetag/></d:prop></d:propfind>';
private $etagPropfindBody = '<?xml version="1.0"?>'
. '<d:propfind xmlns:d="DAV:" '
. 'xmlns:oc="http://owncloud.org/ns" '
. 'xmlns:ocs="http://open-collaboration-services.org/ns">'
. '<d:prop><d:getetag/></d:prop></d:propfind>';
/**
* @param string $spaceName
@@ -246,7 +246,11 @@ class SpacesContext implements Context {
if ($spaceName === "Personal") {
$spaceName = $this->featureContext->getUserDisplayName($user);
}
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
if (strtolower($user) === 'admin') {
$this->theUserListsAllAvailableSpacesUsingTheGraphApi($user);
} else {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
}
$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");
@@ -393,6 +397,51 @@ class SpacesContext implements Context {
);
}
/**
* @AfterScenario
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function cleanDataAfterTests(): void {
// TODO enable when admin can disable and delete spaces
// $this->deleteAllSpacesOfTheType('project');
// $this->deleteAllSpacesOfTheType('personal');
}
/**
* The method first disables and then deletes spaces
*
* @param string $driveType
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function deleteAllSpacesOfTheType(string $driveType): void {
$query = "\$filter=driveType eq $driveType";
$userAdmin = $this->featureContext->getAdminUsername();
for ($i = 0; $i < 2; ++$i) {
$this->theUserListsAllAvailableSpacesUsingTheGraphApi(
$userAdmin,
$query
);
$drives = $this->getAvailableSpaces();
if (!empty($drives)) {
foreach ($drives as $value) {
if (!\array_key_exists("deleted", $value["root"])) {
$this->sendDisableSpaceRequest($userAdmin, $value["name"]);
} else {
$this->sendDeleteSpaceRequest($userAdmin, $value["name"]);
}
}
}
}
}
/**
* Send Graph List My Spaces Request
*
@@ -560,7 +609,6 @@ class SpacesContext implements Context {
* @param string $xRequestId
* @param array $headers
*
*
* @return ResponseInterface
*
* @throws GuzzleException
@@ -1748,55 +1796,55 @@ class SpacesContext implements Context {
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
}
/**
* @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fileDestination
* @param string $spaceName
*
* @return void
*/
public function userMovesFileWithinSpaceUsingTheWebDAVAPI(
string $user,
string $fileSource,
string $fileDestination,
string $spaceName
):void {
$space = $this->getSpaceByName($user, $spaceName);
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName(
$user,
$fileDestination,
$spaceName
);
/**
* @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fileDestination
* @param string $spaceName
*
* @return void
*/
public function userMovesFileWithinSpaceUsingTheWebDAVAPI(
string $user,
string $fileSource,
string $fileDestination,
string $spaceName
):void {
$space = $this->getSpaceByName($user, $spaceName);
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName(
$user,
$fileDestination,
$spaceName
);
$fullUrl = $space["root"]["webDavUrl"] . '/' . \trim($fileSource, "/");
$this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
}
$fullUrl = $space["root"]["webDavUrl"] . '/' . \trim($fileSource, "/");
$this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
}
/**
* MOVE request for files|folders
*
* @param string $user
* @param string $fullUrl
* @param string $headers
*
* @return void
* @throws GuzzleException
*/
public function moveFilesAndFoldersRequest(string $user, string $fullUrl, array $headers):void {
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
'MOVE',
$user,
$this->featureContext->getPasswordForUser($user),
$headers,
)
);
}
/**
* MOVE request for files|folders
*
* @param string $user
* @param string $fullUrl
* @param string $headers
*
* @return void
* @throws GuzzleException
*/
public function moveFilesAndFoldersRequest(string $user, string $fullUrl, array $headers):void {
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
'MOVE',
$user,
$this->featureContext->getPasswordForUser($user),
$headers,
)
);
}
/**
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
@@ -1823,31 +1871,30 @@ class SpacesContext implements Context {
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
}
/**
* @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
* @param string $fileDestination
* @param string $toSpaceName
*
* @return void
* @throws GuzzleException
*/
public function userMovesFileFromAndToSpaceBetweenSpaces(
string $user,
string $fileSource,
string $fromSpaceName,
string $fileDestination,
string $toSpaceName
):void {
$space = $this->getSpaceByName($user, $fromSpaceName);
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName);
$fullUrl = $space["root"]["webDavUrl"] . '/' . \ltrim($fileSource, "/");
$this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
}
/**
* @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
* @param string $fileDestination
* @param string $toSpaceName
*
* @return void
* @throws GuzzleException
*/
public function userMovesFileFromAndToSpaceBetweenSpaces(
string $user,
string $fileSource,
string $fromSpaceName,
string $fileDestination,
string $toSpaceName
):void {
$space = $this->getSpaceByName($user, $fromSpaceName);
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName);
$fullUrl = $space["root"]["webDavUrl"] . '/' . \ltrim($fileSource, "/");
$this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
}
/**
* returns a url for destination with spacename
@@ -2852,7 +2899,7 @@ class SpacesContext implements Context {
);
$should = ($shouldOrNot !== "not");
$responseArray = json_decode(json_encode($this->featureContext->getResponseXml()->data),true, 512, JSON_THROW_ON_ERROR);
$responseArray = json_decode(json_encode($this->featureContext->getResponseXml()->data), true, 512, JSON_THROW_ON_ERROR);
if ($should) {
Assert::assertNotEmpty($responseArray, __METHOD__ . ' Response should contain a link, but it is empty');