Skip to content
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
19 changes: 16 additions & 3 deletions tests/TestHelpers/WebDavHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ public static function listFolder(
* than download it all up-front.
* @param int $timeout
* @param Client|null $client
* @param array $urlParameter to concatenate with path
* @param string $doDavRequestAsUser run the DAV as this user, if null its same as $user
*
* @return ResponseInterface
*/
Expand All @@ -360,13 +362,24 @@ public static function makeDavRequest(
$authType = "basic",
$stream = false,
$timeout = 0,
$client = null
$client = null,
$urlParameter = [],
$doDavRequestAsUser = null
) {
$baseUrl = self::sanitizeUrl($baseUrl, true);
$davPath = self::getDavPath($user, $davPathVersionToUse, $type);
if ($doDavRequestAsUser === null) {
$davPath = self::getDavPath($user, $davPathVersionToUse, $type);
} else {
$davPath = self::getDavPath($doDavRequestAsUser, $davPathVersionToUse, $type);
}
//replace %, # and ? and in the path, Guzzle will not encode them
$urlSpecialChar = [['%', '#', '?'],['%25', '%23', '%3F']];
$urlSpecialChar = [['%', '#', '?'], ['%25', '%23', '%3F']];
$path = \str_replace($urlSpecialChar[0], $urlSpecialChar[1], $path);

if (!empty($urlParameter)) {
$urlParameter = \http_build_query($urlParameter, '', '&');
$path .= '?' . $urlParameter;
}
$fullUrl = self::sanitizeUrl($baseUrl . $davPath . $path);

if ($authType === 'bearer') {
Expand Down
9 changes: 9 additions & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ default:
- WebDavPropertiesContext:
- TagsContext:

apiWebdavPreviews:
paths:
- '%paths.base%/../features/apiWebdavPreviews'
context: *common_ldap_suite_context
contexts:
- FeatureContext: *common_feature_context_params
- WebDavPropertiesContext:
- OccContext:

apiWebdavProperties:
paths:
- '%paths.base%/../features/apiWebdavProperties'
Expand Down
141 changes: 141 additions & 0 deletions tests/acceptance/features/apiWebdavPreviews/previews.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
@api @TestAlsoOnExternalUserBackend
@skipOnOcis
Feature: previews of files downloaded through the webdav API

Background:
Given user "user0" has been created with default attributes and without skeleton files

Scenario Outline: download previews of different sizes
Given user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
When user "user0" downloads the preview of "/parent.txt" with width <width> and height <height> using the WebDAV API
Then the HTTP status code should be "200"
And the downloaded image should be <width> pixels wide and <height> pixels high
Examples:
| width | height |
| 1 | 1 |
| 32 | 32 |
| 1024 | 1024 |
| 1 | 1024 |
| 1024 | 1 |

Scenario Outline: download previews with invalid width
Given user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
When user "user0" downloads the preview of "/parent.txt" with width "<width>" and height "32" using the WebDAV API
Then the HTTP status code should be "400"
And the value of the item "/d:error/s:message" in the response should be "Cannot set width of 0 or smaller!"
And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\BadRequest"
Examples:
| width |
| 0 |
| 0.5 |
| -1 |
| false |
| true |
| A |
| %2F |

Scenario Outline: download previews with invalid height
Given user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
When user "user0" downloads the preview of "/parent.txt" with width "32" and height "<height>" using the WebDAV API
Then the HTTP status code should be "400"
And the value of the item "/d:error/s:message" in the response should be "Cannot set height of 0 or smaller!"
And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\BadRequest"
Examples:
| height |
| 0 |
| 0.5 |
| -1 |
| false |
| true |
| A |
| %2F |

Scenario: download previews of files inside sub-folders
Given user "user0" has created folder "subfolder"
And user "user0" has uploaded file "filesForUpload/lorem.txt" to "/subfolder/parent.txt"
When user "user0" downloads the preview of "/subfolder/parent.txt" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "200"
And the downloaded image should be "32" pixels wide and "32" pixels high

Scenario Outline: download previews of file types that don't support preview
Given user "user0" has uploaded file "filesForUpload/<filename>" to "/<newfilename>"
When user "user0" downloads the preview of "/<newfilename>" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "404"
And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\NotFound"
Examples:
| filename | newfilename |
| simple.pdf | test.pdf |
| simple.odt | test.odt |
| new-data.zip | test.zip |

@issue-ocis-webdav-187
Scenario Outline: download previews of different image file types
Given user "user0" has uploaded file "filesForUpload/<imageName>" to "/<newImageName>"
When user "user0" downloads the preview of "/<newImageName>" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "200"
And the downloaded image should be "32" pixels wide and "32" pixels high
Examples:
Comment thread
individual-it marked this conversation as resolved.
| imageName | newImageName |
| testavatar.jpg | testimage.jpg |
| testavatar.png | testimage.png |

@issue-ocis-webdav-187
Scenario: download previews of image after renaming it
Given user "user0" has uploaded file "filesForUpload/testavatar.jpg" to "/testimage.jpg"
When user "user0" moves file "/testimage.jpg" to "/testimage.txt" using the WebDAV API
And user "user0" downloads the preview of "/testimage.txt" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "200"
And the downloaded image should be "32" pixels wide and "32" pixels high

Scenario: download previews of shared files
Given user "user1" has been created with default attributes and without skeleton files
And user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
And user "user0" has shared file "/parent.txt" with user "user1"
When user "user1" downloads the preview of "/parent.txt" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "200"
And the downloaded image should be "32" pixels wide and "32" pixels high

Scenario: download previews of other users files
Given user "user1" has been created with default attributes and without skeleton files
And user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
When user "user1" downloads the preview of "/parent.txt" of "user0" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "404"
And the value of the item "/d:error/s:message" in the response should be "File not found: parent.txt in 'user0'"
And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\NotFound"

Scenario: download previews of folders
Given user "user0" has created folder "subfolder"
When user "user0" downloads the preview of "/subfolder/" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "400"
And the value of the item "/d:error/s:message" in the response should be "Unsupported file type"
And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\BadRequest"

Scenario: download previews of not-existing files
When user "user0" downloads the preview of "/parent.txt" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "404"
And the value of the item "/d:error/s:message" in the response should be "File with name parent.txt could not be located"
And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\NotFound"

Scenario: Download file previews when it is disabled by the administrator
Given the administrator has updated system config key "enable_previews" with value "false" and type "boolean"
And user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
When user "user0" downloads the preview of "/parent.txt" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "404"
And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\NotFound"

Scenario: unset maximum size of previews
Given user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
And the administrator has updated system config key "preview_max_x" with value "null"
Comment thread
phil-davis marked this conversation as resolved.
And the administrator has updated system config key "preview_max_y" with value "null"
When user "user0" downloads the preview of "/parent.txt" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "404"
And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\NotFound"

Scenario: set maximum size of previews
Comment thread
phil-davis marked this conversation as resolved.
Given user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
When the administrator updates system config key "preview_max_x" with value "null" using the occ command
And the administrator updates system config key "preview_max_y" with value "null" using the occ command
Comment on lines +136 to +137

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the test would be something like:

Suggested change
When the administrator updates system config key "preview_max_x" with value "null" using the occ command
And the administrator updates system config key "preview_max_y" with value "null" using the occ command
When the administrator updates system config key "preview_max_x" with value "32" using the occ command
And the administrator updates system config key "preview_max_y" with value "32" using the occ command

And then try to download a preview of size 64x64.

And see what happens.

Then the HTTP status code should be "201"
When user "user0" downloads the preview of "/parent.txt" with width "null" and height "null" using the WebDAV API
Then the HTTP status code should be "400"
And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\BadRequest"
76 changes: 74 additions & 2 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ public function getDavPath($for = null) {
* @param bool $stream Set to true to stream a response rather
* than download it all up-front.
* @param string|null $password
* @param array $urlParameter
* @param string $doDavRequestAsUser
*
* @return ResponseInterface
*/
Expand All @@ -315,7 +317,9 @@ public function makeDavRequest(
$type = "files",
$davPathVersion = null,
$stream = false,
$password = null
$password = null,
$urlParameter = [],
$doDavRequestAsUser = null
) {
if ($this->customDavPath !== null) {
$path = $this->customDavPath . $path;
Expand All @@ -332,7 +336,28 @@ public function makeDavRequest(
$this->getBaseUrl(),
$user, $password, $method,
$path, $headers, $body, $davPathVersion,
$type, null, "basic", $stream, $this->httpRequestTimeout
$type, null, "basic", $stream, $this->httpRequestTimeout, null, $urlParameter, $doDavRequestAsUser
);
}

/**
* @param $user
* @param $path
* @param $doDavRequestAsUser
* @param $width
* @param $height
*
* @return ResponseInterface
*/
public function downloadPreviews($user, $path, $doDavRequestAsUser, $width, $height) {
$urlParameter = [
'x' => $width,
'y' => $height,
'forceIcon' => '0',
'preview' => '1'
];
$this->response = $this->makeDavRequest(
$user, "GET", $path, [], null, "files", 2, false, null, $urlParameter, $doDavRequestAsUser
);
}

Expand Down Expand Up @@ -2925,6 +2950,53 @@ public function userHasDeletedEverythingInFolder($user, $folder) {
$this->userDeletesEverythingInFolder($user, $folder, true);
}

/**
* @When user :user downloads the preview of :path with width :width and height :height using the WebDAV API
*
* @param $user
* @param $path
* @param $width
* @param $height
*
* @return void
*/
public function downloadPreviewOfFiles($user, $path, $width, $height) {
$this->downloadPreviews(
$user, $path, null, $width, $height
);
}

/**
* @When user :user1 downloads the preview of :path of :user2 with width :width and height :height using the WebDAV API
*
* @param $user1
* @param $path
* @param $doDavRequestAsUser
* @param $width
* @param $height
*
* @return void
*/
public function downloadPreviewOfOtherUser($user1, $path, $doDavRequestAsUser, $width, $height) {
Comment thread
phil-davis marked this conversation as resolved.
$this->downloadPreviews(
$user1, $path, $doDavRequestAsUser, $width, $height
);
}

/**
* @Then the downloaded image should be :width pixels wide and :height pixels high
*
* @param $width
* @param $height
*
* @return void
*/
public function imageDimensionsShouldBe($width, $height) {
$size = \getimagesizefromstring($this->response->getBody()->getContents());
Assert::assertNotFalse($size, "could not get size of image");
Assert::assertEquals($width, $size[0], "width not as expected");
Assert::assertEquals($height, $size[1], "height not as expected");
}
/**
* @param string $user
* @param string $path
Expand Down