diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index e5dad7be111..a879e5f3563 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: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: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) +- [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 8eb99ccf0aa..c6ca84816d2 100644 --- a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature +++ b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature @@ -42,7 +42,8 @@ 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 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: | permissions | expectedPermissions | password | linkName | diff --git a/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature b/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature index 317ca3f4653..6885d90377c 100644 --- a/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature +++ b/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature @@ -36,7 +36,8 @@ 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 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" Examples: diff --git a/tests/acceptance/features/bootstrap/PublicWebDavContext.php b/tests/acceptance/features/bootstrap/PublicWebDavContext.php index 8bb24e42a7d..9b2a12be7ae 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'; @@ -36,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 @@ -57,7 +56,7 @@ public function downloadPublicFileWithRange(string $range, string $publicWebDAVA } else { $path = ""; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + return $this->downloadFileFromPublicFolder( $path, $password, $range, @@ -80,27 +79,31 @@ public function downloadPublicFileWithRangeAndPassword(string $range, string $pa } else { $path = ""; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadFileFromPublicFolder( $path, $password, $range, $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** * @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 * * @return void */ public function downloadPublicFile(string $publicWebDAVAPIVersion):void { - $this->downloadPublicFileWithRange("", $publicWebDAVAPIVersion); + $response = $this->downloadPublicFileWithRange("", $publicWebDAVAPIVersion); + $this->featureContext->setResponse($response); } /** * @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 @@ -108,7 +111,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); } /** @@ -230,34 +234,32 @@ public function thePublicRenamesFileFromTheLastPublicShareUsingThePasswordPasswo * @return void */ public function downloadPublicFileInsideAFolder(string $path, string $publicWebDAVAPIVersion = "old"):void { - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadFileFromPublicFolder( $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 $password * @param string $publicWebDAVAPIVersion * * @return void */ - public function publicDownloadsTheFileInsideThePublicSharedFolderWithPassword( - string $path, - ?string $password = "", - string $publicWebDAVAPIVersion = "old" - ):void { - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + public function publicDownloadsFileFromInsideLastPublicSharedFolderWithPassword(string $path, string $password = "", string $publicWebDAVAPIVersion = "old"):void { + $response = $this->downloadFileFromPublicFolder( $path, $password, "", $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** @@ -270,30 +272,29 @@ public function publicDownloadsTheFileInsideThePublicSharedFolderWithPassword( * @return void */ public function downloadPublicFileInsideAFolderWithRange(string $path, string $range, string $publicWebDAVAPIVersion):void { - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadFileFromPublicFolder( $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 downloadFileFromPublicFolder( string $path, string $password, string $range, string $publicWebDAVAPIVersion = "old" - ):void { + ):ResponseInterface { $path = \ltrim($path, "/"); $password = $this->featureContext->getActualPassword($password); $token = $this->featureContext->getLastCreatedPublicShareToken(); @@ -315,24 +316,23 @@ 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); } /** * @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 publicUploadFile(string $source, string $publicWebDAVAPIVersion):ResponseInterface { + return $this->publicUploadContent( \basename($source), '', \file_get_contents($source), @@ -351,10 +351,11 @@ public function publiclyUploadingFile(string $source, string $publicWebDAVAPIVer * @return void */ public function thePublicUploadsFileUsingTheWebDAVApi(string $source, string $publicWebDAVAPIVersion):void { - $this->publiclyUploadingFile( + $response = $this->publiclUploadFile( $source, $publicWebDAVAPIVersion ); + $this->featureContext->setResponse($response); } /** @@ -367,20 +368,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 +389,6 @@ public function publiclyCopyingFile( null, $headers ); - $this->featureContext->setResponse($response); } /** @@ -409,11 +409,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,11 +426,11 @@ public function thePublicCopiesFileUsingTheWebDAVApi(string $source, string $des * @return void */ public function thePublicHasUploadedFileUsingTheWebDAVApi(string $source, string $publicWebDAVAPIVersion):void { - $this->publiclyUploadingFile( + $response = $this->publicUploadFile( $source, $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response); } /** @@ -439,10 +440,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 +455,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 +468,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 +478,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 +512,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 +537,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 +551,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 +567,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 +584,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 +596,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 +627,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 +650,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); } /** @@ -671,7 +676,6 @@ public function checkLastPublicSharedFileDownload( "", $expectedContent ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); } /** @@ -692,7 +696,6 @@ public function checkLastPublicSharedFileDownloadPlusEndOfLine( "", "$expectedContent\n" ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); } /** @@ -714,18 +717,19 @@ public function checkLastPublicSharedFileWithPasswordDownload( return; } - $this->downloadPublicFileWithRange( + $response = $this->downloadPublicFileWithRange( "", $publicWebDAVAPIVersion, $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" + "Checking the content of the last public shared file after downloading with the $publicWebDAVAPIVersion public WebDAV API", + $response ); - - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); } /** @@ -742,19 +746,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); } /** @@ -863,15 +867,16 @@ public function shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPasswordAn return; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPassword( + $response = $this->downloadFileFromPublicFolder( $path, $password, + "", $publicWebDAVAPIVersion ); - $this->featureContext->downloadedContentShouldBePlusEndOfLine($content); + $this->featureContext->checkDownloadedContentMatches("$content\n", "", $response); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** @@ -895,15 +900,15 @@ public function shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPasswordAn return; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPassword( + $response = $this->downloadFileFromPublicFolder( $path, $password, + "", $publicWebDAVAPIVersion ); + $this->featureContext->checkDownloadedContentMatches($content, "", $response); - $this->featureContext->downloadedContentShouldBe($content); - - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** @@ -971,13 +976,13 @@ public function shouldBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPas return; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadFileFromPublicFolder( $path, $password, $range, $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** @@ -1003,21 +1008,21 @@ public function shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWith return; } - $this->publicDownloadsTheFileInsideThePublicSharedFolderWithPasswordAndRange( + $response = $this->downloadFileFromPublicFolder( $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); } /** @@ -1088,7 +1093,7 @@ public function publiclyUploadingShouldToSharedFileShouldFail( } $filename = (string)$this->featureContext->getLastCreatedPublicShare()->file_target; - $this->publicUploadContent( + $response = $this->publicUploadContent( $filename, '', 'test', @@ -1097,7 +1102,7 @@ public function publiclyUploadingShouldToSharedFileShouldFail( $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode); + $this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode, "", $response); } /** @@ -1117,7 +1122,7 @@ public function publiclyUploadingShouldNotWork( return; } - $this->publicUploadContent( + $response = $this->publicUploadContent( 'whateverfilefortesting.txt', '', 'test', @@ -1126,14 +1131,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 +1156,7 @@ public function publiclyUploadingIntoFolderWithPasswordShouldWork( string $publicWebDAVAPIVersion, string $password ):void { - $this->publicUploadContent( + $response = $this->publicUploadContent( $filename, $password, 'test', @@ -1160,7 +1165,7 @@ public function publiclyUploadingIntoFolderWithPasswordShouldWork( $publicWebDAVAPIVersion ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response); } /** @@ -1179,7 +1184,7 @@ public function publiclyUploadingIntoFolderWithPasswordShouldFail( string $password, string $expectedHttpCode ):void { - $this->publicUploadContent( + $response = $this->publicUploadContent( $filename, $password, 'test', @@ -1188,11 +1193,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 +1217,7 @@ public function publiclyUploadingShouldWork(string $publicWebDAVAPIVersion):void return; } - $this->publicUploadContent( + $response = $this->publicUploadContent( $path, '', $content, @@ -1220,7 +1225,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 " . @@ -1230,7 +1235,13 @@ public function publiclyUploadingShouldWork(string $publicWebDAVAPIVersion):void $path, $publicWebDAVAPIVersion ); - $this->featureContext->checkDownloadedContentMatches($content); + $response = $this->downloadFileFromPublicFolder( + $path, + "", + "", + $publicWebDAVAPIVersion + ); + $this->featureContext->checkDownloadedContentMatches($content, "", $response); } /** @@ -1256,7 +1267,7 @@ public function publiclyUploadingToPublicLinkSharedFileShouldWork( $path = ""; } - $this->publicUploadContent( + $response = $this->publicUploadContent( $path, '', $content, @@ -1264,7 +1275,6 @@ public function publiclyUploadingToPublicLinkSharedFileShouldWork( [], $publicWebDAVAPIVersion ); - $response = $this->featureContext->getResponse(); if ($should) { Assert::assertTrue( ($response->getStatusCode() == 204), @@ -1272,14 +1282,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; @@ -1309,7 +1320,7 @@ public function thePublicUploadsFileToLastSharedFolderWithMtimeUsingTheWebdavApi $mtime = new DateTime($mtime); $mtime = $mtime->format('U'); - $this->publicUploadContent( + $response = $this->publicUploadContent( $fileName, '', 'test', @@ -1317,18 +1328,19 @@ public function thePublicUploadsFileToLastSharedFolderWithMtimeUsingTheWebdavApi ["X-OC-Mtime" => $mtime], $davVersion ); + $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, @@ -1348,14 +1360,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 ); } @@ -1367,7 +1377,7 @@ public function publicCreatesFolderUsingPassword( * @return void */ public function publicCreatesFolder(string $destination):void { - $this->publicCreatesFolderUsingPassword($destination, ''); + $this->featureContext->setResponse($this->publicCreatesFolderUsingPassword($destination, '')); } /** @@ -1382,8 +1392,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); } /** @@ -1400,11 +1410,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 ); } @@ -1473,7 +1484,7 @@ public function theMtimeOfFileInTheLastSharedPublicLinkUsingTheWebdavApiShouldNo * @param array $additionalHeaders * @param string $publicWebDAVAPIVersion * - * @return void + * @return ResponseInterface|null */ public function publicUploadContent( string $filename, @@ -1482,9 +1493,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 +1526,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 +1534,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..b79d8c56d20 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); } /** diff --git a/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature b/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature index cc407f0876d..43312180368 100644 --- a/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature +++ b/tests/acceptance/features/coreApiSharePublicLink1/createPublicLinkShare.feature @@ -59,10 +59,11 @@ 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 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/" - 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" + 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: | ocs_api_version | ocs_status_code | diff --git a/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature b/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature index 2793fd062b2..48728c54c1a 100644 --- a/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature +++ b/tests/acceptance/features/coreApiSharePublicLink2/reShareAsPublicLinkToSharesNewDav.feature @@ -37,7 +37,8 @@ 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 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: @@ -90,7 +91,8 @@ 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 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: @@ -111,7 +113,8 @@ 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 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: