From 2ca502e32dfa94776317c2d787904004b57f25ea Mon Sep 17 00:00:00 2001 From: nabim777 Date: Tue, 12 Sep 2023 12:47:57 +0545 Subject: [PATCH] adding the path check --- tests/TestHelpers/WebDavHelper.php | 8 +- .../features/apiSearch/apiSpaceSearch.feature | 18 ++--- .../features/apiSearch/contentSearch.feature | 16 ++-- .../features/apiSearch/tagSearch.feature | 24 +++--- .../acceptance/features/bootstrap/WebDav.php | 74 ++++++++++++++++--- 5 files changed, 98 insertions(+), 42 deletions(-) diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index 13cfb816ca9..9fa5103a663 100644 --- a/tests/TestHelpers/WebDavHelper.php +++ b/tests/TestHelpers/WebDavHelper.php @@ -738,10 +738,10 @@ public static function getDavPath( return "remote.php/dav/"; } if ($davPathVersionToUse === self::DAV_VERSION_SPACES) { - if (($spaceId === null) || (\strlen($spaceId) === 0)) { - throw new InvalidArgumentException( - __METHOD__ . " A spaceId must be passed when using DAV path version 3 (spaces)" - ); + // return spaces root path if spaceid is null + // REPORT request uses spaces root path + if ($spaceId === null) { + return "/remote.php/dav/spaces/"; } if ($type === "trash-bin") { return "/remote.php/dav/spaces/trash-bin/" . $spaceId . '/'; diff --git a/tests/acceptance/features/apiSearch/apiSpaceSearch.feature b/tests/acceptance/features/apiSearch/apiSpaceSearch.feature index 800d6c6486c..acd495e3c81 100644 --- a/tests/acceptance/features/apiSearch/apiSpaceSearch.feature +++ b/tests/acceptance/features/apiSearch/apiSpaceSearch.feature @@ -52,9 +52,9 @@ Feature: Search Then the HTTP status code should be "207" And the search result should contain "4" entries And the search result of user "Brian" should contain these entries: - | /SubFolder1 | - | /SubFolder1/subFOLDER2 | - | /SubFolder1/subFOLDER2/insideTheFolder.txt | + | folderMain/SubFolder1 | + | folderMain/SubFolder1/subFOLDER2 | + | folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt | And for user "Brian" the search result should contain space "mountpoint/folderMain" @@ -115,9 +115,9 @@ Feature: Search Then the HTTP status code should be "207" And the search result should contain "3" entries And the search result of user "Alice" should contain only these entries: - | /SubFolder1 | - | /SubFolder1/subFOLDER2 | - | /SubFolder1/subFOLDER2/insideTheFolder.txt | + | folderMain/SubFolder1 | + | folderMain/SubFolder1/subFOLDER2 | + | folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt | But the search result of user "Alice" should not contain these entries: | /folderMain | @@ -131,8 +131,8 @@ Feature: Search When user "Brian" searches for "folder" inside folder "/folderMain" in space "Shares" using the WebDAV API Then the HTTP status code should be "207" And the search result of user "Brian" should contain only these entries: - | /SubFolder1 | - | /SubFolder1/subFOLDER2 | - | /SubFolder1/subFOLDER2/insideTheFolder.txt | + | folderMain/SubFolder1 | + | folderMain/SubFolder1/subFOLDER2 | + | folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt | But the search result of user "Brian" should not contain these entries: | /folderMain | diff --git a/tests/acceptance/features/apiSearch/contentSearch.feature b/tests/acceptance/features/apiSearch/contentSearch.feature index 7be1880d201..f7c28aed694 100644 --- a/tests/acceptance/features/apiSearch/contentSearch.feature +++ b/tests/acceptance/features/apiSearch/contentSearch.feature @@ -39,9 +39,9 @@ Feature: content search When user "Brian" searches for "Content:hello" using the WebDAV API Then the HTTP status code should be "207" And the search result of user "Brian" should contain only these files: - | keywordAtStart.txt | - | keywordAtMiddle.txt | - | keywordAtLast.txt | + | uploadFolder/keywordAtStart.txt | + | uploadFolder/keywordAtMiddle.txt | + | uploadFolder/keywordAtLast.txt | Examples: | dav-path-version | | old | @@ -63,8 +63,8 @@ Feature: content search When user "Alice" searches for "Content:hello" using the WebDAV API Then the HTTP status code should be "207" And the search result of user "Alice" should contain only these files: - | keywordAtStart.txt | - | keywordAtMiddle.txt | + | uploadFolder/keywordAtStart.txt | + | keywordAtMiddle.txt | Examples: | dav-path-version | | old | @@ -118,9 +118,9 @@ Feature: content search When user "Alice" searches for "Content:hello" using the WebDAV API Then the HTTP status code should be "207" And the search result of user "Alice" should contain only these files: - | keywordAtStart.txt | - | keywordAtMiddle.txt | - | keywordAtLast.txt | + | keywordAtStart.txt | + | spacesFolderWithFile/keywordAtMiddle.txt | + | spacesFolderWithFile/spacesSubFolder/keywordAtLast.txt | Examples: | dav-path-version | | old | diff --git a/tests/acceptance/features/apiSearch/tagSearch.feature b/tests/acceptance/features/apiSearch/tagSearch.feature index 140d9b26467..88c3141b4ec 100644 --- a/tests/acceptance/features/apiSearch/tagSearch.feature +++ b/tests/acceptance/features/apiSearch/tagSearch.feature @@ -26,9 +26,9 @@ Feature: tag search When user "Alice" searches for "Tags:tag1" using the WebDAV API Then the HTTP status code should be "207" And the search result of user "Alice" should contain only these files: - | fileInRootLevel.txt | - | fileInsideFolder.txt | - | fileInsideSubFolder.txt | + | fileInRootLevel.txt | + | folderWithFile/fileInsideFolder.txt | + | folderWithFile/subFolder/fileInsideSubFolder.txt | Examples: | dav-path-version | | old | @@ -54,9 +54,9 @@ Feature: tag search When user "Alice" searches for "Tags:tag1" using the WebDAV API Then the HTTP status code should be "207" And the search result of user "Alice" should contain only these files: - | spacesFile.txt | - | spacesFileInsideFolder.txt | - | spacesFileInsideSubFolder.txt | + | spacesFile.txt | + | spacesFolderWithFile/spacesFileInsideFolder.txt | + | spacesFolderWithFile/spacesSubFolder/spacesFileInsideSubFolder.txt | Examples: | dav-path-version | | old | @@ -103,8 +103,8 @@ Feature: tag search When user "Alice" searches for "Tags:tag1" using the WebDAV API Then the HTTP status code should be "207" And the search result of user "Alice" should contain only these files: - | spacesFolder | - | spacesSubFolder | + | spacesFolder | + | spacesFolder/spacesSubFolder | Examples: | dav-path-version | | old | @@ -132,8 +132,8 @@ Feature: tag search When user "Brian" searches for "Tags:tag1" using the WebDAV API Then the HTTP status code should be "207" And the search result of user "Brian" should contain only these files: - | file1.txt | - | file2.txt | + | uploadFolder/file1.txt | + | uploadFolder/file2.txt | Examples: | dav-path-version | | old | @@ -246,8 +246,8 @@ Feature: tag search When user "Alice" searches for "file" inside folder "/Folder" using the WebDAV API Then the HTTP status code should be "207" And the search result of user "Alice" should contain only these entries: - | file2.txt | - | file3.txt | + | /Folder/file2.txt | + | /Folder/SubFolder/file3.txt | But the search result of user "Alice" should not contain these entries: | file1.txt | Examples: diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 1c1e17ad2aa..d34d6d1ca98 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -4875,22 +4875,33 @@ public function propfindResultShouldContainEntries( $elementRows = $expectedFiles->getRows(); $should = ($shouldOrNot !== "not"); foreach ($elementRows as $expectedFile) { - $fileFound = $this->findEntryFromPropfindResponse( - $expectedFile[0], - $user, - $method, - "files", - $folderpath - ); + $resource = $expectedFile[0]; + if ($resource === '') { + continue; + } + if ($method === "REPORT") { + $fileFound = $this->findEntryFromSearchResponse( + $resource + ); + } else { + $fileFound = $this->findEntryFromPropfindResponse( + $resource, + $user, + $method, + "files", + $folderpath + ); + } + if ($should) { Assert::assertNotEmpty( $fileFound, - "response does not contain the entry '$expectedFile[0]'" + "response does not contain the entry '$resource'" ); } else { Assert::assertFalse( $fileFound, - "response does contain the entry '$expectedFile[0]' but should not" + "response does contain the entry '$resource' but should not" ); } } @@ -5338,6 +5349,51 @@ public function findEntryFromPropfindResponse( return false; } + /** + * parses a REPORT response from $this->response into xml + * and returns found search results if found else returns false + * + * @param string|null $entryNameToSearch + * + * @return string|array|boolean + * + * string if $entryNameToSearch is given and is found + * array if $entryNameToSearch is not given + * boolean false if $entryNameToSearch is given and is not found + * + * @throws GuzzleException + */ + public function findEntryFromSearchResponse( + ?string $entryNameToSearch = null + ) { + // trim any leading "/" passed by the caller, we can just match the "raw" name + if ($entryNameToSearch !== null) { + $entryNameToSearch = \trim($entryNameToSearch, "/"); + } + $spacesBaseUrl = webDavHelper::getDavPath(null, webDavHelper::DAV_VERSION_SPACES); + $searchResults = $this->getResponseXml()->xpath("//d:multistatus/d:response"); + $results = []; + foreach ($searchResults as $item) { + $href = (string)$item->xpath("d:href")[0]; + $shareRootXml = $item->xpath("d:propstat//oc:shareroot"); + $href = \str_replace($spacesBaseUrl, "", $href); + $resourcePath = \substr($href, \strpos($href, '/') + 1); + if (\count($shareRootXml)) { + $shareroot = \trim((string)$shareRootXml[0], "/"); + $resourcePath = $shareroot . "/" . $resourcePath; + } + $resourcePath = \rawurldecode($resourcePath); + if ($entryNameToSearch === $resourcePath) { + return $resourcePath; + } + $results[] = $resourcePath; + } + if ($entryNameToSearch === null) { + return $results; + } + return false; + } + /** * Prevent creating two uploads and/or deletes with the same "stime" * That is based on seconds in some implementations.