Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only]TUS tests for chunking with checksum #38471

Merged
merged 2 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/acceptance/features/apiWebdavUploadTUS/checksums.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,59 @@ Feature: checksums
| new | MD5 827ccb0eea8a706c4c34a16891f84e7a |
| old | SHA1 8cb2237d0679ca88db6464eac60da96345513963 |
| new | SHA1 8cb2237d0679ca88db6464eac60da96345513963 |

Scenario Outline: Uploading a chunked file with correct checksum should work
Given using <dav_version> DAV path
And user "Alice" has created a new TUS resource on the WebDAV API with these headers:
| Upload-Length | 10 |
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
When user "Alice" sends a chunk to the last created TUS Location with offset "0" and data "01234" with checksum "MD5 4100c4d44da9177247e44a5fc1546778" using the TUS protocol on the WebDAV API
And user "Alice" sends a chunk to the last created TUS Location with offset "5" and data "56789" with checksum "MD5 099ebea48ea9666a7da2177267983138" using the TUS protocol on the WebDAV API
Then the HTTP status code should be "204"
And the content of file "/textFile.txt" for user "Alice" should be "0123456789"
Examples:
| dav_version |
| old |
| new |

Scenario Outline: Uploading a chunked file with correct checksum should return the checksum in the propfind
Given using <dav_version> DAV path
And user "Alice" has created a new TUS resource on the WebDAV API with these headers:
| Upload-Length | 10 |
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
And user "Alice" has uploaded a chunk to the last created TUS Location with offset "0" and data "01234" with checksum "MD5 4100c4d44da9177247e44a5fc1546778" using the TUS protocol on the WebDAV API
And user "Alice" has uploaded a chunk to the last created TUS Location with offset "5" and data "56789" with checksum "MD5 099ebea48ea9666a7da2177267983138" using the TUS protocol on the WebDAV API
When user "Alice" requests the checksum of "/textFile.txt" via propfind
Then the webdav checksum should match "SHA1:87acec17cd9dcd20a716cc2cf67417b71c8a7016 MD5:781e5e245d69b566979b86e28d23f2c7 ADLER32:0aff020e"
Examples:
| dav_version |
| old |
| new |

Scenario Outline: Uploading a chunked file with checksum should return the checksum in the download header
Given using <dav_version> DAV path
And user "Alice" has created a new TUS resource on the WebDAV API with these headers:
| Upload-Length | 10 |
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
And user "Alice" has uploaded a chunk to the last created TUS Location with offset "0" and data "01234" with checksum "MD5 4100c4d44da9177247e44a5fc1546778" using the TUS protocol on the WebDAV API
And user "Alice" has uploaded a chunk to the last created TUS Location with offset "5" and data "56789" with checksum "MD5 099ebea48ea9666a7da2177267983138" using the TUS protocol on the WebDAV API
When user "Alice" downloads file "/textFile.txt" using the WebDAV API
Then the header checksum should match "SHA1:87acec17cd9dcd20a716cc2cf67417b71c8a7016"
Examples:
| dav_version |
| old |
| new |

Scenario Outline: Uploading second chunk of file with incorrect checksum should not work
Given using <dav_version> DAV path
And user "Alice" has created a new TUS resource on the WebDAV API with these headers:
| Upload-Length | 10 |
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
When user "Alice" sends a chunk to the last created TUS Location with offset "0" and data "01234" with checksum "MD5 4100c4d44da9177247e44a5fc1546799" using the TUS protocol on the WebDAV API
And user "Alice" sends a chunk to the last created TUS Location with offset "5" and data "56789" with checksum "MD5 781e5e245d69b566979b86e28d23f2c7" using the TUS protocol on the WebDAV API
Then the HTTP status code should be "409"
And as "Alice" file "textFile.txt" should not exist
Examples:
| dav_version |
| old |
| new |
43 changes: 42 additions & 1 deletion tests/acceptance/features/bootstrap/TUSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function sendsAChunkToTUSLocationWithOffsetAndData(string $user, string $
* Don't Base64 encode the value.
* @param int $noOfChunks
* @param int $bytes
* @param string $checksum
*
* @return void
* @throws ConnectionException
Expand All @@ -147,7 +148,8 @@ public function userUploadsUsingTusAFileTo(
string $destination,
array $uploadMetadata = [],
int $noOfChunks = 1,
int $bytes = null
int $bytes = null,
string $checksum = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string $checksum = ''
string $checksum = null

) {
$user = $this->featureContext->getActualUsername($user);
$password = $this->featureContext->getUserPassword($user);
Expand All @@ -161,6 +163,13 @@ public function userUploadsUsingTusAFileTo(
];
$headers = \array_merge($headers, $creationWithUploadHeader);
}
if ($checksum != '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($checksum != '') {
if (!$checksum) {

$checksumHeader = [
'Upload-Checksum' => $checksum
];
$headers = \array_merge($headers, $checksumHeader);
}

$client = new Client(
$this->featureContext->getBaseUrl(),
['verify' => false,
Expand Down Expand Up @@ -349,6 +358,7 @@ public function userUploadsFileWithChecksum(
) {
$this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
}

/**
* @Given user :user has uploaded file with checksum :checksum to the last created TUS Location with offset :offset and content :content using the TUS protocol on the WebDAV API
*
Expand All @@ -369,4 +379,35 @@ public function userHasUploadedFileWithChecksum(
$this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
$this->featureContext->theHTTPStatusCodeShouldBe(204, "");
}

/**
* @When user :user sends a chunk to the last created TUS Location with offset :offset and data :data with checksum :checksum using the TUS protocol on the WebDAV API
*
* @param string $user
* @param string $offset
* @param string $data
* @param string $checksum
*
* @return void
* @throws Exception
*/
public function userUploadsChunkFileWithChecksum($user, $offset, $data, $checksum) {
$this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
}

/**
* @Given user :user has uploaded a chunk to the last created TUS Location with offset :offset and data :data with checksum :checksum using the TUS protocol on the WebDAV API
*
* @param string $user
* @param string $offset
* @param string $data
* @param string $checksum
*
* @return void
* @throws Exception
*/
public function userHasUploadedChunkFileWithChecksum($user, $offset, $data, $checksum) {
$this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
$this->featureContext->theHTTPStatusCodeShouldBe(204, "");
}
}