Skip to content
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
30 changes: 29 additions & 1 deletion tests/acceptance/bootstrap/ArchiverContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,41 @@ public function userDownloadsTheArchiveOfTheseItems(
}
$queryString = \join('&', $queryString);

$data = $this->featureContext->getPublicLinkData();

$fileIds = $data['fileIds'];
$signature = $data['signature'];
$expiration = $data['expiration'];

$token = $this->featureContext->isUsingSharingNG()
? $this->featureContext->shareNgGetLastCreatedLinkShareToken()
: $this->featureContext->getLastCreatedPublicShareToken();

$queryParts = [];

$queryParts[] = "public-token=" . urlencode($token);

foreach ($fileIds as $fileId) {
$queryParts[] = "id=" . urlencode($fileId);
}

$queryParts[] = "signature=" . urlencode($signature);
$queryParts[] = "expiration=" . urlencode($expiration);

$queryString = implode('&', $queryParts);

$url = $this->featureContext->getBaseUrl() . "/archiver?" . $queryString;

$this->featureContext->setResponse(
HttpRequestHelper::get(
$this->getArchiverUrl($queryString),
$url,
$user,
$this->featureContext->getPasswordForUser($user),
),
);
file_put_contents('archive.zip', $this->featureContext->getResponse()->getBody()->getContents());

var_dump($this->featureContext->getResponse()->getBody()->getContents(), "archive urllllll: " . $this->getArchiverUrl($queryString));
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/acceptance/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,25 @@ public function mkDirOnServer(string $dirPathFromServerRoot): void {
);
}

private string $propfindResponseBody = '';
private array $publicLinkData = [];

public function setPropfindResponseBody(string $body): void {
$this->propfindResponseBody = $body;
}

public function getPropfindResponseBody(): string {
return $this->propfindResponseBody;
}

public function setPublicLinkData(array $data): void {
$this->publicLinkData = $data;
}

public function getPublicLinkData(): array {
return $this->publicLinkData;
}

/**
* @return string
*/
Expand Down
128 changes: 114 additions & 14 deletions tests/acceptance/bootstrap/PublicWebDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,27 @@ public function thePublicUploadsFileWithContentUsingThePublicWebDavApi(
$this->featureContext->pushToLastStatusCodesArrays();
}

/**
* @When /^the public uploads the following files using the public WebDAV API:$/
*
* @param \Behat\Gherkin\Node\TableNode $table table with filename and content
*
* @return void
*/
public function thePublicUploadsTheFollowingFilesUsingThePublicWebDavApi(
\Behat\Gherkin\Node\TableNode $table,
): void {
foreach ($table->getHash() as $row) {
$filename = $row['filename'];
$content = $row['content'] ?? 'test';

$response = $this->publicUploadContent($filename, '', $content);

$this->featureContext->setResponse($response);
$this->featureContext->pushToLastStatusCodesArrays();
}
}

/**
* @Given the public has uploaded file :filename with content :body
*
Expand Down Expand Up @@ -1212,6 +1233,43 @@ public function before(BeforeScenarioScope $scope): void {
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}

private function extractPublicLinkData(string $xml): array {
$doc = new \SimpleXMLElement($xml);

$doc->registerXPathNamespace('d', 'DAV:');
$doc->registerXPathNamespace('oc', 'http://owncloud.org/ns');

$fileIds = [];
$signature = null;
$expiration = null;

foreach ($doc->xpath('//d:response') as $response) {
$type = $response->xpath('.//oc:public-link-item-type');
$fileId = $response->xpath('.//oc:fileid');
$sig = $response->xpath('.//oc:signature');
$exp = $response->xpath('.//oc:expiration');

// only files
if (!empty($type) && (string)$type[0] === 'file' && !empty($fileId)) {
$fileIds[] = (string)$fileId[0];
}

if ($signature === null && !empty($sig)) {
$signature = (string)$sig[0];
}

if ($expiration === null && !empty($exp)) {
$expiration = (string)$exp[0];
}
}

return [
'fileIds' => $fileIds,
'signature' => $signature,
'expiration' => $expiration,
];
}

/**
* @When /^the public sends "([^"]*)" request to the last public link share using the public WebDAV API(?: with password "([^"]*)")?$/
*
Expand All @@ -1224,41 +1282,83 @@ public function before(BeforeScenarioScope $scope): void {
public function publicSendsRequestToLastPublicShare(string $method, ?string $password = ''): void {
if ($method === "PROPFIND") {
$body = '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:prop>
<d:resourcetype/>
<oc:public-link-item-type/>
<oc:public-link-permission/>
<oc:public-link-expiration/>
<oc:public-link-share-datetime/>
<oc:public-link-share-owner/>
</d:prop>
</d:propfind>';
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:prop>
<d:resourcetype/>
<oc:public-link-item-type/>
<oc:public-link-permission/>
<oc:public-link-expiration/>
<oc:fileid/>
<oc:downloadURL/>
<oc:signature-auth/>
<oc:public-link-expiration/>
<oc:public-link-share-datetime/>
<oc:public-link-share-owner/>
</d:prop>
</d:propfind>';
} else {
$body = null;
}
$token = ($this->featureContext->isUsingSharingNG())

$token = $this->featureContext->isUsingSharingNG()
? $this->featureContext->shareNgGetLastCreatedLinkShareToken()
: $this->featureContext->getLastCreatedPublicShareToken();
var_dump("tokennnnnnnnnnnnnnnnnnnnn", $token);
var_dump(
"token bothhhhhhhhhhh",
$this->featureContext->shareNgGetLastCreatedLinkShareToken(),
);
$davPath = WebDavHelper::getDavPath(
WebDavHelper::DAV_VERSION_NEW,
$token,
"public-files",
);
var_dump("davPathhhhhhhhhhhhhhhhhhhh", $davPath);
$password = $this->featureContext->getActualPassword($password);
$username = $this->getUsernameForPublicWebdavApi(
$token,
$password,
);
$fullUrl = $this->featureContext->getBaseUrl() . "/$davPath";
var_dump("username", $username);

$fullUrl = $this->featureContext->getBaseUrl() . "/dav/public-files/$token";
// $fullUrl = $this->featureContext->getBaseUrl() . "/remote.php/dav/public-files/$token/";

var_dump("fullURL issssssssssssssss", $fullUrl);

$headers = [
"Depth" => "1",
"OCS-APIRequest" => "true",
"public-token" => $token,
"Content-Type" => "application/xml; charset=utf-8",
"Authorization" => "Basic " . base64_encode("public:$password"),
];
var_dump("headersssssss", $headers['Authorization']);
$response = HttpRequestHelper::sendRequest(
$fullUrl,
$method,
$username,
$password,
null,
null,
$headers,
$body,
);

$responseBody = $response->getBody()->getContents();

var_dump("responsseeeeeeeeeeeeeeeeeeeeeeee", $responseBody);

$this->featureContext->setResponse($response);

// Debug output
var_dump("fullURL lasttttt", $fullUrl, "body", $body);
var_dump("response yeeeeeeeeeeeee", $response->getBody()->getContents());

// store raw XML
$this->featureContext->setPropfindResponseBody($responseBody);

$data = $this->extractPublicLinkData($responseBody);

// store structured data
$this->featureContext->setPublicLinkData($data);
}
}
3 changes: 2 additions & 1 deletion tests/acceptance/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ public function userHasCreatedTheFollowingResourceLinkShare(string $user, TableN
"'resource' should be provided in the data-table while sharing a resource",
);
$response = $this->createLinkShare($user, $body);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Failed while creating public share link!", $response);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Failed while creating public
share link!", $response);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4702,7 +4702,7 @@ public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $res
'',
'',
),
);
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,24 @@ Feature: Public can download folders from project space public link
And the downloaded zip archive should contain these files:
| name | content |
| folder/test.txt | some content |

@env-config
Scenario: public tries to download multiple files from a public link of a folder inside a space
Given the config "SHARING_PUBLIC_SHARE_MUST_HAVE_PASSWORD" has been set to "false" for "sharing" service
And using SharingNG
And user "Alice" has created a folder "project-folder" in space "new-space"
And user "Alice" has uploaded a file inside space "new-space" with content "some content1" to "project-folder/test1.txt"
And user "Alice" has uploaded a file inside space "new-space" with content "some content2" to "project-folder/test2.txt"
And user "Alice" has uploaded a file inside space "new-space" with content "some content3" to "project-folder/test3.txt"
And user "Alice" has created the following resource link share:
| resource | project-folder |
| space | new-space |
| permissionsRole | View |
| password | %public% |
When the public sends "PROPFIND" request to the last public link share using the public WebDAV API with password "%public%"
Then the HTTP status code should be "207"
When user "Alice" downloads the archive of these items using the resource ids
| project-folder/test1.txt |
| project-folder/test2.txt |
| project-folder/test3.txt |
Then the HTTP status code should be "200"
Loading