Skip to content

Commit

Permalink
Merge pull request #31459 from paurakhsharma/stable10-API-test-downlo…
Browse files Browse the repository at this point in the history
…adFromShare

[Stable10] api test download from share
  • Loading branch information
phil-davis authored May 16, 2018
2 parents a3220ba + fcec141 commit 7996cc5
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 1 deletion.
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

0 comments on commit 7996cc5

Please sign in to comment.