Merge pull request #2830 from owncloud/apiTestQuota

[tests-only] ApiTest: state of the quota
This commit is contained in:
Viktor Scharf
2021-12-03 11:27:23 +01:00
committed by GitHub
6 changed files with 249 additions and 55 deletions

View File

@@ -9,3 +9,6 @@
#### [downloading an archive with non existing / accessible id returns HTTP/500](https://github.com/owncloud/ocis/issues/2795)
- [apiArchiver/downloadById.feature:69](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadByPath.feature#L69)
#### [Overwriting a file in the space within the allowed quota does not work](https://github.com/owncloud/ocis/issues/2829)
- [apiSpaces/quota.feature:56](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/quota.feature#L56)

View File

@@ -8,12 +8,11 @@ Feature: Change data of space
Background:
Given user "Alice" has been created with default attributes and without skeleton files
And the administrator gives "Alice" the role "Admin" using the settings api
And the administrator has given "Alice" the role "Admin" using the settings api
Scenario: Alice changes a name of the space via the Graph api, she expects a 204 code and checks that the space name has changed
When user "Alice" creates a space "Project Jupiter" of type "project" with quota "20" using the GraphApi
And user "Alice" lists all available spaces via the GraphApi
And user "Alice" changes the name of the "Project Jupiter" space to "Project Death Star"
Given user "Alice" has created a space "Project Jupiter" of type "project" with quota "20"
When user "Alice" changes the name of the "Project Jupiter" space to "Project Death Star"
Then the HTTP status code should be "204"
When user "Alice" lists all available spaces via the GraphApi
Then the json responded should contain a space "Project Death Star" with these key and value pairs:
@@ -24,9 +23,8 @@ Feature: Change data of space
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
Scenario: Alice increases quota of the space via the Graph api, she expects a 204 code and checks that the quota has changed
When user "Alice" creates a space "Project Earth" of type "project" with quota "20" using the GraphApi
And user "Alice" lists all available spaces via the GraphApi
And user "Alice" changes the quota of the "Project Earth" space to "100"
Given user "Alice" has created a space "Project Earth" of type "project" with quota "20"
When user "Alice" changes the quota of the "Project Earth" space to "100"
Then the HTTP status code should be "204"
When user "Alice" lists all available spaces via the GraphApi
Then the json responded should contain a space "Project Earth" with these key and value pairs:

View File

@@ -30,7 +30,7 @@ Feature: List and create spaces
Then the HTTP status code should be "401"
Scenario: Alice creates Space via Graph api with default quota, she expects a 201 code the correct data and that space exists
Given the administrator gives "Alice" the role "Admin" using the settings api
Given the administrator has given "Alice" the role "Admin" using the settings api
When user "Alice" creates a space "Project Mars" of type "project" with the default quota using the GraphApi
Then the HTTP status code should be "201"
And the json responded should contain a space "Project Mars" with these key and value pairs:
@@ -45,7 +45,7 @@ Feature: List and create spaces
| .space/ |
Scenario: Alice creates Space via Graph api with certain quota, she expects a 201 code and the correct data in the response
Given the administrator gives "Alice" the role "Admin" using the settings api
Given the administrator has given "Alice" the role "Admin" using the settings api
When user "Alice" creates a space "Project Venus" of type "project" with quota "2000" using the GraphApi
Then the HTTP status code should be "201"
And the json responded should contain a space "Project Venus" with these key and value pairs:

View File

@@ -0,0 +1,68 @@
@api @skipOnOcV10
Feature: State of the quota
As a user
I want to be able to see the state of the quota and and not let the quota overrun:
quota state indication:
| 0 - 75% | normal |
| 76 - 90% | nearing |
| 91 - 99% | critical |
| 100 % | exceeded |
Note - this feature is run in CI with ACCOUNTS_HASH_DIFFICULTY set to the default for production
See https://github.com/owncloud/ocis/issues/1542 and https://github.com/owncloud/ocis/pull/839
Background:
Given user "Alice" has been created with default attributes and without skeleton files
And the administrator has given "Alice" the role "Admin" using the settings api
Scenario Outline: check the quota display
Given user "Alice" has created a space "<spaceName>" of type "project" with quota "<total>"
And user "Alice" has uploaded a file inside space "<spaceName>" with content "<fileContent>" to "test.txt"
When user "Alice" lists all available spaces via the GraphApi
Then the json responded should contain a space "<spaceName>" with these key and value pairs:
| key | value |
| name | <spaceName> |
| quota@@@state | <state> |
| quota@@@total | <total> |
| quota@@@remaining| <remaining> |
| quota@@@used | <used> |
Examples:
| spaceName | fileContent | state | total | remaining | used |
| Quota1% | 1 | normal | 100 | 99 | 1 |
| Quota75% | 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12345 | normal | 100 | 25 | 75 |
| Quota76% | 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456 | nearing | 100 | 24 | 76 |
| Quota90% | 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567890 | nearing | 100 | 10 | 90 |
| Quota91% | 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1 | critical | 100 | 9 | 91 |
| Quota99% | 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 | critical | 100 | 1 | 99 |
| Quota100% | 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567890 | exceeded | 100 | 0 | 100 |
Scenario: uploading a file with an insufficient quota
Given user "Alice" has created a space "Project Alfa" of type "project" with quota "10"
When user "Alice" uploads a file inside space "Project Alfa" with content "More than 10 bytes" to "test.txt" using the WebDAV API
Then the HTTP status code should be "507"
Scenario: creating a folder with an insufficient quota
Given user "Alice" has created a space "Project Beta" of type "project" with quota "7"
And user "Alice" has uploaded a file inside space "Project Beta" with content "7 bytes" to "test.txt"
When user "Alice" creates a folder "NewFolder" in space "Project Beta" using the WebDav Api
Then the HTTP status code should be "201"
And for user "Alice" the space "Project Beta" should contain these entries:
| NewFolder |
Scenario: overwriting a file with an enough quota
Given user "Alice" has created a space "Project Gamma" of type "project" with quota "10"
And user "Alice" has uploaded a file inside space "Project Gamma" with content "7 bytes" to "test.txt"
When user "Alice" uploads a file inside space "Project Gamma" with content "0010 bytes" to "test.txt" using the WebDAV API
Then the HTTP status code should be "204"
Scenario: overwriting a file with an insufficient quota
When user "Alice" has created a space "Project Delta" of type "project" with quota "10"
And user "Alice" has uploaded a file inside space "Project Delta" with content "7 bytes" to "test.txt"
When user "Alice" uploads a file inside space "Project Delta" with content "00011 bytes" to "test.txt" using the WebDAV API
Then the HTTP status code should be "507"

View File

@@ -9,30 +9,25 @@ Feature: Upload files into a space
Background:
Given user "Alice" has been created with default attributes and without skeleton files
And user "Bob" has been created with default attributes and without skeleton files
And the administrator has given "Alice" the role "Admin" using the settings api
Scenario: Alice creates a folder via the Graph api in space, she expects a 201 code and she checks that folder exists
Given the administrator gives "Alice" the role "Admin" using the settings api
When user "Alice" creates a space "Project Venus" of type "project" with quota "2000" using the GraphApi
And user "Alice" lists all available spaces via the GraphApi
And user "Alice" creates a folder "mainFolder" in space "Project Venus" using the WebDav Api
Given user "Alice" has created a space "Project Ceres" of type "project" with quota "2000"
When user "Alice" creates a folder "mainFolder" in space "Project Ceres" using the WebDav Api
Then the HTTP status code should be "201"
And for user "Alice" the space "Project Venus" should contain these entries:
And for user "Alice" the space "Project Ceres" should contain these entries:
| mainFolder |
Scenario: Bob creates a folder via the Graph api in a space, he expects a 404 code and Alice checks that this folder does not exist
Given the administrator gives "Alice" the role "Admin" using the settings api
When user "Alice" creates a space "Project Merkur" of type "project" with quota "2000" using the GraphApi
And user "Alice" lists all available spaces via the GraphApi
And user "Bob" creates a folder "forAlice" in space "Project Merkur" using the WebDav Api
Given user "Alice" has created a space "Project Merkur" of type "project" with quota "2000"
And user "Bob" creates a folder "forAlice" in space "Project Merkur" owned by the user "Alice" using the WebDav Api
Then the HTTP status code should be "404"
And for user "Alice" the space "Project Merkur" should not contain these entries:
| forAlice |
Scenario: Alice creates a folder via Graph api and uploads a file
Given the administrator gives "Alice" the role "Admin" using the settings api
When user "Alice" creates a space "Project Moon" of type "project" with quota "2000" using the GraphApi
And user "Alice" lists all available spaces via the GraphApi
And user "Alice" creates a folder "NewFolder" in space "Project Moon" using the WebDav Api
Given user "Alice" has created a space "Project Moon" of type "project" with quota "2000"
When user "Alice" creates a folder "NewFolder" in space "Project Moon" using the WebDav Api
Then the HTTP status code should be "201"
And user "Alice" uploads a file inside space "Project Moon" with content "Test" to "test.txt" using the WebDAV API
Then the HTTP status code should be "201"
@@ -41,16 +36,13 @@ Feature: Upload files into a space
| test.txt |
Scenario: Bob uploads a file via the Graph api in a space, he expects a 404 code and Alice checks that this file does not exist
Given the administrator gives "Alice" the role "Admin" using the settings api
When user "Alice" creates a space "Project Pluto" of type "project" with quota "2000" using the GraphApi
And user "Alice" lists all available spaces via the GraphApi
And user "Bob" uploads a file inside space "Project Pluto" with content "Test" to "test.txt" using the WebDAV API
Given user "Alice" has created a space "Project Pluto" of type "project" with quota "2000"
When user "Bob" uploads a file inside space "Project Pluto" owned by the user "Alice" with content "Test" to "test.txt" using the WebDAV API
Then the HTTP status code should be "404"
And for user "Alice" the space "Project Pluto" should not contain these entries:
| test.txt |
Scenario: Alice creates uploads a file and checks her quota
Given the administrator gives "Alice" the role "Admin" using the settings api
When user "Alice" creates a space "Project Saturn" of type "project" with quota "2000" using the GraphApi
And the json responded should contain a space "Project Saturn" with these key and value pairs:
| key | value |
@@ -58,13 +50,12 @@ Feature: Upload files into a space
| id | %space_id% |
| name | Project Saturn|
| quota@@@total | 2000 |
And user "Alice" lists all available spaces via the GraphApi
And user "Alice" uploads a file inside space "Project Saturn" with content "Test" to "test.txt" using the WebDAV API
Then the HTTP status code should be "201"
And for user "Alice" the space "Project Saturn" should contain these entries:
| test.txt |
And user "Alice" lists all available spaces via the GraphApi
And the json responded should contain a space "Project Saturn" with these key and value pairs:
When user "Alice" lists all available spaces via the GraphApi
Then the json responded should contain a space "Project Saturn" with these key and value pairs:
| key | value |
| driveType | project |
| id | %space_id% |

View File

@@ -22,6 +22,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Behat\Testwork\Environment\Environment;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
@@ -177,13 +178,20 @@ class SpacesContext implements Context {
}
/**
* @param string $name
* The method finds available spaces to the user and returns the space by spaceName
*
* @param string $user
* @param string $spaceName
*
* @return array
*/
public function getSpaceByName(string $name): array {
public function getSpaceByName(string $user, string $name): array {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
$spaces = $this->getAvailableSpaces();
Assert::assertIsArray($spaces[$name]);
Assert::assertIsArray($spaces[$name], "Space with name $name for user $user not found");
Assert::assertNotEmpty($spaces[$name]["root"]["webDavUrl"], "WebDavUrl for space with name $name for user $user not found");
return $spaces[$name];
}
@@ -408,7 +416,7 @@ class SpacesContext implements Context {
}
/**
* @When /^the administrator gives "([^"]*)" the role "([^"]*)" using the settings api$/
* @When /^the administrator has given "([^"]*)" the role "([^"]*)" using the settings api$/
*
* @param string $user
* @param string $role
@@ -519,7 +527,7 @@ class SpacesContext implements Context {
string $user,
string $spaceName
): void {
$space = $this->getSpaceByName($spaceName);
$space = $this->getSpaceByName($user, $spaceName);
Assert::assertIsArray($space);
Assert::assertNotEmpty($spaceId = $space["id"]);
Assert::assertNotEmpty($spaceWebDavUrl = $space["root"]["webDavUrl"]);
@@ -793,14 +801,56 @@ class SpacesContext implements Context {
string $folder,
string $spaceName
): void {
$space = $this->getSpaceByName($user, $spaceName);
$baseUrl = $this->featureContext->getBaseUrl();
if (!str_ends_with($baseUrl, '/')) {
$baseUrl .= '/';
}
$fullUrl = $baseUrl . "dav/spaces/" . $space['id'] . '/' . $folder;
$this->featureContext->setResponse(
$this->sendCreateFolderRequest(
$this->featureContext->getBaseUrl(),
$fullUrl,
"MKCOL",
$user,
$this->featureContext->getPasswordForUser($user),
$folder,
$spaceName
$this->featureContext->getPasswordForUser($user)
)
);
}
/**
* @When /^user "([^"]*)" creates a folder "([^"]*)" in space "([^"]*)" owned by the user "([^"]*)" using the WebDav Api$/
*
* @param string $user
* @param string $folder
* @param string $spaceName
* @param string $ownerUser
*
* @return void
*
* @throws GuzzleException
*/
public function theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi(
string $user,
string $folder,
string $spaceName,
string $ownerUser
): void {
$space = $this->getSpaceByName($ownerUser, $spaceName);
$baseUrl = $this->featureContext->getBaseUrl();
if (!str_ends_with($baseUrl, '/')) {
$baseUrl .= '/';
}
$fullUrl = $baseUrl . "dav/spaces/" . $space['id'] . '/' . $folder;
$this->featureContext->setResponse(
$this->sendCreateFolderRequest(
$fullUrl,
"MKCOL",
$user,
$this->featureContext->getPasswordForUser($user)
)
);
}
@@ -823,7 +873,43 @@ class SpacesContext implements Context {
string $content,
string $destination
): void {
$space = $this->getSpaceByName($spaceName);
$space = $this->getSpaceByName($user, $spaceName);
Assert::assertIsArray($space, "Space with name $spaceName not found");
Assert::assertNotEmpty($space["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName not found");
$this->featureContext->setResponse(
$this->sendPutRequestToUrl(
$space["root"]["webDavUrl"] . "/" . $destination,
$user,
$this->featureContext->getPasswordForUser($user),
"",
[],
$content
)
);
}
/**
* @When /^user "([^"]*)" uploads a file inside space "([^"]*)" owned by the user "([^"]*)" with content "([^"]*)" to "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $spaceName
* @param string $ownerUser
* @param string $content
* @param string $destination
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserUploadsAFileToAnotherOwnerSpace(
string $user,
string $spaceName,
string $ownerUser,
string $content,
string $destination
): void {
$space = $this->getSpaceByName($ownerUser, $spaceName);
Assert::assertIsArray($space, "Space with name $spaceName not found");
Assert::assertNotEmpty($space["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName not found");
@@ -842,12 +928,10 @@ class SpacesContext implements Context {
/**
* Send Graph Create Folder Request
*
* @param string $baseUrl
* @param string $fullUrl
* @param string $method
* @param string $user
* @param string $password
* @param string $folder
* @param string $spaceName
* @param string $xRequestId
* @param array $headers
*
@@ -856,22 +940,13 @@ class SpacesContext implements Context {
* @throws GuzzleException
*/
public function sendCreateFolderRequest(
string $baseUrl,
string $fullUrl,
string $method,
string $user,
string $password,
string $folder,
string $spaceName,
string $xRequestId = '',
array $headers = []
): ResponseInterface {
$spaceId = $this->getAvailableSpaces()[$spaceName]["id"];
$fullUrl = $baseUrl;
if (!str_ends_with($fullUrl, '/')) {
$fullUrl .= '/';
}
$fullUrl .= "dav/spaces/" . $spaceId . '/' . $folder;
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers);
}
@@ -891,7 +966,7 @@ class SpacesContext implements Context {
string $spaceName,
string $newName
): void {
$space = $this->getSpaceByName($spaceName);
$space = $this->getSpaceByName($user, $spaceName);
$spaceId = $space["id"];
$bodyData = ["Name" => $newName];
@@ -924,7 +999,7 @@ class SpacesContext implements Context {
string $spaceName,
int $newQuota
): void {
$space = $this->getSpaceByName($spaceName);
$space = $this->getSpaceByName($user, $spaceName);
$spaceId = $space["id"];
$bodyData = ["quota" => ["total" => $newQuota]];
@@ -974,4 +1049,63 @@ class SpacesContext implements Context {
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers, $body);
}
/**
* @Given /^user "([^"]*)" has created a space "([^"]*)" of type "([^"]*)" with quota "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $spaceType
* @param int $quota
*
* @return void
*/
public function userHasCreatedSpace(string $user, string $spaceName, string $spaceType, int $quota):void {
$space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]];
$body = json_encode($space);
$this->featureContext->setResponse(
$this->sendCreateSpaceRequest(
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$body,
""
)
);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201 (Created)"
);
}
/**
* @Given /^user "([^"]*)" has uploaded a file inside space "([^"]*)" with content "([^"]*)" to "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $fileContent
* @param string $destination
*
* @return void
*/
public function userHasUploadedFile(string $user, string $spaceName, string $fileContent, string $destination):void {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
$space = $this->getSpaceByName($user, $spaceName);
Assert::assertIsArray($space, "Space with name $spaceName not found");
Assert::assertNotEmpty($space["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName not found");
$this->featureContext->setResponse(
$this->sendPutRequestToUrl(
$space["root"]["webDavUrl"] . "/" . $destination,
$user,
$this->featureContext->getPasswordForUser($user),
"",
[],
$fileContent
)
);
$this->featureContext->theHTTPStatusCodeShouldBeOr(201, 204);
}
}