Merge pull request #4440 from owncloud/add-tests-quota-tus
[tests-only] Add api tests for tus upload when quota is set
This commit is contained in:
9 files changed
+219
-162
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# The test runner source for API tests
|
# The test runner source for API tests
|
||||||
CORE_COMMITID=b51fb4c01f08763e023aece4f90308e07a7ac73f
|
CORE_COMMITID=dc32078d4c9a158f7c412c780035bc90906a8ab8
|
||||||
CORE_BRANCH=master
|
CORE_BRANCH=master
|
||||||
|
|
||||||
# The test runner source for UI tests
|
# The test runner source for UI tests
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ default:
|
|||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
- WebDavLockingContext:
|
- WebDavLockingContext:
|
||||||
- TusContext:
|
- TUSContext:
|
||||||
|
- SpacesTUSContext:
|
||||||
|
|
||||||
apiArchiver:
|
apiArchiver:
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
@@ -24,17 +24,18 @@ Feature: Preview file in project space
|
|||||||
|
|
||||||
|
|
||||||
Scenario Outline: An user can preview image files in the project space
|
Scenario Outline: An user can preview image files in the project space
|
||||||
Given user "Alice" has uploaded a file "<entity>" via TUS inside of the space "previews of the files" using the WebDAV API
|
Given using spaces DAV path
|
||||||
When user "Alice" downloads the preview of "<entity>" of the space "previews of the files" with width "<width>" and height "<height>" using the WebDAV API
|
And user "Alice" has uploaded a file from "<source>" to "<destination>" via TUS inside of the space "previews of the files" using the WebDAV API
|
||||||
|
When user "Alice" downloads the preview of "<destination>" of the space "previews of the files" with width "<width>" and height "<height>" using the WebDAV API
|
||||||
Then the HTTP status code should be "200"
|
Then the HTTP status code should be "200"
|
||||||
Examples:
|
Examples:
|
||||||
| entity | width | height |
|
| source | destination | width | height |
|
||||||
| qrcode.png | 36 | 36 |
|
| filesForUpload/testavatar.png | testavatar.png | 36 | 36 |
|
||||||
| qrcode.png | 1200 | 1200 |
|
| filesForUpload/testavatar.png | testavatar.png | 1200 | 1200 |
|
||||||
| qrcode.png | 1920 | 1920 |
|
| filesForUpload/testavatar.png | testavatar.png | 1920 | 1920 |
|
||||||
| testavatar.jpg | 36 | 36 |
|
| filesForUpload/testavatar.jpg | testavatar.jpg | 36 | 36 |
|
||||||
| testavatar.jpg | 1200 | 1200 |
|
| filesForUpload/testavatar.jpg | testavatar.jpg | 1200 | 1200 |
|
||||||
| testavatar.jpg | 1920 | 1920 |
|
| filesForUpload/testavatar.jpg | testavatar.jpg | 1920 | 1920 |
|
||||||
| example.gif | 36 | 36 |
|
| filesForUpload/example.gif | example.gif | 36 | 36 |
|
||||||
| example.gif | 1200 | 1200 |
|
| filesForUpload/example.gif | example.gif | 1200 | 1200 |
|
||||||
| example.gif | 1280 | 1280 |
|
| filesForUpload/example.gif | example.gif | 1280 | 1280 |
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
@api @skipOnOcV10
|
||||||
|
Feature: upload resources using TUS protocol
|
||||||
|
As a user
|
||||||
|
I want to be able to upload files
|
||||||
|
So that I can store and share files between multiple client systems
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given these users have been created with default attributes and without skeleton files:
|
||||||
|
| username |
|
||||||
|
| Alice |
|
||||||
|
And the administrator has given "Alice" the role "Space Admin" using the settings api
|
||||||
|
And using spaces DAV path
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: upload a file within the set quota to a project space
|
||||||
|
Given user "Alice" has created a space "Project Jupiter" of type "project" with quota "10000"
|
||||||
|
When user "Alice" uploads a file with content "uploaded content" to "/upload.txt" via TUS inside of the space "Project Jupiter" using the WebDAV API
|
||||||
|
Then the HTTP status code should be "200"
|
||||||
|
And for user "Alice" the space "Project Jupiter" should contain these entries:
|
||||||
|
| upload.txt |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: upload a file bigger than the set quota to a project space
|
||||||
|
Given user "Alice" has created a space "Project Jupiter" of type "project" with quota "10"
|
||||||
|
When user "Alice" creates a new TUS resource for the space "Project Jupiter" using the WebDAV API with these headers:
|
||||||
|
| Upload-Length | 100 |
|
||||||
|
# dXBsb2FkLnR4dA== is the base64 encoded value of filename upload.txt
|
||||||
|
| Upload-Metadata | filename dXBsb2FkLnR4dA== |
|
||||||
|
| Tus-Resumable | 1.0.0 |
|
||||||
|
Then the HTTP status code should be "507"
|
||||||
|
And for user "Alice" the space "Project Jupiter" should not contain these entries:
|
||||||
|
| upload.txt |
|
||||||
|
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* ownCloud
|
||||||
|
*
|
||||||
|
* @author Viktor Scharf <v.scharf@owncloud.com>
|
||||||
|
* @copyright Copyright (c) 2022 Viktor Scharf v.scharf@owncloud.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Behat\Behat\Context\Context;
|
||||||
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
use TestHelpers\HttpRequestHelper;
|
||||||
|
use Behat\Gherkin\Node\TableNode;
|
||||||
|
use TestHelpers\WebDavHelper;
|
||||||
|
|
||||||
|
require_once 'bootstrap.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context for the TUS-specific steps using the Graph API
|
||||||
|
*/
|
||||||
|
class SpacesTUSContext implements Context {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var FeatureContext
|
||||||
|
*/
|
||||||
|
private FeatureContext $featureContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var TUSContext
|
||||||
|
*/
|
||||||
|
private TUSContext $tusContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SpacesContext
|
||||||
|
*/
|
||||||
|
private SpacesContext $spacesContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private string $baseUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will run before EVERY scenario.
|
||||||
|
* It will set the properties for this object.
|
||||||
|
*
|
||||||
|
* @BeforeScenario
|
||||||
|
*
|
||||||
|
* @param BeforeScenarioScope $scope
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function before(BeforeScenarioScope $scope): void {
|
||||||
|
// Get the environment
|
||||||
|
$environment = $scope->getEnvironment();
|
||||||
|
// Get all the contexts you need in this context from here
|
||||||
|
$this->featureContext = $environment->getContext('FeatureContext');
|
||||||
|
$this->spacesContext = $environment->getContext('SpacesContext');
|
||||||
|
$this->tusContext = $environment->getContext('TUSContext');
|
||||||
|
$this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Given /^user "([^"]*)" has uploaded a file from "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param string $source
|
||||||
|
* @param string $destination
|
||||||
|
* @param string $spaceName
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function userHasUploadedFileViaTusInSpace(string $user, string $source, string $destination, string $spaceName): void {
|
||||||
|
$this->userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi($user, $source, $destination, $spaceName);
|
||||||
|
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Expected response status code should be 200");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When /^user "([^"]*)" uploads a file from "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param string $source
|
||||||
|
* @param string $spaceName
|
||||||
|
* @param string $destination
|
||||||
|
* @param array|null $uploadMetadata
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(
|
||||||
|
string $user,
|
||||||
|
string $source,
|
||||||
|
string $destination,
|
||||||
|
string $spaceName,
|
||||||
|
?array $uploadMetadata = null
|
||||||
|
): void {
|
||||||
|
$this->spacesContext->setSpaceIDByName($user, $spaceName);
|
||||||
|
$this->tusContext->userUploadsUsingTusAFileTo($user, $source, $destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Given user :user has created a new TUS resource for the space :spaceName using the WebDAV API with these headers:
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param string $spaceName
|
||||||
|
* @param TableNode $headers
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function userHasCreatedANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(
|
||||||
|
string $user,
|
||||||
|
string $spaceName,
|
||||||
|
TableNode $headers
|
||||||
|
): void {
|
||||||
|
$this->userCreatesANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders($user, $spaceName, $headers);
|
||||||
|
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When user :user creates a new TUS resource for the space :spaceName using the WebDAV API with these headers:
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param string $spaceName
|
||||||
|
* @param TableNode $headers
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(
|
||||||
|
string $user,
|
||||||
|
string $spaceName,
|
||||||
|
TableNode $headers
|
||||||
|
): void {
|
||||||
|
$this->spacesContext->setSpaceIDByName($user, $spaceName);
|
||||||
|
$this->tusContext->createNewTUSResourceWithHeaders($user, $headers, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When /^user "([^"]*)" uploads a file with content "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param string $content
|
||||||
|
* @param string $resource
|
||||||
|
* @param string $spaceName
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws Exception|GuzzleException
|
||||||
|
*/
|
||||||
|
public function userUploadsAFileWithContentToViaTusInsideOfTheSpaceUsingTheWebdavApi(
|
||||||
|
string $user,
|
||||||
|
string $content,
|
||||||
|
string $resource,
|
||||||
|
string $spaceName
|
||||||
|
): void {
|
||||||
|
$this->spacesContext->setSpaceIDByName($user, $spaceName);
|
||||||
|
$this->tusContext->userUploadsAFileWithContentToUsingTus($user, $content, $resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
/**
|
|
||||||
* ownCloud
|
|
||||||
*
|
|
||||||
* @author Viktor Scharf <v.scharf@owncloud.com>
|
|
||||||
* @copyright Copyright (c) 2022 Viktor Scharf v.scharf@owncloud.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Behat\Behat\Context\Context;
|
|
||||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
|
||||||
use TestHelpers\HttpRequestHelper;
|
|
||||||
|
|
||||||
require_once 'bootstrap.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Context for the TUS-specific steps using the Graph API
|
|
||||||
*/
|
|
||||||
class TusContext implements Context {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var FeatureContext
|
|
||||||
*/
|
|
||||||
private FeatureContext $featureContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var SpacesContext
|
|
||||||
*/
|
|
||||||
private SpacesContext $spacesContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private string $baseUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function acceptanceTestsDirLocation(): string {
|
|
||||||
return \dirname(__FILE__) . "/../../filesForUpload/";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will run before EVERY scenario.
|
|
||||||
* It will set the properties for this object.
|
|
||||||
*
|
|
||||||
* @BeforeScenario
|
|
||||||
*
|
|
||||||
* @param BeforeScenarioScope $scope
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function before(BeforeScenarioScope $scope): void {
|
|
||||||
// Get the environment
|
|
||||||
$environment = $scope->getEnvironment();
|
|
||||||
// Get all the contexts you need in this context from here
|
|
||||||
$this->featureContext = $environment->getContext('FeatureContext');
|
|
||||||
$this->spacesContext = $environment->getContext('SpacesContext');
|
|
||||||
$this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Given /^user "([^"]*)" has uploaded a file "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
|
|
||||||
*
|
|
||||||
* @param string $user
|
|
||||||
* @param string $resource
|
|
||||||
* @param string $spaceName
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* @throws GuzzleException
|
|
||||||
*/
|
|
||||||
public function uploadFileViaTus(string $user, string $resource, string $spaceName): void {
|
|
||||||
$resourceLocation = $this->getResourceLocation($user, $resource, $spaceName);
|
|
||||||
$file = \fopen($this->acceptanceTestsDirLocation() . $resource, 'r');
|
|
||||||
|
|
||||||
$this->featureContext->setResponse(
|
|
||||||
HttpRequestHelper::sendRequest(
|
|
||||||
$resourceLocation,
|
|
||||||
"",
|
|
||||||
'HEAD',
|
|
||||||
$user,
|
|
||||||
$this->featureContext->getPasswordForUser($user),
|
|
||||||
[],
|
|
||||||
""
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Expected response status code should be 200");
|
|
||||||
|
|
||||||
$this->featureContext->setResponse(
|
|
||||||
HttpRequestHelper::sendRequest(
|
|
||||||
$resourceLocation,
|
|
||||||
"",
|
|
||||||
'PATCH',
|
|
||||||
$user,
|
|
||||||
$this->featureContext->getPasswordForUser($user),
|
|
||||||
["Tus-Resumable" => "1.0.0", "Upload-Offset" => 0, 'Content-Type' => 'application/offset+octet-stream'],
|
|
||||||
$file
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(204, "Expected response status code should be 204");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* send POST and return the url of the resource location in the response header
|
|
||||||
*
|
|
||||||
* @param string $user
|
|
||||||
* @param string $resource
|
|
||||||
* @param string $spaceName
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
* @throws Exception|GuzzleException
|
|
||||||
*/
|
|
||||||
public function getResourceLocation(string $user, string $resource, string $spaceName): string {
|
|
||||||
$space = $this->spacesContext->getSpaceByName($user, $spaceName);
|
|
||||||
$fullUrl = $this->baseUrl . "/remote.php/dav/spaces/" . $space["id"];
|
|
||||||
|
|
||||||
$tusEndpoint = "tusEndpoint " . base64_encode(str_replace("$", "%", $fullUrl));
|
|
||||||
$fileName = "filename " . base64_encode($resource);
|
|
||||||
|
|
||||||
$headers = [
|
|
||||||
"Tus-Resumable" => "1.0.0",
|
|
||||||
"Upload-Metadata" => $tusEndpoint . ',' . $fileName,
|
|
||||||
"Upload-Length" => filesize($this->acceptanceTestsDirLocation() . $resource)
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->featureContext->setResponse(
|
|
||||||
HttpRequestHelper::post(
|
|
||||||
$fullUrl,
|
|
||||||
"",
|
|
||||||
$this->featureContext->getActualUsername($user),
|
|
||||||
$this->featureContext->getUserPassword($user),
|
|
||||||
$headers,
|
|
||||||
''
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201");
|
|
||||||
|
|
||||||
$locationHeader = $this->featureContext->getResponse()->getHeader('Location');
|
|
||||||
if (\sizeof($locationHeader) > 0) {
|
|
||||||
return $locationHeader[0];
|
|
||||||
}
|
|
||||||
throw new \Exception(__METHOD__ . " Location header could not be found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 226 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 536 B |
Binary file not shown.
|
Before Width: | Height: | Size: 52 KiB |
Reference in new issue
Block a user