Skip to content

Commit

Permalink
Merge pull request #38466 from owncloud/tusTests-checksum
Browse files Browse the repository at this point in the history
[tests-only] TUS tests for checksum
  • Loading branch information
swoichha authored Mar 5, 2021
2 parents 82ca858 + 1083510 commit 143faf2
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ default:
- PublicWebDavContext:
- TUSContext:
- FilesVersionsContext:
- ChecksumContext:

apiWebdavEtagPropagation1:
paths:
Expand Down
62 changes: 62 additions & 0 deletions tests/acceptance/features/apiWebdavUploadTUS/checksums.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@api @skipOnOcV10
Feature: checksums

Background:
Given user "Alice" has been created with default attributes and without skeleton files

Scenario Outline: Uploading a file with 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 | 5 |
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
When user "Alice" uploads file with checksum "<checksum>" to the last created TUS Location with offset "0" and content "12345" 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 "12345"
Examples:
| dav_version | checksum |
| old | MD5 827ccb0eea8a706c4c34a16891f84e7b |
| new | MD5 827ccb0eea8a706c4c34a16891f84e7b |
| old | SHA1 8cb2237d0679ca88db6464eac60da96345513964 |
| new | SHA1 8cb2237d0679ca88db6464eac60da96345513964 |

Scenario Outline: Uploading a file with 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 | 5 |
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
When user "Alice" uploads file with checksum "MD5 827ccb0eea8a706c4c34a16891f84e7b" to the last created TUS Location with offset "0" and content "12345" using the TUS protocol on the WebDAV API
And user "Alice" requests the checksum of "/textFile.txt" via propfind
Then the webdav checksum should match "SHA1:8cb2237d0679ca88db6464eac60da96345513964 MD5:827ccb0eea8a706c4c34a16891f84e7b ADLER32:02f80100"
Examples:
| dav_version |
| old |
| new |

Scenario Outline: Uploading a 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 | 5 |
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
And user "Alice" has uploaded file with checksum "MD5 827ccb0eea8a706c4c34a16891f84e7b" to the last created TUS Location with offset "0" and content "12345" 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:8cb2237d0679ca88db6464eac60da96345513964"
Examples:
| dav_version |
| old |
| new |


Scenario Outline: Uploading a 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 | 5 |
| Upload-Metadata | filename dGV4dEZpbGUudHh0 |
When user "Alice" uploads file with checksum "<incorrect_checksum>" to the last created TUS Location with offset "0" and content "12345" using the TUS protocol on the WebDAV API
Then the HTTP status code should be "406"
And as "Alice" file "textFile.txt" should not exist
Examples:
| dav_version | incorrect_checksum |
| old | MD5 827ccb0eea8a706c4c34a16891f84e7a |
| new | MD5 827ccb0eea8a706c4c34a16891f84e7a |
| old | SHA1 8cb2237d0679ca88db6464eac60da96345513963 |
| new | SHA1 8cb2237d0679ca88db6464eac60da96345513963 |
46 changes: 44 additions & 2 deletions tests/acceptance/features/bootstrap/TUSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ public function createNewTUSresource(string $user, TableNode $headers) {
* @param string $user
* @param string $offset
* @param string $data
* @param string $checksum
*
* @return void
*
* @throws Exception
*/
public function sendsAChunkToTUSLocationWithOffsetAndData(string $user, string $offset, string $data) {
public function sendsAChunkToTUSLocationWithOffsetAndData(string $user, string $offset, string $data, string $checksum = '') {
$user = $this->featureContext->getActualUsername($user);
$password = $this->featureContext->getUserPassword($user);
$this->featureContext->setResponse(
Expand All @@ -114,6 +115,7 @@ public function sendsAChunkToTUSLocationWithOffsetAndData(string $user, string $
[
'Content-Type' => 'application/offset+octet-stream',
'Tus-Resumable' => '1.0.0',
'Upload-Checksum' => $checksum,
'Upload-Offset' => $offset
],
$data
Expand Down Expand Up @@ -317,7 +319,7 @@ public function userCreatesWithUpload(
* @return void
*/
public function userUploadsWithCreatesWithUpload(
string$user,
string $user,
string $source,
string $content
) {
Expand All @@ -327,4 +329,44 @@ public function userUploadsWithCreatesWithUpload(
);
\unlink($tmpfname);
}

/**
* @When user :user uploads file with checksum :checksum to the last created TUS Location with offset :offset and content :content using the TUS protocol on the WebDAV API
*
* @param string $user
* @param string $checksum
* @param string $offset
* @param string $content
*
* @return void
* @throws Exception
*/
public function userUploadsFileWithChecksum(
string $user,
string $checksum,
string $offset,
string $content
) {
$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
*
* @param string $user
* @param string $checksum
* @param string $offset
* @param string $content
*
* @return void
* @throws Exception
*/
public function userHasUploadedFileWithChecksum(
string $user,
string $checksum,
string $offset,
string $content
) {
$this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
$this->featureContext->theHTTPStatusCodeShouldBe(204, "");
}
}

0 comments on commit 143faf2

Please sign in to comment.