From 9abff5bdeea45e6ca37d4426987f642b4011e084 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Wed, 25 Mar 2020 18:08:13 +0545 Subject: [PATCH 1/8] test webdav previews --- tests/TestHelpers/WebDavHelper.php | 4 +- tests/acceptance/config/behat.yml | 8 ++ .../apiWebdavPreviews/previews.feature | 79 +++++++++++++++++++ .../acceptance/features/bootstrap/WebDav.php | 30 +++++++ 4 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 tests/acceptance/features/apiWebdavPreviews/previews.feature diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index 05f577c8a228..7f5f86d46423 100644 --- a/tests/TestHelpers/WebDavHelper.php +++ b/tests/TestHelpers/WebDavHelper.php @@ -365,8 +365,8 @@ public static function makeDavRequest( $baseUrl = self::sanitizeUrl($baseUrl, true); $davPath = self::getDavPath($user, $davPathVersionToUse, $type); //replace %, # and ? and in the path, Guzzle will not encode them - $urlSpecialChar = [['%', '#', '?'],['%25', '%23', '%3F']]; - $path = \str_replace($urlSpecialChar[0], $urlSpecialChar[1], $path); + // $urlSpecialChar = [['%', '#', '?'],['%25', '%23', '%3F']]; + // $path = \str_replace($urlSpecialChar[0], $urlSpecialChar[1], $path); $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..a9b7175cb7ab 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -350,6 +350,14 @@ default: - WebDavPropertiesContext: - TagsContext: + apiWebdavPreviews: + paths: + - '%paths.base%/../features/apiWebdavPreviews' + context: *common_ldap_suite_context + contexts: + - FeatureContext: *common_feature_context_params + - WebDavPropertiesContext: + 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..b06499b9d632 --- /dev/null +++ b/tests/acceptance/features/apiWebdavPreviews/previews.feature @@ -0,0 +1,79 @@ +@api @TestAlsoOnExternalUserBackend +Feature: previews of files downloaded thought 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 pixel wide and pixel high + Examples: + | width | height | + | 1 | 1 | + | 32 | 32 | + | 1024 | 1024 | + | 1 | 1024 | + | 1024 | 1 | + + @issue-37165 + 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 "500" + #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 "Exception" + Examples: + | width | + | 0 | + | -1 | + | false | + | true | + | A | + | %2F | + + @issue-37165 + 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 "500" + #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 "Exception" + Examples: + | height | + | 0 | + | 0.5 | + | -1 | + | 1.5 | + | 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" pixel wide and "32" pixel high + + Scenario: download previews of different file types + + Scenario: download previews of shared files + + Scenario: download previews of other users files + + 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 "500" + And the body of the response should be empty + + Scenario: download previews of not-existing files + + Scenario: disable previews + + Scenario: set maximum size of previews diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 3f7a648c88f0..0ee79d86eed7 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -2925,6 +2925,36 @@ 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 downloadPreview($user, $path, $width, $height) { + $this->response = $this->makeDavRequest( + $user, "GET", $path . "?x=$width&y=$height&forceIcon=0&preview=1", [], null, "files", 2 + ); + } + + /** + * @Then the downloaded image should be :width pixel wide and :height pixel 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 From 39c0011e672690ca0d264df55a40c83b73170805 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Thu, 26 Mar 2020 11:46:18 +0545 Subject: [PATCH 2/8] more tests --- .../acceptance/features/apiWebdavPreviews/previews.feature | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/acceptance/features/apiWebdavPreviews/previews.feature b/tests/acceptance/features/apiWebdavPreviews/previews.feature index b06499b9d632..369db3dfd5f4 100644 --- a/tests/acceptance/features/apiWebdavPreviews/previews.feature +++ b/tests/acceptance/features/apiWebdavPreviews/previews.feature @@ -63,6 +63,12 @@ Feature: previews of files downloaded thought the webdav API Scenario: download previews of different file types 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" pixel wide and "32" pixel high Scenario: download previews of other users files From 6f02979a30edb697fba2ebe834fd05d1a7ae8916 Mon Sep 17 00:00:00 2001 From: swoichha Date: Mon, 30 Mar 2020 16:11:58 +0545 Subject: [PATCH 3/8] added more tests --- tests/TestHelpers/WebDavHelper.php | 2 +- .../apiWebdavPreviews/previews.feature | 50 +++++++++++++++---- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index 7f5f86d46423..29f36e901dc2 100644 --- a/tests/TestHelpers/WebDavHelper.php +++ b/tests/TestHelpers/WebDavHelper.php @@ -365,7 +365,7 @@ public static function makeDavRequest( $baseUrl = self::sanitizeUrl($baseUrl, true); $davPath = self::getDavPath($user, $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); $fullUrl = self::sanitizeUrl($baseUrl . $davPath . $path); diff --git a/tests/acceptance/features/apiWebdavPreviews/previews.feature b/tests/acceptance/features/apiWebdavPreviews/previews.feature index 369db3dfd5f4..24900e186b68 100644 --- a/tests/acceptance/features/apiWebdavPreviews/previews.feature +++ b/tests/acceptance/features/apiWebdavPreviews/previews.feature @@ -17,14 +17,12 @@ Feature: previews of files downloaded thought the webdav API | 1 | 1024 | | 1024 | 1 | - @issue-37165 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 "500" - #Then the HTTP status code should be "400" + 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 "Exception" + And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\BadRequest" Examples: | width | | 0 | @@ -34,14 +32,12 @@ Feature: previews of files downloaded thought the webdav API | A | | %2F | - @issue-37165 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 "500" - #Then the HTTP status code should be "400" + 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 "Exception" + And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\BadRequest" Examples: | height | | 0 | @@ -60,7 +56,33 @@ Feature: previews of files downloaded thought the webdav API Then the HTTP status code should be "200" And the downloaded image should be "32" pixel wide and "32" pixel high - Scenario: download previews of different file types + Scenario Outline: download previews of different 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 "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 | + + Scenario Outline: download previews of different image file types + Given user "user0" has uploaded file "filesForUpload/" to "/testimage.jpg" + When user "user0" downloads the preview of "/testimage.jpg" 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" pixel wide and "32" pixel high + Examples: + |imageName| + |testavatar.jpg| + |testavatar.png| + + 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" pixel wide and "32" pixel high Scenario: download previews of shared files Given user "user1" has been created with default attributes and without skeleton files @@ -71,6 +93,12 @@ Feature: previews of files downloaded thought the webdav API And the downloaded image should be "32" pixel wide and "32" pixel 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" 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 previews of folders Given user "user0" has created folder "subfolder" @@ -79,6 +107,10 @@ Feature: previews of files downloaded thought the webdav API And the body of the response should be empty 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: disable previews From 3fec16aa642eef68a5185bbce9a2e39f97924a8f Mon Sep 17 00:00:00 2001 From: swoichha Date: Tue, 31 Mar 2020 17:18:00 +0545 Subject: [PATCH 4/8] added test scenarios for disable previews and set maximum size of previews --- tests/acceptance/config/behat.yml | 1 + .../apiWebdavPreviews/previews.feature | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index a9b7175cb7ab..a00e3784eb1a 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -357,6 +357,7 @@ default: contexts: - FeatureContext: *common_feature_context_params - WebDavPropertiesContext: + - OccContext: apiWebdavProperties: paths: diff --git a/tests/acceptance/features/apiWebdavPreviews/previews.feature b/tests/acceptance/features/apiWebdavPreviews/previews.feature index 24900e186b68..415ddc6c1f2f 100644 --- a/tests/acceptance/features/apiWebdavPreviews/previews.feature +++ b/tests/acceptance/features/apiWebdavPreviews/previews.feature @@ -26,6 +26,7 @@ Feature: previews of files downloaded thought the webdav API Examples: | width | | 0 | + | 0.5 | | -1 | | false | | true | @@ -43,7 +44,6 @@ Feature: previews of files downloaded thought the webdav API | 0 | | 0.5 | | -1 | - | 1.5 | | false | | true | | A | @@ -68,14 +68,14 @@ Feature: previews of files downloaded thought the webdav API | new-data.zip | test.zip | Scenario Outline: download previews of different image file types - Given user "user0" has uploaded file "filesForUpload/" to "/testimage.jpg" - When user "user0" downloads the preview of "/testimage.jpg" with width "32" and height "32" using the WebDAV API + 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" pixel wide and "32" pixel high Examples: - |imageName| - |testavatar.jpg| - |testavatar.png| + | imageName | newImageName | + | testavatar.jpg | testimage.jpg | + | testavatar.png | testimage.png | Scenario: download previews of image after renaming it Given user "user0" has uploaded file "filesForUpload/testavatar.jpg" to "/testimage.jpg" @@ -103,8 +103,9 @@ Feature: previews of files downloaded thought the webdav API 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 "500" - And the body of the response should be empty + 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 @@ -113,5 +114,15 @@ Feature: previews of files downloaded thought the webdav API And the value of the item "/d:error/s:exception" in the response should be "Sabre\DAV\Exception\NotFound" Scenario: disable previews + 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: set maximum size of previews + Given user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt" + 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: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" From 762c15bdb96b5a421b9741e4f40c932fc2673779 Mon Sep 17 00:00:00 2001 From: swoichha Date: Wed, 1 Apr 2020 14:04:14 +0545 Subject: [PATCH 5/8] made changes in WebDav and WebDavHelper to pass special character in path --- tests/TestHelpers/WebDavHelper.php | 22 ++++++++--- .../apiWebdavPreviews/previews.feature | 15 +++---- .../acceptance/features/bootstrap/WebDav.php | 39 +++++++++++++++++-- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index 29f36e901dc2..cacac2a36305 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 $user2 * * @return ResponseInterface */ @@ -360,13 +362,24 @@ public static function makeDavRequest( $authType = "basic", $stream = false, $timeout = 0, - $client = null + $client = null, + $urlParameter = [], + $user2 = null ) { $baseUrl = self::sanitizeUrl($baseUrl, true); - $davPath = self::getDavPath($user, $davPathVersionToUse, $type); + if ($user2 === null) { + $davPath = self::getDavPath($user, $davPathVersionToUse, $type); + } else { + $davPath = self::getDavPath($user2, $davPathVersionToUse, $type); + } //replace %, # and ? and in the path, Guzzle will not encode them - // $urlSpecialChar = [['%', '#', '?'],['%25', '%23', '%3F']]; - // $path = \str_replace($urlSpecialChar[0], $urlSpecialChar[1], $path); + $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') { @@ -403,7 +416,6 @@ public static function makeDavRequest( * @param int $davPathVersionToUse (1|2) * @param string $type * - * @throws InvalidArgumentException * @return string */ public static function getDavPath( diff --git a/tests/acceptance/features/apiWebdavPreviews/previews.feature b/tests/acceptance/features/apiWebdavPreviews/previews.feature index 415ddc6c1f2f..cf316d697382 100644 --- a/tests/acceptance/features/apiWebdavPreviews/previews.feature +++ b/tests/acceptance/features/apiWebdavPreviews/previews.feature @@ -1,5 +1,5 @@ @api @TestAlsoOnExternalUserBackend -Feature: previews of files downloaded thought the webdav API +Feature: previews of files downloaded through the webdav API Background: Given user "user0" has been created with default attributes and without skeleton files @@ -95,9 +95,9 @@ Feature: previews of files downloaded thought the webdav API 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" with width "32" and height "32" using the WebDAV API + 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 with name parent.txt could not be located" + 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 @@ -122,7 +122,8 @@ Feature: previews of files downloaded thought the webdav API Scenario: set maximum size of previews Given user "user0" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt" - 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: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" + 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" diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 0ee79d86eed7..baffdf490b8f 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 $user2 * * @return ResponseInterface */ @@ -315,7 +317,9 @@ public function makeDavRequest( $type = "files", $davPathVersion = null, $stream = false, - $password = null + $password = null, + $urlParameter = [], + $user2 = null ) { if ($this->customDavPath !== null) { $path = $this->customDavPath . $path; @@ -332,7 +336,7 @@ 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, $user2 ); } @@ -2936,8 +2940,37 @@ public function userHasDeletedEverythingInFolder($user, $folder) { * @return void */ public function downloadPreview($user, $path, $width, $height) { + $urlParameter = [ + 'x' => $width, + 'y' => $height, + 'forceIcon' => '0', + 'preview' => '1' + ]; $this->response = $this->makeDavRequest( - $user, "GET", $path . "?x=$width&y=$height&forceIcon=0&preview=1", [], null, "files", 2 + $user, "GET", $path, [], null, "files", 2, false, null, $urlParameter + ); + } + + /** + * @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 $user2 + * @param $width + * @param $height + * + * @return ResponseInterface + */ + public function downloadPreviewOfOtherUser($user1, $path, $user2, $width, $height) { + $urlParameter = [ + 'x' => $width, + 'y' => $height, + 'forceIcon' => '0', + 'preview' => '1' + ]; + $this->response = $this->makeDavRequest( + $user1, "GET", $path, [], null, "files", 2, false, null, $urlParameter, $user2 ); } From 9afe6816487390bbe3b4db266ad22a7099850080 Mon Sep 17 00:00:00 2001 From: swoichha Date: Mon, 6 Apr 2020 11:03:57 +0545 Subject: [PATCH 6/8] few scenario title changed --- tests/TestHelpers/WebDavHelper.php | 8 ++++---- .../features/apiWebdavPreviews/previews.feature | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index cacac2a36305..ec8ac05d289b 100644 --- a/tests/TestHelpers/WebDavHelper.php +++ b/tests/TestHelpers/WebDavHelper.php @@ -344,7 +344,7 @@ public static function listFolder( * @param int $timeout * @param Client|null $client * @param array $urlParameter to concatenate with path - * @param string $user2 + * @param string $doDavRequestAsUser run the DAV as this user, if null its same as $user * * @return ResponseInterface */ @@ -364,13 +364,13 @@ public static function makeDavRequest( $timeout = 0, $client = null, $urlParameter = [], - $user2 = null + $doDavRequestAsUser = null ) { $baseUrl = self::sanitizeUrl($baseUrl, true); - if ($user2 === null) { + if ($doDavRequestAsUser === null) { $davPath = self::getDavPath($user, $davPathVersionToUse, $type); } else { - $davPath = self::getDavPath($user2, $davPathVersionToUse, $type); + $davPath = self::getDavPath($doDavRequestAsUser, $davPathVersionToUse, $type); } //replace %, # and ? and in the path, Guzzle will not encode them $urlSpecialChar = [['%', '#', '?'], ['%25', '%23', '%3F']]; diff --git a/tests/acceptance/features/apiWebdavPreviews/previews.feature b/tests/acceptance/features/apiWebdavPreviews/previews.feature index cf316d697382..4982239511e1 100644 --- a/tests/acceptance/features/apiWebdavPreviews/previews.feature +++ b/tests/acceptance/features/apiWebdavPreviews/previews.feature @@ -56,7 +56,7 @@ Feature: previews of files downloaded through the webdav API Then the HTTP status code should be "200" And the downloaded image should be "32" pixel wide and "32" pixel high - Scenario Outline: download previews of different file types + Scenario Outline: download previews of file types that doesn'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" @@ -113,7 +113,7 @@ Feature: previews of files downloaded through the webdav API 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: disable previews + Scenario: Download file previews when it 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 From d3c099923145db7cac7b210466fbfce27966bd1e Mon Sep 17 00:00:00 2001 From: swoichha Date: Tue, 7 Apr 2020 16:55:14 +0545 Subject: [PATCH 7/8] added issue tag --- .../features/apiWebdavPreviews/previews.feature | 5 ++++- tests/acceptance/features/bootstrap/WebDav.php | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/acceptance/features/apiWebdavPreviews/previews.feature b/tests/acceptance/features/apiWebdavPreviews/previews.feature index 4982239511e1..3d15d7d232e0 100644 --- a/tests/acceptance/features/apiWebdavPreviews/previews.feature +++ b/tests/acceptance/features/apiWebdavPreviews/previews.feature @@ -1,4 +1,5 @@ @api @TestAlsoOnExternalUserBackend +@skipOnOcis Feature: previews of files downloaded through the webdav API Background: @@ -67,6 +68,7 @@ Feature: previews of files downloaded through the webdav API | 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 @@ -77,6 +79,7 @@ Feature: previews of files downloaded through the webdav API | 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 @@ -113,7 +116,7 @@ Feature: previews of files downloaded through the webdav API 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 disabled by the administrator + 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 diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index baffdf490b8f..03f77fc6e1b8 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -304,7 +304,7 @@ public function getDavPath($for = null) { * than download it all up-front. * @param string|null $password * @param array $urlParameter - * @param string $user2 + * @param string $doDavRequestAsUser * * @return ResponseInterface */ @@ -319,7 +319,7 @@ public function makeDavRequest( $stream = false, $password = null, $urlParameter = [], - $user2 = null + $doDavRequestAsUser = null ) { if ($this->customDavPath !== null) { $path = $this->customDavPath . $path; @@ -336,7 +336,7 @@ public function makeDavRequest( $this->getBaseUrl(), $user, $password, $method, $path, $headers, $body, $davPathVersion, - $type, null, "basic", $stream, $this->httpRequestTimeout, null, $urlParameter, $user2 + $type, null, "basic", $stream, $this->httpRequestTimeout, null, $urlParameter, $doDavRequestAsUser ); } @@ -2956,13 +2956,13 @@ public function downloadPreview($user, $path, $width, $height) { * * @param $user1 * @param $path - * @param $user2 + * @param $doDavRequestAsUser * @param $width * @param $height * * @return ResponseInterface */ - public function downloadPreviewOfOtherUser($user1, $path, $user2, $width, $height) { + public function downloadPreviewOfOtherUser($user1, $path, $doDavRequestAsUser, $width, $height) { $urlParameter = [ 'x' => $width, 'y' => $height, @@ -2970,7 +2970,7 @@ public function downloadPreviewOfOtherUser($user1, $path, $user2, $width, $heigh 'preview' => '1' ]; $this->response = $this->makeDavRequest( - $user1, "GET", $path, [], null, "files", 2, false, null, $urlParameter, $user2 + $user1, "GET", $path, [], null, "files", 2, false, null, $urlParameter, $doDavRequestAsUser ); } From 0cc0426e1ad43f5f2a46300012c95e8fc3005139 Mon Sep 17 00:00:00 2001 From: swoichha Date: Wed, 8 Apr 2020 18:10:18 +0545 Subject: [PATCH 8/8] added test to set/unset preview size and downloadPreviews method --- tests/TestHelpers/WebDavHelper.php | 1 + .../apiWebdavPreviews/previews.feature | 23 ++++++--- .../acceptance/features/bootstrap/WebDav.php | 47 +++++++++++-------- 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index ec8ac05d289b..d54c19192964 100644 --- a/tests/TestHelpers/WebDavHelper.php +++ b/tests/TestHelpers/WebDavHelper.php @@ -416,6 +416,7 @@ public static function makeDavRequest( * @param int $davPathVersionToUse (1|2) * @param string $type * + * @throws InvalidArgumentException * @return string */ public static function getDavPath( diff --git a/tests/acceptance/features/apiWebdavPreviews/previews.feature b/tests/acceptance/features/apiWebdavPreviews/previews.feature index 3d15d7d232e0..a535270800d9 100644 --- a/tests/acceptance/features/apiWebdavPreviews/previews.feature +++ b/tests/acceptance/features/apiWebdavPreviews/previews.feature @@ -9,7 +9,7 @@ Feature: previews of files downloaded through the webdav API 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 pixel wide and pixel high + And the downloaded image should be pixels wide and pixels high Examples: | width | height | | 1 | 1 | @@ -55,9 +55,9 @@ Feature: previews of files downloaded through the webdav API 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" pixel wide and "32" pixel high + And the downloaded image should be "32" pixels wide and "32" pixels high - Scenario Outline: download previews of file types that doesn't support preview + 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" @@ -73,7 +73,7 @@ Feature: previews of files downloaded through the webdav API 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" pixel wide and "32" pixel high + And the downloaded image should be "32" pixels wide and "32" pixels high Examples: | imageName | newImageName | | testavatar.jpg | testimage.jpg | @@ -85,7 +85,7 @@ Feature: previews of files downloaded through the webdav API 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" pixel wide and "32" pixel high + 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 @@ -93,7 +93,7 @@ Feature: previews of files downloaded through the webdav API 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" pixel wide and "32" pixel high + 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 @@ -123,10 +123,19 @@ Feature: previews of files downloaded through 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 + 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 03f77fc6e1b8..9041ae2bd0a9 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -340,6 +340,27 @@ public function makeDavRequest( ); } + /** + * @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 + ); + } + /** * @When user :user tries to get versions of file :file from :fileOwner * @@ -2939,15 +2960,9 @@ public function userHasDeletedEverythingInFolder($user, $folder) { * * @return void */ - public function downloadPreview($user, $path, $width, $height) { - $urlParameter = [ - 'x' => $width, - 'y' => $height, - 'forceIcon' => '0', - 'preview' => '1' - ]; - $this->response = $this->makeDavRequest( - $user, "GET", $path, [], null, "files", 2, false, null, $urlParameter + public function downloadPreviewOfFiles($user, $path, $width, $height) { + $this->downloadPreviews( + $user, $path, null, $width, $height ); } @@ -2960,22 +2975,16 @@ public function downloadPreview($user, $path, $width, $height) { * @param $width * @param $height * - * @return ResponseInterface + * @return void */ public function downloadPreviewOfOtherUser($user1, $path, $doDavRequestAsUser, $width, $height) { - $urlParameter = [ - 'x' => $width, - 'y' => $height, - 'forceIcon' => '0', - 'preview' => '1' - ]; - $this->response = $this->makeDavRequest( - $user1, "GET", $path, [], null, "files", 2, false, null, $urlParameter, $doDavRequestAsUser + $this->downloadPreviews( + $user1, $path, $doDavRequestAsUser, $width, $height ); } /** - * @Then the downloaded image should be :width pixel wide and :height pixel high + * @Then the downloaded image should be :width pixels wide and :height pixels high * * @param $width * @param $height