Skip to content

Commit

Permalink
Merge pull request #39708 from owncloud/enhance-theWebdavChecksumShou…
Browse files Browse the repository at this point in the history
…ldMatch

[tests-only] enhance theWebdavChecksumShouldMatch test
  • Loading branch information
phil-davis authored Jan 24, 2022
2 parents 3c8a95d + 72f1be5 commit c190a8a
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 29 deletions.
3 changes: 2 additions & 1 deletion tests/acceptance/features/apiMain/checksums.feature
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ Feature: checksums
When user "Alice" shares file "/myChecksumFile.txt" with user "Brian" using the sharing API
And user "Brian" accepts share "/myChecksumFile.txt" offered by user "Alice" using the sharing API
And user "Brian" requests the checksum of "/Shares/myChecksumFile.txt" via propfind
Then the webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960"
Then the HTTP status code should be "207"
And the webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960"
Examples:
| dav_version |
| new |
Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance/features/apiWebdavMove2/moveFile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ Feature: move (rename) file
| old |
| new |

@skipOnOcV10.8 @skipOnOcV10.9.0 @skipOnOcV10.9.1
Scenario Outline: Moving a file (deep moves with various folder and file names)
Given using <dav_version> DAV path
And user "Alice" has created folder "<source_folder>"
Expand Down Expand Up @@ -434,6 +435,7 @@ Feature: move (rename) file
| new | texta | file.txt | textb | 0 |
| new | texta | file.txt | textb | 1 |

@skipOnOcV10.8 @skipOnOcV10.9.0 @skipOnOcV10.9.1
Scenario Outline: Moving a file from a folder to the root
Given using <dav_version> DAV path
And user "Alice" has created folder "<source_folder>"
Expand Down
125 changes: 97 additions & 28 deletions tests/acceptance/features/bootstrap/ChecksumContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,56 +184,125 @@ public function userRequestsTheChecksumOfViaPropfind(string $user, string $path)
}

/**
* @Then the webdav checksum should match :checksum
* @Then the webdav checksum should match :expectedChecksum
*
* @param string $checksum
* @param string $expectedChecksum
*
* @return void
* @throws Exception
*/
public function theWebdavChecksumShouldMatch(string $checksum):void {
public function theWebdavChecksumShouldMatch(string $expectedChecksum):void {
$service = new Sabre\Xml\Service();
$parsed = $service->parse(
$this->featureContext->getResponse()->getBody()->getContents()
);
$bodyContents = $this->featureContext->getResponse()->getBody()->getContents();
$parsed = $service->parse($bodyContents);

/*
* Fetch the checksum array
* Maybe we want to do this a bit cleaner ;)
* The checksums are way down in the array:
* $checksums = $parsed[0]['value'][1]['value'][0]['value'][0];
* And inside is the actual checksum string:
* $checksums['value'][0]['value']
* The Asserts below check the existence of the expected key at every level
* of the nested array. This helps to see what happened if a test fails
* because the response structure is not as expected.
*/
$checksums = $parsed[0]['value'][1]['value'][0]['value'][0];

Assert::assertIsArray(
$parsed,
__METHOD__ . " could not parse response as XML: " . $bodyContents
);
Assert::assertArrayHasKey(
0,
$parsed,
__METHOD__ . " parsed XML does not have key 0"
);
$parsed0 = $parsed[0];
Assert::assertArrayHasKey(
'value',
$parsed0,
__METHOD__ . " parsed XML parsed0 does not have key value"
);
$parsed0Value = $parsed0['value'];
Assert::assertArrayHasKey(
1,
$parsed0Value,
__METHOD__ . " parsed XML parsed0Value does not have key 1"
);
$parsed0Value1 = $parsed0Value[1];
Assert::assertArrayHasKey(
'value',
$parsed0Value1,
__METHOD__ . " parsed XML parsed0Value1 does not have key value after key 1"
);
$parsed0Value1Value = $parsed0Value1['value'];
Assert::assertArrayHasKey(
0,
$parsed0Value1Value,
__METHOD__ . " parsed XML parsed0Value1Value does not have key 0"
);
$parsed0Value1Value0 = $parsed0Value1Value[0];
Assert::assertArrayHasKey(
'value',
$parsed0Value1Value0,
__METHOD__ . " parsed XML parsed0Value1Value0 does not have key value"
);
$parsed0Value1Value0Value = $parsed0Value1Value0['value'];
Assert::assertArrayHasKey(
0,
$parsed0Value1Value0Value,
__METHOD__ . " parsed XML parsed0Value1Value0Value does not have key 0"
);
$checksums = $parsed0Value1Value0Value[0];
Assert::assertArrayHasKey(
'value',
$checksums,
__METHOD__ . " parsed XML checksums does not have key value"
);
$checksumsValue = $checksums['value'];
Assert::assertArrayHasKey(
0,
$checksumsValue,
__METHOD__ . " parsed XML checksumsValue does not have key 0"
);
$checksumsValue0 = $checksumsValue[0];
Assert::assertArrayHasKey(
'value',
$checksumsValue0,
__METHOD__ . " parsed XML checksumsValue0 does not have key value"
);
$actualChecksum = $checksumsValue0['value'];
Assert::assertEquals(
$checksum,
$checksums['value'][0]['value'],
"Expected: webDav checksum should be {$checksum} but got {$checksums['value'][0]['value']}"
$expectedChecksum,
$actualChecksum,
"Expected: webDav checksum should be {$expectedChecksum} but got {$actualChecksum}"
);
}

/**
* @Then as user :user the webdav checksum of :path via propfind should match :checksum
* @Then as user :user the webdav checksum of :path via propfind should match :expectedChecksum
*
* @param string $user
* @param string $path
* @param string $checksum
* @param string $expectedChecksum
*
* @return void
* @throws Exception
*/
public function theWebdavChecksumOfViaPropfindShouldMatch(string $user, string $path, string $checksum):void {
public function theWebdavChecksumOfViaPropfindShouldMatch(string $user, string $path, string $expectedChecksum):void {
$user = $this->featureContext->getActualUsername($user);
$this->userRequestsTheChecksumOfViaPropfind($user, $path);
$this->theWebdavChecksumShouldMatch($checksum);
$this->theWebdavChecksumShouldMatch($expectedChecksum);
}

/**
* @Then the header checksum should match :checksum
* @Then the header checksum should match :expectedChecksum
*
* @param string $checksum
* @param string $expectedChecksum
*
* @return void
* @throws Exception
*/
public function theHeaderChecksumShouldMatch(string $checksum):void {
public function theHeaderChecksumShouldMatch(string $expectedChecksum):void {
$headerChecksums
= $this->featureContext->getResponse()->getHeader('OC-Checksum');

Expand All @@ -257,9 +326,9 @@ public function theHeaderChecksumShouldMatch(string $checksum):void {
$headerChecksum
= $headerChecksums[0];
Assert::assertEquals(
$checksum,
$expectedChecksum,
$headerChecksum,
"Expected: header checksum should match {$checksum} but got {$headerChecksum}"
"Expected: header checksum should match {$expectedChecksum} but got {$headerChecksum}"
);
}

Expand Down Expand Up @@ -304,14 +373,14 @@ public function theOcChecksumHeaderShouldNotBeThere():void {
}

/**
* @When user :user uploads chunk file :num of :total with :data to :destination with checksum :checksum using the WebDAV API
* @When user :user uploads chunk file :num of :total with :data to :destination with checksum :expectedChecksum using the WebDAV API
*
* @param string $user
* @param int $num
* @param int $total
* @param string $data
* @param string $destination
* @param string $checksum
* @param string $expectedChecksum
*
* @return void
*/
Expand All @@ -321,7 +390,7 @@ public function userUploadsChunkFileOfWithToWithChecksum(
int $total,
string $data,
string $destination,
string $checksum
string $expectedChecksum
):void {
$user = $this->featureContext->getActualUsername($user);
$num -= 1;
Expand All @@ -330,22 +399,22 @@ public function userUploadsChunkFileOfWithToWithChecksum(
$user,
'PUT',
$file,
['OC-Checksum' => $checksum, 'OC-Chunked' => '1'],
['OC-Checksum' => $expectedChecksum, 'OC-Chunked' => '1'],
$data,
"files"
);
$this->featureContext->setResponse($response);
}

/**
* @Given user :user has uploaded chunk file :num of :total with :data to :destination with checksum :checksum
* @Given user :user has uploaded chunk file :num of :total with :data to :destination with checksum :expectedChecksum
*
* @param string $user
* @param int $num
* @param int $total
* @param string $data
* @param string $destination
* @param string $checksum
* @param string $expectedChecksum
*
* @return void
*/
Expand All @@ -355,15 +424,15 @@ public function userHasUploadedChunkFileOfWithToWithChecksum(
int $total,
string $data,
string $destination,
string $checksum
string $expectedChecksum
):void {
$this->userUploadsChunkFileOfWithToWithChecksum(
$user,
$num,
$total,
$data,
$destination,
$checksum
$expectedChecksum
);
$this->featureContext->theHTTPStatusCodeShouldBeOr(201, 206);
}
Expand Down

0 comments on commit c190a8a

Please sign in to comment.