Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC][tests-only] configurable for remote.php path #10078

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ def localApiTests(suite, storage, extra_environment = {}):
"EXPECTED_FAILURES_FILE": "%s/tests/acceptance/expected-failures-localAPI-on-%s-storage.md" % (dirs["base"], storage.upper()),
"UPLOAD_DELETE_WAIT_TIME": "1" if storage == "owncloud" else 0,
"OCIS_WRAPPER_URL": "http://ocis-server:5200",
"WITH_REMOTE_PHP": True,
}

for item in extra_environment:
Expand Down Expand Up @@ -1136,6 +1137,7 @@ def coreApiTests(ctx, part_number = 1, number_of_parts = 1, storage = "ocis", ac
"EXPECTED_FAILURES_FILE": expectedFailuresFile,
"UPLOAD_DELETE_WAIT_TIME": "1" if storage == "owncloud" else 0,
"OCIS_WRAPPER_URL": "http://ocis-server:5200",
"WITH_REMOTE_PHP": True,
},
"commands": [
"make -C %s test-acceptance-api" % (dirs["base"]),
Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/TestHelpers/CollaborationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* A helper class for managing wopi requests
*/
class CollaborationHelper {

/**
* @param string $fileId
* @param string $app
Expand Down
33 changes: 33 additions & 0 deletions tests/acceptance/TestHelpers/HttpRequestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ public static function numRetriesOnHttpTooEarly():int {
return 10;
}

/**
* @param string $url
*
* @return bool
*/
public static function isDAVRequest(string $url): bool {
if (\str_contains($url, '/dav') || \str_contains($url, '/webdav')) {
return true;
}
return false;
}

/**
*
* @param string|null $url
Expand Down Expand Up @@ -104,6 +116,27 @@ public static function sendRequestOnce(
$timeout
);
}

if (self::isDAVRequest($url)) {
$withRemotePhp = \getenv("WITH_REMOTE_PHP") === "true";
$urlHasRemotePhp = \str_contains($url, 'remote.php');
if (!$withRemotePhp && $urlHasRemotePhp) {
throw new Exception("remote.php is disabled but found in the URL: $url");
}
if ($withRemotePhp && !$urlHasRemotePhp) {
throw new Exception("remote.php is enabled but not found in the URL: $url");
}

if ($headers && \array_key_exists("Destination", $headers)) {
if (!$withRemotePhp && $urlHasRemotePhp) {
throw new Exception("remote.php is disabled but found in the URL: $url");
}
if ($withRemotePhp && !$urlHasRemotePhp) {
throw new Exception("remote.php is enabled but not found in the URL: $url");
}
}
}

$request = self::createRequest(
$url,
$xRequestId,
Expand Down
84 changes: 49 additions & 35 deletions tests/acceptance/TestHelpers/WebDavHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ class WebDavHelper {
*/
public static array $spacesIdRef = [];

/**
* clear space id reference for user
*
* @param string $urlPath
*
* @return string
*/
public static function withRemotePhp(string $urlPath): string {
if (\getenv("WITH_REMOTE_PHP") === "true") {
return "remote.php/$urlPath";
}
return $urlPath;
}

/**
* clear space id reference for user
*
Expand Down Expand Up @@ -522,7 +536,7 @@ public static function getPersonalSpaceIdForUser(string $baseUrl, string $user,
if ($json === null) {
// the graph endpoint did not give a useful answer
// try getting the information from the webdav endpoint
$fullUrl = $trimmedBaseUrl . '/remote.php/webdav';
$fullUrl = $trimmedBaseUrl . self::getDavPath($user, self::DAV_VERSION_OLD);
$response = HttpRequestHelper::sendRequest(
$fullUrl,
$xRequestId,
Expand Down Expand Up @@ -720,14 +734,14 @@ public static function makeDavRequest(
$urlParameter = \http_build_query($urlParameter, '', '&');
$path .= '?' . $urlParameter;
}
$fullUrl = self::sanitizeUrl($baseUrl . "/$davPath" . $path);
$fullUrl = self::sanitizeUrl("{$baseUrl}/{$davPath}/{$path}");

if ($authType === 'bearer') {
$headers['Authorization'] = 'Bearer ' . $password;
$user = null;
$password = null;
}
if ($type === "public-files-new") {
if ($type === "public-files") {
if ($password === null || $password === "") {
$user = null;
} else {
Expand Down Expand Up @@ -775,67 +789,66 @@ public static function makeDavRequest(
/**
* get the dav path
*
* @param string|null $user
* @param int|null $davPathVersionToUse (1|2)
* @param string|null $userOrToken
* @param int|null $davPathVersionToUse (1|2|3)
* @param string|null $type
* @param string|null $spaceId
*
* @return string
*/
public static function getDavPath(
?string $user,
?string $userOrToken, // TODO: merge to userOrTokenOrSpaceId
?int $davPathVersionToUse = null,
?string $type = "files",
?string $spaceId = null
):string {
$newTrashbinDavPath = "remote.php/dav/trash-bin/$user/";

switch ($type) {
case 'public-files':
case 'public-files-old':
return "public.php/webdav/";
case 'public-files-new':
return "remote.php/dav/public-files/$user/";
case 'archive':
return "remote.php/dav/archive/$user/files";
return self::withRemotePhp("dav/archive/$userOrToken/files");
case 'versions':
case 'customgroups':
return "remote.php/dav/";
return self::withRemotePhp("dav/meta");
case 'comments':
return self::withRemotePhp("dav/comments/files");
default:
break;
}

if ($davPathVersionToUse === self::DAV_VERSION_SPACES) {
if ($type === "trash-bin") {
if ($spaceId === null) {
throw new InvalidArgumentException("Space ID is required for trash-bin endpoint");
}
return self::withRemotePhp("dav/spaces/trash-bin/$spaceId");
} elseif ($type === "public-files") {
// spaces DAV path doesn't have own public-files endpoint
return self::withRemotePhp("dav/public-files/$userOrToken");
}
// return spaces root path if spaceid is null
// REPORT request uses spaces root path
if ($spaceId === null) {
return "remote.php/dav/spaces/";
return self::withRemotePhp("dav/spaces");
}
return self::withRemotePhp("dav/spaces/$spaceId");
} else {
if ($type === "trash-bin") {
return "remote.php/dav/spaces/trash-bin/" . $spaceId . '/';
// Since there is no trash bin endpoint for old dav version,
// new dav version's endpoint is used here.
return self::withRemotePhp("dav/trash-bin/$userOrToken");
}
return "remote.php/dav/spaces/" . $spaceId . '/';
} else {
if ($davPathVersionToUse === self::DAV_VERSION_OLD) {
if ($type === "trash-bin") {
// Since there is no trash bin endpoint for old dav version, new dav version's endpoint is used here.
return $newTrashbinDavPath;
if ($type === "public-files") {
return "public.php/webdav";
}
return "remote.php/webdav/";
return self::withRemotePhp("webdav");
} elseif ($davPathVersionToUse === self::DAV_VERSION_NEW) {
if ($type === "files") {
$path = 'remote.php/dav/files/';
return $path . $user . '/';
} elseif ($type === "trash-bin") {
return $newTrashbinDavPath;
} else {
return "remote.php/dav";
return self::withRemotePhp("dav/files/$userOrToken");
} elseif ($type === "public-files") {
return self::withRemotePhp("dav/public-files/$userOrToken");
}
} else {
throw new InvalidArgumentException(
"DAV path version $davPathVersionToUse is unknown"
);
return self::withRemotePhp("dav");
}
throw new InvalidArgumentException("Invalid DAV path: $davPathVersionToUse");
}
}

Expand Down Expand Up @@ -903,11 +916,12 @@ public static function getMtimeOfFileInPublicLinkShare(
?string $xRequestId = '',
?int $davVersionToUse = self::DAV_VERSION_NEW
):string {
$path = self::getDavPath($token, $davVersionToUse, "public-files");
$response = self::propfind(
$baseUrl,
null,
null,
"/public-files/$token/$fileName",
"{$path}/{$fileName}",
['d:getlastmodified'],
$xRequestId,
'1',
Expand Down
20 changes: 2 additions & 18 deletions tests/acceptance/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,6 @@ public function getOCSPath(string $ocsApiVersion): string {
return \ltrim($this->getBasePath() . "/ocs/v$ocsApiVersion.php", "/");
}

/**
* returns the complete DAV path including the base path e.g. owncloud-core/remote.php/dav
*
* @return string
*/
public function getDAVPathIncludingBasePath(): string {
return \ltrim($this->getBasePath() . "/" . $this->getDavPath(), "/");
}

/**
* returns the base URL but without "http(s)://" in front of it
*
Expand Down Expand Up @@ -2038,7 +2029,8 @@ public function getVersionStringFromStatus(): ?string {
*/
public function getCommentUrlRegExp(): string {
$basePath = \ltrim($this->getBasePath() . "/", "/");
return "/{$basePath}remote.php/dav/comments/files/([0-9]+)";
$commentsPath = WebDAVHelper::getDavPath(null, null, "comments");
return "/{$basePath}/{$commentsPath}/([0-9]+)";
}

/**
Expand Down Expand Up @@ -2145,14 +2137,6 @@ public function substituteInLineCodes(
],
"parameter" => []
],
[
"code" => "%dav_path%",
"function" => [
$this,
"getDAVPathIncludingBasePath"
],
"parameter" => []
],
[
"code" => "%ocs_path_v1%",
"function" => [
Expand Down
46 changes: 30 additions & 16 deletions tests/acceptance/bootstrap/PublicWebDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
class PublicWebDavContext implements Context {
private FeatureContext $featureContext;

/**
* @param string $versionString (old|new)
*
* @return int
*/
public function getPublicDavVersion(string $versionString): int {
if ($versionString === "old") {
return WebDavHelper::DAV_VERSION_OLD;
} elseif ($versionString === "new") {
return WebDavHelper::DAV_VERSION_NEW;
}
throw new Exception("Unknown public WebDAV version: $versionString");
}

/**
* @param string $range ignore if empty
* @param string $publicWebDAVAPIVersion
Expand Down Expand Up @@ -132,8 +146,8 @@ public function deleteFileFromPublicShare(string $fileName, string $publicWebDAV
$token = ($this->featureContext->isUsingSharingNG()) ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() : $this->featureContext->getLastCreatedPublicShareToken();
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-$publicWebDAVAPIVersion"
$this->getPublicDavVersion($publicWebDAVAPIVersion),
"public-files"
);
$password = $this->featureContext->getActualPassword($password);
$fullUrl = $this->featureContext->getBaseUrl() . "/$davPath$fileName";
Expand Down Expand Up @@ -203,8 +217,8 @@ public function renameFileFromPublicShare(string $fileName, string $toFileName,
$token = ($this->featureContext->isUsingSharingNG()) ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() : $this->featureContext->getLastCreatedPublicShareToken();
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-$publicWebDAVAPIVersion"
$this->getPublicDavVersion($publicWebDAVAPIVersion),
"public-files"
);
$fullUrl = $this->featureContext->getBaseUrl() . "/$davPath$fileName";
$password = $this->featureContext->getActualPassword($password);
Expand Down Expand Up @@ -318,8 +332,8 @@ public function downloadFromPublicLinkAsUser(string $path, string $user): Respon

$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-new"
$this->featureContext->getDavPathVersion(),
"public-files"
);

$username = $this->featureContext->getActualUsername($user);
Expand Down Expand Up @@ -358,8 +372,8 @@ public function downloadFileFromPublicFolder(
}
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-$publicWebDAVAPIVersion"
$this->getPublicDavVersion($publicWebDAVAPIVersion),
"public-files"
);
$fullUrl = $this->featureContext->getBaseUrl() . "/$davPath$path";
$userName = $this->getUsernameForPublicWebdavApi(
Expand Down Expand Up @@ -462,8 +476,8 @@ public function thePublicCopiesFileUsingTheWebDAVApi(string $source, string $des
$token = ($this->featureContext->isUsingSharingNG()) ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() : $this->featureContext->getLastCreatedPublicShareToken();
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-$publicWebDAVAPIVersion"
$this->getPublicDavVersion($publicWebDAVAPIVersion),
"public-files"
);
$baseUrl = $this->featureContext->getLocalBaseUrl() . '/' . $davPath;

Expand Down Expand Up @@ -1552,8 +1566,8 @@ public function publicCreatesFolderUsingPassword(
$token = ($this->featureContext->isUsingSharingNG()) ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() : $this->featureContext->getLastCreatedPublicShareToken();
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-new"
$this - featureContext->getDavPathVersion(),
"public-files"
);
$url = $this->featureContext->getBaseUrl() . "/$davPath";
$password = $this->featureContext->getActualPassword($password);
Expand Down Expand Up @@ -1713,8 +1727,8 @@ public function publicUploadContent(
}
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-$publicWebDAVAPIVersion"
$this->getPublicDavVersion($publicWebDAVAPIVersion),
"public-files"
);
$url = $this->featureContext->getBaseUrl() . "/$davPath";
$userName = $this->getUsernameForPublicWebdavApi(
Expand Down Expand Up @@ -1818,8 +1832,8 @@ public function publicSendsRequestToLastPublicShare(string $method, string $publ
$token = ($this->featureContext->isUsingSharingNG()) ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() : $this->featureContext->getLastCreatedPublicShareToken();
$davPath = WebDavHelper::getDavPath(
null,
null,
"public-files-$publicWebDAVAPIVersion"
$this->getPublicDavVersion($publicWebDAVAPIVersion),
"public-files"
);
$password = $this->featureContext->getActualPassword($password);
$username = $this->getUsernameForPublicWebdavApi(
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/bootstrap/SearchContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function userSearchesUsingWebDavAPI(

if ($davPathVersionToUse == WebDavHelper::DAV_VERSION_NEW) {
// Removes the last component('username' in this case) from the WebDAV path by going up one level in the directory structure.
// e.g. remote.php/dav/files/Alice ==> remote.php/dav/files/
// e.g. dav/files/Alice ==> dav/files/
$davPath = \dirname($davPath, 1);
}

Expand Down
Loading