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

[Stable10] api test download from share #31459

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,91 @@ Feature: sharing
And the downloaded content when downloading file "/textfile0 (2).txt" for user "user2" with range "bytes=0-8" should be "BLABLABLA"
And user "user2" should see the following elements
| /common/sub/textfile0.txt |
| /textfile0%20(2).txt |
| /textfile0%20(2).txt |

Scenario: Download a file that is in a folder contained in a folder that has been shared with a user with default permissions
Given user "user0" has been created
And user "user1" has been created
And user "user0" creates a share using the API with settings
| path | PARENT |
| shareType | 0 |
| shareWith | user1 |
Then the user "user1" should be able to download the file "/PARENT (2)/CHILD/child.txt" using the API

Scenario: Download a file that is in a folder contained in a folder that has been shared with a group with default permissions
Given user "user0" has been created
And user "user1" has been created
And group "sharegroup" has been created
And user "user1" has been added to group "sharegroup"
And user "user0" has shared folder "PARENT" with group "sharegroup"
Then the user "user1" should be able to download the file "/PARENT (2)/CHILD/child.txt" using the API

Scenario: Download a file that is in a folder contained in a folder that has been shared with public with default permissions
Given user "user0" has been created
When user "user0" creates a share using the API with settings
| path | PARENT |
| shareType | 3 |
| password | publicpw |
Then the public should be able to download the range "bytes=1-7" of file "/CHILD/child.txt" from inside the last public shared folder with password "publicpw" and the content should be "wnCloud"

Scenario: Download a file that is in a folder contained in a folder that has been shared with a user with Read/Write permission
Given user "user0" has been created
And user "user1" has been created
When user "user0" creates a share using the API with settings
| path | PARENT |
| shareType | 0 |
| shareWith | user1 |
| permissions | 15 |
Then the user "user1" should be able to download the file "/PARENT (2)/CHILD/child.txt" using the API

Scenario: Download a file that is in a folder contained in a folder that has been shared with a group with Read/Write permission
Given user "user0" has been created
And user "user1" has been created
And group "sharegroup" has been created
And user "user1" has been added to group "sharegroup"
When user "user0" creates a share using the API with settings
| path | PARENT |
| shareType | 1 |
| shareWith | sharegroup |
| permissions | 15 |
Then the user "user1" should be able to download the file "/PARENT (2)/CHILD/child.txt" using the API

Scenario: Download a file that is in a folder contained in a folder that has been shared with public with Read/Write permission
Given user "user0" has been created
When user "user0" creates a share using the API with settings
| path | PARENT |
| shareType | 3 |
| password | publicpw |
| permissions | 15 |
Then the public should be able to download the range "bytes=1-7" of file "/CHILD/child.txt" from inside the last public shared folder with password "publicpw" and the content should be "wnCloud"

Scenario: Download a file that is in a folder contained in a folder that has been shared with a user with Read only permission
Given user "user0" has been created
And user "user1" has been created
When user "user0" creates a share using the API with settings
| path | PARENT |
| shareType | 0 |
| shareWith | user1 |
| permissions | 1 |
Then the user "user1" should be able to download the file "/PARENT (2)/CHILD/child.txt" using the API

Scenario: Download a file that is in a folder contained in a folder that has been shared with a group with Read only permission
Given user "user0" has been created
And user "user1" has been created
And group "sharegroup" has been created
And user "user1" has been added to group "sharegroup"
When user "user0" creates a share using the API with settings
| path | PARENT |
| shareType | 1 |
| shareWith | sharegroup |
| permissions | 1 |
Then the user "user1" should be able to download the file "/PARENT (2)/CHILD/child.txt" using the API

Scenario: Download a file that is in a folder contained in a folder that has been shared with public with Read only permission
Given user "user0" has been created
When user "user0" creates a share using the API with settings
| path | PARENT |
| shareType | 3 |
| password | publicpw |
| permissions | 1 |
Then the public should be able to download the range "bytes=1-7" of file "/CHILD/child.txt" from inside the last public shared folder with password "publicpw" and the content should be "wnCloud"
48 changes: 48 additions & 0 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,54 @@ public function checkLastPublicSharedFileWithPasswordDownload($password) {
$this->checkDownload($fullUrl, [$token, $password], 'text/plain');
}

/**
* @Then /^the user "([^"]*)" should be able to download the file "([^"]*)" using the API$/
*
* @param string $user
* @param string $path
*
* @return void
*/
public function theUserShouldBeAbleToDownloadTheFileUsingTheApi($user, $path) {
$path = ltrim($path, "/");
$options = [];
$options['auth'] = $this->getAuthOptionForUser($user);

$fullUrl = $this->getBaseUrl() . "/remote.php/webdav/$path";
$this->checkUserDownload($fullUrl, $options, "text/plain");
}

/**
* @param string $url
* @param array $options
* @param string $mimeType
*
* @return void
*/
private function checkUserDownload($url, $options, $mimeType) {
$client = new Client();
$this->response = $client->get($url, $options);
PHPUnit_Framework_Assert::assertEquals(
200,
$this->response->getStatusCode()
);

$buf = '';
$body = $this->response->getBody();
while (!$body->eof()) {
// read everything
$buf .= $body->read(8192);
}
$mimeType = 'text/plain';
if ($mimeType !== null) {
$finfo = new finfo;
PHPUnit_Framework_Assert::assertEquals(
$mimeType,
$finfo->buffer($buf, FILEINFO_MIME_TYPE)
);
}
}

/**
* @param string $url
* @param string $auth
Expand Down