adding the path check

This commit is contained in:
nabim777
2023-09-21 09:38:58 +05:45
committed by nabim777
parent 48dc83f4cb
commit 2ca502e32d
5 changed files with 98 additions and 42 deletions
+65 -9
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.