test(api): add test to try to download public link using basic auth (#8485)

This commit is contained in:
Sawjan Gurung
2024-02-19 16:47:19 +05:45
committed by GitHub
parent 0df64c26cd
commit 7db5f15625
2 changed files with 56 additions and 0 deletions
@@ -115,6 +115,19 @@ class PublicWebDavContext implements Context {
$this->featureContext->setResponse($response);
}
/**
* @When /^user "([^"]*)" tries to download file "([^"]*)" from the last public link using own basic auth and new public WebDAV API$/
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userTriesToDownloadFileFromPublicLinkUsingBasicAuthAndPublicWebdav(string $user, string $path): void {
$response = $this->downloadFromPublicLinkAsUser($path, $user);
$this->featureContext->setResponse($response);
}
/**
* @When /^the public deletes (?:file|folder|entry) "([^"]*)" from the last public link share using the (old|new) public WebDAV API$/
*
@@ -283,6 +296,38 @@ class PublicWebDavContext implements Context {
$this->featureContext->setResponse($response);
}
/**
* @param string $path
* @param string $user
* @param bool $shareNg
*
* @return ResponseInterface
*/
public function downloadFromPublicLinkAsUser(string $path, string $user, bool $shareNg = false): ResponseInterface {
$path = \ltrim($path, "/");
if ($shareNg) {
$token = $this->featureContext->shareNgGetLastCreatedLinkShareToken();
} else {
$token = $this->featureContext->getLastCreatedPublicShareToken();
}
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-new"
);
$username = $this->featureContext->getActualUsername($user);
$password = $this->featureContext->getPasswordForUser($user);
$fullUrl = $this->featureContext->getBaseUrl() . "/$davPath$path";
return HttpRequestHelper::get(
$fullUrl,
$this->featureContext->getStepLineRef(),
$username,
$password
);
}
/**
* @param string $path
* @param string $password
@@ -57,3 +57,14 @@ Feature: accessing a public link share
| testavatar.jpg |
| textfile0.txt |
Then the HTTP status code of responses on all endpoints should be "200"
@issue-web-10473
Scenario: user tries to download public link file using own basic auth
And user "Alice" has created folder "FOLDER"
And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "FOLDER/textfile.txt"
And user "Alice" has created a public link share with settings
| path | FOLDER |
| permissions | change |
| password | %public% |
When user "Alice" tries to download file "textfile.txt" from the last public link using own basic auth and new public WebDAV API
Then the HTTP status code should be "401"