adding the path check (#7007)
This commit is contained in:
@@ -738,10 +738,10 @@ class WebDavHelper {
|
|||||||
return "remote.php/dav/";
|
return "remote.php/dav/";
|
||||||
}
|
}
|
||||||
if ($davPathVersionToUse === self::DAV_VERSION_SPACES) {
|
if ($davPathVersionToUse === self::DAV_VERSION_SPACES) {
|
||||||
if (($spaceId === null) || (\strlen($spaceId) === 0)) {
|
// return spaces root path if spaceid is null
|
||||||
throw new InvalidArgumentException(
|
// REPORT request uses spaces root path
|
||||||
__METHOD__ . " A spaceId must be passed when using DAV path version 3 (spaces)"
|
if ($spaceId === null) {
|
||||||
);
|
return "/remote.php/dav/spaces/";
|
||||||
}
|
}
|
||||||
if ($type === "trash-bin") {
|
if ($type === "trash-bin") {
|
||||||
return "/remote.php/dav/spaces/trash-bin/" . $spaceId . '/';
|
return "/remote.php/dav/spaces/trash-bin/" . $spaceId . '/';
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ Feature: Search
|
|||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result should contain "4" entries
|
And the search result should contain "4" entries
|
||||||
And the search result of user "Brian" should contain these entries:
|
And the search result of user "Brian" should contain these entries:
|
||||||
| /SubFolder1 |
|
| folderMain/SubFolder1 |
|
||||||
| /SubFolder1/subFOLDER2 |
|
| folderMain/SubFolder1/subFOLDER2 |
|
||||||
| /SubFolder1/subFOLDER2/insideTheFolder.txt |
|
| folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt |
|
||||||
And for user "Brian" the search result should contain space "mountpoint/folderMain"
|
And for user "Brian" the search result should contain space "mountpoint/folderMain"
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
@@ -163,9 +163,9 @@ Feature: Search
|
|||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result should contain "3" entries
|
And the search result should contain "3" entries
|
||||||
And the search result of user "Alice" should contain only these entries:
|
And the search result of user "Alice" should contain only these entries:
|
||||||
| /SubFolder1 |
|
| folderMain/SubFolder1 |
|
||||||
| /SubFolder1/subFOLDER2 |
|
| folderMain/SubFolder1/subFOLDER2 |
|
||||||
| /SubFolder1/subFOLDER2/insideTheFolder.txt |
|
| folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt |
|
||||||
But the search result of user "Alice" should not contain these entries:
|
But the search result of user "Alice" should not contain these entries:
|
||||||
| /folderMain |
|
| /folderMain |
|
||||||
Examples:
|
Examples:
|
||||||
@@ -185,9 +185,9 @@ Feature: Search
|
|||||||
When user "Brian" searches for "*folder*" inside folder "/folderMain" in space "Shares" using the WebDAV API
|
When user "Brian" searches for "*folder*" inside folder "/folderMain" in space "Shares" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Brian" should contain only these entries:
|
And the search result of user "Brian" should contain only these entries:
|
||||||
| /SubFolder1 |
|
| folderMain/SubFolder1 |
|
||||||
| /SubFolder1/subFOLDER2 |
|
| folderMain/SubFolder1/subFOLDER2 |
|
||||||
| /SubFolder1/subFOLDER2/insideTheFolder.txt |
|
| folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt |
|
||||||
But the search result of user "Brian" should not contain these entries:
|
But the search result of user "Brian" should not contain these entries:
|
||||||
| /folderMain |
|
| /folderMain |
|
||||||
Examples:
|
Examples:
|
||||||
@@ -208,8 +208,8 @@ Feature: Search
|
|||||||
When user "Alice" searches for "*file*" inside folder "/Folder" using the WebDAV API
|
When user "Alice" searches for "*file*" inside folder "/Folder" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Alice" should contain only these entries:
|
And the search result of user "Alice" should contain only these entries:
|
||||||
| file2.txt |
|
| /Folder/file2.txt |
|
||||||
| file3.txt |
|
| /Folder/SubFolder/file3.txt |
|
||||||
But the search result of user "Alice" should not contain these entries:
|
But the search result of user "Alice" should not contain these entries:
|
||||||
| file1.txt |
|
| file1.txt |
|
||||||
Examples:
|
Examples:
|
||||||
@@ -231,7 +231,7 @@ Feature: Search
|
|||||||
When user "Brian" searches for "shared*" using the WebDAV API
|
When user "Brian" searches for "shared*" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Brian" should contain these entries:
|
And the search result of user "Brian" should contain these entries:
|
||||||
| /sharedToBrian |
|
| foo/sharedToBrian |
|
||||||
But the search result of user "Brian" should not contain these entries:
|
But the search result of user "Brian" should not contain these entries:
|
||||||
| /sharedToCarol |
|
| /sharedToCarol |
|
||||||
Examples:
|
Examples:
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ Feature: content search
|
|||||||
When user "Brian" searches for "Content:hello" using the WebDAV API
|
When user "Brian" searches for "Content:hello" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Brian" should contain only these files:
|
And the search result of user "Brian" should contain only these files:
|
||||||
| keywordAtStart.txt |
|
| uploadFolder/keywordAtStart.txt |
|
||||||
| keywordAtMiddle.txt |
|
| uploadFolder/keywordAtMiddle.txt |
|
||||||
| keywordAtLast.txt |
|
| uploadFolder/keywordAtLast.txt |
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
| old |
|
| old |
|
||||||
@@ -59,8 +59,8 @@ Feature: content search
|
|||||||
When user "Alice" searches for "Content:hello" using the WebDAV API
|
When user "Alice" searches for "Content:hello" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Alice" should contain only these files:
|
And the search result of user "Alice" should contain only these files:
|
||||||
| keywordAtStart.txt |
|
| uploadFolder/keywordAtStart.txt |
|
||||||
| keywordAtMiddle.txt |
|
| keywordAtMiddle.txt |
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
| old |
|
| old |
|
||||||
@@ -114,9 +114,9 @@ Feature: content search
|
|||||||
When user "Alice" searches for "Content:hello" using the WebDAV API
|
When user "Alice" searches for "Content:hello" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Alice" should contain only these files:
|
And the search result of user "Alice" should contain only these files:
|
||||||
| keywordAtStart.txt |
|
| keywordAtStart.txt |
|
||||||
| keywordAtMiddle.txt |
|
| spacesFolderWithFile/keywordAtMiddle.txt |
|
||||||
| keywordAtLast.txt |
|
| spacesFolderWithFile/spacesSubFolder/keywordAtLast.txt |
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
| old |
|
| old |
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ Feature: tag search
|
|||||||
When user "Alice" searches for "Tags:tag1" using the WebDAV API
|
When user "Alice" searches for "Tags:tag1" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Alice" should contain only these files:
|
And the search result of user "Alice" should contain only these files:
|
||||||
| fileInRootLevel.txt |
|
| fileInRootLevel.txt |
|
||||||
| fileInsideFolder.txt |
|
| folderWithFile/fileInsideFolder.txt |
|
||||||
| fileInsideSubFolder.txt |
|
| folderWithFile/subFolder/fileInsideSubFolder.txt |
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
| old |
|
| old |
|
||||||
@@ -54,9 +54,9 @@ Feature: tag search
|
|||||||
When user "Alice" searches for "Tags:tag1" using the WebDAV API
|
When user "Alice" searches for "Tags:tag1" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Alice" should contain only these files:
|
And the search result of user "Alice" should contain only these files:
|
||||||
| spacesFile.txt |
|
| spacesFile.txt |
|
||||||
| spacesFileInsideFolder.txt |
|
| spacesFolderWithFile/spacesFileInsideFolder.txt |
|
||||||
| spacesFileInsideSubFolder.txt |
|
| spacesFolderWithFile/spacesSubFolder/spacesFileInsideSubFolder.txt |
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
| old |
|
| old |
|
||||||
@@ -103,8 +103,8 @@ Feature: tag search
|
|||||||
When user "Alice" searches for "Tags:tag1" using the WebDAV API
|
When user "Alice" searches for "Tags:tag1" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Alice" should contain only these files:
|
And the search result of user "Alice" should contain only these files:
|
||||||
| spacesFolder |
|
| spacesFolder |
|
||||||
| spacesSubFolder |
|
| spacesFolder/spacesSubFolder |
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
| old |
|
| old |
|
||||||
@@ -132,8 +132,8 @@ Feature: tag search
|
|||||||
When user "Brian" searches for "Tags:tag1" using the WebDAV API
|
When user "Brian" searches for "Tags:tag1" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result of user "Brian" should contain only these files:
|
And the search result of user "Brian" should contain only these files:
|
||||||
| file1.txt |
|
| uploadFolder/file1.txt |
|
||||||
| file2.txt |
|
| uploadFolder/file2.txt |
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
| old |
|
| old |
|
||||||
|
|||||||
@@ -4876,22 +4876,33 @@ trait WebDav {
|
|||||||
$elementRows = $expectedFiles->getRows();
|
$elementRows = $expectedFiles->getRows();
|
||||||
$should = ($shouldOrNot !== "not");
|
$should = ($shouldOrNot !== "not");
|
||||||
foreach ($elementRows as $expectedFile) {
|
foreach ($elementRows as $expectedFile) {
|
||||||
$fileFound = $this->findEntryFromPropfindResponse(
|
$resource = $expectedFile[0];
|
||||||
$expectedFile[0],
|
if ($resource === '') {
|
||||||
$user,
|
continue;
|
||||||
$method,
|
}
|
||||||
"files",
|
if ($method === "REPORT") {
|
||||||
$folderpath
|
$fileFound = $this->findEntryFromSearchResponse(
|
||||||
);
|
$resource
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$fileFound = $this->findEntryFromPropfindResponse(
|
||||||
|
$resource,
|
||||||
|
$user,
|
||||||
|
$method,
|
||||||
|
"files",
|
||||||
|
$folderpath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($should) {
|
if ($should) {
|
||||||
Assert::assertNotEmpty(
|
Assert::assertNotEmpty(
|
||||||
$fileFound,
|
$fileFound,
|
||||||
"response does not contain the entry '$expectedFile[0]'"
|
"response does not contain the entry '$resource'"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Assert::assertFalse(
|
Assert::assertFalse(
|
||||||
$fileFound,
|
$fileFound,
|
||||||
"response does contain the entry '$expectedFile[0]' but should not"
|
"response does contain the entry '$resource' but should not"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5339,6 +5350,51 @@ trait WebDav {
|
|||||||
return false;
|
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"
|
* Prevent creating two uploads and/or deletes with the same "stime"
|
||||||
* That is based on seconds in some implementations.
|
* That is based on seconds in some implementations.
|
||||||
|
|||||||
Reference in New Issue
Block a user