From ad47e05061880681186894ba6c01bd97988ce09a Mon Sep 17 00:00:00 2001 From: Parajuli Kiran Date: Mon, 4 Apr 2022 17:25:01 +0545 Subject: [PATCH 1/2] Decode href value before assertions Signed-off-by: Parajuli Kiran --- .../getFileProperties.feature | 96 +++++++++---------- .../bootstrap/WebDavPropertiesContext.php | 27 ++++-- 2 files changed, 67 insertions(+), 56 deletions(-) diff --git a/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature b/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature index 715f261b7871..07eca8dd5def 100644 --- a/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature +++ b/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature @@ -41,25 +41,25 @@ Feature: get file properties When user "Alice" gets the properties of file "" using the WebDAV API Then the HTTP status code should be "201" And the properties response should contain an etag - And the value of the item "//d:response/d:href" in the response to user "Alice" should match "//" - Examples: - | dav_version | file_name | expected_href | - | old | /C++ file.cpp | remote\.php\/webdav\/C%2[bB]%2[bB]%20file\.cpp | - | old | /file #2.txt | remote\.php\/webdav\/file%20%232\.txt | - | old | /file ?2.txt | remote\.php\/webdav\/file%20%3[fF]2\.txt | - | old | /file &2.txt | remote\.php\/webdav\/file%20%262\.txt | - | new | /C++ file.cpp | remote\.php\/dav\/files\/%username%\/C%2[bB]%2[bB]%20file\.cpp | - | new | /file #2.txt | remote\.php\/dav\/files\/%username%\/file%20%232\.txt | - | new | /file ?2.txt | remote\.php\/dav\/files\/%username%\/file%20%3[fF]2\.txt | - | new | /file &2.txt | remote\.php\/dav\/files\/%username%\/file%20%262\.txt | + And there should be an entry with href containing "" in the response to user "Alice" + Examples: + | dav_version | file_name | expected_href | + | old | /C++ file.cpp | remote.php/webdav/C++ file.cpp | + | old | /file #2.txt | remote.php/webdav/file #2.txt | + | old | /file ?2.txt | remote.php/webdav/file ?2.txt | + | old | /file &2.txt | remote.php/webdav/file &2.txt | + | new | /C++ file.cpp | remote.php/dav/files/%username%/C++ file.cpp | + | new | /file #2.txt | remote.php/dav/files/%username%/file #2.txt | + | new | /file ?2.txt | remote.php/dav/files/%username%/file ?2.txt | + | new | /file &2.txt | remote.php/dav/files/%username%/file &2.txt | @skipOnOcV10 @personalSpace Examples: - | dav_version | file_name | expected_href | - | spaces | /C++ file.cpp | dav\/spaces\/%spaceid%\/C%2[bB]%2[bB]%20file\.cpp | - | spaces | /file #2.txt | dav\/spaces\/%spaceid%\/file%20%232\.txt | - | spaces | /file ?2.txt | dav\/spaces\/%spaceid%\/file%20%3[fF]2\.txt | - | spaces | /file &2.txt | dav\/spaces\/%spaceid%\/file%20%262\.txt | + | dav_version | file_name | expected_href | + | spaces | /C++ file.cpp | dav/spaces/%spaceid%/C++ file.cpp | + | spaces | /file #2.txt | dav/spaces/%spaceid%/file #2.txt | + | spaces | /file ?2.txt | dav/spaces/%spaceid%/file ?2.txt | + | spaces | /file &2.txt | dav/spaces/%spaceid%/file &2.txt | @issue-ocis-reva-214 Scenario Outline: Do a PROPFIND of various folder names @@ -69,36 +69,36 @@ Feature: get file properties And user "Alice" has uploaded file with content "uploaded content" to "/file2.txt" When user "Alice" gets the properties of folder "" with depth 1 using the WebDAV API Then the HTTP status code should be "201" - And there should be an entry with href matching "/\//" in the response to user "Alice" - And there should be an entry with href matching "/\/file1.txt/" in the response to user "Alice" - And there should be an entry with href matching "/\/file2.txt/" in the response to user "Alice" - Examples: - | dav_version | folder_name | expected_href | - | old | /upload | remote\.php\/webdav\/upload | - | old | /strängé folder | remote\.php\/webdav\/str%[cC]3%[aA]4ng%[cC]3%[aA]9%20folder | - | old | /C++ folder | remote\.php\/webdav\/C%2[bB]%2[bB]%20folder | - | old | /नेपाली | remote\.php\/webdav\/%[eE]0%[aA]4%[aA]8%[eE]0%[aA]5%87%[eE]0%[aA]4%[aA]a%[eE]0%[aA]4%be%[eE]0%[aA]4%b2%[eE]0%[aA]5%80 | - | old | /folder #2.txt | remote\.php\/webdav\/folder%20%232\.txt | - | old | /folder ?2.txt | remote\.php\/webdav\/folder%20%3[fF]2\.txt | - | old | /folder &2.txt | remote\.php\/webdav\/folder%20%262\.txt | - | new | /upload | remote\.php\/dav\/files\/%username%\/upload | - | new | /strängé folder | remote\.php\/dav\/files\/%username%\/str%[cC]3%[aA]4ng%[cC]3%[aA]9%20folder | - | new | /C++ folder | remote\.php\/dav\/files\/%username%\/C%2[bB]%2[bB]%20folder | - | new | /नेपाली | remote\.php\/dav\/files\/%username%\/%[eE]0%[aA]4%[aA]8%[eE]0%[aA]5%87%[eE]0%[aA]4%[aA]a%[eE]0%[aA]4%be%[eE]0%[aA]4%b2%[eE]0%[aA]5%80 | - | new | /folder #2.txt | remote\.php\/dav\/files\/%username%\/folder%20%232\.txt | - | new | /folder ?2.txt | remote\.php\/dav\/files\/%username%\/folder%20%3[fF]2\.txt | - | new | /folder &2.txt | remote\.php\/dav\/files\/%username%\/folder%20%262\.txt | + And there should be an entry with href containing "/" in the response to user "Alice" + And there should be an entry with href containing "/file1.txt" in the response to user "Alice" + And there should be an entry with href containing "/file2.txt" in the response to user "Alice" + Examples: + | dav_version | folder_name | expected_href | + | old | /upload | remote.php/webdav/upload | + | old | /strängé folder | remote.php/webdav/strängé folder | + | old | /C++ folder | remote.php/webdav/C++ folder | + | old | /नेपाली | remote.php/webdav/नेपाली | + | old | /folder #2.txt | remote.php/webdav/folder #2.txt | + | old | /folder ?2.txt | remote.php/webdav/folder ?2.txt | + | old | /folder &2.txt | remote.php/webdav/folder &2.txt | + | new | /upload | remote.php/dav/files/%username%/upload | + | new | /strängé folder | remote.php/dav/files/%username%/strängé folder | + | new | /C++ folder | remote.php/dav/files/%username%/C++ folder | + | new | /नेपाली | remote.php/dav/files/%username%/नेपाली | + | new | /folder #2.txt | remote.php/dav/files/%username%/folder #2.txt | + | new | /folder ?2.txt | remote.php/dav/files/%username%/folder ?2.txt | + | new | /folder &2.txt | remote.php/dav/files/%username%/folder &2.txt | @skipOnOcV10 @personalSpace Examples: - | dav_version | folder_name | expected_href | - | spaces | /upload | dav\/spaces\/%spaceid%\/upload | - | spaces | /strängé folder | dav\/spaces\/%spaceid%\/str%[cC]3%[aA]4ng%[cC]3%[aA]9%20folder | - | spaces | /C++ folder | dav\/spaces\/%spaceid%\/C%2[bB]%2[bB]%20folder | - | spaces | /नेपाली | dav\/spaces\/%spaceid%\/%[eE]0%[aA]4%[aA]8%[eE]0%[aA]5%87%[eE]0%[aA]4%[aA]a%[eE]0%[aA]4%be%[eE]0%[aA]4%b2%[eE]0%[aA]5%80 | - | spaces | /folder #2.txt | dav\/spaces\/%spaceid%\/folder%20%232\.txt | - | spaces | /folder ?2.txt | dav\/spaces\/%spaceid%\/folder%20%3[fF]2\.txt | - | spaces | /folder &2.txt | dav\/spaces\/%spaceid%\/folder%20%262\.txt | + | dav_version | folder_name | expected_href | + | spaces | /upload | dav/spaces/%spaceid%/upload | + | spaces | /strängé folder | dav/spaces/%spaceid%/strängé folder | + | spaces | /C++ folder | dav/spaces/%spaceid%/C++ folder | + | spaces | /नेपाली | dav/spaces/%spaceid%/नेपाली | + | spaces | /folder #2.txt | dav/spaces/%spaceid%/folder #2.txt | + | spaces | /folder ?2.txt | dav/spaces/%spaceid%/folder ?2.txt | + | spaces | /folder &2.txt | dav/spaces/%spaceid%/folder &2.txt | Scenario Outline: Do a PROPFIND of various files inside various folders @@ -113,12 +113,12 @@ Feature: get file properties | old | /upload | abc.txt | | old | /strängé folder | strängé file.txt | | old | /C++ folder | C++ file.cpp | - | old | /नेपाली | नेपाली | + | old | /नेपाली | नेपाली | | old | /folder #2.txt | file #2.txt | | new | /upload | abc.txt | | new | /strängé folder (duplicate #2 &) | strängé file (duplicate #2 &) | | new | /C++ folder | C++ file.cpp | - | new | /नेपाली | नेपाली | + | new | /नेपाली | नेपाली | | new | /folder #2.txt | file #2.txt | @skipOnOcV10 @personalSpace @@ -127,7 +127,7 @@ Feature: get file properties | spaces | /upload | abc.txt | | spaces | /strängé folder | strängé file.txt | | spaces | /C++ folder | C++ file.cpp | - | spaces | /नेपाली | नेपाली | + | spaces | /नेपाली | नेपाली | | spaces | /folder #2.txt | file #2.txt | @issue-ocis-reva-265 @@ -370,7 +370,7 @@ Feature: get file properties | spaces | @issue-36920 - @skipOnOcV10.3 @skipOnOcV10.4.0 @issue-ocis-reva-217 + @skipOnOcV10.3 @skipOnOcV10.4.0 @issue-ocis-reva-217 Scenario Outline: add multiple properties to files inside a folder and do a propfind of the parent folder Given using DAV path And user "Alice" has created folder "/TestFolder" @@ -655,4 +655,4 @@ Feature: get file properties @skipOnOcV10 @personalSpace Examples: | dav_version | - | spaces | \ No newline at end of file + | spaces | diff --git a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php index b459786922d9..444283967280 100644 --- a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php +++ b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php @@ -776,15 +776,15 @@ public function publicGetsThePropertiesOfFolderAndAssertValueOfItemInResponseReg } /** - * @Then there should be an entry with href matching :pattern in the response to user :user + * @Then there should be an entry with href containing :expectedHref in the response to user :user * - * @param string $pattern + * @param string $expectedHref * @param string $user * * @return void * @throws Exception */ - public function assertEntryWithHrefMatchingRegExpInResponseToUser(string $pattern, string $user):void { + public function assertEntryWithHrefMatchingRegExpInResponseToUser(string $expectedHref, string $user):void { $resXml = $this->featureContext->getResponseXmlObject(); if ($resXml === null) { $resXml = HttpRequestHelper::getResponseXml( @@ -794,8 +794,8 @@ public function assertEntryWithHrefMatchingRegExpInResponseToUser(string $patter } $user = $this->featureContext->getActualUsername($user); - $pattern = $this->featureContext->substituteInLineCodes( - $pattern, + $expectedHref = $this->featureContext->substituteInLineCodes( + $expectedHref, $user, ['preg_quote' => ['/']] ); @@ -808,11 +808,22 @@ public function assertEntryWithHrefMatchingRegExpInResponseToUser(string $patter // If we have run out of entries in the response, then fail the test Assert::assertTrue( isset($xmlPart[0]), - "Cannot find any entry with href matching $pattern in response to $user" + "Cannot find any entry having href with value $expectedHref in response to $user" ); $value = $xmlPart[0]->__toString(); - if (\preg_match($pattern, $value) === 1) { - break; + $decodedValue = \rawurldecode($value); + // for folders decoded value will be like: "/owncloud/core/remote.php/webdav/strängé folder/" + // expected href should be like: "remote.php/webdav/strängé folder/" + // for files decoded value will be like: "/owncloud/core/remote.php/ebdav/strängé folder/file.txt" + // expected href should be like: "remote.php/webdav/strängé folder/file.txt" + $explodeDecoded = \explode('/', $decodedValue); + $remotePhpIndex = \array_search('remote.php', $explodeDecoded); + if ($remotePhpIndex) { + $explodedHrefPartArray = \array_slice($explodeDecoded, $remotePhpIndex); + $actualHrefPart = \implode('/', $explodedHrefPartArray); + if ($actualHrefPart === $expectedHref) { + break; + } } } } From 589c426d801d9f176a8c7c395714afb06f116445 Mon Sep 17 00:00:00 2001 From: Kiran Parajuli Date: Tue, 5 Apr 2022 11:35:45 +0545 Subject: [PATCH 2/2] Fix href case for spaces webdav Signed-off-by: Kiran Parajuli --- .../bootstrap/WebDavPropertiesContext.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php index 444283967280..09de8965f230 100644 --- a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php +++ b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php @@ -812,15 +812,25 @@ public function assertEntryWithHrefMatchingRegExpInResponseToUser(string $expect ); $value = $xmlPart[0]->__toString(); $decodedValue = \rawurldecode($value); - // for folders decoded value will be like: "/owncloud/core/remote.php/webdav/strängé folder/" + // for folders, decoded value will be like: "/owncloud/core/remote.php/webdav/strängé folder/" // expected href should be like: "remote.php/webdav/strängé folder/" - // for files decoded value will be like: "/owncloud/core/remote.php/ebdav/strängé folder/file.txt" + // for files, decoded value will be like: "/owncloud/core/remote.php/webdav/strängé folder/file.txt" // expected href should be like: "remote.php/webdav/strängé folder/file.txt" $explodeDecoded = \explode('/', $decodedValue); - $remotePhpIndex = \array_search('remote.php', $explodeDecoded); + // get the first item of the expected href. + // i.e remote.php from "remote.php/webdav/strängé folder/file.txt" + // or dav from "dav/spaces/%spaceid%/C++ file.cpp" + $explodeExpected = \explode('/', $expectedHref); + $remotePhpIndex = \array_search($explodeExpected[0], $explodeDecoded); if ($remotePhpIndex) { $explodedHrefPartArray = \array_slice($explodeDecoded, $remotePhpIndex); $actualHrefPart = \implode('/', $explodedHrefPartArray); + if ($this->featureContext->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES) { + // for spaces webdav, space id is included in the href + // space id from our helper is returned as d8c029e0\-2bc9\-4b9a\-8613\-c727e5417f05 + // so we've to remove "\" before every "-" + $expectedHref = str_replace('\-', '-', $expectedHref); + } if ($actualHrefPart === $expectedHref) { break; }