test: make remote.php configurable

test: build dav paths

test: fix paths

test: merge method args

test: add issue tags

test: add new expected failure file

test: merge expected-failure files before running tests
This commit is contained in:
Saw-jan
2024-10-21 16:57:58 +05:45
parent 273915506e
commit f86d137f87
100 changed files with 2484 additions and 2329 deletions
+110 -213
View File
@@ -37,9 +37,9 @@ use TestHelpers\GraphHelper;
* WebDav functions
*/
trait WebDav {
private string $davPath = "remote.php/webdav";
private bool $usingOldDavPath = true;
private bool $usingSpacesDavPath = false;
// defaults to the new DAV path
// maybe we want to make spaces the default in the future
private int $currentDAVPath = WebDavHelper::DAV_VERSION_NEW;
/**
* @var ResponseInterface[]
@@ -53,12 +53,6 @@ trait WebDav {
private ?int $lastUploadDeleteTime = null;
/**
* a variable that contains the DAV path without "remote.php/(web)dav"
* when setting $this->davPath directly by usingDavPath()
*/
private ?string $customDavPath = null;
/**
* response content parsed from XML to an array
*/
@@ -125,13 +119,6 @@ trait WebDav {
return $this->lastUploadDeleteTime;
}
/**
* @return SimpleXMLElement|null
*/
public function getResponseXmlObject():?SimpleXMLElement {
return $this->responseXmlObject;
}
/**
* @param SimpleXMLElement $responseXmlObject
*
@@ -203,83 +190,33 @@ trait WebDav {
}
/**
* @return string
*/
public function getOldDavPath():string {
return "remote.php/webdav";
}
/**
* @return string
*/
public function getNewDavPath():string {
return "remote.php/dav";
}
/**
* @return string
*/
public function getSpacesDavPath():string {
return "dav/spaces";
}
/**
* @Given /^using (old|new|spaces) (?:dav|DAV) path$/
* @Given /^using (old|new|spaces) DAV path$/
*
* @param string $davChoice
*
* @return void
*/
public function usingOldOrNewDavPath(string $davChoice):void {
if ($davChoice === 'old') {
$this->usingOldDavPath();
} elseif ($davChoice === 'new') {
$this->usingNewDavPath();
} else {
$this->usingSpacesDavPath();
public function usingOldOrNewOrSpacesDavPath(string $davChoice):void {
switch ($davChoice) {
case 'old':
$this->currentDAVPath = WebDavHelper::DAV_VERSION_OLD;
break;
case 'new':
$this->currentDAVPath = WebDavHelper::DAV_VERSION_NEW;
break;
case 'spaces':
$this->currentDAVPath = WebDavHelper::DAV_VERSION_SPACES;
break;
default:
throw new Exception("Invalid DAV path: $davChoice");
break;
}
}
/**
* Select the old DAV path as the default for later scenario steps
*
* @return void
*/
public function usingOldDavPath():void {
$this->davPath = $this->getOldDavPath();
$this->usingOldDavPath = true;
$this->customDavPath = null;
$this->usingSpacesDavPath = false;
}
/**
* Select the new DAV path as the default for later scenario steps
*
* @return void
*/
public function usingNewDavPath():void {
$this->davPath = $this->getNewDavPath();
$this->usingOldDavPath = false;
$this->customDavPath = null;
$this->usingSpacesDavPath = false;
}
/**
* Select the spaces dav path as the default for later scenario steps
*
* @return void
*/
public function usingSpacesDavPath():void {
$this->davPath = $this->getSpacesDavPath();
$this->usingOldDavPath = false;
$this->customDavPath = null;
$this->usingSpacesDavPath = true;
}
/**
* gives the DAV path of a file including the subfolder of the webserver
* e.g. when the server runs in `http://localhost/owncloud/`
* this function will return `owncloud/remote.php/webdav/prueba.txt`
* this function will return `owncloud/webdav/prueba.txt`
*
* @param string $user
* @param string $spaceId
@@ -296,21 +233,27 @@ trait WebDav {
$this->getStepLineRef()
);
}
$path = $this->getBasePath() . "/" .
WebDavHelper::getDavPath($user, $this->getDavPathVersion(), "files", $spaceId);
$davPathVersion = $this->getDavPathVersion();
$uniquePath = $user;
if ($davPathVersion === WebDavHelper::DAV_VERSION_SPACES) {
$uniquePath = $spaceId;
}
$davPath = WebDavHelper::getDavPath($davPathVersion, $uniquePath);
$path = "{$this->getBasePath()}/{$davPath}";
$path = WebDavHelper::sanitizeUrl($path);
return \ltrim($path, "/");
}
/**
* @param string $token
* @param string $type
*
* @return string
*/
public function getPublicLinkDavPath(string $token, string $type):string {
$path = $this->getBasePath() . "/" .
WebDavHelper::getDavPath($token, $this->getDavPathVersion(), $type);
public function getPublicLinkDavPath(string $token):string {
$davPath = WebDavHelper::getDavPath($this->getDavPathVersion(), $token, "public-files");
$path = "{$this->getBasePath()}/{$davPath}";
$path = WebDavHelper::sanitizeUrl($path);
return \ltrim($path, "/");
}
@@ -326,45 +269,12 @@ trait WebDav {
* @return int DAV path version (1, 2 or 3) selected, or appropriate for the endpoint
*/
public function getDavPathVersion(?string $for = null):?int {
if ($this->usingSpacesDavPath) {
return WebDavHelper::DAV_VERSION_SPACES;
}
if ($for === 'systemtags') {
// systemtags only exists since DAV v2
if (\in_array($for, ['systemtags', 'file_versions'])) {
// 'systemtags' only exists since new DAV
// 'file_versions' only exists since new DAV
return WebDavHelper::DAV_VERSION_NEW;
}
if ($for === 'file_versions') {
// file_versions only exists since DAV v2
return WebDavHelper::DAV_VERSION_NEW;
}
if ($this->usingOldDavPath === true) {
return WebDavHelper::DAV_VERSION_OLD;
} else {
return WebDavHelper::DAV_VERSION_NEW;
}
}
/**
* Select a suitable DAV path.
* Some endpoints have only existed since a certain point in time, so for
* those make sure to return a DAV path that works for that endpoint.
* Otherwise return the currently selected DAV path.
*
* @param string|null $for the category of endpoint that the DAV path will be used for
*
* @return string DAV path selected, or appropriate for the endpoint
*/
public function getDavPath(?string $for = null):string {
$davPathVersion = $this->getDavPathVersion($for);
if ($davPathVersion === WebDavHelper::DAV_VERSION_OLD) {
return $this->getOldDavPath();
}
if ($davPathVersion === WebDavHelper::DAV_VERSION_NEW) {
return $this->getNewDavPath();
}
return $this->getSpacesDavPath();
return $this->currentDAVPath;
}
/**
@@ -396,7 +306,7 @@ trait WebDav {
$body = null,
?string $spaceId = null,
?string $type = "files",
?string $davPathVersion = null,
?int $davPathVersion = null,
bool $stream = false,
?string $password = null,
?array $urlParameter = [],
@@ -404,9 +314,6 @@ trait WebDav {
?bool $isGivenStep = false
):ResponseInterface {
$user = $this->getActualUsername($user);
if ($this->customDavPath !== null) {
$path = $this->customDavPath . $path;
}
if ($davPathVersion === null) {
$davPathVersion = $this->getDavPathVersion();
@@ -454,7 +361,6 @@ trait WebDav {
* @throws GuzzleException | JsonException
*/
public function createFolder(string $user, string $folder, ?bool $isGivenStep = false, ?string $password = null, ?string $spaceId=null): ResponseInterface {
$folder = '/' . \ltrim($folder, '/');
return $this->makeDavRequest(
$user,
"MKCOL",
@@ -485,10 +391,11 @@ trait WebDav {
public function downloadPreviews(string $user, ?string $path, ?string $doDavRequestAsUser, ?string $width, ?string $height):ResponseInterface {
$user = $this->getActualUsername($user);
$doDavRequestAsUser = $this->getActualUsername($doDavRequestAsUser);
$doDavRequestAsUser = $doDavRequestAsUser ?? $user;
$password = $this->getPasswordForUser($doDavRequestAsUser);
$urlParameter = [
'x' => $width,
'y' => $height,
'forceIcon' => '0',
'preview' => '1'
];
return $this->makeDavRequest(
@@ -501,7 +408,7 @@ trait WebDav {
"files",
null,
false,
null,
$password,
$urlParameter,
$doDavRequestAsUser
);
@@ -516,7 +423,7 @@ trait WebDav {
* @throws Exception
*/
public function theNumberOfVersionsShouldBe(int $number):void {
$resXml = $this->getResponseXmlObject();
$resXml = $this->getResponseXml();
if ($resXml === null) {
$resXml = HttpRequestHelper::getResponseXml(
$this->getResponse(),
@@ -542,7 +449,7 @@ trait WebDav {
* @throws Exception
*/
public function theNumberOfEtagElementInTheResponseShouldBe(int $number):void {
$resXml = $this->getResponseXmlObject();
$resXml = $this->getResponseXml();
if ($resXml === null) {
$resXml = HttpRequestHelper::getResponseXml(
$this->getResponse(),
@@ -575,8 +482,15 @@ trait WebDav {
$fileDestination = \preg_replace("/^Shares\//", "", $fileDestination);
}
}
$fullUrl = $this->getBaseUrl() . '/' .
WebDavHelper::getDavPath($user, $this->getDavPathVersion(), "files", $spaceId);
$davPathVersion = $this->getDavPathVersion();
$uniquePath = $user;
if ($davPathVersion === WebDavHelper::DAV_VERSION_SPACES) {
$uniquePath = $spaceId;
}
$davPath = WebDavHelper::getDavPath($davPathVersion, $uniquePath);
$fullUrl = $this->getBaseUrl() . "/$davPath";
return \rtrim($fullUrl, '/') . '/' . $fileDestination;
}
@@ -1199,7 +1113,8 @@ trait WebDav {
*/
public function publicGetsSizeOfLastSharedPublicLinkUsingTheWebdavApi():void {
$token = ($this->isUsingSharingNG()) ? $this->shareNgGetLastCreatedLinkShareToken() : $this->getLastCreatedPublicShareToken();
$url = $this->getBaseUrl() . "/remote.php/dav/public-files/$token";
$davPath = WebDavHelper::getDavPath($this->getDavPathVersion(), $token, "public-files");
$url = "{$this->getBaseUrl()}/{$davPath}";
$this->response = HttpRequestHelper::sendRequest(
$url,
$this->getStepLineRef(),
@@ -1532,10 +1447,6 @@ trait WebDav {
?string $spaceId = null,
string $type = "files"
):ResponseInterface {
if ($this->customDavPath !== null) {
$path = $this->customDavPath . $path;
}
return WebDavHelper::listFolder(
$this->getBaseUrl(),
$this->getActualUsername($user),
@@ -1844,9 +1755,9 @@ trait WebDav {
$noOfChunks,
"What does it mean to have $noOfChunks chunks?"
);
//use the chunking version that works with the set DAV version
// use the chunking version that works with the set DAV version
if ($chunkingVersion === null) {
if ($this->usingOldDavPath || $this->usingSpacesDavPath) {
if (\in_array($this->currentDAVPath, [WebDavHelper::DAV_VERSION_OLD, WebDavHelper::DAV_VERSION_SPACES])) {
$chunkingVersion = "v1";
} else {
$chunkingVersion = "v2";
@@ -2297,6 +2208,11 @@ trait WebDav {
): ResponseInterface {
$user = $this->getActualUsername($user);
$this->pauseUploadDelete();
if (\str_starts_with($destination, "Shares/") && $this->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES) {
$spaceId = $this->spacesContext->getSpaceIdByName($user, "Shares");
$destination = \str_replace("Shares/", "", $destination);
}
$response = $this->makeDavRequest(
$user,
"PUT",
@@ -2731,21 +2647,23 @@ trait WebDav {
}
/**
* @When user :user deletes file :filename from space :space using file-id path :davPath
* @When user :user deletes file :filename from space :space using file-id :fileId
*
* @param string $user
* @param string $filename
* @param string $space
* @param string $davPath
* @param string $fileId
*
* @return void
*/
public function userDeletesFileFromSpaceUsingFileIdPath(string $user, string $filename, string $space, string $davPath):void {
$requestUrl = $this->getBaseUrl() . $davPath;
public function userDeletesFileFromSpaceUsingFileIdPath(string $user, string $filename, string $space, string $fileId):void {
$baseUrl = $this->getBaseUrl();
$davPath = WebDavHelper::getDavPath($this->getDavPathVersion());
$user = $this->getActualUsername($user);
$password = $this->getPasswordForUser($user);
$fullUrl = "$baseUrl/$davPath/$fileId";
$response = HttpRequestHelper::sendRequest(
$requestUrl,
$fullUrl,
null,
'DELETE',
$user,
@@ -3764,7 +3682,7 @@ trait WebDav {
* @return void
*/
public function userDownloadsThePreviewOfSharedResourceWithWidthAndHeightUsingTheWebdavApi(string $user, string $path, string $width, string $height): void {
if ($this->getDavPathVersion() === 3) {
if ($this->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES) {
$this->setResponse($this->downloadSharedFilePreview($user, $path, $width, $height));
} else {
$this->setResponse($this->downloadPreviews($user, $path, null, $width, $height));
@@ -3817,7 +3735,7 @@ trait WebDav {
* @return void
*/
public function userHasDownloadedThePreviewOfSharedResourceWithWidthAndHeight(string $user, string $path, string $width, string $height): void {
if ($this->getDavPathVersion() === 3) {
if ($this->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES) {
$response = $this->downloadSharedFilePreview($user, $path, $width, $height);
} else {
$response = $this->downloadPreviews($user, $path, null, $width, $height);
@@ -3841,7 +3759,7 @@ trait WebDav {
* @return void
*/
public function asUserThePreviewOfSharedResourceWithWidthAndHeightShouldHaveBeenChanged(string $user, string $path, string $width, string $height):void {
if ($this->getDavPathVersion() === 3) {
if ($this->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES) {
$response = $this->downloadSharedFilePreview($user, $path, $width, $height);
} else {
$response = $this->downloadPreviews($user, $path, null, $width, $height);
@@ -3870,11 +3788,7 @@ trait WebDav {
* @return void
*/
public function userUploadsFileWithContentSharedResourceToUsingTheWebdavApi(string $user, string $content, string $destination): void {
if ($this->getDavPathVersion() === 3) {
$this->setResponse($this->uploadToSharedFolder($user, $destination, $content));
} else {
$this->setResponse($this->uploadFileWithContent($user, $content, $destination, null));
}
$this->setResponse($this->uploadFileWithContent($user, $content, $destination));
}
/**
@@ -3933,10 +3847,17 @@ trait WebDav {
} else {
$urlParameter = null;
}
$sharesPath = $this->getSharesMountPath($user, $path) . '/?' . $urlParameter;
$davPath = WebDavHelper::getDavPath($user, $this->getDavPathVersion());
$fullUrl = $this->getBaseUrl() . "/$davPath" . $sharesPath;
$davPathVersion = $this->getDavPathVersion();
$uniquePath = $user;
if ($davPathVersion === WebDavHelper::DAV_VERSION_SPACES) {
$uniquePath = $this->getSharesMountPath($user, $path);
$path = "";
}
$path = \ltrim($path, "/");
$davPath = WebDavHelper::getDavPath($this->getDavPathVersion(), $uniquePath);
$davPath = \rtrim($davPath, "/");
$fullUrl = $this->getBaseUrl() . "/$davPath/$path?$urlParameter";
return HttpRequestHelper::sendRequest(
$fullUrl,
@@ -3948,50 +3869,21 @@ trait WebDav {
}
/**
* @When user :user downloads the preview of :path of :ofUser with width :width and height :height using the WebDAV API
*
* @param string $user
* @param string $destination
* @param string|null $content
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function uploadToSharedFolder(
string $user,
string $destination,
?string $content = null
): ResponseInterface {
$sharesPath = $this->getSharesMountPath($user, $destination);
$davPath = WebDavHelper::getDavPath($user, $this->getDavPathVersion());
$fullUrl = $this->getBaseUrl() . "/$davPath" . $sharesPath;
return HttpRequestHelper::sendRequest(
$fullUrl,
$this->getStepLineRef(),
'PUT',
$user,
$this->getPasswordForUser($user),
null,
$content
);
}
/**
* @When user :user1 downloads the preview of :path of :user2 with width :width and height :height using the WebDAV API
*
* @param string $user1
* @param string $path
* @param string $doDavRequestAsUser
* @param string $ofUser
* @param string $width
* @param string $height
*
* @return void
*/
public function downloadPreviewOfOtherUser(string $user1, string $path, string $doDavRequestAsUser, string $width, string $height):void {
public function downloadPreviewOfOtherUser(string $user, string $path, string $ofUser, string $width, string $height):void {
$response = $this->downloadPreviews(
$user1,
$ofUser,
$path,
$doDavRequestAsUser,
$user,
$width,
$height
);
@@ -4193,9 +4085,7 @@ trait WebDav {
?string $folderpath = '',
?string $spaceId = null
):void {
if ($folderpath === "/") {
$folderpath = "";
}
$folderpath = \trim($folderpath, "/");
$this->verifyTableNodeColumnsCount($expectedFiles, 1);
$elementRows = $expectedFiles->getRows();
$should = ($shouldOrNot !== "not");
@@ -4478,10 +4368,10 @@ trait WebDav {
public function theLastPublicDavResponseShouldContainTheseNodes(TableNode $table):void {
$token = ($this->isUsingSharingNG()) ? $this->shareNgGetLastCreatedLinkShareToken() : $this->getLastCreatedPublicShareToken();
$this->verifyTableNodeColumns($table, ["name"]);
$type = $this->usingOldDavPath ? "public-files" : "public-files-new";
foreach ($table->getHash() as $row) {
$path = $this->substituteInLineCodes($row['name']);
$res = $this->findEntryFromPropfindResponse($path, $token, $type);
$res = $this->findEntryFromPropfindResponse($path, $token, "public-files");
Assert::assertNotFalse($res, "expected $path to be in DAV response but was not found");
}
}
@@ -4497,10 +4387,10 @@ trait WebDav {
public function theLastPublicDavResponseShouldNotContainTheseNodes(TableNode $table):void {
$token = ($this->isUsingSharingNG()) ? $this->shareNgGetLastCreatedLinkShareToken() : $this->getLastCreatedPublicShareToken();
$this->verifyTableNodeColumns($table, ["name"]);
$type = $this->usingOldDavPath ? "public-files" : "public-files-new";
foreach ($table->getHash() as $row) {
$path = $this->substituteInLineCodes($row['name']);
$res = $this->findEntryFromPropfindResponse($path, $token, $type);
$res = $this->findEntryFromPropfindResponse($path, $token, "public-files");
Assert::assertFalse($res, "expected $path to not be in DAV response but was found");
}
}
@@ -4515,13 +4405,14 @@ trait WebDav {
*/
public function thePublicListsTheResourcesInTheLastCreatedPublicLinkWithDepthUsingTheWebdavApi(string $depth):void {
$token = ($this->isUsingSharingNG()) ? $this->shareNgGetLastCreatedLinkShareToken() : $this->getLastCreatedPublicShareToken();
// https://drone.owncloud.com/owncloud/ocis/39693/29/6
$response = $this->listFolder(
$token,
'/',
$depth,
null,
null,
$this->usingOldDavPath ? "public-files" : "public-files-new"
"public-files"
);
$this->setResponse($response);
$this->setResponseXml(HttpRequestHelper::parseResponseAsXml($this->response));
@@ -4533,7 +4424,7 @@ trait WebDav {
* @return array
*/
public function findEntryFromReportResponse(?string $user):array {
$responseXmlObj = $this->getResponseXmlObject();
$responseXmlObj = $this->getResponseXml();
$responseResources = [];
$hrefs = $responseXmlObj->xpath('//d:href');
foreach ($hrefs as $href) {
@@ -4648,16 +4539,13 @@ trait WebDav {
}
// url encode for spaces and brackets that may appear in the filePath
$folderPath = $this->escapePath($folderPath);
// topWebDavPath should be something like /remote.php/webdav/ or
// /remote.php/dav/files/alice/
// topWebDavPath should be something like '/webdav/' or '/dav/files/{user}/'
$topWebDavPath = "/" . $this->getFullDavFilesPath($user, $spaceId) . "/" . $folderPath;
switch ($type) {
case "files":
break;
case "public-files":
case "public-files-old":
case "public-files-new":
$topWebDavPath = "/" . $this->getPublicLinkDavPath($user, $type) . "/";
$topWebDavPath = "/" . $this->getPublicLinkDavPath($user) . "/";
break;
default:
throw new Exception("error");
@@ -4705,18 +4593,27 @@ trait WebDav {
if ($entryNameToSearch !== null) {
$entryNameToSearch = \trim($entryNameToSearch, "/");
}
$spacesBaseUrl = "/" . webDavHelper::getDavPath(null, webDavHelper::DAV_VERSION_SPACES, 'files', $spaceId);
$spacesBaseUrl = "/" . WebDavHelper::getDavPath($this->getDavPathVersion(), $spaceId);
$spacesBaseUrl = \rtrim($spacesBaseUrl, "/") . "/";
$hrefRegex = \preg_quote($spacesBaseUrl, "/");
if (\in_array($this->getDavPathVersion(), [WebDavHelper::DAV_VERSION_SPACES, WebDavHelper::DAV_VERSION_NEW])
&& !GraphHelper::isSpaceId($entryNameToSearch ?? '')
) {
$hrefRegex .= "[a-zA-Z0-9-_$!:%]+";
}
$hrefRegex = "/^" . $hrefRegex . "/";
$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 = $href;
$resourcePath = \preg_replace($hrefRegex, "", $href);
// do not try to parse the resource path
// if the item to search is space itself
if (!GraphHelper::isSpaceId($entryNameToSearch ?? '')) {
$resourcePath = \substr($href, \strpos($href, '/') + 1);
$resourcePath = \substr($resourcePath, \strpos($resourcePath, '/') + 1);
}
if (\count($shareRootXml)) {
$shareroot = \trim((string)$shareRootXml[0], "/");
@@ -4787,7 +4684,7 @@ trait WebDav {
*/
public function checkAuthorOfAVersionOfFile(string $index, string $expectedUsername):void {
$expectedUserDisplayName = $this->getUserDisplayName($expectedUsername);
$resXml = $this->getResponseXmlObject();
$resXml = $this->getResponseXml();
if ($resXml === null) {
$resXml = HttpRequestHelper::getResponseXml(
$this->getResponse(),