From acaed2cf5217987592f77d4a66ec0ac6cad37db2 Mon Sep 17 00:00:00 2001 From: KarunAtreya Date: Fri, 6 Oct 2023 16:33:25 +0545 Subject: [PATCH 1/7] refactored given steps --- .../bootstrap/PublicWebDavContext.php | 105 +++++++++--------- .../bootstrap/WebDavLockingContext.php | 3 +- 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/tests/acceptance/features/bootstrap/PublicWebDavContext.php b/tests/acceptance/features/bootstrap/PublicWebDavContext.php index 8bb24e42a7d..af84a537a71 100644 --- a/tests/acceptance/features/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/features/bootstrap/PublicWebDavContext.php @@ -26,6 +26,7 @@ use PHPUnit\Framework\Assert; use TestHelpers\HttpRequestHelper; use TestHelpers\WebDavHelper; +use Psr\Http\Message\ResponseInterface; require_once 'bootstrap.php'; @@ -329,10 +330,10 @@ public function publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAnd * @param string $source target file name * @param string $publicWebDAVAPIVersion * - * @return void + * @return ResponseInterface */ - public function publiclyUploadingFile(string $source, string $publicWebDAVAPIVersion):void { - $this->publicUploadContent( + public function publiclyUploadingFile(string $source, string $publicWebDAVAPIVersion):ResponseInterface { + return $this->publicUploadContent( \basename($source), '', \file_get_contents($source), @@ -351,10 +352,11 @@ public function publiclyUploadingFile(string $source, string $publicWebDAVAPIVer * @return void */ public function thePublicUploadsFileUsingTheWebDAVApi(string $source, string $publicWebDAVAPIVersion):void { - $this->publiclyUploadingFile( + $response = $this->publiclyUploadingFile( $source, $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** @@ -425,11 +427,11 @@ public function thePublicCopiesFileUsingTheWebDAVApi(string $source, string $des * @return void */ public function thePublicHasUploadedFileUsingTheWebDAVApi(string $source, string $publicWebDAVAPIVersion):void { - $this->publiclyUploadingFile( + $response = $this->publiclyUploadingFile( $source, $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response); } /** @@ -439,10 +441,10 @@ public function thePublicHasUploadedFileUsingTheWebDAVApi(string $source, string * @param string $filename target file name * @param string $body content to upload * - * @return void + * @return ResponseInterface */ - public function publiclyUploadingContentAutoRename(string $filename, string $body = 'test'):void { - $this->publicUploadContent($filename, '', $body, true); + public function publiclyUploadingContentAutoRename(string $filename, string $body = 'test'):ResponseInterface { + return $this->publicUploadContent($filename, '', $body, true); } /** @@ -454,7 +456,8 @@ public function publiclyUploadingContentAutoRename(string $filename, string $bod * @return void */ public function thePublicUploadsFileWithContentWithAutoRenameMode(string $filename, string $body = 'test'):void { - $this->publiclyUploadingContentAutoRename($filename, $body); + $response = $this->publiclyUploadingContentAutoRename($filename, $body); + $this->featureContext->setResponse($response); } /** @@ -466,8 +469,8 @@ public function thePublicUploadsFileWithContentWithAutoRenameMode(string $filena * @return void */ public function thePublicHasUploadedFileWithContentWithAutoRenameMode(string $filename, string $body = 'test'):void { - $this->publiclyUploadingContentAutoRename($filename, $body); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $response = $this->publiclyUploadingContentAutoRename($filename, $body); + $this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response); } /** @@ -476,15 +479,15 @@ public function thePublicHasUploadedFileWithContentWithAutoRenameMode(string $fi * @param string $body content to upload * @param string $publicWebDAVAPIVersion * - * @return void + * @return ResponseInterface */ public function publiclyUploadingContentWithPassword( string $filename, string $password = '', string $body = 'test', string $publicWebDAVAPIVersion = "old" - ):void { - $this->publicUploadContent( + ):ResponseInterface { + return $this->publicUploadContent( $filename, $password, $body, @@ -510,12 +513,13 @@ public function thePublicUploadsFileWithPasswordAndContentUsingPublicWebDAVApi( string $body = 'test', string $publicWebDAVAPIVersion = "old" ):void { - $this->publiclyUploadingContentWithPassword( + $response = $this->publiclyUploadingContentWithPassword( $filename, $password, $body, $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** @@ -534,13 +538,13 @@ public function thePublicHasUploadedFileWithPasswordAndContentUsingPublicWebDAVA string $body = 'test', string $publicWebDAVAPIVersion = "old" ):void { - $this->publiclyUploadingContentWithPassword( + $response = $this->publiclyUploadingContentWithPassword( $filename, $password, $body, $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response); } /** @@ -548,10 +552,10 @@ public function thePublicHasUploadedFileWithPasswordAndContentUsingPublicWebDAVA * @param string $body content to upload * @param string $publicWebDAVAPIVersion * - * @return void + * @return ResponseInterface */ - public function publiclyOverwritingContent(string $filename, string $body = 'test', string $publicWebDAVAPIVersion = 'old'):void { - $this->publicUploadContent($filename, '', $body, false, [], $publicWebDAVAPIVersion); + public function publiclyOverwritingContent(string $filename, string $body = 'test', string $publicWebDAVAPIVersion = 'old'):ResponseInterface { + return $this->publicUploadContent($filename, '', $body, false, [], $publicWebDAVAPIVersion); } /** @@ -564,11 +568,12 @@ public function publiclyOverwritingContent(string $filename, string $body = 'tes * @return void */ public function thePublicOverwritesFileWithContentUsingWebDavApi(string $filename, string $body = 'test', string $publicWebDAVAPIVersion = 'old'):void { - $this->publiclyOverwritingContent( + $response = $this->publiclyOverwritingContent( $filename, $body, $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** @@ -580,11 +585,11 @@ public function thePublicOverwritesFileWithContentUsingWebDavApi(string $filenam * @return void */ public function thePublicHasOverwrittenFileWithContentUsingOldWebDavApi(string $filename, string $body = 'test'):void { - $this->publiclyOverwritingContent( + $response = $this->publiclyOverwritingContent( $filename, $body ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response); } /** @@ -592,14 +597,14 @@ public function thePublicHasOverwrittenFileWithContentUsingOldWebDavApi(string $ * @param string $body content to upload * @param string $publicWebDAVAPIVersion * - * @return void + * @return ResponseInterface */ public function publiclyUploadingContent( string $filename, string $body = 'test', string $publicWebDAVAPIVersion = "old" - ):void { - $this->publicUploadContent( + ):ResponseInterface { + return $this->publicUploadContent( $filename, '', $body, @@ -623,11 +628,12 @@ public function thePublicUploadsFileWithContentUsingThePublicWebDavApi( string $body = 'test', string $publicWebDAVAPIVersion = "old" ):void { - $this->publiclyUploadingContent( + $response = $this->publiclyUploadingContent( $filename, $body, $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); $this->featureContext->pushToLastStatusCodesArrays(); } @@ -645,12 +651,12 @@ public function thePublicHasUploadedFileWithContentUsingThePublicWebDavApi( string $body = 'test', string $publicWebDAVAPIVersion = "old" ):void { - $this->publiclyUploadingContent( + $response = $this->publiclyUploadingContent( $filename, $body, $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response); } /** @@ -1088,7 +1094,7 @@ public function publiclyUploadingShouldToSharedFileShouldFail( } $filename = (string)$this->featureContext->getLastCreatedPublicShare()->file_target; - $this->publicUploadContent( + $response = $this->publicUploadContent( $filename, '', 'test', @@ -1097,7 +1103,7 @@ public function publiclyUploadingShouldToSharedFileShouldFail( $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode); + $this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode, "", $response); } /** @@ -1117,7 +1123,7 @@ public function publiclyUploadingShouldNotWork( return; } - $this->publicUploadContent( + $response = $this->publicUploadContent( 'whateverfilefortesting.txt', '', 'test', @@ -1126,14 +1132,14 @@ public function publiclyUploadingShouldNotWork( $publicWebDAVAPIVersion ); - $response = $this->featureContext->getResponse(); if ($expectedHttpCode === null) { $expectedHttpCode = [507, 400, 401, 403, 404, 423]; } $this->featureContext->theHTTPStatusCodeShouldBe( $expectedHttpCode, "upload should have failed but passed with code " . - $response->getStatusCode() + $response->getStatusCode(), + $response ); } @@ -1151,7 +1157,7 @@ public function publiclyUploadingIntoFolderWithPasswordShouldWork( string $publicWebDAVAPIVersion, string $password ):void { - $this->publicUploadContent( + $response = $this->publicUploadContent( $filename, $password, 'test', @@ -1160,7 +1166,7 @@ public function publiclyUploadingIntoFolderWithPasswordShouldWork( $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response); } /** @@ -1179,7 +1185,7 @@ public function publiclyUploadingIntoFolderWithPasswordShouldFail( string $password, string $expectedHttpCode ):void { - $this->publicUploadContent( + $response = $this->publicUploadContent( $filename, $password, 'test', @@ -1188,11 +1194,11 @@ public function publiclyUploadingIntoFolderWithPasswordShouldFail( $publicWebDAVAPIVersion ); - $response = $this->featureContext->getResponse(); $this->featureContext->theHTTPStatusCodeShouldBe( $expectedHttpCode, "upload of $filename into the last publicly shared folder should have failed with code " . - $expectedHttpCode . " but the code was " . $response->getStatusCode() + $expectedHttpCode . " but the code was " . $response->getStatusCode(), + $response ); } @@ -1212,7 +1218,7 @@ public function publiclyUploadingShouldWork(string $publicWebDAVAPIVersion):void return; } - $this->publicUploadContent( + $response = $this->publicUploadContent( $path, '', $content, @@ -1220,7 +1226,7 @@ public function publiclyUploadingShouldWork(string $publicWebDAVAPIVersion):void [], $publicWebDAVAPIVersion ); - $response = $this->featureContext->getResponse(); + Assert::assertTrue( ($response->getStatusCode() == 201), "upload should have passed but failed with code " . @@ -1256,7 +1262,7 @@ public function publiclyUploadingToPublicLinkSharedFileShouldWork( $path = ""; } - $this->publicUploadContent( + $response = $this->publicUploadContent( $path, '', $content, @@ -1264,7 +1270,6 @@ public function publiclyUploadingToPublicLinkSharedFileShouldWork( [], $publicWebDAVAPIVersion ); - $response = $this->featureContext->getResponse(); if ($should) { Assert::assertTrue( ($response->getStatusCode() == 204), @@ -1309,7 +1314,7 @@ public function thePublicUploadsFileToLastSharedFolderWithMtimeUsingTheWebdavApi $mtime = new DateTime($mtime); $mtime = $mtime->format('U'); - $this->publicUploadContent( + $response = $this->publicUploadContent( $fileName, '', 'test', @@ -1317,6 +1322,7 @@ public function thePublicUploadsFileToLastSharedFolderWithMtimeUsingTheWebdavApi ["X-OC-Mtime" => $mtime], $davVersion ); + $this->featureContext->setResponse($response); } /** @@ -1473,7 +1479,7 @@ public function theMtimeOfFileInTheLastSharedPublicLinkUsingTheWebdavApiShouldNo * @param array $additionalHeaders * @param string $publicWebDAVAPIVersion * - * @return void + * @return ResponseInterface|null */ public function publicUploadContent( string $filename, @@ -1482,9 +1488,9 @@ public function publicUploadContent( bool $autoRename = false, array $additionalHeaders = [], string $publicWebDAVAPIVersion = "old" - ):void { + ):?ResponseInterface { if ($publicWebDAVAPIVersion === "old") { - return; + return null; } $password = $this->featureContext->getActualPassword($password); $token = $this->featureContext->getLastCreatedPublicShareToken(); @@ -1515,7 +1521,7 @@ public function publicUploadContent( $headers['OC-Autorename'] = 1; } $headers = \array_merge($headers, $additionalHeaders); - $response = HttpRequestHelper::put( + return HttpRequestHelper::put( $url, $this->featureContext->getStepLineRef(), $userName, @@ -1523,7 +1529,6 @@ public function publicUploadContent( $headers, $body ); - $this->featureContext->setResponse($response); } /** diff --git a/tests/acceptance/features/bootstrap/WebDavLockingContext.php b/tests/acceptance/features/bootstrap/WebDavLockingContext.php index 18d29a990a6..3a2a9b3624b 100644 --- a/tests/acceptance/features/bootstrap/WebDavLockingContext.php +++ b/tests/acceptance/features/bootstrap/WebDavLockingContext.php @@ -619,7 +619,7 @@ public function publicUploadFileSendingLockTokenOfUser( $headers = [ "If" => "(<" . $this->tokenOfLastLock[$lockOwner][$itemToUseLockOf] . ">)" ]; - $this->publicWebDavContext->publicUploadContent( + $response = $this->publicWebDavContext->publicUploadContent( $filename, '', $content, @@ -627,6 +627,7 @@ public function publicUploadFileSendingLockTokenOfUser( $headers, $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** From e1e728aa2e3a410aaf4c14c4b7501b58aad1c6b5 Mon Sep 17 00:00:00 2001 From: KarunAtreya Date: Mon, 9 Oct 2023 13:16:03 +0545 Subject: [PATCH 2/7] refactored some when stepa --- .../bootstrap/PublicWebDavContext.php | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/acceptance/features/bootstrap/PublicWebDavContext.php b/tests/acceptance/features/bootstrap/PublicWebDavContext.php index af84a537a71..fffbfb1836c 100644 --- a/tests/acceptance/features/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/features/bootstrap/PublicWebDavContext.php @@ -37,15 +37,13 @@ class PublicWebDavContext implements Context { private FeatureContext $featureContext; /** - * @When /^the public downloads the last public link shared file with range "([^"]*)" using the (old|new) public WebDAV API$/ - * * @param string $range ignore if empty * @param string $publicWebDAVAPIVersion * @param string|null $password * - * @return void + * @return ResponseInterface */ - public function downloadPublicFileWithRange(string $range, string $publicWebDAVAPIVersion, ?string $password = ""):void { + public function downloadPublicFileWithRange(string $range, string $publicWebDAVAPIVersion, ?string $password = ""):ResponseInterface { if ($publicWebDAVAPIVersion === "new") { // In this case a single file has been shared as a public link. // Even if that file is somewhere down inside a folder(s), when @@ -58,7 +56,7 @@ public function downloadPublicFileWithRange(string $range, string $publicWebDAVA } else { $path = ""; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + return $this->downloadTheFileInsideThePublicSharedFolder( $path, $password, $range, @@ -81,12 +79,13 @@ public function downloadPublicFileWithRangeAndPassword(string $range, string $pa } else { $path = ""; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadTheFileInsideThePublicSharedFolder( $path, $password, $range, $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** @@ -97,7 +96,8 @@ public function downloadPublicFileWithRangeAndPassword(string $range, string $pa * @return void */ public function downloadPublicFile(string $publicWebDAVAPIVersion):void { - $this->downloadPublicFileWithRange("", $publicWebDAVAPIVersion); + $response = $this->downloadPublicFileWithRange("", $publicWebDAVAPIVersion); + $this->featureContext->setResponse($response); } /** @@ -109,7 +109,8 @@ public function downloadPublicFile(string $publicWebDAVAPIVersion):void { * @return void */ public function downloadPublicFileWithPassword(string $password, string $publicWebDAVAPIVersion):void { - $this->downloadPublicFileWithRange("", $publicWebDAVAPIVersion, $password); + $response = $this->downloadPublicFileWithRange("", $publicWebDAVAPIVersion, $password); + $this->featureContext->setResponse($response); } /** @@ -231,29 +232,28 @@ public function thePublicRenamesFileFromTheLastPublicShareUsingThePasswordPasswo * @return void */ public function downloadPublicFileInsideAFolder(string $path, string $publicWebDAVAPIVersion = "old"):void { - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadTheFileInsideThePublicSharedFolder( $path, "", "", $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** - * @When /^the public downloads file "([^"]*)" from inside the last public link shared folder with password "([^"]*)" using the (old|new) public WebDAV API$/ - * * @param string $path * @param string|null $password * @param string $publicWebDAVAPIVersion * - * @return void + * @return ResponseInterface */ - public function publicDownloadsTheFileInsideThePublicSharedFolderWithPassword( + public function downloadTheFileInsideThePublicSharedFolderWithPassword( string $path, ?string $password = "", string $publicWebDAVAPIVersion = "old" - ):void { - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + ):ResponseInterface { + return $this->downloadTheFileInsideThePublicSharedFolder( $path, $password, "", @@ -271,30 +271,29 @@ public function publicDownloadsTheFileInsideThePublicSharedFolderWithPassword( * @return void */ public function downloadPublicFileInsideAFolderWithRange(string $path, string $range, string $publicWebDAVAPIVersion):void { - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadTheFileInsideThePublicSharedFolder( $path, "", $range, $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** - * @When /^the public downloads file "([^"]*)" from inside the last public link shared folder with password "([^"]*)" with range "([^"]*)" using the (old|new) public WebDAV API$/ - * * @param string $path * @param string $password * @param string $range ignored when empty * @param string $publicWebDAVAPIVersion * - * @return void + * @return ResponseInterface */ - public function publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + public function downloadTheFileInsideThePublicSharedFolder( string $path, string $password, string $range, string $publicWebDAVAPIVersion = "old" - ):void { + ):ResponseInterface { $path = \ltrim($path, "/"); $password = $this->featureContext->getActualPassword($password); $token = $this->featureContext->getLastCreatedPublicShareToken(); @@ -316,14 +315,13 @@ public function publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAnd if ($range !== "") { $headers['Range'] = $range; } - $response = HttpRequestHelper::get( + return HttpRequestHelper::get( $fullUrl, $this->featureContext->getStepLineRef(), $userName, $password, $headers ); - $this->featureContext->setResponse($response); } /** @@ -720,7 +718,7 @@ public function checkLastPublicSharedFileWithPasswordDownload( return; } - $this->downloadPublicFileWithRange( + $response = $this->downloadPublicFileWithRange( "", $publicWebDAVAPIVersion, $password @@ -728,10 +726,11 @@ public function checkLastPublicSharedFileWithPasswordDownload( $this->featureContext->checkDownloadedContentMatches( $expectedContent, - "Checking the content of the last public shared file after downloading with the $publicWebDAVAPIVersion public WebDAV API" + "Checking the content of the last public shared file after downloading with the $publicWebDAVAPIVersion public WebDAV API", + $response ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** @@ -748,19 +747,19 @@ public function theLastPublicSharedFileShouldNotBeAbleToBeDownloadedWithPassword string $password, string $expectedHttpCode ):void { - $this->downloadPublicFileWithRange( + $response = $this->downloadPublicFileWithRange( "", $publicWebDAVAPIVersion, $password ); - $responseContent = $this->featureContext->getResponse()->getBody()->getContents(); + $responseContent = $response->getBody()->getContents(); \libxml_use_internal_errors(true); Assert::assertNotFalse( \simplexml_load_string($responseContent), "response body is not valid XML, maybe download did work\n" . "response body: \n$responseContent\n" ); - $this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode); + $this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode, "", $response); } /** @@ -869,15 +868,15 @@ public function shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPasswordAn return; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPassword( + $response = $this->downloadTheFileInsideThePublicSharedFolderWithPassword( $path, $password, $publicWebDAVAPIVersion ); - $this->featureContext->downloadedContentShouldBePlusEndOfLine($content); + $this->featureContext->checkDownloadedContentMatches("$content\n", "", $response); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** @@ -901,15 +900,15 @@ public function shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPasswordAn return; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPassword( + $response = $this->downloadTheFileInsideThePublicSharedFolderWithPassword( $path, $password, $publicWebDAVAPIVersion ); - $this->featureContext->downloadedContentShouldBe($content); + $this->featureContext->checkDownloadedContentMatches($content, "", $response); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** @@ -977,13 +976,13 @@ public function shouldBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPas return; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadTheFileInsideThePublicSharedFolder( $path, $password, $range, $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** @@ -1009,21 +1008,21 @@ public function shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWith return; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadTheFileInsideThePublicSharedFolder( $path, $password, $range, $publicWebDAVAPIVersion ); - $responseContent = $this->featureContext->getResponse()->getBody()->getContents(); + $responseContent = $response->getBody()->getContents(); \libxml_use_internal_errors(true); Assert::assertNotFalse( \simplexml_load_string($responseContent), "response body is not valid XML, maybe download did work\n" . "response body: \n$responseContent\n" ); - $this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode); + $this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode, "", $response); } /** @@ -1277,14 +1276,15 @@ public function publiclyUploadingToPublicLinkSharedFileShouldWork( $response->getStatusCode() ); - $this->downloadPublicFileWithRange( + $response = $this->downloadPublicFileWithRange( "", $publicWebDAVAPIVersion ); $this->featureContext->checkDownloadedContentMatches( $content, - "Checking the content of the last public shared file after downloading with the $publicWebDAVAPIVersion public WebDAV API" + "Checking the content of the last public shared file after downloading with the $publicWebDAVAPIVersion public WebDAV API", + $response ); } else { $expectedCode = 403; From 745e80a15a41d62108260b8e470f21a591212d12 Mon Sep 17 00:00:00 2001 From: KarunAtreya Date: Mon, 9 Oct 2023 16:04:48 +0545 Subject: [PATCH 3/7] refactored remaining when and then steps --- .../bootstrap/PublicWebDavContext.php | 79 +++++++++---------- .../bootstrap/WebDavLockingContext.php | 2 +- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/tests/acceptance/features/bootstrap/PublicWebDavContext.php b/tests/acceptance/features/bootstrap/PublicWebDavContext.php index fffbfb1836c..4c717562d3d 100644 --- a/tests/acceptance/features/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/features/bootstrap/PublicWebDavContext.php @@ -85,7 +85,7 @@ public function downloadPublicFileWithRangeAndPassword(string $range, string $pa $range, $publicWebDAVAPIVersion ); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** @@ -97,7 +97,7 @@ public function downloadPublicFileWithRangeAndPassword(string $range, string $pa */ public function downloadPublicFile(string $publicWebDAVAPIVersion):void { $response = $this->downloadPublicFileWithRange("", $publicWebDAVAPIVersion); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** @@ -110,7 +110,7 @@ public function downloadPublicFile(string $publicWebDAVAPIVersion):void { */ public function downloadPublicFileWithPassword(string $password, string $publicWebDAVAPIVersion):void { $response = $this->downloadPublicFileWithRange("", $publicWebDAVAPIVersion, $password); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** @@ -238,7 +238,7 @@ public function downloadPublicFileInsideAFolder(string $path, string $publicWebD "", $publicWebDAVAPIVersion ); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** @@ -277,7 +277,7 @@ public function downloadPublicFileInsideAFolderWithRange(string $path, string $r $range, $publicWebDAVAPIVersion ); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** @@ -330,8 +330,8 @@ public function downloadTheFileInsideThePublicSharedFolder( * * @return ResponseInterface */ - public function publiclyUploadingFile(string $source, string $publicWebDAVAPIVersion):ResponseInterface { - return $this->publicUploadContent( + public function publicUploadFile(string $source, string $publicWebDAVAPIVersion):ResponseInterface { + return $this->publicUploadContent( \basename($source), '', \file_get_contents($source), @@ -350,11 +350,11 @@ public function publiclyUploadingFile(string $source, string $publicWebDAVAPIVer * @return void */ public function thePublicUploadsFileUsingTheWebDAVApi(string $source, string $publicWebDAVAPIVersion):void { - $response = $this->publiclyUploadingFile( + $response = $this->publiclUploadFile( $source, $publicWebDAVAPIVersion ); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** @@ -367,20 +367,20 @@ public function thePublicUploadsFileUsingTheWebDAVApi(string $source, string $pu * @param string $source * @param string $destination * - * @return void + * @return ResponseInterface */ public function publiclyCopyingFile( string $baseUrl, string $source, string $destination - ):void { + ):ResponseInterface { $fullSourceUrl = $baseUrl . $source; $fullDestUrl = WebDavHelper::sanitizeUrl( $baseUrl . $destination ); $headers["Destination"] = $fullDestUrl; - $response = HttpRequestHelper::sendRequest( + return HttpRequestHelper::sendRequest( $fullSourceUrl, $this->featureContext->getStepLineRef(), "COPY", @@ -388,7 +388,6 @@ public function publiclyCopyingFile( null, $headers ); - $this->featureContext->setResponse($response); } /** @@ -409,11 +408,12 @@ public function thePublicCopiesFileUsingTheWebDAVApi(string $source, string $des ); $baseUrl = $this->featureContext->getLocalBaseUrl() . '/' . $davPath; - $this->publiclyCopyingFile( + $response = $this->publiclyCopyingFile( $baseUrl, $source, $destination ); + $this->featureContext->setResponse($response); } /** @@ -425,7 +425,7 @@ public function thePublicCopiesFileUsingTheWebDAVApi(string $source, string $des * @return void */ public function thePublicHasUploadedFileUsingTheWebDAVApi(string $source, string $publicWebDAVAPIVersion):void { - $response = $this->publiclyUploadingFile( + $response = $this->publicUploadFile( $source, $publicWebDAVAPIVersion ); @@ -455,7 +455,7 @@ public function publiclyUploadingContentAutoRename(string $filename, string $bod */ public function thePublicUploadsFileWithContentWithAutoRenameMode(string $filename, string $body = 'test'):void { $response = $this->publiclyUploadingContentAutoRename($filename, $body); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** @@ -517,7 +517,7 @@ public function thePublicUploadsFileWithPasswordAndContentUsingPublicWebDAVApi( $body, $publicWebDAVAPIVersion ); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** @@ -571,7 +571,7 @@ public function thePublicOverwritesFileWithContentUsingWebDavApi(string $filenam $body, $publicWebDAVAPIVersion ); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** @@ -631,7 +631,7 @@ public function thePublicUploadsFileWithContentUsingThePublicWebDavApi( $body, $publicWebDAVAPIVersion ); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); $this->featureContext->pushToLastStatusCodesArrays(); } @@ -675,7 +675,6 @@ public function checkLastPublicSharedFileDownload( "", $expectedContent ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); } /** @@ -696,7 +695,6 @@ public function checkLastPublicSharedFileDownloadPlusEndOfLine( "", "$expectedContent\n" ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); } /** @@ -727,7 +725,7 @@ public function checkLastPublicSharedFileWithPasswordDownload( $this->featureContext->checkDownloadedContentMatches( $expectedContent, "Checking the content of the last public shared file after downloading with the $publicWebDAVAPIVersion public WebDAV API", - $response + $response ); $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); @@ -1138,7 +1136,7 @@ public function publiclyUploadingShouldNotWork( $expectedHttpCode, "upload should have failed but passed with code " . $response->getStatusCode(), - $response + $response ); } @@ -1197,7 +1195,7 @@ public function publiclyUploadingIntoFolderWithPasswordShouldFail( $expectedHttpCode, "upload of $filename into the last publicly shared folder should have failed with code " . $expectedHttpCode . " but the code was " . $response->getStatusCode(), - $response + $response ); } @@ -1284,7 +1282,7 @@ public function publiclyUploadingToPublicLinkSharedFileShouldWork( $this->featureContext->checkDownloadedContentMatches( $content, "Checking the content of the last public shared file after downloading with the $publicWebDAVAPIVersion public WebDAV API", - $response + $response ); } else { $expectedCode = 403; @@ -1322,19 +1320,19 @@ public function thePublicUploadsFileToLastSharedFolderWithMtimeUsingTheWebdavApi ["X-OC-Mtime" => $mtime], $davVersion ); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** * @param string $destination * @param string $password * - * @return void + * @return ResponseInterface */ public function publicCreatesFolderUsingPassword( string $destination, string $password - ):void { + ):ResponseInterface { $token = $this->featureContext->getLastCreatedPublicShareToken(); $davPath = WebDavHelper::getDavPath( $token, @@ -1354,14 +1352,12 @@ public function publicCreatesFolderUsingPassword( ); $url .= \ltrim($foldername, '/'); - $this->featureContext->setResponse( - HttpRequestHelper::sendRequest( - $url, - $this->featureContext->getStepLineRef(), - 'MKCOL', - $userName, - $password - ) + return HttpRequestHelper::sendRequest( + $url, + $this->featureContext->getStepLineRef(), + 'MKCOL', + $userName, + $password ); } @@ -1373,7 +1369,7 @@ public function publicCreatesFolderUsingPassword( * @return void */ public function publicCreatesFolder(string $destination):void { - $this->publicCreatesFolderUsingPassword($destination, ''); + $this->featureContext->setResponse($this->publicCreatesFolderUsingPassword($destination, '')); } /** @@ -1388,8 +1384,8 @@ public function publicShouldBeAbleToCreateFolderWithPassword( string $foldername, string $password ):void { - $this->publicCreatesFolderUsingPassword($foldername, $password); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $response = $this->publicCreatesFolderUsingPassword($foldername, $password); + $this->featureContext->theHTTPStatusCodeShouldBe(201, "", $response); } /** @@ -1406,11 +1402,12 @@ public function publicCreationOfFolderWithPasswordShouldFail( string $password, string $expectedHttpCode ):void { - $this->publicCreatesFolderUsingPassword($foldername, $password); + $response = $this->publicCreatesFolderUsingPassword($foldername, $password); $this->featureContext->theHTTPStatusCodeShouldBe( $expectedHttpCode, "creation of $foldername in the last publicly shared folder should have failed with code " . - $expectedHttpCode + $expectedHttpCode, + $response ); } diff --git a/tests/acceptance/features/bootstrap/WebDavLockingContext.php b/tests/acceptance/features/bootstrap/WebDavLockingContext.php index 3a2a9b3624b..b79d8c56d20 100644 --- a/tests/acceptance/features/bootstrap/WebDavLockingContext.php +++ b/tests/acceptance/features/bootstrap/WebDavLockingContext.php @@ -627,7 +627,7 @@ public function publicUploadFileSendingLockTokenOfUser( $headers, $publicWebDAVAPIVersion ); - $this->featureContext->setResponse($response); + $this->featureContext->setResponse($response); } /** From 965cff6b8ef85fffa88ee86493d0e4a9a11ca728 Mon Sep 17 00:00:00 2001 From: KarunAtreya Date: Tue, 10 Oct 2023 10:48:40 +0545 Subject: [PATCH 4/7] use of when step for the action --- .../apiSpaces/editPublicLinkOfSpace.feature | 3 ++- .../shareSpacesViaLink.feature | 3 ++- .../bootstrap/PublicWebDavContext.php | 27 ++++++++++++++++++- .../createPublicLinkShare.feature | 6 +++-- .../reShareAsPublicLinkToSharesNewDav.feature | 9 ++++--- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature index 8eb99ccf0aa..c2c05825864 100644 --- a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature +++ b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature @@ -43,7 +43,8 @@ Feature: A manager of the space can edit public link | displayname_owner | %displayname% | | name | | And the public should be able to download file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" - And the downloaded content should be "some content" + When the public downloads file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" + Then the downloaded content should be "some content" Examples: | permissions | expectedPermissions | password | linkName | | 5 | read,create | newPass | | diff --git a/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature b/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature index 317ca3f4653..832a36a6c92 100644 --- a/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature +++ b/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature @@ -37,7 +37,8 @@ Feature: Share spaces via link | uid_owner | %username% | | name | | And the public should be able to download file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" - And the downloaded content should be "some content" + When the public downloads file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" + Then the downloaded content should be "some content" But the public should not be able to download file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" Examples: | permissions | expectedPermissions | password | linkName | expireDate | diff --git a/tests/acceptance/features/bootstrap/PublicWebDavContext.php b/tests/acceptance/features/bootstrap/PublicWebDavContext.php index 4c717562d3d..bacb5315700 100644 --- a/tests/acceptance/features/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/features/bootstrap/PublicWebDavContext.php @@ -241,6 +241,25 @@ public function downloadPublicFileInsideAFolder(string $path, string $publicWebD $this->featureContext->setResponse($response); } + /** + * @When /^the public downloads file "([^"]*)" from inside the last public link shared folder using the (old|new) public WebDAV API with password "([^"]*)"$/ + * + * @param string $path + * @param string $publicWebDAVAPIVersion + * @param string $password + * + * @return void + */ + public function downloadPublicFileInsideAFolderWithPassword(string $path, string $publicWebDAVAPIVersion = "old", string $password = ""):void { + $response = $this->downloadTheFileInsideThePublicSharedFolder( + $path, + $password, + "", + $publicWebDAVAPIVersion + ); + $this->featureContext->setResponse($response); + } + /** * @param string $path * @param string|null $password @@ -1233,7 +1252,13 @@ public function publiclyUploadingShouldWork(string $publicWebDAVAPIVersion):void $path, $publicWebDAVAPIVersion ); - $this->featureContext->checkDownloadedContentMatches($content); + $response = $this->downloadTheFileInsideThePublicSharedFolder( + $path, + "", + "", + $publicWebDAVAPIVersion + ); + $this->featureContext->checkDownloadedContentMatches($content, "", $response); } /** diff --git a/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature b/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature index cc407f0876d..195e76a4070 100644 --- a/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature +++ b/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature @@ -61,9 +61,11 @@ Feature: create a public link share And the public should be able to download the last publicly shared file using the new public WebDAV API with password "%public%" and the content should be "Random data" And the HTTP status code should be "200" And the public download of the last publicly shared file using the new public WebDAV API with password "%regular%" should fail with HTTP status code "401" - And the value of the item "//s:message" in the response should match "/Username or password was incorrect/" + When the public downloads the last public link shared file with password "%regular%" using the new public WebDAV API + Then the value of the item "//s:message" in the response should match "/Username or password was incorrect/" And the public download of the last publicly shared file using the new public WebDAV API without a password should fail with HTTP status code "401" - And the value of the item "//s:message" in the response should match "/No 'Authorization: Basic' header found/" + When the public downloads the last public link shared file using the new public WebDAV API + Then the value of the item "//s:message" in the response should match "/No 'Authorization: Basic' header found/" Examples: | ocs_api_version | ocs_status_code | | 1 | 100 | diff --git a/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature b/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature index 2793fd062b2..31dcdaa8cf2 100644 --- a/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature +++ b/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature @@ -38,7 +38,8 @@ Feature: reshare as public link Then the OCS status code should be "" And the HTTP status code should be "200" And the public should be able to download file "file.txt" from inside the last public link shared folder using the new public WebDAV API - And the downloaded content should be "some content" + When the public downloads file "file.txt" from inside the last public link shared folder using the new public WebDAV API + Then the downloaded content should be "some content" But uploading a file should not work using the new public WebDAV API Examples: | ocs_api_version | ocs_status_code | @@ -91,7 +92,8 @@ Feature: reshare as public link Then the OCS status code should be "" And the HTTP status code should be "200" And the public should be able to download file "file.txt" from inside the last public link shared folder using the new public WebDAV API - And the downloaded content should be "some content" + When the public downloads file "file.txt" from inside the last public link shared folder using the new public WebDAV API + Then the downloaded content should be "some content" But uploading a file should not work using the new public WebDAV API Examples: | ocs_api_version | ocs_status_code | @@ -112,7 +114,8 @@ Feature: reshare as public link Then the OCS status code should be "" And the HTTP status code should be "200" And the public should be able to download file "file.txt" from inside the last public link shared folder using the new public WebDAV API - And the downloaded content should be "some content" + When the public downloads file "file.txt" from inside the last public link shared folder using the new public WebDAV API + Then the downloaded content should be "some content" And uploading a file should work using the new public WebDAV API Examples: | ocs_api_version | ocs_status_code | From 8a2e22e296cd49ac29937b8b8056a2d09765ea5d Mon Sep 17 00:00:00 2001 From: KarunAtreya Date: Tue, 10 Oct 2023 11:29:46 +0545 Subject: [PATCH 5/7] changed line no in expected failure --- tests/acceptance/expected-failures-API-on-OCIS-storage.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index e5dad7be111..1422d499d7d 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -204,7 +204,7 @@ cannot share a folder with create permission #### [Public link enforce permissions](https://github.com/owncloud/ocis/issues/1269) -- [coreApiSharePublicLink1/createPublicLinkShare.feature:327](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature#L327) +- [coreApiSharePublicLink1/createPublicLinkShare.feature:329](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature#L329) #### [copying a folder within a public link folder to folder with same name as an already existing file overwrites the parent file](https://github.com/owncloud/ocis/issues/1232) @@ -339,8 +339,8 @@ API, search, favorites, config, capabilities, not existing endpoints, CORS and o - [coreApiAuthOcs/ocsGETAuth.feature:106](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsGETAuth.feature#L106) - [coreApiAuthOcs/ocsGETAuth.feature:123](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsGETAuth.feature#L123) - [coreApiAuthOcs/ocsPOSTAuth.feature:10](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsPOSTAuth.feature#L10) -- [coreApiAuthOcs/ocsPUTAuth.feature:7](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsPUTAuth.feature#L7) -- [coreApiSharePublicLink1/createPublicLinkShare.feature:317](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature#L317) +- [coreApiAuthOcs/ocsPUTAuth.feature:10](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsPUTAuth.feature#L10) +- [coreApiSharePublicLink1/createPublicLinkShare.feature:319](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature#L319) #### [sending MKCOL requests to another or non-existing user's webDav endpoints as normal user should return 404](https://github.com/owncloud/ocis/issues/5049) From fba11da4381cff775728254ec61648318998f393 Mon Sep 17 00:00:00 2001 From: KarunAtreya Date: Tue, 10 Oct 2023 15:35:11 +0545 Subject: [PATCH 6/7] remove and add same kind of steps in the scenario and refactored function names --- .../expected-failures-API-on-OCIS-storage.md | 4 +- .../apiSpaces/editPublicLinkOfSpace.feature | 4 +- .../shareSpacesViaLink.feature | 4 +- .../bootstrap/PublicWebDavContext.php | 45 ++++++------------- .../createPublicLinkShare.feature | 9 ++-- .../reShareAsPublicLinkToSharesNewDav.feature | 12 ++--- 6 files changed, 29 insertions(+), 49 deletions(-) diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index 1422d499d7d..57eed70f678 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -204,7 +204,7 @@ cannot share a folder with create permission #### [Public link enforce permissions](https://github.com/owncloud/ocis/issues/1269) -- [coreApiSharePublicLink1/createPublicLinkShare.feature:329](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature#L329) +- [coreApiSharePublicLink1/createPublicLinkShare.feature:328](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature#L328) #### [copying a folder within a public link folder to folder with same name as an already existing file overwrites the parent file](https://github.com/owncloud/ocis/issues/1232) @@ -340,7 +340,7 @@ API, search, favorites, config, capabilities, not existing endpoints, CORS and o - [coreApiAuthOcs/ocsGETAuth.feature:123](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsGETAuth.feature#L123) - [coreApiAuthOcs/ocsPOSTAuth.feature:10](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsPOSTAuth.feature#L10) - [coreApiAuthOcs/ocsPUTAuth.feature:10](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsPUTAuth.feature#L10) -- [coreApiSharePublicLink1/createPublicLinkShare.feature:319](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature#L319) +- [coreApiSharePublicLink1/createPublicLinkShare.feature:318](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature#L318) #### [sending MKCOL requests to another or non-existing user's webDav endpoints as normal user should return 404](https://github.com/owncloud/ocis/issues/5049) diff --git a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature index c2c05825864..36869f78777 100644 --- a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature +++ b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature @@ -42,9 +42,9 @@ Feature: A manager of the space can edit public link | share_type | public_link | | displayname_owner | %displayname% | | name | | - And the public should be able to download file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" When the public downloads file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" - Then the downloaded content should be "some content" + Then the HTTP status code should be "200" + And the downloaded content should be "some content" Examples: | permissions | expectedPermissions | password | linkName | | 5 | read,create | newPass | | diff --git a/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature b/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature index 832a36a6c92..31aa7eb7667 100644 --- a/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature +++ b/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature @@ -36,9 +36,9 @@ Feature: Share spaces via link | displayname_owner | %displayname% | | uid_owner | %username% | | name | | - And the public should be able to download file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" When the public downloads file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" - Then the downloaded content should be "some content" + Then the HTTP status code should be "200" + And the downloaded content should be "some content" But the public should not be able to download file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" Examples: | permissions | expectedPermissions | password | linkName | expireDate | diff --git a/tests/acceptance/features/bootstrap/PublicWebDavContext.php b/tests/acceptance/features/bootstrap/PublicWebDavContext.php index bacb5315700..bdc802b484a 100644 --- a/tests/acceptance/features/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/features/bootstrap/PublicWebDavContext.php @@ -56,7 +56,7 @@ public function downloadPublicFileWithRange(string $range, string $publicWebDAVA } else { $path = ""; } - return $this->downloadTheFileInsideThePublicSharedFolder( + return $this->downloadFileFromPublicFolder( $path, $password, $range, @@ -79,7 +79,7 @@ public function downloadPublicFileWithRangeAndPassword(string $range, string $pa } else { $path = ""; } - $response = $this->downloadTheFileInsideThePublicSharedFolder( + $response = $this->downloadFileFromPublicFolder( $path, $password, $range, @@ -232,7 +232,7 @@ public function thePublicRenamesFileFromTheLastPublicShareUsingThePasswordPasswo * @return void */ public function downloadPublicFileInsideAFolder(string $path, string $publicWebDAVAPIVersion = "old"):void { - $response = $this->downloadTheFileInsideThePublicSharedFolder( + $response = $this->downloadFileFromPublicFolder( $path, "", "", @@ -251,7 +251,7 @@ public function downloadPublicFileInsideAFolder(string $path, string $publicWebD * @return void */ public function downloadPublicFileInsideAFolderWithPassword(string $path, string $publicWebDAVAPIVersion = "old", string $password = ""):void { - $response = $this->downloadTheFileInsideThePublicSharedFolder( + $response = $this->downloadFileFromPublicFolder( $path, $password, "", @@ -260,26 +260,6 @@ public function downloadPublicFileInsideAFolderWithPassword(string $path, string $this->featureContext->setResponse($response); } - /** - * @param string $path - * @param string|null $password - * @param string $publicWebDAVAPIVersion - * - * @return ResponseInterface - */ - public function downloadTheFileInsideThePublicSharedFolderWithPassword( - string $path, - ?string $password = "", - string $publicWebDAVAPIVersion = "old" - ):ResponseInterface { - return $this->downloadTheFileInsideThePublicSharedFolder( - $path, - $password, - "", - $publicWebDAVAPIVersion - ); - } - /** * @When /^the public downloads file "([^"]*)" from inside the last public link shared folder with range "([^"]*)" using the (old|new) public WebDAV API$/ * @@ -290,7 +270,7 @@ public function downloadTheFileInsideThePublicSharedFolderWithPassword( * @return void */ public function downloadPublicFileInsideAFolderWithRange(string $path, string $range, string $publicWebDAVAPIVersion):void { - $response = $this->downloadTheFileInsideThePublicSharedFolder( + $response = $this->downloadFileFromPublicFolder( $path, "", $range, @@ -307,7 +287,7 @@ public function downloadPublicFileInsideAFolderWithRange(string $path, string $r * * @return ResponseInterface */ - public function downloadTheFileInsideThePublicSharedFolder( + public function downloadFileFromPublicFolder( string $path, string $password, string $range, @@ -885,9 +865,10 @@ public function shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPasswordAn return; } - $response = $this->downloadTheFileInsideThePublicSharedFolderWithPassword( + $response = $this->downloadFileFromPublicFolder( $path, $password, + "", $publicWebDAVAPIVersion ); @@ -917,12 +898,12 @@ public function shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPasswordAn return; } - $response = $this->downloadTheFileInsideThePublicSharedFolderWithPassword( + $response = $this->downloadFileFromPublicFolder( $path, $password, + "", $publicWebDAVAPIVersion ); - $this->featureContext->checkDownloadedContentMatches($content, "", $response); $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); @@ -993,7 +974,7 @@ public function shouldBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPas return; } - $response = $this->downloadTheFileInsideThePublicSharedFolder( + $response = $this->downloadFileFromPublicFolder( $path, $password, $range, @@ -1025,7 +1006,7 @@ public function shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWith return; } - $response = $this->downloadTheFileInsideThePublicSharedFolder( + $response = $this->downloadFileFromPublicFolder( $path, $password, $range, @@ -1252,7 +1233,7 @@ public function publiclyUploadingShouldWork(string $publicWebDAVAPIVersion):void $path, $publicWebDAVAPIVersion ); - $response = $this->downloadTheFileInsideThePublicSharedFolder( + $response = $this->downloadFileFromPublicFolder( $path, "", "", diff --git a/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature b/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature index 195e76a4070..67ca2eda7af 100644 --- a/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature +++ b/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature @@ -59,13 +59,12 @@ Feature: create a public link share | uid_owner | %username% | | name | | And the public should be able to download the last publicly shared file using the new public WebDAV API with password "%public%" and the content should be "Random data" - And the HTTP status code should be "200" - And the public download of the last publicly shared file using the new public WebDAV API with password "%regular%" should fail with HTTP status code "401" When the public downloads the last public link shared file with password "%regular%" using the new public WebDAV API - Then the value of the item "//s:message" in the response should match "/Username or password was incorrect/" - And the public download of the last publicly shared file using the new public WebDAV API without a password should fail with HTTP status code "401" + Then the HTTP status code should be "401" + And the value of the item "//s:message" in the response should match "/Username or password was incorrect/" When the public downloads the last public link shared file using the new public WebDAV API - Then the value of the item "//s:message" in the response should match "/No 'Authorization: Basic' header found/" + Then the HTTP status code should be "401" + And the value of the item "//s:message" in the response should match "/No 'Authorization: Basic' header found/" Examples: | ocs_api_version | ocs_status_code | | 1 | 100 | diff --git a/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature b/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature index 31dcdaa8cf2..48728c54c1a 100644 --- a/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature +++ b/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature @@ -37,9 +37,9 @@ Feature: reshare as public link | publicUpload | false | Then the OCS status code should be "" And the HTTP status code should be "200" - And the public should be able to download file "file.txt" from inside the last public link shared folder using the new public WebDAV API When the public downloads file "file.txt" from inside the last public link shared folder using the new public WebDAV API - Then the downloaded content should be "some content" + Then the HTTP status code should be "200" + And the downloaded content should be "some content" But uploading a file should not work using the new public WebDAV API Examples: | ocs_api_version | ocs_status_code | @@ -91,9 +91,9 @@ Feature: reshare as public link | publicUpload | false | Then the OCS status code should be "" And the HTTP status code should be "200" - And the public should be able to download file "file.txt" from inside the last public link shared folder using the new public WebDAV API When the public downloads file "file.txt" from inside the last public link shared folder using the new public WebDAV API - Then the downloaded content should be "some content" + Then the HTTP status code should be "200" + And the downloaded content should be "some content" But uploading a file should not work using the new public WebDAV API Examples: | ocs_api_version | ocs_status_code | @@ -113,9 +113,9 @@ Feature: reshare as public link | publicUpload | true | Then the OCS status code should be "" And the HTTP status code should be "200" - And the public should be able to download file "file.txt" from inside the last public link shared folder using the new public WebDAV API When the public downloads file "file.txt" from inside the last public link shared folder using the new public WebDAV API - Then the downloaded content should be "some content" + Then the HTTP status code should be "200" + And the downloaded content should be "some content" And uploading a file should work using the new public WebDAV API Examples: | ocs_api_version | ocs_status_code | From d5055da36d1b9a7fb5382765148ba88009e202ea Mon Sep 17 00:00:00 2001 From: KarunAtreya Date: Thu, 12 Oct 2023 09:48:00 +0545 Subject: [PATCH 7/7] adressing reviews --- .../expected-failures-API-on-OCIS-storage.md | 2 +- .../features/apiSpaces/editPublicLinkOfSpace.feature | 2 +- .../apiSpacesShares/shareSpacesViaLink.feature | 2 +- .../features/bootstrap/PublicWebDavContext.php | 12 +++++++----- .../createPublicLinkShare.feature | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index 57eed70f678..a879e5f3563 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -339,7 +339,7 @@ API, search, favorites, config, capabilities, not existing endpoints, CORS and o - [coreApiAuthOcs/ocsGETAuth.feature:106](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsGETAuth.feature#L106) - [coreApiAuthOcs/ocsGETAuth.feature:123](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsGETAuth.feature#L123) - [coreApiAuthOcs/ocsPOSTAuth.feature:10](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsPOSTAuth.feature#L10) -- [coreApiAuthOcs/ocsPUTAuth.feature:10](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsPUTAuth.feature#L10) +- [coreApiAuthOcs/ocsPUTAuth.feature:7](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiAuthOcs/ocsPUTAuth.feature#L7) - [coreApiSharePublicLink1/createPublicLinkShare.feature:318](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature#L318) #### [sending MKCOL requests to another or non-existing user's webDav endpoints as normal user should return 404](https://github.com/owncloud/ocis/issues/5049) diff --git a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature index 36869f78777..c6ca84816d2 100644 --- a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature +++ b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature @@ -42,7 +42,7 @@ Feature: A manager of the space can edit public link | share_type | public_link | | displayname_owner | %displayname% | | name | | - When the public downloads file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" + When the public downloads file "/test.txt" from inside the last public link shared folder with password "" using the new public WebDAV API Then the HTTP status code should be "200" And the downloaded content should be "some content" Examples: diff --git a/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature b/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature index 31aa7eb7667..6885d90377c 100644 --- a/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature +++ b/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature @@ -36,7 +36,7 @@ Feature: Share spaces via link | displayname_owner | %displayname% | | uid_owner | %username% | | name | | - When the public downloads file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "" + When the public downloads file "/test.txt" from inside the last public link shared folder with password "" using the new public WebDAV API Then the HTTP status code should be "200" And the downloaded content should be "some content" But the public should not be able to download file "/test.txt" from inside the last public link shared folder using the new public WebDAV API with password "wrong pass" diff --git a/tests/acceptance/features/bootstrap/PublicWebDavContext.php b/tests/acceptance/features/bootstrap/PublicWebDavContext.php index bdc802b484a..9b2a12be7ae 100644 --- a/tests/acceptance/features/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/features/bootstrap/PublicWebDavContext.php @@ -90,6 +90,7 @@ public function downloadPublicFileWithRangeAndPassword(string $range, string $pa /** * @When /^the public downloads the last public link shared file using the (old|new) public WebDAV API$/ + * @When /^the public tries to download the last public link shared file using the (old|new) public WebDAV API$/ * * @param string $publicWebDAVAPIVersion * @@ -102,6 +103,7 @@ public function downloadPublicFile(string $publicWebDAVAPIVersion):void { /** * @When /^the public downloads the last public link shared file with password "([^"]*)" using the (old|new) public WebDAV API$/ + * @When /^the public tries to download the last public link shared file with password "([^"]*)" using the (old|new) public WebDAV API$/ * * @param string $password * @param string $publicWebDAVAPIVersion @@ -242,15 +244,15 @@ public function downloadPublicFileInsideAFolder(string $path, string $publicWebD } /** - * @When /^the public downloads file "([^"]*)" from inside the last public link shared folder using the (old|new) public WebDAV API with password "([^"]*)"$/ + * @When /^the public downloads file "([^"]*)" from inside the last public link shared folder with password "([^"]*)" using the (old|new) public WebDAV API$/ * * @param string $path - * @param string $publicWebDAVAPIVersion * @param string $password + * @param string $publicWebDAVAPIVersion * * @return void */ - public function downloadPublicFileInsideAFolderWithPassword(string $path, string $publicWebDAVAPIVersion = "old", string $password = ""):void { + public function publicDownloadsFileFromInsideLastPublicSharedFolderWithPassword(string $path, string $password = "", string $publicWebDAVAPIVersion = "old"):void { $response = $this->downloadFileFromPublicFolder( $path, $password, @@ -721,13 +723,13 @@ public function checkLastPublicSharedFileWithPasswordDownload( $password ); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); + $this->featureContext->checkDownloadedContentMatches( $expectedContent, "Checking the content of the last public shared file after downloading with the $publicWebDAVAPIVersion public WebDAV API", $response ); - - $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** diff --git a/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature b/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature index 67ca2eda7af..43312180368 100644 --- a/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature +++ b/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature @@ -59,10 +59,10 @@ Feature: create a public link share | uid_owner | %username% | | name | | And the public should be able to download the last publicly shared file using the new public WebDAV API with password "%public%" and the content should be "Random data" - When the public downloads the last public link shared file with password "%regular%" using the new public WebDAV API + When the public tries to download the last public link shared file with password "%regular%" using the new public WebDAV API Then the HTTP status code should be "401" And the value of the item "//s:message" in the response should match "/Username or password was incorrect/" - When the public downloads the last public link shared file using the new public WebDAV API + When the public tries to download the last public link shared file using the new public WebDAV API Then the HTTP status code should be "401" And the value of the item "//s:message" in the response should match "/No 'Authorization: Basic' header found/" Examples: