From b1b66fda714a231982a8e84451217ac6e1868510 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Mon, 7 Oct 2024 18:18:12 +0545 Subject: [PATCH] test: fix paths --- tests/acceptance/TestHelpers/WebDavHelper.php | 3 +- .../bootstrap/FilesVersionsContext.php | 8 +-- tests/acceptance/bootstrap/OcmContext.php | 1 - .../bootstrap/PublicWebDavContext.php | 64 +++---------------- tests/acceptance/bootstrap/SearchContext.php | 1 + tests/acceptance/bootstrap/SpacesContext.php | 49 +++++++++++--- tests/acceptance/bootstrap/WebDav.php | 6 +- .../enforcePasswordPublicLink.feature | 24 +++---- 8 files changed, 70 insertions(+), 86 deletions(-) diff --git a/tests/acceptance/TestHelpers/WebDavHelper.php b/tests/acceptance/TestHelpers/WebDavHelper.php index 04a096921d9..3a7e7b7c291 100644 --- a/tests/acceptance/TestHelpers/WebDavHelper.php +++ b/tests/acceptance/TestHelpers/WebDavHelper.php @@ -716,7 +716,7 @@ public static function makeDavRequest( } // get space id if testing with spaces dav - if ($spaceId === null && $davPathVersionToUse === self::DAV_VERSION_SPACES) { + if ($spaceId === null && $davPathVersionToUse === self::DAV_VERSION_SPACES && $type !== "public-files") { $path = \ltrim($path, "/"); if (\str_starts_with($path, "Shares/")) { $spaceId = self::getSharesSpaceIdForUser( @@ -779,6 +779,7 @@ public static function makeDavRequest( } } + // if ($method==="PROPFIND") var_dump($fullUrl); return HttpRequestHelper::sendRequest( $fullUrl, $xRequestId, diff --git a/tests/acceptance/bootstrap/FilesVersionsContext.php b/tests/acceptance/bootstrap/FilesVersionsContext.php index c9c7a6afb66..116d73c86d8 100644 --- a/tests/acceptance/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/bootstrap/FilesVersionsContext.php @@ -42,7 +42,7 @@ class FilesVersionsContext implements Context { * @return string */ private function getVersionsPathForFileId(string $fileId):string { - return "/meta/$fileId/v"; + return "$fileId/v"; } /** @@ -126,8 +126,7 @@ public function getFileVersions( null, null, $spaceId, - null, - '2' + "versions" ); } @@ -192,9 +191,8 @@ public function getFileVersionMetadata(string $user, string $file) : ResponseInt $this->getVersionsPathForFileId($fileId), null, $body, - '', null, - '2' + "versions", ); } diff --git a/tests/acceptance/bootstrap/OcmContext.php b/tests/acceptance/bootstrap/OcmContext.php index 102ea6aef06..b87e5cb73f1 100644 --- a/tests/acceptance/bootstrap/OcmContext.php +++ b/tests/acceptance/bootstrap/OcmContext.php @@ -332,5 +332,4 @@ public function deleteConnection(string $user, string $ocmUser): ResponseInterfa $ocmUser['idp'] ); } - } diff --git a/tests/acceptance/bootstrap/PublicWebDavContext.php b/tests/acceptance/bootstrap/PublicWebDavContext.php index 1d7a8676e19..ef9c945b680 100644 --- a/tests/acceptance/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/bootstrap/PublicWebDavContext.php @@ -36,6 +36,7 @@ class PublicWebDavContext implements Context { private FeatureContext $featureContext; + // TODO: mayeb this will not be required anymore /** * @param string $versionString (old|new) * @@ -383,7 +384,7 @@ public function downloadFileFromPublicFolder( $this->getPublicDavVersion($publicWebDAVAPIVersion), "public-files" ); - $fullUrl = $this->featureContext->getBaseUrl() . "/$davPath$path"; + $fullUrl = $this->featureContext->getBaseUrl() . "/$davPath/$path"; $userName = $this->getUsernameForPublicWebdavApi( $token, $password, @@ -687,46 +688,18 @@ public function thePublicHasOverwrittenFileWithContentUsingOldWebDavApi(string $ } /** - * @param string $filename target file name - * @param string $body content to upload - * @param string $publicWebDAVAPIVersion - * - * @return ResponseInterface - */ - public function publiclyUploadingContent( - string $filename, - string $body = 'test', - string $publicWebDAVAPIVersion = "old" - ):ResponseInterface { - return $this->publicUploadContent( - $filename, - '', - $body, - false, - [], - $publicWebDAVAPIVersion - ); - } - - /** - * @When /^the public uploads file "([^"]*)" with content "([^"]*)" using the (old|new) public WebDAV API$/ + * @When /^the public uploads file "([^"]*)" with content "([^"]*)" using the (?:old|new) public WebDAV API$/ * * @param string $filename target file name * @param string $body content to upload - * @param string $publicWebDAVAPIVersion * * @return void */ public function thePublicUploadsFileWithContentUsingThePublicWebDavApi( string $filename, - string $body = 'test', - string $publicWebDAVAPIVersion = "old" + string $body = 'test' ):void { - $response = $this->publiclyUploadingContent( - $filename, - $body, - $publicWebDAVAPIVersion - ); + $response = $this->publicUploadContent($filename, '', $body); $this->featureContext->setResponse($response); $this->featureContext->pushToLastStatusCodesArrays(); } @@ -736,20 +709,11 @@ public function thePublicUploadsFileWithContentUsingThePublicWebDavApi( * * @param string $filename target file name * @param string $body content to upload - * @param string $publicWebDAVAPIVersion * * @return void */ - public function thePublicHasUploadedFileWithContentUsingThePublicWebDavApi( - string $filename, - string $body = 'test', - string $publicWebDAVAPIVersion = "old" - ):void { - $response = $this->publiclyUploadingContent( - $filename, - $body, - $publicWebDAVAPIVersion - ); + public function thePublicHasUploadedFileWithContent(string $filename, string $body): void { + $response = $this->publicUploadContent($filename, '', $body); $this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response); } @@ -1218,14 +1182,6 @@ public function tryingToDownloadUsingWebDAVAPI( $publicWebDAVAPIVersion, $shareNg ); - - $responseContent = $response->getBody()->getContents(); - \libxml_use_internal_errors(true); - Assert::assertNotFalse( - \simplexml_load_string($responseContent), - "response body is not valid XML, maybe download did work\n" . - "response body: \n$responseContent\n" - ); $this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode, "", $response); } @@ -1745,10 +1701,9 @@ public function publicUploadContent( } $davPath = WebDavHelper::getDavPath( $token, - $this->getPublicDavVersion($publicWebDAVAPIVersion), + $this->getPublicDavVersion("new"), "public-files" ); - $url = $this->featureContext->getBaseUrl() . "/$davPath"; $userName = $this->getUsernameForPublicWebdavApi( $token, $password, @@ -1759,7 +1714,8 @@ public function publicUploadContent( '/', \array_map('rawurlencode', \explode('/', $filename)) ); - $url .= \ltrim($filename, '/'); + $encodedFilePath = \ltrim($filename, '/'); + $url = $this->featureContext->getBaseUrl() . "/$davPath/$encodedFilePath"; // Trim any "/" from the end. For example, if we are putting content to a // single file that has been shared with a link, then the URL should end // with the link token and no "/" at the end. diff --git a/tests/acceptance/bootstrap/SearchContext.php b/tests/acceptance/bootstrap/SearchContext.php index a2de1fa4f82..6e1fe604998 100644 --- a/tests/acceptance/bootstrap/SearchContext.php +++ b/tests/acceptance/bootstrap/SearchContext.php @@ -104,6 +104,7 @@ public function userSearchesUsingWebDavAPI( } $body .= " "; $davPathVersionToUse = $this->featureContext->getDavPathVersion(); + // TODO: need to fix for spaces $davPath = WebDavHelper::getDavPath($doDavRequestAsUser ?? $user, $davPathVersionToUse, 'files', null); if ($davPathVersionToUse == WebDavHelper::DAV_VERSION_NEW) { diff --git a/tests/acceptance/bootstrap/SpacesContext.php b/tests/acceptance/bootstrap/SpacesContext.php index 3dfc744eb9c..0b612cb8049 100644 --- a/tests/acceptance/bootstrap/SpacesContext.php +++ b/tests/acceptance/bootstrap/SpacesContext.php @@ -47,6 +47,7 @@ class SpacesContext implements Context { private FavoritesContext $favoritesContext; private ChecksumContext $checksumContext; private FilesVersionsContext $filesVersionsContext; + private ArchiverContext $archiverContext; /** * key is space name and value is the username that created the space @@ -402,11 +403,13 @@ public function setUpScenario(BeforeScenarioScope $scope): void { $this->favoritesContext = new FavoritesContext(); $this->checksumContext = new ChecksumContext(); $this->filesVersionsContext = new FilesVersionsContext(); + $this->archiverContext = new ArchiverContext(); $environment->registerContext($this->trashbinContext); $environment->registerContext($this->webDavPropertiesContext); $environment->registerContext($this->favoritesContext); $environment->registerContext($this->checksumContext); $environment->registerContext($this->filesVersionsContext); + $environment->registerContext($this->archiverContext); // Get all the contexts you need in this context $this->featureContext = $environment->getContext('FeatureContext'); $this->ocsContext = $environment->getContext('OCSContext'); @@ -1699,7 +1702,11 @@ public function userCopiesFileWithinSpaceUsingTheWebDAVAPI( $spaceName ); - $fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileSource, "/"); + $encodedName = \rawurlencode(ltrim($fileSource, "/")); + $baseUrl = $this->featureContext->getBaseUrl(); + $davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]); + $fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}"; + $this->featureContext->setResponse($this->copyFilesAndFoldersRequest($user, $fullUrl, $headers)); } @@ -1726,8 +1733,11 @@ public function moveFileWithinSpace( ); $headers['Overwrite'] = 'F'; - $fileSource = $this->escapePath(\trim($fileSource, "/")); - $fullUrl = $space["root"]["webDavUrl"] . '/' . $fileSource; + $encodedName = \rawurlencode(ltrim($fileSource, "/")); + $baseUrl = $this->featureContext->getBaseUrl(); + $davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]); + $fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}"; + return $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); } @@ -1840,7 +1850,11 @@ public function userCopiesFileFromAndToSpaceBetweenSpaces( } } - $fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileSource, "/"); + $encodedName = \rawurlencode(ltrim($fileSource, "/")); + $baseUrl = $this->featureContext->getBaseUrl(); + $davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]); + $fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}"; + $this->featureContext->setResponse($this->copyFilesAndFoldersRequest($user, $fullUrl, $headers)); } @@ -1868,7 +1882,12 @@ public function userOverwritesFileFromAndToSpaceBetweenSpaces( $space = $this->getSpaceByName($user, $fromSpaceName); $headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName); $headers['Overwrite'] = 'T'; - $fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileSource, "/"); + + $encodedName = \rawurlencode(ltrim($fileSource, "/")); + $baseUrl = $this->featureContext->getBaseUrl(); + $davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]); + $fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}"; + if ($action === 'copying') { $response = $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers); } else { @@ -1931,7 +1950,12 @@ public function userMovesFileFromAndToSpaceBetweenSpaces( ):void { $space = $this->getSpaceByName($user, $fromSpaceName); $headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName); - $fullUrl = $space["root"]["webDavUrl"] . '/' . \ltrim($fileSource, "/"); + + $encodedName = \rawurlencode(ltrim($fileSource, "/")); + $baseUrl = $this->featureContext->getBaseUrl(); + $davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]); + $fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}"; + $this->featureContext->setResponse($this->moveFilesAndFoldersRequest($user, $fullUrl, $headers)); $this->featureContext->pushToLastHttpStatusCodesArray(); } @@ -2526,9 +2550,14 @@ public function removeObjectFromSpace( string $spaceName ): ResponseInterface { $space = $this->getSpaceByName($user, $spaceName); - $spaceWebDavUrl = $space["root"]["webDavUrl"] . '/' . ltrim($object, "/"); + + $encodedName = \rawurlencode(ltrim($object, "/")); + $baseUrl = $this->featureContext->getBaseUrl(); + $davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]); + $fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}"; + return HttpRequestHelper::delete( - $spaceWebDavUrl, + $fullUrl, $this->featureContext->getStepLineRef(), $user, $this->featureContext->getPasswordForUser($user) @@ -3959,7 +3988,7 @@ public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $res $queryString = 'public-token=' . $token . '&id=' . $resourceId[0][0]; $this->featureContext->setResponse( HttpRequestHelper::get( - $this->featureContext->getBaseUrl() . '/archiver?' . $queryString, + $this->archiverContext->getArchiverUrl($queryString), $this->featureContext->getStepLineRef(), '', '', @@ -4048,7 +4077,7 @@ public function theUserShouldHaveSpaceWithRecipient( */ public function userDownloadsTheSpaceUsingTheWebdavApi(string $user, string $spaceName, string $owner = ''):void { $space = $this->getSpaceByName($owner ?: $user, $spaceName); - $url = $this->featureContext->getBaseUrl() . '/archiver?id=' . $space['id']; + $url = $this->archiverContext->getArchiverUrl('id=' . $space['id']); $this->featureContext->setResponse( HttpRequestHelper::get( $url, diff --git a/tests/acceptance/bootstrap/WebDav.php b/tests/acceptance/bootstrap/WebDav.php index 65fc10a175d..5b55a704873 100644 --- a/tests/acceptance/bootstrap/WebDav.php +++ b/tests/acceptance/bootstrap/WebDav.php @@ -394,7 +394,6 @@ public function downloadPreviews(string $user, ?string $path, ?string $doDavRequ $urlParameter = [ 'x' => $width, 'y' => $height, - 'forceIcon' => '0', 'preview' => '1' ]; return $this->makeDavRequest( @@ -3667,7 +3666,7 @@ public function userDownloadsThePreviewOfWithPreviewZero(string $user, string $p * @return void */ public function userDownloadsThePreviewOfSharedResourceWithWidthAndHeightUsingTheWebdavApi(string $user, string $path, string $width, string $height): void { - if ($this->getDavPathVersion() === 3) { + if ($this->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES) { $this->setResponse($this->downloadSharedFilePreview($user, $path, $width, $height)); } else { $this->setResponse($this->downloadPreviews($user, $path, null, $width, $height)); @@ -3839,7 +3838,7 @@ public function downloadSharedFilePreview( $sharesPath = $this->getSharesMountPath($user, $path) . '/?' . $urlParameter; $davPath = WebDavHelper::getDavPath($user, $this->getDavPathVersion()); - $fullUrl = $this->getBaseUrl() . "/$davPath" . $sharesPath; + $fullUrl = $this->getBaseUrl() . "/$davPath/$sharesPath"; return HttpRequestHelper::sendRequest( $fullUrl, @@ -4418,6 +4417,7 @@ public function theLastPublicDavResponseShouldNotContainTheseNodes(TableNode $ta */ public function thePublicListsTheResourcesInTheLastCreatedPublicLinkWithDepthUsingTheWebdavApi(string $depth):void { $token = ($this->isUsingSharingNG()) ? $this->shareNgGetLastCreatedLinkShareToken() : $this->getLastCreatedPublicShareToken(); + // https://drone.owncloud.com/owncloud/ocis/39693/29/6 $response = $this->listFolder( $token, '/', diff --git a/tests/acceptance/features/apiGraph/enforcePasswordPublicLink.feature b/tests/acceptance/features/apiGraph/enforcePasswordPublicLink.feature index 49d26aea514..a132d11a854 100644 --- a/tests/acceptance/features/apiGraph/enforcePasswordPublicLink.feature +++ b/tests/acceptance/features/apiGraph/enforcePasswordPublicLink.feature @@ -71,9 +71,9 @@ Feature: enforce password on public link Then the HTTP status code should be "200" And the OCS status code should be "" And the OCS status message should be "OK" - And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password - And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" - But the public should be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "%public%" + And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password + And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" + But the public should be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "%public%" Examples: | ocs-api-version | ocs-status-code | | 1 | 100 | @@ -99,9 +99,9 @@ Feature: enforce password on public link Then the HTTP status code should be "200" And the OCS status code should be "" And the OCS status message should be "OK" - And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password - And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" - But the public should be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "3s:5WW9uE5h=A" + And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password + And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" + But the public should be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "3s:5WW9uE5h=A" Examples: | ocs-api-version | ocs-status-code | | 1 | 100 | @@ -163,9 +163,9 @@ Feature: enforce password on public link Then the HTTP status code should be "200" And the OCS status code should be "" And the OCS status message should be "OK" - And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password - And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" - But the public should be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "6a0Q;A3 +i^m[" + And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password + And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" + But the public should be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "6a0Q;A3 +i^m[" Examples: | ocs-api-version | ocs-status-code | | 1 | 100 | @@ -221,9 +221,9 @@ Feature: enforce password on public link Then the HTTP status code should be "200" And the OCS status code should be "200" And the OCS status message should be "OK" - And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password - And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" - But the public should be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "" + And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password + And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" + But the public should be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "" Examples: | config | config-value | password | | OCIS_PASSWORD_POLICY_MIN_CHARACTERS | 4 | Ps-1 |