Skip to content

Commit

Permalink
Add api tests for tus upload when quota is set
Browse files Browse the repository at this point in the history
  • Loading branch information
SwikritiT committed Aug 25, 2022
1 parent 9ceaf14 commit 61e2a65
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 40 deletions.
23 changes: 23 additions & 0 deletions tests/acceptance/features/apiSpaces/tusUpload.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@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


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 "lorem.txt" via TUS inside of the space "Project Jupiter" using the WebDAV API
Then the HTTP status code should be "204"


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 "lorem.txt" for the space "Project Jupiter" using the WebDAV API
Then the HTTP status code should be "507"
7 changes: 3 additions & 4 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ public function deleteAllSpacesOfTheType(string $driveType): void {
*/
public function deleteAllPersonalSpaces(): void {
$query = "\$filter=driveType eq personal";
$createdUsers= $this->featureContext->getCreatedUsers();
$createdUsers = $this->featureContext->getCreatedUsers();

foreach($createdUsers as $user) {
foreach ($createdUsers as $user) {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi(
$user["actualUsername"],
$query
Expand Down Expand Up @@ -586,7 +586,6 @@ public function sendCreateSpaceRequest(
array $headers = []
): ResponseInterface {
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/";

return HttpRequestHelper::post($fullUrl, $xRequestId, $user, $password, $headers, $body);
}

Expand Down Expand Up @@ -3027,7 +3026,7 @@ public function forUserSpaceShouldContainLinks(
string $fileName = ''
): void {
$body = '';
if (!empty ($fileName)) {
if (!empty($fileName)) {
$body = $this->getFileId($user, $spaceName, $fileName);
} else {
$space = $this->getSpaceByName($user, $spaceName);
Expand Down
106 changes: 70 additions & 36 deletions tests/acceptance/features/bootstrap/TusContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,47 +74,55 @@ public function before(BeforeScenarioScope $scope): void {
* @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->createTusResource($user, $resource, $spaceName);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201");
$this->uploadResourceThroughTUS($user, $resource);
$this->featureContext->theHTTPStatusCodeShouldBe(204, "Expected response status code should be 204");
}

/**
* @When /^user "([^"]*)" uploads 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 userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $resource, string $spaceName) {
$this->createTusResource($user, $resource, $spaceName);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201");
$this->uploadResourceThroughTUS($user, $resource);
}

/**
* @When /^user "([^"]*)" creates a new TUS resource "([^"]*)" for the space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return void
* @throws Exception|GuzzleException
*/
public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApi(string $user, string $resource, string $spaceName):void {
$this->createTusResource($user, $resource, $spaceName);
}

/**
* send POST and return the url of the resource location in the response header
* send POST request to create the TUS resource
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return string
* @return void
* @throws Exception|GuzzleException
*/
public function getResourceLocation(string $user, string $resource, string $spaceName): string {
public function createTusResource(string $user, string $resource, string $spaceName): void {
$space = $this->spacesContext->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . "/remote.php/dav/spaces/" . $space["id"];

Expand All @@ -126,7 +134,6 @@ public function getResourceLocation(string $user, string $resource, string $spac
"Upload-Metadata" => $tusEndpoint . ',' . $fileName,
"Upload-Length" => filesize($this->acceptanceTestsDirLocation() . $resource)
];

$this->featureContext->setResponse(
HttpRequestHelper::post(
$fullUrl,
Expand All @@ -137,12 +144,39 @@ public function getResourceLocation(string $user, string $resource, string $spac
''
)
);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201");
}

$locationHeader = $this->featureContext->getResponse()->getHeader('Location');
if (\sizeof($locationHeader) > 0) {
return $locationHeader[0];
public function uploadResourceThroughTUS(string $user, string $resource) {
$resourceLocation = $this->featureContext->getResponse()->getHeader('Location');
if (\sizeof($resourceLocation) > 0) {
$resourceLocation = $resourceLocation[0];
} else {
throw new \Exception(__METHOD__ . " Location header could not be found");
}
throw new \Exception(__METHOD__ . " Location header could not be found");
$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
)
);
}
}
7 changes: 7 additions & 0 deletions tests/acceptance/filesForUpload/lorem.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est
qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora
incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum
exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?

0 comments on commit 61e2a65

Please sign in to comment.