Skip to content

Commit

Permalink
test: fix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Oct 8, 2024
1 parent 6dece1f commit b1b66fd
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 86 deletions.
3 changes: 2 additions & 1 deletion tests/acceptance/TestHelpers/WebDavHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public static function makeDavRequest(
}

// get space id if testing with spaces dav
if ($spaceId === null && $davPathVersionToUse === self::DAV_VERSION_SPACES) {
if ($spaceId === null && $davPathVersionToUse === self::DAV_VERSION_SPACES && $type !== "public-files") {
$path = \ltrim($path, "/");
if (\str_starts_with($path, "Shares/")) {
$spaceId = self::getSharesSpaceIdForUser(
Expand Down Expand Up @@ -779,6 +779,7 @@ public static function makeDavRequest(
}
}

// if ($method==="PROPFIND") var_dump($fullUrl);
return HttpRequestHelper::sendRequest(
$fullUrl,
$xRequestId,
Expand Down
8 changes: 3 additions & 5 deletions tests/acceptance/bootstrap/FilesVersionsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FilesVersionsContext implements Context {
* @return string
*/
private function getVersionsPathForFileId(string $fileId):string {
return "/meta/$fileId/v";
return "$fileId/v";
}

/**
Expand Down Expand Up @@ -126,8 +126,7 @@ public function getFileVersions(
null,
null,
$spaceId,
null,
'2'
"versions"
);
}

Expand Down Expand Up @@ -192,9 +191,8 @@ public function getFileVersionMetadata(string $user, string $file) : ResponseInt
$this->getVersionsPathForFileId($fileId),
null,
$body,
'',
null,
'2'
"versions",
);
}

Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/bootstrap/OcmContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,4 @@ public function deleteConnection(string $user, string $ocmUser): ResponseInterfa
$ocmUser['idp']
);
}

}
64 changes: 10 additions & 54 deletions tests/acceptance/bootstrap/PublicWebDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
class PublicWebDavContext implements Context {
private FeatureContext $featureContext;

// TODO: mayeb this will not be required anymore
/**
* @param string $versionString (old|new)
*
Expand Down Expand Up @@ -383,7 +384,7 @@ public function downloadFileFromPublicFolder(
$this->getPublicDavVersion($publicWebDAVAPIVersion),
"public-files"
);
$fullUrl = $this->featureContext->getBaseUrl() . "/$davPath$path";
$fullUrl = $this->featureContext->getBaseUrl() . "/$davPath/$path";
$userName = $this->getUsernameForPublicWebdavApi(
$token,
$password,
Expand Down Expand Up @@ -687,46 +688,18 @@ public function thePublicHasOverwrittenFileWithContentUsingOldWebDavApi(string $
}

/**
* @param string $filename target file name
* @param string $body content to upload
* @param string $publicWebDAVAPIVersion
*
* @return ResponseInterface
*/
public function publiclyUploadingContent(
string $filename,
string $body = 'test',
string $publicWebDAVAPIVersion = "old"
):ResponseInterface {
return $this->publicUploadContent(
$filename,
'',
$body,
false,
[],
$publicWebDAVAPIVersion
);
}

/**
* @When /^the public uploads file "([^"]*)" with content "([^"]*)" using the (old|new) public WebDAV API$/
* @When /^the public uploads file "([^"]*)" with content "([^"]*)" using the (?:old|new) public WebDAV API$/
*
* @param string $filename target file name
* @param string $body content to upload
* @param string $publicWebDAVAPIVersion
*
* @return void
*/
public function thePublicUploadsFileWithContentUsingThePublicWebDavApi(
string $filename,
string $body = 'test',
string $publicWebDAVAPIVersion = "old"
string $body = 'test'
):void {
$response = $this->publiclyUploadingContent(
$filename,
$body,
$publicWebDAVAPIVersion
);
$response = $this->publicUploadContent($filename, '', $body);
$this->featureContext->setResponse($response);
$this->featureContext->pushToLastStatusCodesArrays();
}
Expand All @@ -736,20 +709,11 @@ public function thePublicUploadsFileWithContentUsingThePublicWebDavApi(
*
* @param string $filename target file name
* @param string $body content to upload
* @param string $publicWebDAVAPIVersion
*
* @return void
*/
public function thePublicHasUploadedFileWithContentUsingThePublicWebDavApi(
string $filename,
string $body = 'test',
string $publicWebDAVAPIVersion = "old"
):void {
$response = $this->publiclyUploadingContent(
$filename,
$body,
$publicWebDAVAPIVersion
);
public function thePublicHasUploadedFileWithContent(string $filename, string $body): void {
$response = $this->publicUploadContent($filename, '', $body);
$this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response);
}

Expand Down Expand Up @@ -1218,14 +1182,6 @@ public function tryingToDownloadUsingWebDAVAPI(
$publicWebDAVAPIVersion,
$shareNg
);

$responseContent = $response->getBody()->getContents();
\libxml_use_internal_errors(true);
Assert::assertNotFalse(
\simplexml_load_string($responseContent),
"response body is not valid XML, maybe download did work\n" .
"response body: \n$responseContent\n"
);
$this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode, "", $response);
}

Expand Down Expand Up @@ -1745,10 +1701,9 @@ public function publicUploadContent(
}
$davPath = WebDavHelper::getDavPath(
$token,
$this->getPublicDavVersion($publicWebDAVAPIVersion),
$this->getPublicDavVersion("new"),
"public-files"
);
$url = $this->featureContext->getBaseUrl() . "/$davPath";
$userName = $this->getUsernameForPublicWebdavApi(
$token,
$password,
Expand All @@ -1759,7 +1714,8 @@ public function publicUploadContent(
'/',
\array_map('rawurlencode', \explode('/', $filename))
);
$url .= \ltrim($filename, '/');
$encodedFilePath = \ltrim($filename, '/');
$url = $this->featureContext->getBaseUrl() . "/$davPath/$encodedFilePath";
// Trim any "/" from the end. For example, if we are putting content to a
// single file that has been shared with a link, then the URL should end
// with the link token and no "/" at the end.
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bootstrap/SearchContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function userSearchesUsingWebDavAPI(
}
$body .= " </oc:search-files>";
$davPathVersionToUse = $this->featureContext->getDavPathVersion();
// TODO: need to fix for spaces
$davPath = WebDavHelper::getDavPath($doDavRequestAsUser ?? $user, $davPathVersionToUse, 'files', null);

if ($davPathVersionToUse == WebDavHelper::DAV_VERSION_NEW) {
Expand Down
49 changes: 39 additions & 10 deletions tests/acceptance/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class SpacesContext implements Context {
private FavoritesContext $favoritesContext;
private ChecksumContext $checksumContext;
private FilesVersionsContext $filesVersionsContext;
private ArchiverContext $archiverContext;

/**
* key is space name and value is the username that created the space
Expand Down Expand Up @@ -402,11 +403,13 @@ public function setUpScenario(BeforeScenarioScope $scope): void {
$this->favoritesContext = new FavoritesContext();
$this->checksumContext = new ChecksumContext();
$this->filesVersionsContext = new FilesVersionsContext();
$this->archiverContext = new ArchiverContext();
$environment->registerContext($this->trashbinContext);
$environment->registerContext($this->webDavPropertiesContext);
$environment->registerContext($this->favoritesContext);
$environment->registerContext($this->checksumContext);
$environment->registerContext($this->filesVersionsContext);
$environment->registerContext($this->archiverContext);
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->ocsContext = $environment->getContext('OCSContext');
Expand Down Expand Up @@ -1699,7 +1702,11 @@ public function userCopiesFileWithinSpaceUsingTheWebDAVAPI(
$spaceName
);

$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileSource, "/");
$encodedName = \rawurlencode(ltrim($fileSource, "/"));
$baseUrl = $this->featureContext->getBaseUrl();
$davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]);
$fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}";

$this->featureContext->setResponse($this->copyFilesAndFoldersRequest($user, $fullUrl, $headers));
}

Expand All @@ -1726,8 +1733,11 @@ public function moveFileWithinSpace(
);
$headers['Overwrite'] = 'F';

$fileSource = $this->escapePath(\trim($fileSource, "/"));
$fullUrl = $space["root"]["webDavUrl"] . '/' . $fileSource;
$encodedName = \rawurlencode(ltrim($fileSource, "/"));
$baseUrl = $this->featureContext->getBaseUrl();
$davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]);
$fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}";

return $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
}

Expand Down Expand Up @@ -1840,7 +1850,11 @@ public function userCopiesFileFromAndToSpaceBetweenSpaces(
}
}

$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileSource, "/");
$encodedName = \rawurlencode(ltrim($fileSource, "/"));
$baseUrl = $this->featureContext->getBaseUrl();
$davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]);
$fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}";

$this->featureContext->setResponse($this->copyFilesAndFoldersRequest($user, $fullUrl, $headers));
}

Expand Down Expand Up @@ -1868,7 +1882,12 @@ public function userOverwritesFileFromAndToSpaceBetweenSpaces(
$space = $this->getSpaceByName($user, $fromSpaceName);
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName);
$headers['Overwrite'] = 'T';
$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileSource, "/");

$encodedName = \rawurlencode(ltrim($fileSource, "/"));
$baseUrl = $this->featureContext->getBaseUrl();
$davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]);
$fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}";

if ($action === 'copying') {
$response = $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
} else {
Expand Down Expand Up @@ -1931,7 +1950,12 @@ public function userMovesFileFromAndToSpaceBetweenSpaces(
):void {
$space = $this->getSpaceByName($user, $fromSpaceName);
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName);
$fullUrl = $space["root"]["webDavUrl"] . '/' . \ltrim($fileSource, "/");

$encodedName = \rawurlencode(ltrim($fileSource, "/"));
$baseUrl = $this->featureContext->getBaseUrl();
$davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]);
$fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}";

$this->featureContext->setResponse($this->moveFilesAndFoldersRequest($user, $fullUrl, $headers));
$this->featureContext->pushToLastHttpStatusCodesArray();
}
Expand Down Expand Up @@ -2526,9 +2550,14 @@ public function removeObjectFromSpace(
string $spaceName
): ResponseInterface {
$space = $this->getSpaceByName($user, $spaceName);
$spaceWebDavUrl = $space["root"]["webDavUrl"] . '/' . ltrim($object, "/");

$encodedName = \rawurlencode(ltrim($object, "/"));
$baseUrl = $this->featureContext->getBaseUrl();
$davPath = WebdavHelper::getDavPath(null, WebDavHelper::DAV_VERSION_SPACES, null, $space["id"]);
$fullUrl = "{$baseUrl}/{$davPath}/{$encodedName}";

return HttpRequestHelper::delete(
$spaceWebDavUrl,
$fullUrl,
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user)
Expand Down Expand Up @@ -3959,7 +3988,7 @@ public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $res
$queryString = 'public-token=' . $token . '&id=' . $resourceId[0][0];
$this->featureContext->setResponse(
HttpRequestHelper::get(
$this->featureContext->getBaseUrl() . '/archiver?' . $queryString,
$this->archiverContext->getArchiverUrl($queryString),
$this->featureContext->getStepLineRef(),
'',
'',
Expand Down Expand Up @@ -4048,7 +4077,7 @@ public function theUserShouldHaveSpaceWithRecipient(
*/
public function userDownloadsTheSpaceUsingTheWebdavApi(string $user, string $spaceName, string $owner = ''):void {
$space = $this->getSpaceByName($owner ?: $user, $spaceName);
$url = $this->featureContext->getBaseUrl() . '/archiver?id=' . $space['id'];
$url = $this->archiverContext->getArchiverUrl('id=' . $space['id']);
$this->featureContext->setResponse(
HttpRequestHelper::get(
$url,
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ public function downloadPreviews(string $user, ?string $path, ?string $doDavRequ
$urlParameter = [
'x' => $width,
'y' => $height,
'forceIcon' => '0',
'preview' => '1'
];
return $this->makeDavRequest(
Expand Down Expand Up @@ -3667,7 +3666,7 @@ public function userDownloadsThePreviewOfWithPreviewZero(string $user, string $p
* @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));
Expand Down Expand Up @@ -3839,7 +3838,7 @@ public function downloadSharedFilePreview(
$sharesPath = $this->getSharesMountPath($user, $path) . '/?' . $urlParameter;

$davPath = WebDavHelper::getDavPath($user, $this->getDavPathVersion());
$fullUrl = $this->getBaseUrl() . "/$davPath" . $sharesPath;
$fullUrl = $this->getBaseUrl() . "/$davPath/$sharesPath";

return HttpRequestHelper::sendRequest(
$fullUrl,
Expand Down Expand Up @@ -4418,6 +4417,7 @@ public function theLastPublicDavResponseShouldNotContainTheseNodes(TableNode $ta
*/
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,
'/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ Feature: enforce password on public link
Then the HTTP status code should be "200"
And the OCS status code should be "<ocs-status-code>"
And the OCS status message should be "OK"
And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password
And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass"
But the public should be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "%public%"
And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password
And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass"
But the public should be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "%public%"
Examples:
| ocs-api-version | ocs-status-code |
| 1 | 100 |
Expand All @@ -99,9 +99,9 @@ Feature: enforce password on public link
Then the HTTP status code should be "200"
And the OCS status code should be "<ocs-status-code>"
And the OCS status message should be "OK"
And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password
And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass"
But the public should be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "3s:5WW9uE5h=A"
And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password
And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass"
But the public should be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "3s:5WW9uE5h=A"
Examples:
| ocs-api-version | ocs-status-code |
| 1 | 100 |
Expand Down Expand Up @@ -163,9 +163,9 @@ Feature: enforce password on public link
Then the HTTP status code should be "200"
And the OCS status code should be "<ocs-status-code>"
And the OCS status message should be "OK"
And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password
And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass"
But the public should be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "6a0Q;A3 +i^m["
And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password
And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass"
But the public should be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "6a0Q;A3 +i^m["
Examples:
| ocs-api-version | ocs-status-code |
| 1 | 100 |
Expand Down Expand Up @@ -221,9 +221,9 @@ Feature: enforce password on public link
Then the HTTP status code should be "200"
And the OCS status code should be "200"
And the OCS status message should be "OK"
And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password
And the public should not be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass"
But the public should be able to download file "/textfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "<password>"
And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API without a password
And the public should not be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass"
But the public should be able to download file "/testfile.txt" from inside the last public link shared folder using the new public WebDAV API with password "<password>"
Examples:
| config | config-value | password |
| OCIS_PASSWORD_POLICY_MIN_CHARACTERS | 4 | Ps-1 |
Expand Down

0 comments on commit b1b66fd

Please sign in to comment.