From 9a9b5c4c7c63e7be8f2ec0d082e59be86463f5f8 Mon Sep 17 00:00:00 2001 From: "sagargurung1001@gmail.com" Date: Fri, 5 Aug 2022 16:56:04 +0545 Subject: [PATCH 1/2] Add /Shares realated tests from core --- .../features/apiSpaces/checksum.feature | 31 +++++++++ .../features/bootstrap/SpacesContext.php | 68 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 tests/acceptance/features/apiSpaces/checksum.feature diff --git a/tests/acceptance/features/apiSpaces/checksum.feature b/tests/acceptance/features/apiSpaces/checksum.feature new file mode 100644 index 0000000000..a423b18bc8 --- /dev/null +++ b/tests/acceptance/features/apiSpaces/checksum.feature @@ -0,0 +1,31 @@ +@api @skipOnOcV10 +Feature: checksums + + Background: + Given user "Alice" has been created with default attributes and without skeleton files + + @files_sharing-app-required @issue-ocis-reva-196 + Scenario: Sharing a file with checksum should return the checksum in the propfind using new DAV path + Given the administrator has set the default folder for received shares to "Shares" + And auto-accept shares has been disabled + And using spaces DAV path + And user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" + And user "Alice" has shared file "/myChecksumFile.txt" with user "Brian" + And user "Brian" has accepted share "/myChecksumFile.txt" offered by user "Alice" + When user "Brian" requests the checksum of "/myChecksumFile.txt" in space "Shares Jail" via propfind + Then the HTTP status code should be "207" + And the webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960" + + @files_sharing-app-required @issue-ocis-reva-196 + Scenario: Modifying a shared file should return correct checksum in the propfind using new DAV path + Given the administrator has set the default folder for received shares to "Shares" + And auto-accept shares has been disabled + And using spaces DAV path + And user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" + And user "Alice" has shared file "/myChecksumFile.txt" with user "Brian" + And user "Brian" has accepted share "/myChecksumFile.txt" offered by user "Alice" + When user "Brian" uploads file with checksum "SHA1:ce5582148c6f0c1282335b87df5ed4be4b781399" and content "Some Text" to "/myChecksumFile.txt" in space "Shares Jail" using the WebDAV API + Then the HTTP status code should be "204" + And as user "Alice" the webdav checksum of "/myChecksumFile.txt" via propfind should match "SHA1:ce5582148c6f0c1282335b87df5ed4be4b781399 MD5:56e57920c3c8c727bfe7a5288cdf61c4 ADLER32:1048035a" diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index df6d7fdddb..ad823a2bcd 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -2559,6 +2559,74 @@ class SpacesContext implements Context { ); } + /** + * @When /^user "([^"]*)" requests the checksum of "([^"]*)" in space "([^"]*)" via propfind$/ + * + * @param string $user + * @param string $path + * @param string $spaceName + * + * @throws GuzzleException + */ + public function userRequestsTheChecksumViaPropfindInSpace( + string $user, + string $path, + string $spaceName + ): void { + $space = $this->getSpaceByName($user, $spaceName); + $fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($path, "/"); + $body = ' + + + + + '; + + $this->featureContext->setResponse( + $this->sendPropfindRequestToUrl( + $fullUrl, + $user, + $this->featureContext->getPasswordForUser($user), + $this->featureContext->getStepLineRef(), + [], + $body + ) + ); + } + + /** + * @When /^user "([^"]*)" uploads file with checksum "([^"]*)" and content "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $checksum + * @param string $content + * @param string $path + * @param string $spaceName + * + * @throws GuzzleException + */ + public function userUploadsFileWithChecksumWithContentInSpace( + string $user, + string $checksum, + string $content, + string $path, + string $spaceName + ): void { + $space = $this->getSpaceByName($user, $spaceName); + $fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($path, "/"); + + $this->featureContext->setResponse( + $this->sendPutRequestToUrl( + $fullUrl, + $user, + $this->featureContext->getPasswordForUser($user), + "", + ['OC-Checksum' => $checksum], + $content + ) + ); + } + /** * @When /^user "([^"]*)" downloads version of the file "([^"]*)" with the index "([^"]*)" of the space "([^"]*)" using the WebDAV API$/ * From 1cea0248898342c18b427d24dc7233f6b3e3e41d Mon Sep 17 00:00:00 2001 From: "sagargurung1001@gmail.com" Date: Wed, 10 Aug 2022 12:59:31 +0545 Subject: [PATCH 2/2] Addressed review for the implementation --- .../features/apiSpaces/checksum.feature | 18 +++++++----------- .../features/bootstrap/SpacesContext.php | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/acceptance/features/apiSpaces/checksum.feature b/tests/acceptance/features/apiSpaces/checksum.feature index a423b18bc8..08e68f0ab6 100644 --- a/tests/acceptance/features/apiSpaces/checksum.feature +++ b/tests/acceptance/features/apiSpaces/checksum.feature @@ -3,27 +3,23 @@ Feature: checksums Background: Given user "Alice" has been created with default attributes and without skeleton files - - @files_sharing-app-required @issue-ocis-reva-196 - Scenario: Sharing a file with checksum should return the checksum in the propfind using new DAV path - Given the administrator has set the default folder for received shares to "Shares" + And the administrator has set the default folder for received shares to "Shares" And auto-accept shares has been disabled And using spaces DAV path And user "Brian" has been created with default attributes and without skeleton files - And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" + + @files_sharing-app-required @issue-ocis-reva-196 + Scenario: Sharing a file with checksum should return the checksum in the propfind using new DAV path + Given user "Alice" has uploaded file "filesForUpload/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" And user "Alice" has shared file "/myChecksumFile.txt" with user "Brian" And user "Brian" has accepted share "/myChecksumFile.txt" offered by user "Alice" - When user "Brian" requests the checksum of "/myChecksumFile.txt" in space "Shares Jail" via propfind + When user "Brian" requests the checksum of file "/myChecksumFile.txt" in space "Shares Jail" via propfind using the WebDAV API Then the HTTP status code should be "207" And the webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960" @files_sharing-app-required @issue-ocis-reva-196 Scenario: Modifying a shared file should return correct checksum in the propfind using new DAV path - Given the administrator has set the default folder for received shares to "Shares" - And auto-accept shares has been disabled - And using spaces DAV path - And user "Brian" has been created with default attributes and without skeleton files - And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" + Given user "Alice" has uploaded file "filesForUpload/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" And user "Alice" has shared file "/myChecksumFile.txt" with user "Brian" And user "Brian" has accepted share "/myChecksumFile.txt" offered by user "Alice" When user "Brian" uploads file with checksum "SHA1:ce5582148c6f0c1282335b87df5ed4be4b781399" and content "Some Text" to "/myChecksumFile.txt" in space "Shares Jail" using the WebDAV API diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index ad823a2bcd..9548d0f637 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -2560,7 +2560,7 @@ class SpacesContext implements Context { } /** - * @When /^user "([^"]*)" requests the checksum of "([^"]*)" in space "([^"]*)" via propfind$/ + * @When /^user "([^"]*)" requests the checksum of (?:file|folder|entry) "([^"]*)" in space "([^"]*)" via propfind using the WebDAV API$/ * * @param string $user * @param string $path