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

Remove Hardcoded MimeTypes from the sharing functions #34087

Merged
merged 1 commit into from
Jan 9, 2019
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 @@ -42,14 +42,14 @@ Feature: sharing
| path | PARENT |
| shareType | user |
| shareWith | user1 |
Then user "user1" should be able to download file "/PARENT (2)/CHILD/child.txt" using the sharing API
Then user "user1" should be able to download the range "bytes=1-7" of file "/PARENT (2)/CHILD/child.txt" using the sharing API 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 group with default permissions
Given user "user1" has been created with default attributes
And group "grp1" has been created
And user "user1" has been added to group "grp1"
When user "user0" has shared folder "PARENT" with group "grp1"
Then user "user1" should be able to download file "/PARENT (2)/CHILD/child.txt" using the sharing API
Then user "user1" should be able to download the range "bytes=1-7" of file "/PARENT (2)/CHILD/child.txt" using the sharing API and the content should be "wnCloud"

@smokeTest @public_link_share-feature-required
Scenario: Download a file that is in a folder contained in a folder that has been shared with public with default permissions
Expand All @@ -65,7 +65,7 @@ Feature: sharing
| shareType | user |
| shareWith | user1 |
| permissions | change |
Then user "user1" should be able to download file "/PARENT (2)/CHILD/child.txt" using the sharing API
Then user "user1" should be able to download the range "bytes=1-7" of file "/PARENT (2)/CHILD/child.txt" using the sharing API 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 group with Read/Write permission
Given user "user1" has been created with default attributes
Expand All @@ -76,7 +76,7 @@ Feature: sharing
| shareType | group |
| shareWith | grp1 |
| permissions | change |
Then user "user1" should be able to download file "/PARENT (2)/CHILD/child.txt" using the sharing API
Then user "user1" should be able to download the range "bytes=1-7" of file "/PARENT (2)/CHILD/child.txt" using the sharing API and the content should be "wnCloud"

@public_link_share-feature-required
Scenario: Download a file that is in a folder contained in a folder that has been shared with public with Read/Write permission
Expand All @@ -93,7 +93,7 @@ Feature: sharing
| shareType | user |
| shareWith | user1 |
| permissions | read |
Then user "user1" should be able to download file "/PARENT (2)/CHILD/child.txt" using the sharing API
Then user "user1" should be able to download the range "bytes=1-7" of file "/PARENT (2)/CHILD/child.txt" using the sharing API 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 group with Read only permission
Given user "user1" has been created with default attributes
Expand All @@ -104,7 +104,7 @@ Feature: sharing
| shareType | group |
| shareWith | grp1 |
| permissions | read |
Then user "user1" should be able to download file "/PARENT (2)/CHILD/child.txt" using the sharing API
Then user "user1" should be able to download the range "bytes=1-7" of file "/PARENT (2)/CHILD/child.txt" using the sharing API and the content should be "wnCloud"

@public_link_share-feature-required
Scenario: Download a file that is in a folder contained in a folder that has been shared with public with Read only permission
Expand Down
39 changes: 33 additions & 6 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ public function publicSharedFileCannotBeDownloaded($path) {
);
}

/**
* Give the mimetype of the last shared file
*
* @return string
*/
public function getMimeTypeOfLastSharedFile() {
return \json_decode(\json_encode($this->lastShareData->data->mimetype), 1)[0];
}

/**
* @Then /^the last public shared file should be able to be downloaded without a password$/
*
Expand All @@ -394,7 +403,7 @@ public function checkLastPublicSharedFileDownload() {
$url = $this->lastShareData->data->url;
}
$fullUrl = "$url/download";
$this->checkDownload($fullUrl, null, null, 'text/plain');
$this->checkDownload($fullUrl, null, null, $this->getMimeTypeOfLastSharedFile());
}

/**
Expand All @@ -407,7 +416,7 @@ public function checkLastPublicSharedFileDownload() {
public function checkLastPublicSharedFileWithPasswordDownload($password) {
$token = $this->getLastShareToken();
$fullUrl = $this->getBaseUrl() . "/public.php/webdav";
$this->checkDownload($fullUrl, $token, $password, 'text/plain');
$this->checkDownload($fullUrl, $token, $password, $this->getMimeTypeOfLastSharedFile());
}

/**
Expand All @@ -430,17 +439,35 @@ public function theLastPublicSharedFileShouldNotBeAbleToBeDownloadedWithPassword
}

/**
* @Then /^user "([^"]*)" should be able to download file "([^"]*)" using the sharing API$/
* @Then user :user should be able to download the range :range of file :path using the sharing API and the content should be :content
*
* @param string $user
* @param string $range
* @param string $path
* @param string $content
*
* @return void
*/
public function userShouldBeAbleToDownloadFileUsingTheSharingApi($user, $path) {
public function userShouldBeAbleToDownloadTheRangeOfFileAndTheContentShouldBe($user, $range, $path, $content) {
$path = \ltrim($path, "/");
$fullUrl = $this->getBaseUrl() . "/remote.php/webdav/$path";
$this->checkUserDownload($fullUrl, $user, "text/plain");
$url = $this->getBaseUrl() . "/remote.php/webdav/$path";
$headers = [
'Range' => $range
];
$this->response = HttpRequestHelper::get(
$url, $user, $this->getPasswordForUser($user), $headers
);
PHPUnit_Framework_Assert::assertEquals(
206,
$this->response->getStatusCode()
);
$buf = '';
$body = $this->response->getBody();
while (!$body->eof()) {
// read everything
$buf .= $body->read(8192);
}
PHPUnit_Framework_Assert::assertSame($content, $buf);
}

/**
Expand Down