Merge pull request #7280 from owncloud/backport-refactor-step-search-result-should-contain-only-these-files

[tests-only][full-ci] Backport refactor step search result should contain only these files
This commit is contained in:
Prarup Gurung
2023-09-21 11:43:57 +05:45
committed by GitHub
5 changed files with 98 additions and 42 deletions

View File

@@ -738,10 +738,10 @@ class WebDavHelper {
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 . '/';

View File

@@ -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 |

View File

@@ -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 |

View File

@@ -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:

View File

@@ -4875,22 +4875,33 @@ trait WebDav {
$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 @@ trait WebDav {
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.