From 613d41477be656330c0d00b56d61856984e46d8b Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Thu, 5 Jan 2023 14:39:18 +0545 Subject: [PATCH 1/2] add PROPFIND tests to public link share --- .../bootstrap/PublicWebDavContext.php | 51 +++++++++++++++++++ .../bootstrap/WebDavPropertiesContext.php | 10 +++- .../coreApiWebdavOperations/propfind.feature | 51 ++++++++++++++++++- 3 files changed, 110 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/features/bootstrap/PublicWebDavContext.php b/tests/acceptance/features/bootstrap/PublicWebDavContext.php index bdcb48f67..71e2d3ada 100644 --- a/tests/acceptance/features/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/features/bootstrap/PublicWebDavContext.php @@ -1658,4 +1658,55 @@ class PublicWebDavContext implements Context { $this->featureContext = $environment->getContext('FeatureContext'); $this->occContext = $environment->getContext('OccContext'); } + + /** + * @When /^the public sends "([^"]*)" request to the last public link share using the (old|new) public WebDAV API(?: with password "([^"]*)")?$/ + * + * @param string $method + * @param string $publicWebDAVAPIVersion + * @param string $password + * + * @return void + * @throws GuzzleException + */ + public function publicSendsRequestToLastPublicShare(string $method, string $publicWebDAVAPIVersion, ?string $password = ''):void { + if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") { + return; + } + if ($method === "PROPFIND") { + $body = ' + + + + + + + + + + '; + } + $token = $this->featureContext->getLastPublicShareToken(); + $davPath = WebDavHelper::getDavPath( + null, + null, + "public-files-$publicWebDAVAPIVersion" + ); + $username = $this->getUsernameForPublicWebdavApi( + $token, + $password, + $publicWebDAVAPIVersion + ); + $fullUrl = $this->featureContext->getBaseUrl() . "/$davPath$token"; + $response = HttpRequestHelper::sendRequest( + $fullUrl, + $this->featureContext->getStepLineRef(), + $method, + $username, + $password, + null, + $body + ); + $this->featureContext->setResponse($response); + } } diff --git a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php index 6aa673e1b..08cdec9a6 100644 --- a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php +++ b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php @@ -886,7 +886,15 @@ class WebDavPropertiesContext implements Context { $pattern = $this->featureContext->substituteInLineCodes( $pattern, $user, - ['preg_quote' => ['/']] + ['preg_quote' => ['/']], + [ + [ + "code" => "%public_token%", + "function" => + [$this->featureContext, "getLastPublicShareToken"], + "parameter" => [] + ], + ] ); Assert::assertMatchesRegularExpression( $pattern, diff --git a/tests/acceptance/features/coreApiWebdavOperations/propfind.feature b/tests/acceptance/features/coreApiWebdavOperations/propfind.feature index 7994cdcf5..ff3598b68 100644 --- a/tests/acceptance/features/coreApiWebdavOperations/propfind.feature +++ b/tests/acceptance/features/coreApiWebdavOperations/propfind.feature @@ -47,4 +47,53 @@ Feature: PROPFIND Examples: | dav_path | depth_infinity_allowed | depth | http_status | | /remote.php/dav/spaces/%spaceid% | 1 | 0 | 207 | - | /remote.php/dav/spaces/%spaceid% | 1 | infinity | 207 | \ No newline at end of file + | /remote.php/dav/spaces/%spaceid% | 1 | infinity | 207 | + + + Scenario: send PROPFIND request to a public link + Given user "Alice" has been created with default attributes and without skeleton files + And user "Alice" has created folder "/PARENT" + And user "Alice" has created a public link share with settings + | path | /PARENT | + | permissions | read | + When the public sends "PROPFIND" request to the last public link share using the new public WebDAV API + Then the HTTP status code should be "207" + And the value of the item "//d:href" in the response should match "/%base_path%\/remote.php\/dav\/public-files\/%public_token%\/$/" + And the value of the item "//oc:public-link-share-owner" in the response should be "Alice" + + + Scenario: send PROPFIND request to a public link shared with password + Given user "Alice" has been created with default attributes and without skeleton files + And user "Alice" has created folder "/PARENT" + And user "Alice" has created a public link share with settings + | path | /PARENT | + | permissions | read | + | password | 1111 | + When the public sends "PROPFIND" request to the last public link share using the new public WebDAV API with password "1111" + Then the HTTP status code should be "207" + And the value of the item "//d:href" in the response should match "/%base_path%\/remote.php\/dav\/public-files\/%public_token%\/$/" + And the value of the item "//oc:public-link-share-owner" in the response should be "Alice" + + + Scenario: send PROPFIND request to a public link shared with password (request without password) + Given user "Alice" has been created with default attributes and without skeleton files + And user "Alice" has created folder "/PARENT" + And user "Alice" has created a public link share with settings + | path | /PARENT | + | permissions | read | + | password | 1111 | + When the public sends "PROPFIND" request to the last public link share using the new public WebDAV API + Then the HTTP status code should be "401" + And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\NotAuthenticated" + + + Scenario: send PROPFIND request to a public link shared with password (request with incorrect password) + Given user "Alice" has been created with default attributes and without skeleton files + And user "Alice" has created folder "/PARENT" + And user "Alice" has created a public link share with settings + | path | /PARENT | + | permissions | read | + | password | 1111 | + When the public sends "PROPFIND" request to the last public link share using the new public WebDAV API with password "1234" + Then the HTTP status code should be "401" + And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\NotAuthenticated" \ No newline at end of file From 669f93b239cc7237a693663bf7277f7700d0e550 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Fri, 6 Jan 2023 15:21:22 +0545 Subject: [PATCH 2/2] debug requests before sending --- tests/TestHelpers/HttpRequestHelper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/TestHelpers/HttpRequestHelper.php b/tests/TestHelpers/HttpRequestHelper.php index 2348e7d6b..828314681 100644 --- a/tests/TestHelpers/HttpRequestHelper.php +++ b/tests/TestHelpers/HttpRequestHelper.php @@ -144,6 +144,10 @@ class HttpRequestHelper { $debugRequests = false; } + if ($debugRequests) { + self::debugRequest($request, $user, $password); + } + // The exceptions that might happen here include: // ConnectException - in that case there is no response. Don't catch the exception. // RequestException - if there is something in the response then pass it back. @@ -160,10 +164,6 @@ class HttpRequestHelper { } } - if ($debugRequests) { - self::debugRequest($request, $user, $password); - } - return $response; }