Skip to content

Commit

Permalink
Merge pull request owncloud#7280 from owncloud/backport-refactor-step…
Browse files Browse the repository at this point in the history
…-search-result-should-contain-only-these-files

[tests-only][full-ci] Backport refactor step search result should contain only these files
  • Loading branch information
grgprarup authored Sep 21, 2023
2 parents fe8c0c7 + 2ca502e commit f7fde6e
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 42 deletions.
8 changes: 4 additions & 4 deletions tests/TestHelpers/WebDavHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '/';
Expand Down
18 changes: 9 additions & 9 deletions tests/acceptance/features/apiSearch/apiSpaceSearch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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 |

Expand All @@ -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 |
16 changes: 8 additions & 8 deletions tests/acceptance/features/apiSearch/contentSearch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down
24 changes: 12 additions & 12 deletions tests/acceptance/features/apiSearch/tagSearch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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:
Expand Down
74 changes: 65 additions & 9 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f7fde6e

Please sign in to comment.