diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index 05f577c8a228..d54c19192964 100644 --- a/tests/TestHelpers/WebDavHelper.php +++ b/tests/TestHelpers/WebDavHelper.php @@ -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 */ @@ -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') { diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 05015c87d0ac..a00e3784eb1a 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -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' diff --git a/tests/acceptance/features/apiWebdavPreviews/previews.feature b/tests/acceptance/features/apiWebdavPreviews/previews.feature new file mode 100644 index 000000000000..a535270800d9 --- /dev/null +++ b/tests/acceptance/features/apiWebdavPreviews/previews.feature @@ -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 and height using the WebDAV API + Then the HTTP status code should be "200" + And the downloaded image should be pixels wide and 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 "" 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 "" 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/" to "/" + When user "user0" downloads the preview of "/" 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/" to "/" + When user "user0" downloads the preview of "/" 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: + | 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" + 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 + 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 + 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" diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 3f7a648c88f0..9041ae2bd0a9 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -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 */ @@ -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; @@ -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 ); } @@ -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) { + $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