Merge pull request #10226 from owncloud/tests/test-coverage-8804
[tests-only] add test coverage for #8804
This commit is contained in:
@@ -2395,7 +2395,7 @@ class FeatureContext extends BehatVariablesContext {
|
|||||||
"code" => "%tus_upload_location%",
|
"code" => "%tus_upload_location%",
|
||||||
"function" => [
|
"function" => [
|
||||||
$this->tusContext,
|
$this->tusContext,
|
||||||
"getTusResourceLocation"
|
"getLastTusResourceLocation"
|
||||||
],
|
],
|
||||||
"parameter" => []
|
"parameter" => []
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -275,8 +275,8 @@ class SpacesTUSContext implements Context {
|
|||||||
string $content,
|
string $content,
|
||||||
string $spaceName
|
string $spaceName
|
||||||
): void {
|
): void {
|
||||||
$this->spacesContext->setSpaceIDByName($user, $spaceName);
|
$resourceLocation = $this->tusContext->getLastTusResourceLocation();
|
||||||
$response = $this->tusContext->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
|
$response = $this->tusContext->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $content, $checksum);
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
|
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,8 +299,8 @@ class SpacesTUSContext implements Context {
|
|||||||
string $content,
|
string $content,
|
||||||
string $spaceName
|
string $spaceName
|
||||||
): void {
|
): void {
|
||||||
$spaceId = $this->spacesContext->setSpaceIDByName($user, $spaceName);
|
$resourceLocation = $this->tusContext->getLastTusResourceLocation();
|
||||||
$response = $this->tusContext->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
|
$response = $this->tusContext->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $content, $checksum);
|
||||||
$this->featureContext->setResponse($response);
|
$this->featureContext->setResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,8 +323,8 @@ class SpacesTUSContext implements Context {
|
|||||||
string $checksum,
|
string $checksum,
|
||||||
string $spaceName
|
string $spaceName
|
||||||
): void {
|
): void {
|
||||||
$this->spacesContext->setSpaceIDByName($user, $spaceName);
|
$resourceLocation = $this->tusContext->getLastTusResourceLocation();
|
||||||
$response = $this->tusContext->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
$response = $this->tusContext->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $data, $checksum);
|
||||||
$this->featureContext->setResponse($response);
|
$this->featureContext->setResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,9 +345,9 @@ class SpacesTUSContext implements Context {
|
|||||||
string $spaceName,
|
string $spaceName,
|
||||||
TableNode $headers
|
TableNode $headers
|
||||||
): void {
|
): void {
|
||||||
$this->spacesContext->setSpaceIDByName($user, $spaceName);
|
|
||||||
$rows = $headers->getRowsHash();
|
$rows = $headers->getRowsHash();
|
||||||
$response = $this->tusContext->sendsAChunkToTUSLocationWithOffsetAndData($user, $rows['Upload-Offset'], $data, $rows['Upload-Checksum'], ['Origin' => $rows['Origin']]);
|
$resourceLocation = $this->tusContext->getLastTusResourceLocation();
|
||||||
|
$response = $this->tusContext->uploadChunkToTUSLocation($user, $resourceLocation, $rows['Upload-Offset'], $data, $rows['Upload-Checksum'], ['Origin' => $rows['Origin']]);
|
||||||
$this->featureContext->setResponse($response);
|
$this->featureContext->setResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,7 +375,8 @@ class SpacesTUSContext implements Context {
|
|||||||
$spaceId = $this->spacesContext->setSpaceIDByName($user, $spaceName);
|
$spaceId = $this->spacesContext->setSpaceIDByName($user, $spaceName);
|
||||||
$createResponse = $this->tusContext->createNewTUSResource($user, $headers, $spaceId);
|
$createResponse = $this->tusContext->createNewTUSResource($user, $headers, $spaceId);
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(201, "", $createResponse);
|
$this->featureContext->theHTTPStatusCodeShouldBe(201, "", $createResponse);
|
||||||
$response = $this->tusContext->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
$resourceLocation = $this->tusContext->getLastTusResourceLocation();
|
||||||
|
$response = $this->tusContext->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $data, $checksum);
|
||||||
$this->featureContext->setResponse($response);
|
$this->featureContext->setResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,18 +40,54 @@ require_once 'bootstrap.php';
|
|||||||
class TUSContext implements Context {
|
class TUSContext implements Context {
|
||||||
private FeatureContext $featureContext;
|
private FeatureContext $featureContext;
|
||||||
|
|
||||||
private ?string $resourceLocation = null;
|
private array $tusResourceLocations = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filenameHash
|
||||||
|
* @param string $location
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function saveTusResourceLocation(string $filenameHash, string $location): void {
|
||||||
|
$this->tusResourceLocations[$filenameHash][] = $location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filenameHash
|
||||||
|
* @param int|null $index
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTusResourceLocation(string $filenameHash, ?int $index = null): string {
|
||||||
|
if ($index === null) {
|
||||||
|
// get the last one
|
||||||
|
$index = \count($this->tusResourceLocations[$filenameHash]) - 1;
|
||||||
|
}
|
||||||
|
return $this->tusResourceLocations[$filenameHash][$index];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTusResourceLocation(): string {
|
public function getLastTusResourceLocation(): string {
|
||||||
return $this->resourceLocation ?: "";
|
$lastKey = \array_key_last($this->tusResourceLocations);
|
||||||
|
$index = \count($this->tusResourceLocations[$lastKey]) - 1;
|
||||||
|
return $this->tusResourceLocations[$lastKey][$index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $uploadMetadata
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function parseFilenameHash(string $uploadMetadata): string {
|
||||||
|
$filenameHash = \explode("filename ", $uploadMetadata)[1] ?? '';
|
||||||
|
return \explode(" ", $filenameHash, 2)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $user
|
* @param string $user
|
||||||
* @param TableNode $headers
|
* @param TableNode $headersTable
|
||||||
* @param string $content
|
* @param string $content
|
||||||
* @param string|null $spaceId
|
* @param string|null $spaceId
|
||||||
*
|
*
|
||||||
@@ -60,17 +96,17 @@ class TUSContext implements Context {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function createNewTUSResourceWithHeaders(string $user, TableNode $headers, string $content = '', ?string $spaceId = null): ResponseInterface {
|
public function createNewTUSResourceWithHeaders(string $user, TableNode $headersTable, string $content = '', ?string $spaceId = null): ResponseInterface {
|
||||||
$this->featureContext->verifyTableNodeColumnsCount($headers, 2);
|
$this->featureContext->verifyTableNodeColumnsCount($headersTable, 2);
|
||||||
$user = $this->featureContext->getActualUsername($user);
|
$user = $this->featureContext->getActualUsername($user);
|
||||||
$password = $this->featureContext->getUserPassword($user);
|
$password = $this->featureContext->getUserPassword($user);
|
||||||
$this->resourceLocation = null;
|
|
||||||
|
|
||||||
|
$headers = $headersTable->getRowsHash();
|
||||||
$response = $this->featureContext->makeDavRequest(
|
$response = $this->featureContext->makeDavRequest(
|
||||||
$user,
|
$user,
|
||||||
"POST",
|
"POST",
|
||||||
null,
|
null,
|
||||||
$headers->getRowsHash(),
|
$headers,
|
||||||
$content,
|
$content,
|
||||||
$spaceId,
|
$spaceId,
|
||||||
"files",
|
"files",
|
||||||
@@ -80,7 +116,8 @@ class TUSContext implements Context {
|
|||||||
);
|
);
|
||||||
$locationHeader = $response->getHeader('Location');
|
$locationHeader = $response->getHeader('Location');
|
||||||
if (\sizeof($locationHeader) > 0) {
|
if (\sizeof($locationHeader) > 0) {
|
||||||
$this->resourceLocation = $locationHeader[0];
|
$filenameHash = $this->parseFilenameHash($headers['Upload-Metadata']);
|
||||||
|
$this->saveTusResourceLocation($filenameHash, $locationHeader[0]);
|
||||||
}
|
}
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
@@ -133,6 +170,7 @@ class TUSContext implements Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $user
|
* @param string $user
|
||||||
|
* @param string $resourceLocation
|
||||||
* @param string $offset
|
* @param string $offset
|
||||||
* @param string $data
|
* @param string $data
|
||||||
* @param string $checksum
|
* @param string $checksum
|
||||||
@@ -143,7 +181,7 @@ class TUSContext implements Context {
|
|||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
* @throws JsonException
|
* @throws JsonException
|
||||||
*/
|
*/
|
||||||
public function sendsAChunkToTUSLocationWithOffsetAndData(string $user, string $offset, string $data, string $checksum = '', ?array $extraHeaders = null): ResponseInterface {
|
public function uploadChunkToTUSLocation(string $user, string $resourceLocation, string $offset, string $data, string $checksum = '', ?array $extraHeaders = null): ResponseInterface {
|
||||||
$user = $this->featureContext->getActualUsername($user);
|
$user = $this->featureContext->getActualUsername($user);
|
||||||
$password = $this->featureContext->getUserPassword($user);
|
$password = $this->featureContext->getUserPassword($user);
|
||||||
$headers = [
|
$headers = [
|
||||||
@@ -155,7 +193,7 @@ class TUSContext implements Context {
|
|||||||
$headers = empty($extraHeaders) ? $headers : array_merge($headers, $extraHeaders);
|
$headers = empty($extraHeaders) ? $headers : array_merge($headers, $extraHeaders);
|
||||||
|
|
||||||
return HttpRequestHelper::sendRequest(
|
return HttpRequestHelper::sendRequest(
|
||||||
$this->resourceLocation,
|
$resourceLocation,
|
||||||
$this->featureContext->getStepLineRef(),
|
$this->featureContext->getStepLineRef(),
|
||||||
'PATCH',
|
'PATCH',
|
||||||
$user,
|
$user,
|
||||||
@@ -178,7 +216,8 @@ class TUSContext implements Context {
|
|||||||
* @throws JsonException
|
* @throws JsonException
|
||||||
*/
|
*/
|
||||||
public function userSendsAChunkToTUSLocationWithOffsetAndData(string $user, string $offset, string $data): void {
|
public function userSendsAChunkToTUSLocationWithOffsetAndData(string $user, string $offset, string $data): void {
|
||||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data);
|
$resourceLocation = $this->getLastTusResourceLocation();
|
||||||
|
$response = $this->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $data);
|
||||||
$this->featureContext->setResponse($response);
|
$this->featureContext->setResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,6 +463,8 @@ class TUSContext implements Context {
|
|||||||
$environment = $scope->getEnvironment();
|
$environment = $scope->getEnvironment();
|
||||||
// Get all the contexts you need in this context
|
// Get all the contexts you need in this context
|
||||||
$this->featureContext = $environment->getContext('FeatureContext');
|
$this->featureContext = $environment->getContext('FeatureContext');
|
||||||
|
// clear TUS locations cache
|
||||||
|
$this->tusResourceLocations = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -492,7 +533,36 @@ class TUSContext implements Context {
|
|||||||
string $offset,
|
string $offset,
|
||||||
string $content
|
string $content
|
||||||
): void {
|
): void {
|
||||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
|
$resourceLocation = $this->getLastTusResourceLocation();
|
||||||
|
$response = $this->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $content, $checksum);
|
||||||
|
$this->featureContext->setResponse($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When user :user uploads content :content with checksum :checksum and offset :offset to the index :locationIndex location of file :filename using the TUS protocol
|
||||||
|
* @When user :user tries to upload content :content with checksum :checksum and offset :offset to the index :locationIndex location of file :filename using the TUS protocol
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param string $content
|
||||||
|
* @param string $checksum
|
||||||
|
* @param string $offset
|
||||||
|
* @param string $locationIndex
|
||||||
|
* @param string $filename
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function userUploadsContentWithChecksumAndOffsetToIndexLocationUsingTUSProtocol(
|
||||||
|
string $user,
|
||||||
|
string $content,
|
||||||
|
string $checksum,
|
||||||
|
string $offset,
|
||||||
|
string $locationIndex,
|
||||||
|
string $filename
|
||||||
|
): void {
|
||||||
|
$filenameHash = \base64_encode($filename);
|
||||||
|
$resourceLocation = $this->getTusResourceLocation($filenameHash, (int)$locationIndex);
|
||||||
|
$response = $this->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $content, $checksum);
|
||||||
$this->featureContext->setResponse($response);
|
$this->featureContext->setResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,7 +583,8 @@ class TUSContext implements Context {
|
|||||||
string $offset,
|
string $offset,
|
||||||
string $content
|
string $content
|
||||||
): void {
|
): void {
|
||||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
|
$resourceLocation = $this->getLastTusResourceLocation();
|
||||||
|
$response = $this->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $content, $checksum);
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
|
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,7 +600,8 @@ class TUSContext implements Context {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function userUploadsChunkFileWithChecksum(string $user, string $offset, string $data, string $checksum): void {
|
public function userUploadsChunkFileWithChecksum(string $user, string $offset, string $data, string $checksum): void {
|
||||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
$resourceLocation = $this->getLastTusResourceLocation();
|
||||||
|
$response = $this->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $data, $checksum);
|
||||||
$this->featureContext->setResponse($response);
|
$this->featureContext->setResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,7 +617,8 @@ class TUSContext implements Context {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function userHasUploadedChunkFileWithChecksum(string $user, string $offset, string $data, string $checksum): void {
|
public function userHasUploadedChunkFileWithChecksum(string $user, string $offset, string $data, string $checksum): void {
|
||||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
$resourceLocation = $this->getLastTusResourceLocation();
|
||||||
|
$response = $this->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $data, $checksum);
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
|
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,7 +640,8 @@ class TUSContext implements Context {
|
|||||||
public function userOverwritesFileWithChecksum(string $user, string $offset, string $data, string $checksum, TableNode $headers): void {
|
public function userOverwritesFileWithChecksum(string $user, string $offset, string $data, string $checksum, TableNode $headers): void {
|
||||||
$createResponse = $this->createNewTUSResource($user, $headers);
|
$createResponse = $this->createNewTUSResource($user, $headers);
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(201, "", $createResponse);
|
$this->featureContext->theHTTPStatusCodeShouldBe(201, "", $createResponse);
|
||||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
$resourceLocation = $this->getLastTusResourceLocation();
|
||||||
|
$response = $this->uploadChunkToTUSLocation($user, $resourceLocation, $offset, $data, $checksum);
|
||||||
$this->featureContext->setResponse($response);
|
$this->featureContext->setResponse($response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,3 +211,26 @@ Feature: upload file
|
|||||||
| old |
|
| old |
|
||||||
| new |
|
| new |
|
||||||
| spaces |
|
| spaces |
|
||||||
|
|
||||||
|
@issue-8804
|
||||||
|
Scenario Outline: multiple upload locations of the same file
|
||||||
|
Given using <dav-path-version> DAV path
|
||||||
|
And user "Alice" has created a new TUS resource on the WebDAV API with these headers:
|
||||||
|
| Upload-Length | 5 |
|
||||||
|
# bG9yZW0udHh0 is the base64 encode of lorem.txt
|
||||||
|
| Upload-Metadata | filename bG9yZW0udHh0 |
|
||||||
|
And user "Alice" has created a new TUS resource on the WebDAV API with these headers:
|
||||||
|
| Upload-Length | 5 |
|
||||||
|
# bG9yZW0udHh0 is the base64 encode of lorem.txt
|
||||||
|
| Upload-Metadata | filename bG9yZW0udHh0 |
|
||||||
|
When user "Alice" uploads content "lorem" with checksum "MD5 d2e16e6ef52a45b7468f1da56bba1953" and offset "0" to the index "1" location of file "lorem.txt" using the TUS protocol
|
||||||
|
Then the HTTP status code should be "204"
|
||||||
|
And the content of file "lorem.txt" for user "Alice" should be "lorem"
|
||||||
|
When user "Alice" tries to upload content "epsum" with checksum "MD5 d6145e3d2ced88009796acae1dc7929f" and offset "0" to the index "0" location of file "lorem.txt" using the TUS protocol
|
||||||
|
Then the HTTP status code should be "409"
|
||||||
|
And the content of file "lorem.txt" for user "Alice" should be "lorem"
|
||||||
|
Examples:
|
||||||
|
| dav-path-version |
|
||||||
|
| old |
|
||||||
|
| new |
|
||||||
|
| spaces |
|
||||||
|
|||||||
Reference in New Issue
Block a user