diff --git a/tests/acceptance/features/apiAntivirus/antivirus.feature b/tests/acceptance/features/apiAntivirus/antivirus.feature index fd7083c3b24..01c4a060cc3 100644 --- a/tests/acceptance/features/apiAntivirus/antivirus.feature +++ b/tests/acceptance/features/apiAntivirus/antivirus.feature @@ -472,7 +472,7 @@ Feature: antivirus And user "Alice" has created a space "new-space" with the default quota using the GraphApi And user "Alice" has created a folder ".space" in space "new-space" And user "Alice" has uploaded a file inside space "new-space" with content "Here you can add a description for this Space." to ".space/readme.md" - And user "Alice" has uploaded a file inside space "new-space" with content "X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*" to ".space/readme.md" + When user "Alice" uploads a file inside space "new-space" with content "X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*" to ".space/readme.md" using the WebDAV API Then the HTTP status code should be "204" And user "Alice" should get a notification with subject "Virus found" and message: | message | diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 45ff6e2f2a3..8ec303b4c97 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -3189,7 +3189,7 @@ public function restoreAdminPassword(): void { */ public function deleteAllResourceCreatedByAdmin(): void { foreach ($this->adminResources as $resource) { - $this->userDeletesFile("admin", $resource); + $this->deleteFile("admin", $resource); } } diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index d25d7ec6a63..b51ad35e178 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -2525,8 +2525,8 @@ function (&$value, $key) { */ public function userDownloadsFailWithMessage(string $fileName, string $user, PyStringNode $errorMessage):void { $user = $this->getActualUsername($user); - $this->downloadFileAsUserUsingPassword($user, $fileName); - $receivedErrorMessage = $this->getResponseXml(null, __METHOD__)->xpath('//s:message'); + $response = $this->downloadFileAsUserUsingPassword($user, $fileName); + $receivedErrorMessage = $this->getResponseXml($response, __METHOD__)->xpath('//s:message'); Assert::assertEquals( $errorMessage, (string) $receivedErrorMessage[0], diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 9eca98f35b3..62fbd95b003 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -1083,6 +1083,7 @@ public function theUserCreatesAFolderUsingTheGraphApi( string $folder, string $spaceName ): void { + $folder = \trim($folder, '/'); $exploded = explode('/', $folder); $path = ''; for ($i = 0; $i < \count($exploded); $i++) { @@ -1121,19 +1122,48 @@ public function theUserTriesToCreateASubFolderUsingTheGraphApi( * * @throws GuzzleException */ - public function theUserHasCreateAFolderUsingTheGraphApi( + public function userHasCreatedAFolderInSpace( string $user, string $folder, string $spaceName ): void { - $this->theUserCreatesAFolderUsingTheGraphApi($user, $folder, $spaceName); - + $folder = \trim($folder, '/'); + $paths = explode('/', $folder); + $folderPath = ''; + foreach ($paths as $path) { + $folderPath .= "$path/"; + $response = $this->createFolderInSpace($user, $folderPath, $spaceName); + } $this->featureContext->theHTTPStatusCodeShouldBe( 201, - "Expected response status code should be 201" + "Expected response status code should be 201", + $response ); } + /** + * @param string $user + * @param string $folder + * @param string $spaceName + * @param string $ownerUser + * + * @return ResponseInterface + * + * @throws GuzzleException + */ + public function createFolderInSpace( + string $user, + string $folder, + string $spaceName, + string $ownerUser = '' + ): ResponseInterface { + if ($ownerUser === '') { + $ownerUser = $user; + } + $this->setSpaceIDByName($ownerUser, $spaceName); + return $this->featureContext->createFolder($user, $folder); + } + /** * @When /^user "([^"]*)" creates a folder "([^"]*)" in space "([^"]*)" owned by the user "([^"]*)" using the WebDav Api$/ * @@ -1152,11 +1182,7 @@ public function theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi( string $spaceName, string $ownerUser = '' ): void { - if ($ownerUser === '') { - $ownerUser = $user; - } - $this->setSpaceIDByName($ownerUser, $spaceName); - $response = $this->featureContext->createFolder($user, $folder); + $response = $this->createFolderInSpace($user, $folder, $spaceName, $ownerUser); $this->featureContext->setResponse($response); } @@ -1168,7 +1194,7 @@ public function theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi( * @param string $content * @param string $destination * - * @return string[] + * @return void * @throws GuzzleException * @throws Exception */ @@ -1177,9 +1203,10 @@ public function theUserUploadsAFileToSpace( string $spaceName, string $content, string $destination - ): array { + ): void { $this->setSpaceIDByName($user, $spaceName); - return $this->featureContext->uploadFileWithContent($user, $content, $destination); + $response = $this->featureContext->uploadFileWithContent($user, $content, $destination); + $this->featureContext->setResponse($response); } /** @@ -1201,7 +1228,8 @@ public function theUserUploadsALocalFileToSpace( string $spaceName ): void { $this->setSpaceIDByName($user, $spaceName); - $this->featureContext->userUploadsAFileTo($user, $source, $destination); + $response = $this->featureContext->uploadFile($user, $source, $destination); + $this->featureContext->setResponse($response); } /** @@ -1225,7 +1253,8 @@ public function theUserUploadsAFileToAnotherOwnerSpace( string $destination ): void { $this->setSpaceIDByName($ownerUser, $spaceName); - $this->featureContext->uploadFileWithContent($user, $content, $destination); + $response = $this->featureContext->uploadFileWithContent($user, $content, $destination); + $this->featureContext->setResponse($response); } /** @@ -1706,19 +1735,19 @@ public function userShouldNotBeAbleToDownloadFileInsideSpace( string $spaceName ):void { $this->setSpaceIDByName($user, $spaceName); - $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user)); + $response = $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user)); Assert::assertGreaterThanOrEqual( 400, - $this->featureContext->getResponse()->getStatusCode(), + $response->getStatusCode(), __METHOD__ . ' download must fail' ); Assert::assertLessThanOrEqual( 499, - $this->featureContext->getResponse()->getStatusCode(), + $response->getStatusCode(), __METHOD__ . ' 4xx error expected but got status code "' - . $this->featureContext->getResponse()->getStatusCode() . '"' + . $response->getStatusCode() . '"' ); } @@ -1830,7 +1859,7 @@ public function userCopiesOrMovesFileWithFileIdFromAndToSpaceBetweenSpaces(strin * @param string $fileContent * @param string $destination * - * @return string[] + * @return array * @throws GuzzleException */ public function userHasUploadedFile( @@ -1840,9 +1869,10 @@ public function userHasUploadedFile( string $destination ): array { $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); - $fileId = $this->theUserUploadsAFileToSpace($user, $spaceName, $fileContent, $destination); - $this->featureContext->theHTTPStatusCodeShouldBeOr(201, 204); - return $fileId; + $this->setSpaceIDByName($user, $spaceName); + $response = $this->featureContext->uploadFileWithContent($user, $fileContent, $destination, true); + $this->featureContext->theHTTPStatusCodeShouldBe(['201', '204'], "", $response); + return $response->getHeader('oc-fileid'); } /** @@ -2646,7 +2676,8 @@ public function downloadFile( string $spaceName ): void { $this->setSpaceIDByName($user, $spaceName); - $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user)); + $response = $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user)); + $this->featureContext->setResponse($response); } /** diff --git a/tests/acceptance/features/bootstrap/TrashbinContext.php b/tests/acceptance/features/bootstrap/TrashbinContext.php index 1b940499dbe..dfdb122ebd6 100644 --- a/tests/acceptance/features/bootstrap/TrashbinContext.php +++ b/tests/acceptance/features/bootstrap/TrashbinContext.php @@ -889,11 +889,11 @@ public function contentOfFileForUserIfAlsoInTrashShouldBeOtherwise( ):void { $isInTrash = $this->isInTrash($user, $fileName); $user = $this->featureContext->getActualUsername($user); - $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName); + $response = $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName); if ($isInTrash) { - $this->featureContext->downloadedContentShouldBe($content); + $this->featureContext->checkDownloadedContentMatches($content, '', $response); } else { - $this->featureContext->downloadedContentShouldBe($alternativeContent); + $this->featureContext->checkDownloadedContentMatches($alternativeContent, '', $response); } } diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 64289299a0d..f5e69882d92 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -603,20 +603,14 @@ public function userHasMovedFile( $user, $fileDestination ); - $this->response = $this->makeDavRequest( + $response = $this->makeDavRequest( $user, "MOVE", $fileSource, $headers ); - $expectedStatusCode = 201; - $actualStatusCode = $this->response->getStatusCode(); - Assert::assertEquals( - $expectedStatusCode, - $actualStatusCode, - __METHOD__ . " Failed moving resource '$fileSource' to '$fileDestination'." - . " Expected status code was '$expectedStatusCode' but got '$actualStatusCode'" - ); + $actualStatusCode = $response->getStatusCode(); + $this->theHTTPStatusCodeShouldBe(201, " Failed moving resource '$fileSource' to '$fileDestination'." . " Expected status code was 201 but got '$actualStatusCode' ", $response); } /** @@ -838,36 +832,47 @@ public function userOnMovesFileUsingTheAPI( } /** - * @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" to "([^"]*)" using the WebDAV API$/ - * * @param string $user * @param string $fileSource * @param string $fileDestination * - * @return void + * @return ResponseInterface */ - public function userCopiesFileUsingTheAPI( + public function copyFile( string $user, string $fileSource, string $fileDestination - ):void { + ):ResponseInterface { $user = $this->getActualUsername($user); $headers['Destination'] = $this->destinationHeaderValue( $user, $fileDestination ); - $this->response = $this->makeDavRequest( + return $this->makeDavRequest( $user, "COPY", $fileSource, $headers ); - $this->setResponseXml( - HttpRequestHelper::parseResponseAsXml($this->response) - ); - $this->pushToLastHttpStatusCodesArray( - (string) $this->getResponse()->getStatusCode() - ); + } + + /** + * @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" to "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $fileSource + * @param string $fileDestination + * + * @return void + */ + public function userCopiesFileUsingTheAPI( + string $user, + string $fileSource, + string $fileDestination + ):void { + $response = $this->copyFile($user, $fileSource, $fileDestination); + $this->setResponse($response); + $this->pushToLastHttpStatusCodesArray(); } /** @@ -884,12 +889,12 @@ public function userHasCopiedFileUsingTheAPI( string $fileSource, string $fileDestination ):void { - $this->userCopiesFileUsingTheAPI($user, $fileSource, $fileDestination); + $response = $this->copyFile($user, $fileSource, $fileDestination); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to copy file '$fileSource' to '$fileDestination' for user '$user'" + "HTTP status code was not 201 or 204 while trying to copy file '$fileSource' to '$fileDestination' for user '$user'", + $response ); - $this->emptyLastHTTPStatusCodesArray(); } /** @@ -913,10 +918,11 @@ public function theUserCopiesFileUsingTheAPI(string $fileSource, string $fileDes * @return void */ public function theUserHasCopiedFileUsingTheAPI(string $fileSource, string $fileDestination):void { - $this->theUserCopiesFileUsingTheAPI($fileSource, $fileDestination); + $response = $this->copyFile($this->getCurrentUser(), $fileSource, $fileDestination); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to copy file '$fileSource' to '$fileDestination'" + "HTTP status code was not 201 or 204 while trying to copy file '$fileSource' to '$fileDestination'", + $response ); } @@ -928,8 +934,8 @@ public function theUserHasCopiedFileUsingTheAPI(string $fileSource, string $file * * @return void */ - public function downloadFileWithRange(string $fileSource, string $range):void { - $this->userDownloadsFileWithRange( + public function theUserDownloadsFileWithRange(string $fileSource, string $range):void { + $this->userDownloadsFileWithRangeUsingWebDavApi( $this->currentUser, $fileSource, $range @@ -937,18 +943,16 @@ public function downloadFileWithRange(string $fileSource, string $range):void { } /** - * @When /^user "([^"]*)" downloads file "([^"]*)" with range "([^"]*)" using the WebDAV API$/ - * * @param string $user * @param string $fileSource * @param string $range * - * @return void + * @return ResponseInterface */ - public function userDownloadsFileWithRange(string $user, string $fileSource, string $range):void { + public function downloadFileWithRange(string $user, string $fileSource, string $range):ResponseInterface { $user = $this->getActualUsername($user); $headers['Range'] = $range; - $this->response = $this->makeDavRequest( + return $this->makeDavRequest( $user, "GET", $fileSource, @@ -956,6 +960,19 @@ public function userDownloadsFileWithRange(string $user, string $fileSource, str ); } + /** + * @When /^user "([^"]*)" downloads file "([^"]*)" with range "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $fileSource + * @param string $range + * + * @return void + */ + public function userDownloadsFileWithRangeUsingWebDavApi(string $user, string $fileSource, string $range):void { + $this->setResponse($this->downloadFileWithRange($user, $fileSource, $range)); + } + /** * @Then /^user "([^"]*)" using password "([^"]*)" should not be able to download file "([^"]*)"$/ * @@ -972,19 +989,19 @@ public function userUsingPasswordShouldNotBeAbleToDownloadFile( ):void { $user = $this->getActualUsername($user); $password = $this->getActualPassword($password); - $this->downloadFileAsUserUsingPassword($user, $fileName, $password); + $response = $this->downloadFileAsUserUsingPassword($user, $fileName, $password); Assert::assertGreaterThanOrEqual( 400, - $this->getResponse()->getStatusCode(), + $response->getStatusCode(), __METHOD__ . ' download must fail' ); Assert::assertLessThanOrEqual( 499, - $this->getResponse()->getStatusCode(), + $response->getStatusCode(), __METHOD__ . ' 4xx error expected but got status code "' - . $this->getResponse()->getStatusCode() . '"' + . $response->getStatusCode() . '"' ); } @@ -1003,19 +1020,19 @@ public function userShouldNotBeAbleToDownloadFile( ):void { $user = $this->getActualUsername($user); $password = $this->getPasswordForUser($user); - $this->downloadFileAsUserUsingPassword($user, $fileName, $password); + $response = $this->downloadFileAsUserUsingPassword($user, $fileName, $password); Assert::assertGreaterThanOrEqual( 400, - $this->getResponse()->getStatusCode(), + $response->getStatusCode(), __METHOD__ . ' download must fail' ); Assert::assertLessThanOrEqual( 499, - $this->getResponse()->getStatusCode(), + $response->getStatusCode(), __METHOD__ . ' 4xx error expected but got status code "' - . $this->getResponse()->getStatusCode() . '"' + . $response->getStatusCode() . '"' ); } @@ -1095,7 +1112,7 @@ public function checkDownloadedContentMatches( // A separate "Then" step can specifically check the HTTP status. // But if the content is wrong (e.g. empty) then it is useful to // report the HTTP status to give some clue what might be the problem. - $actualStatus = $this->response->getStatusCode(); + $actualStatus = $response->getStatusCode(); if ($extraErrorText !== "") { $extraErrorText .= "\n"; } @@ -1176,8 +1193,8 @@ public function downloadedContentShouldBePlusEndOfLine(string $content):void { * @return void */ public function contentOfFileShouldBe(string $fileName, string $content):void { - $this->theUserDownloadsTheFileUsingTheAPI($fileName); - $this->downloadedContentShouldBe($content); + $response = $this->downloadFileAsUserUsingPassword($this->currentUser, $fileName); + $this->checkDownloadedContentMatches($content, '', $response); } /** @@ -1219,14 +1236,14 @@ public function contentOfFileShouldBePlusEndOfLine(string $fileName, string $con */ public function contentOfFileForUserShouldBe(string $fileName, string $user, string $content):void { $user = $this->getActualUsername($user); - $this->downloadFileAsUserUsingPassword($user, $fileName); - $actualStatus = $this->response->getStatusCode(); + $response = $this->downloadFileAsUserUsingPassword($user, $fileName); + $actualStatus = $response->getStatusCode(); if ($actualStatus !== 200) { throw new Exception( "Expected status code to be '200', but got '$actualStatus'" ); } - $this->checkDownloadedContentMatches($content); + $this->checkDownloadedContentMatches($content, '', $response); } /** @@ -1287,8 +1304,8 @@ public function contentOfFileForUserUsingPasswordShouldBe( ):void { $user = $this->getActualUsername($user); $password = $this->getActualPassword($password); - $this->downloadFileAsUserUsingPassword($user, $fileName, $password); - $this->downloadedContentShouldBe($content); + $response = $this->downloadFileAsUserUsingPassword($user, $fileName, $password); + $this->checkDownloadedContentMatches($content, '', $response); } /** @@ -1447,8 +1464,8 @@ public function downloadedContentWhenDownloadingForUserWithRangeShouldBe( string $content ):void { $user = $this->getActualUsername($user); - $this->userDownloadsFileWithRange($user, $fileSource, $range); - $this->downloadedContentShouldBe($content); + $response = $this->downloadFileWithRange($user, $fileSource, $range); + $this->checkDownloadedContentMatches($content, '', $response); } /** @@ -1459,7 +1476,7 @@ public function downloadedContentWhenDownloadingForUserWithRangeShouldBe( * @return void */ public function theUserDownloadsTheFileUsingTheAPI(string $fileName):void { - $this->downloadFileAsUserUsingPassword($this->currentUser, $fileName); + $this->setResponse($this->downloadFileAsUserUsingPassword($this->currentUser, $fileName)); } /** @@ -1474,7 +1491,7 @@ public function userDownloadsFileUsingTheAPI( string $user, string $fileName ):void { - $this->downloadFileAsUserUsingPassword($user, $fileName); + $this->setResponse($this->downloadFileAsUserUsingPassword($user, $fileName)); } /** @@ -1491,7 +1508,7 @@ public function userUsingPasswordDownloadsTheFileUsingTheAPI( ?string $password, string $fileName ):void { - $this->downloadFileAsUserUsingPassword($user, $fileName, $password); + $this->setResponse($this->downloadFileAsUserUsingPassword($user, $fileName, $password)); } /** @@ -1500,17 +1517,17 @@ public function userUsingPasswordDownloadsTheFileUsingTheAPI( * @param string|null $password * @param array|null $headers * - * @return void + * @return ResponseInterface */ public function downloadFileAsUserUsingPassword( string $user, string $fileName, ?string $password = null, ?array $headers = [] - ):void { + ):ResponseInterface { $user = $this->getActualUsername($user); $password = $this->getActualPassword($password); - $this->response = $this->makeDavRequest( + return $this->makeDavRequest( $user, 'GET', $fileName, @@ -2071,25 +2088,23 @@ public function checkElementList( } /** - * @When user :user uploads file :source to :destination using the WebDAV API - * * @param string $user * @param string $source * @param string $destination * @param bool|null $isGivenStep * - * @return void + * @return ResponseInterface */ - public function userUploadsAFileTo( + public function uploadFile( string $user, string $source, string $destination, ?bool $isGivenStep = false - ):void { + ):ResponseInterface { $user = $this->getActualUsername($user); $file = \fopen($this->acceptanceTestsDirLocation() . $source, 'r'); $this->pauseUploadDelete(); - $this->response = $this->makeDavRequest( + $response = $this->makeDavRequest( $user, "PUT", $destination, @@ -2104,8 +2119,27 @@ public function userUploadsAFileTo( $isGivenStep ); $this->lastUploadDeleteTime = \time(); + return $response; + } + + /** + * @When user :user uploads file :source to :destination using the WebDAV API + * + * @param string $user + * @param string $source + * @param string $destination + * + * @return void + */ + public function userUploadsAFileToUsingWebDavApi( + string $user, + string $source, + string $destination + ):void { + $response = $this->uploadFile($user, $source, $destination); + $this->setResponse($response); $this->setResponseXml( - HttpRequestHelper::parseResponseAsXml($this->response) + HttpRequestHelper::parseResponseAsXml($response) ); $this->pushToLastHttpStatusCodesArray( (string) $this->getResponse()->getStatusCode() @@ -2122,12 +2156,12 @@ public function userUploadsAFileTo( * @return void */ public function userHasUploadedAFileTo(string $user, string $source, string $destination):void { - $this->userUploadsAFileTo($user, $source, $destination, true); + $response = $this->uploadFile($user, $source, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to upload file '$source' to '$destination' for user '$user'" + "HTTP status code was not 201 or 204 while trying to upload file '$source' to '$destination' for user '$user'", + $response ); - $this->emptyLastHTTPStatusCodesArray(); } /** @@ -2135,16 +2169,14 @@ public function userHasUploadedAFileTo(string $user, string $source, string $des * * @param string $source * @param string $destination - * @param bool|null $isGivenStep * * @return void */ public function theUserUploadsAFileTo( string $source, - string $destination, - ?bool $isGivenStep = false + string $destination ):void { - $this->userUploadsAFileTo($this->currentUser, $source, $destination, $isGivenStep); + $this->userUploadsAFileToUsingWebDavApi($this->currentUser, $source, $destination); } /** @@ -2156,10 +2188,11 @@ public function theUserUploadsAFileTo( * @return void */ public function theUserHasUploadedFileTo(string $source, string $destination):void { - $this->theUserUploadsAFileTo($source, $destination, true); + $response = $this->uploadFile($this->getCurrentUser(), $source, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to upload file '$source' to '$destination'" + "HTTP status code was not 201 or 204 while trying to upload file '$source' to '$destination'", + $response ); } @@ -2170,7 +2203,6 @@ public function theUserHasUploadedFileTo(string $source, string $destination):vo * @param string $server * @param string $source * @param string $destination - * @param bool|null $isGivenStep * * @return void */ @@ -2178,11 +2210,10 @@ public function userOnUploadsAFileTo( string $user, string $server, string $source, - string $destination, - ?bool $isGivenStep = false + string $destination ):void { $previousServer = $this->usingServer($server); - $this->userUploadsAFileTo($user, $source, $destination, $isGivenStep); + $this->userUploadsAFileToUsingWebDavApi($user, $source, $destination); $this->usingServer($previousServer); } @@ -2651,10 +2682,11 @@ public function theHTTPReasonPhraseOfAllUploadResponsesShouldBe(string $reasonPh */ public function userShouldBeAbleToUploadFileTo(string $user, string $source, string $destination):void { $user = $this->getActualUsername($user); - $this->userUploadsAFileTo($user, $source, $destination); + $response = $this->uploadFile($user, $source, $destination); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to upload file '$destination'" + "HTTP status code was not 201 or 204 while trying to upload file '$destination'", + $response ); $this->asFileOrFolderShouldExist($user, "file", $destination); } @@ -2678,7 +2710,7 @@ public function usersShouldBeAbleToUploadFileTo( $usernames = $table->getHash(); foreach ($usernames as $username) { $actualUser = $this->getActualUsername($username["username"]); - $this->userUploadsAFileTo($actualUser, $source, $destination); + $this->uploadFile($actualUser, $source, $destination); $this->asFileOrFolderShouldExist($actualUser, "file", $destination); } } @@ -2696,14 +2728,14 @@ public function usersShouldBeAbleToUploadFileTo( public function theUserShouldNotBeAbleToUploadFileTo(string $user, string $source, string $destination):void { $fileAlreadyExists = $this->fileOrFolderExists($user, "file", $destination); if ($fileAlreadyExists) { - $this->downloadFileAsUserUsingPassword($user, $destination); - $initialContent = (string) $this->response->getBody(); + $response = $this->downloadFileAsUserUsingPassword($user, $destination); + $initialContent = (string) $response->getBody(); } - $this->userUploadsAFileTo($user, $source, $destination); - $this->theHTTPStatusCodeShouldBe(["403", "423"]); + $response = $this->uploadFile($user, $source, $destination); + $this->theHTTPStatusCodeShouldBe(["403", "423"], "", $response); if ($fileAlreadyExists) { - $this->downloadFileAsUserUsingPassword($user, $destination); - $currentContent = (string) $this->response->getBody(); + $response = $this->downloadFileAsUserUsingPassword($user, $destination); + $currentContent = (string) $response->getBody(); Assert::assertSame( $initialContent, $currentContent, @@ -2913,7 +2945,6 @@ public function userHasUploadedFileToEndingWithOfSizeBytes(string $user, string * @param string $destination * @param string $text * @param string $bytes - * @param bool|null $isGivenStep * * @return void */ @@ -2921,17 +2952,15 @@ public function userUploadsAFileToEndingWithOfSizeBytes( string $user, string $destination, string $text, - string $bytes, - ?bool $isGivenStep = false + string $bytes ):void { $filename = "filespecificSize.txt"; $this->createLocalFileOfSpecificSize($filename, $bytes, $text); Assert::assertFileExists($this->workStorageDirLocation() . $filename); - $this->userUploadsAFileTo( + $this->userUploadsAFileToUsingWebDavApi( $user, $this->temporaryStorageSubfolderName() . "/$filename", - $destination, - $isGivenStep + $destination ); $this->removeFile($this->workStorageDirLocation(), $filename); } @@ -2977,7 +3006,7 @@ public function userUploadsFilesWithContentTo( * @param string $destination * @param bool|null $isGivenStep * - * @return string[] + * @return ResponseInterface * @throws JsonException * @throws GuzzleException */ @@ -2986,10 +3015,10 @@ public function uploadFileWithContent( ?string $content, string $destination, ?bool $isGivenStep = false - ): array { + ): ResponseInterface { $user = $this->getActualUsername($user); $this->pauseUploadDelete(); - $this->response = $this->makeDavRequest( + $response = $this->makeDavRequest( $user, "PUT", $destination, @@ -3003,11 +3032,8 @@ public function uploadFileWithContent( null, $isGivenStep ); - $this->setResponseXml( - HttpRequestHelper::parseResponseAsXml($this->response) - ); $this->lastUploadDeleteTime = \time(); - return $this->response->getHeader('oc-fileid'); + return $response; } /** @@ -3016,13 +3042,16 @@ public function uploadFileWithContent( * @param string|null $content * @param string $destination * - * @return string[] + * @return void + * @throws GuzzleException + * @throws JsonException */ public function adminUploadsAFileWithContentTo( ?string $content, string $destination - ):array { - return $this->uploadFileWithContent($this->getAdminUsername(), $content, $destination); + ):void { + $response = $this->uploadFileWithContent($this->getAdminUsername(), $content, $destination); + $this->setResponse($response); } /** @@ -3031,18 +3060,20 @@ public function adminUploadsAFileWithContentTo( * @param string|null $content * @param string $destination * - * @return string[] + * @return void + * @throws GuzzleException + * @throws JsonException */ public function adminHasUploadedAFileWithContentTo( ?string $content, string $destination - ):array { - $fileId = $this->uploadFileWithContent($this->getAdminUsername(), $content, $destination, true); + ):void { + $response = $this->uploadFileWithContent($this->getAdminUsername(), $content, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to upload file '$destination'" + "HTTP status code was not 201 or 204 while trying to upload file '$destination'", + $response ); - return $fileId; } /** @@ -3061,7 +3092,8 @@ public function userUploadsAFileWithContentTo( ?string $content, string $destination ):void { - $this->uploadFileWithContent($user, $content, $destination); + $response = $this->uploadFileWithContent($user, $content, $destination); + $this->setResponse($response); $this->pushToLastHttpStatusCodesArray(); } @@ -3084,7 +3116,8 @@ public function userUploadsFollowingFilesWithContentTo( $paths = $table->getHash(); foreach ($paths as $destination) { - $this->uploadFileWithContent($user, $content, $destination["path"]); + $response = $this->uploadFileWithContent($user, $content, $destination["path"]); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } } @@ -3270,7 +3303,9 @@ public function theMtimeOfTheFileShouldNotBe( * @param string|null $content * @param string $destination * - * @return string[] + * @return array + * @throws GuzzleException + * @throws JsonException */ public function userHasUploadedAFileWithContentTo( string $user, @@ -3278,13 +3313,13 @@ public function userHasUploadedAFileWithContentTo( string $destination ):array { $user = $this->getActualUsername($user); - $fileId = $this->uploadFileWithContent($user, $content, $destination, true); + $response = $this->uploadFileWithContent($user, $content, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to upload file '$destination' for user '$user'" + "HTTP status code was not 201 or 204 while trying to upload file '$destination' for user '$user'", + $response ); - $this->emptyLastHTTPStatusCodesArray(); - return $fileId; + return $response->getHeader('oc-fileid'); } /** @@ -3294,23 +3329,20 @@ public function userHasUploadedAFileWithContentTo( * @param string|null $content * @param TableNode $table * - * @return array - * @throws Exception + * @return void + * @throws Exception|GuzzleException */ public function userHasUploadedFollowingFilesWithContent( string $user, ?string $content, TableNode $table - ):array { + ):void { $this->verifyTableNodeColumns($table, ["path"]); $files = $table->getHash(); - $fileIds = []; foreach ($files as $destination) { - $fileId = $this->userHasUploadedAFileWithContentTo($user, $content, $destination["path"])[0]; - $fileIds[] = $fileId; + $this->userHasUploadedAFileWithContentTo($user, $content, $destination["path"]); } - return $fileIds; } /** @@ -3330,7 +3362,8 @@ public function userDownloadsFollowingFiles( $files = $table->getHash(); $this->emptyLastHTTPStatusCodesArray(); foreach ($files as $fileName) { - $this->downloadFileAsUserUsingPassword($user, $fileName["path"]); + $response = $this->downloadFileAsUserUsingPassword($user, $fileName["path"]); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } } @@ -3355,39 +3388,34 @@ public function userUploadsAFileWithContentAndMtimeTo( $user = $this->getActualUsername($user); $mtime = new DateTime($mtime); $mtime = $mtime->format('U'); - $this->makeDavRequest( + $response = $this->makeDavRequest( $user, "PUT", $destination, ["X-OC-Mtime" => $mtime], $content ); - $this->theHTTPStatusCodeShouldBe( - ["201", "204"], - "HTTP status code was not 201 or 204 while trying to upload file '$destination' with mtime $mtime for user '$user'" - ); + $this->setResponse($response); } /** - * @When user :user uploads file with checksum :checksum and content :content to :destination using the WebDAV API - * * @param string $user * @param string $checksum * @param string|null $content * @param string $destination * @param bool|null $isGivenStep * - * @return void + * @return ResponseInterface */ - public function userUploadsAFileWithChecksumAndContentTo( + public function uploadFileWithChecksumAndContent( string $user, string $checksum, ?string $content, string $destination, ?bool $isGivenStep = false - ):void { + ):ResponseInterface { $this->pauseUploadDelete(); - $this->response = $this->makeDavRequest( + $response = $this->makeDavRequest( $user, "PUT", $destination, @@ -3402,7 +3430,27 @@ public function userUploadsAFileWithChecksumAndContentTo( $isGivenStep ); $this->lastUploadDeleteTime = \time(); - $this->pushToLastStatusCodesArrays(); + return $response; + } + + /** + * @When user :user uploads file with checksum :checksum and content :content to :destination using the WebDAV API + * + * @param string $user + * @param string $checksum + * @param string $content + * @param string $destination + * + * @return void + */ + public function userUploadsAFileWithChecksumAndContentTo( + string $user, + string $checksum, + string $content, + string $destination + ):void { + $response = $this->uploadFileWithChecksumAndContent($user, $checksum, $content, $destination); + $this->setResponse($response); } /** @@ -3421,7 +3469,7 @@ public function userHasUploadedAFileWithChecksumAndContentTo( ?string $content, string $destination ):void { - $this->userUploadsAFileWithChecksumAndContentTo( + $response = $this->uploadFileWithChecksumAndContent( $user, $checksum, $content, @@ -3430,7 +3478,8 @@ public function userHasUploadedAFileWithChecksumAndContentTo( ); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to upload file with checksum '$checksum' to '$destination' for user '$user'" + "HTTP status code was not 201 or 204 while trying to upload file with checksum '$checksum' to '$destination' for user '$user'", + $response ); } @@ -3447,7 +3496,7 @@ public function userHasUploadedAFileWithChecksumAndContentTo( public function userShouldBeAbleToDeleteEntry(string $user, string $entry, string $source):void { $user = $this->getActualUsername($user); $this->asFileOrFolderShouldExist($user, $entry, $source); - $this->userDeletesFile($user, $source); + $this->deleteFile($user, $source); $this->asFileOrFolderShouldNotExist($user, $entry, $source); } @@ -3463,7 +3512,7 @@ public function userShouldBeAbleToDeleteEntry(string $user, string $entry, strin */ public function theUserShouldNotBeAbleToDeleteEntry(string $user, string $entry, string $source):void { $this->asFileOrFolderShouldExist($user, $entry, $source); - $this->userDeletesFile($user, $source); + $this->deleteFile($user, $source); $this->asFileOrFolderShouldExist($user, $entry, $source); } @@ -3480,19 +3529,31 @@ public function fileHasBeenDeleted(string $file, string $user):void { } /** - * @When user :user deletes file/folder :resource using the WebDAV API - * * @param string $user * @param string $resource * * @return void */ - public function userDeletesFile(string $user, string $resource):void { + public function deleteFile(string $user, string $resource):ResponseInterface { $user = $this->getActualUsername($user); $this->pauseUploadDelete(); - $this->response = $this->makeDavRequest($user, 'DELETE', $resource, []); + $response = $this->makeDavRequest($user, 'DELETE', $resource, []); $this->lastUploadDeleteTime = \time(); - $this->pushToLastHttpStatusCodesArray((string) $this->getResponse()->getStatusCode()); + return $response; + } + + /** + * @When user :user deletes file/folder :resource using the WebDAV API + * + * @param string $user + * @param string $resource + * + * @return void + */ + public function userDeletesFile(string $user, string $resource):void { + $response = $this->deleteFile($user, $resource); + $this->setResponse($response); + $this->pushToLastStatusCodesArrays(); } /** @@ -3506,7 +3567,7 @@ public function userDeletesFile(string $user, string $resource):void { */ public function userHasDeletedResource(string $user, string $resource):void { $user = $this->getActualUsername($user); - $this->userDeletesFile($user, $resource); + $response = $this->deleteFile($user, $resource); // If the file or folder was there and got deleted then we get a 204 // That is good and the expected status // If the file or folder was already not there then we get a 404 @@ -3516,9 +3577,9 @@ public function userHasDeletedResource(string $user, string $resource):void { $this->theHTTPStatusCodeShouldBe( ["204"], - "HTTP status code was not 204 while trying to delete resource '$resource' for user '$user'" + "HTTP status code was not 204 while trying to delete resource '$resource' for user '$user'", + $response ); - $this->emptyLastHTTPStatusCodesArray(); } /** @@ -3567,7 +3628,8 @@ public function userDeletesFollowingFiles(string $user, TableNode $table):void { * @return void */ public function theUserDeletesFile(string $file):void { - $this->userDeletesFile($this->getCurrentUser(), $file); + $response = $this->deleteFile($this->getCurrentUser(), $file); + $this->setResponse($response); } /** @@ -3625,7 +3687,7 @@ public function theUserDeletesFilesFoldersWithoutDelays(TableNode $table):void { */ public function userOnDeletesFile(string $user, string $server, string $file):void { $previousServer = $this->usingServer($server); - $this->userDeletesFile($user, $file); + $this->setResponse($this->deleteFile($user, $file)); $this->usingServer($previousServer); } @@ -3658,13 +3720,12 @@ public function userOnHasDeletedFile(string $user, string $server, string $fileO * @param string $destination * * @return void - * @throws JsonException | GuzzleException - * @throws GuzzleException | JsonException + * @throws JsonException + * @throws GuzzleException */ public function userCreatesFolder(string $user, string $destination):void { $response = $this->createFolder($user, $destination); $this->setResponse($response); - $this->pushToLastHttpStatusCodesArray(); } /** @@ -3678,6 +3739,7 @@ public function userCreatesFolder(string $user, string $destination):void { * @throws GuzzleException */ public function userHasCreatedFolder(string $user, string $destination):void { + $user = $this->getActualUsername($user); $response = $this->createFolder($user, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], @@ -3729,6 +3791,33 @@ public function userHasCreatedFollowingFolders(string $user, TableNode $table):v } } + /** + * @When the user creates folder :destination using the WebDAV API + * + * @param string $destination + * + * @return void + */ + public function theUserCreatesFolder(string $destination):void { + $this->userCreatesFolder($this->getCurrentUser(), $destination); + } + + /** + * @Given the user has created folder :destination + * + * @param string $destination + * + * @return void + */ + public function theUserHasCreatedFolder(string $destination):void { + $response = $this->createFolder($this->getCurrentUser(), $destination, true); + $this->theHTTPStatusCodeShouldBe( + ["201", "204"], + "HTTP status code was not 201 or 204 while trying to create folder '$destination'", + $response + ); + } + /** * @Then user :user should be able to create folder :destination * @@ -3759,10 +3848,11 @@ public function userShouldBeAbleToCreateFolder(string $user, string $destination public function userShouldNotBeAbleToCreateFolder(string $user, string $destination):void { $user = $this->getActualUsername($user); $response = $this->createFolder($user, $destination); - Assert::assertNotEquals( - 201, - $response->getStatusCode(), - "User '$user' should not be able to create folder '$destination' but was successful" + $this->theHTTPStatusCodeShouldBeBetween(400, 499, $response); + $this->asFileOrFolderShouldNotExist( + $user, + "folder", + $destination ); } @@ -3832,8 +3922,6 @@ public function userUploadsTheFollowingChunksUsingOldChunking( /** * Old style chunking upload * - * @When user :user uploads chunk file :num of :total with :data to :destination using the WebDAV API - * * @param string $user * @param int $num * @param int $total @@ -3841,21 +3929,21 @@ public function userUploadsTheFollowingChunksUsingOldChunking( * @param string $destination * @param bool|null $isGivenStep * - * @return void + * @return ResponseInterface */ - public function userUploadsChunkedFile( + public function userUploadChunkedFile( string $user, int $num, int $total, ?string $data, string $destination, ?bool $isGivenStep = false - ):void { + ):ResponseInterface { $user = $this->getActualUsername($user); $num -= 1; $file = "$destination-chunking-42-$total-$num"; $this->pauseUploadDelete(); - $this->response = $this->makeDavRequest( + $response = $this->makeDavRequest( $user, 'PUT', $file, @@ -3870,6 +3958,29 @@ public function userUploadsChunkedFile( $isGivenStep ); $this->lastUploadDeleteTime = \time(); + return $response; + } + + /** + * @When user :user uploads chunk file :num of :total with :data to :destination using the WebDAV API + * + * @param string $user + * @param int $num + * @param int $total + * @param string $data + * @param string $destination + * + * @return void + */ + public function userUploadsChunkedFile( + string $user, + int $num, + int $total, + ?string $data, + string $destination + ):void { + $response = $this->userUploadChunkedFile($user, $num, $total, $data, $destination); + $this->setResponse($response); } /** @@ -3893,10 +4004,11 @@ public function userHasUploadedChunkedFile( string $destination ):void { $user = $this->getActualUsername($user); - $this->userUploadsChunkedFile($user, $num, $total, $data, $destination, true); + $response = $this->userUploadChunkedFile($user, $num, $total, $data, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to upload chunk $num of $total to file '$destination' for user '$user'" + "HTTP status code was not 201 or 204 while trying to upload chunk $num of $total to file '$destination' for user '$user'", + $response ); } @@ -4046,30 +4158,31 @@ public function userUploadsChunksUsingNewChunking( if ($async === true) { $headers = ['OC-LazyOps' => 'true']; } - $this->moveNewDavChunkToFinalFile($user, $chunkingId, $file, $headers, $isGivenStep); + $response = $this->moveNewDavChunkToFinalFile($user, $chunkingId, $file, $headers, $isGivenStep); if ($isGivenStep) { - $this->theHTTPStatusCodeShouldBeSuccess(); + $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); + } else { + $this->setResponse($response); } $this->lastUploadDeleteTime = \time(); } /** - * @When user :user creates a new chunking upload with id :id using the WebDAV API * * @param string $user * @param string $id * @param bool|null $isGivenStep * - * @return void + * @return ResponseInterface */ - public function userCreatesANewChunkingUploadWithId( + public function userCreateANewChunkingUploadWithId( string $user, string $id, ?bool $isGivenStep = false - ):void { + ):ResponseInterface { $user = $this->getActualUsername($user); $destination = "/uploads/$user/$id"; - $this->response = $this->makeDavRequest( + return $this->makeDavRequest( $user, 'MKCOL', $destination, @@ -4085,6 +4198,22 @@ public function userCreatesANewChunkingUploadWithId( ); } + /** + * @When user :user creates a new chunking upload with id :id using the WebDAV API + * + * @param string $user + * @param string $id + * + * @return void + */ + public function userCreatesANewChunkingUploadWithId( + string $user, + string $id + ):void { + $response = $this->userCreateANewChunkingUploadWithId($user, $id); + $this->setResponse($response); + } + /** * @Given user :user has created a new chunking upload with id :id * @@ -4094,31 +4223,29 @@ public function userCreatesANewChunkingUploadWithId( * @return void */ public function userHasCreatedANewChunkingUploadWithId(string $user, string $id):void { - $this->userCreatesANewChunkingUploadWithId($user, $id, true); - $this->theHTTPStatusCodeShouldBeSuccess(); + $response = $this->userCreateANewChunkingUploadWithId($user, $id, true); + $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** - * @When user :user uploads new chunk file :num with :data to id :id using the WebDAV API - * * @param string $user * @param int $num * @param string|null $data * @param string $id * @param bool|null $isGivenStep * - * @return void + * @return ResponseInterface */ - public function userUploadsNewChunkFileOfWithToId( + public function userUploadNewChunkFileOfWithToId( string $user, int $num, ?string $data, string $id, ?bool $isGivenStep = false - ):void { + ):ResponseInterface { $user = $this->getActualUsername($user); $destination = "/uploads/$user/$id/$num"; - $this->response = $this->makeDavRequest( + return $this->makeDavRequest( $user, 'PUT', $destination, @@ -4132,6 +4259,26 @@ public function userUploadsNewChunkFileOfWithToId( null, $isGivenStep ); + } + + /** + * @When user :user uploads new chunk file :num with :data to id :id using the WebDAV API + * + * @param string $user + * @param int $num + * @param string|null $data + * @param string $id + * + * @return void + */ + public function userUploadsNewChunkFileOfWithToId( + string $user, + int $num, + ?string $data, + string $id + ):void { + $response = $this->userUploadNewChunkFileOfWithToId($user, $num, $data, $id); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -4146,8 +4293,29 @@ public function userUploadsNewChunkFileOfWithToId( * @return void */ public function userHasUploadedNewChunkFileOfWithToId(string $user, int $num, ?string $data, string $id):void { - $this->userUploadsNewChunkFileOfWithToId($user, $num, $data, $id, true); - $this->theHTTPStatusCodeShouldBeSuccess(); + $response = $this->userUploadNewChunkFileOfWithToId($user, $num, $data, $id, true); + $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); + } + + /** + * @param string $user + * @param string $id + * @param string $type "asynchronously" or empty + * @param string $dest + * + * @return ResponseInterface + */ + public function userMoveNewChunkFileWithIdToMychunkedfile( + string $user, + string $id, + string $type, + string $dest + ):ResponseInterface { + $headers = []; + if ($type === "asynchronously") { + $headers = ['OC-LazyOps' => 'true']; + } + return $this->moveNewDavChunkToFinalFile($user, $id, $dest, $headers); } /** @@ -4166,11 +4334,7 @@ public function userMovesNewChunkFileWithIdToMychunkedfile( string $type, string $dest ):void { - $headers = []; - if ($type === "asynchronously") { - $headers = ['OC-LazyOps' => 'true']; - } - $this->moveNewDavChunkToFinalFile($user, $id, $dest, $headers); + $this->setResponse($this->userMoveNewChunkFileWithIdToMychunkedfile($user, $id, $type, $dest)); } /** @@ -4189,8 +4353,8 @@ public function userHasMovedNewChunkFileWithIdToMychunkedfile( string $type, string $dest ):void { - $this->userMovesNewChunkFileWithIdToMychunkedfile($user, $id, $type, $dest); - $this->theHTTPStatusCodeShouldBe("201"); + $response = $this->userMoveNewChunkFileWithIdToMychunkedfile($user, $id, $type, $dest); + $this->theHTTPStatusCodeShouldBe("201", "", $response); } /** @@ -4205,7 +4369,8 @@ public function userCancelsUploadWithId( string $user, string $id ):void { - $this->deleteUpload($user, $id, []); + $response = $this->deleteUpload($user, $id, []); + $this->setResponse($response); } /** @@ -4220,38 +4385,64 @@ public function userHasCanceledUploadWithId( string $user, string $id ):void { - $this->userCancelsUploadWithId($user, $id); - $this->theHTTPStatusCodeShouldBe("201"); + $response = $this->deleteUpload($user, $id, []); + $this->theHTTPStatusCodeShouldBe("201", "", $response); } /** - * @When /^user "([^"]*)" moves new chunk file with id "([^"]*)"\s?(asynchronously|) to "([^"]*)" with size (.*) using the WebDAV API$/ - * * @param string $user * @param string $id * @param string $type "asynchronously" or empty * @param string $dest * @param int $size * - * @return void + * @return ResponseInterface */ - public function userMovesNewChunkFileWithIdToMychunkedfileWithSize( + public function userMoveNewChunkFileWithIdToMychunkedfileWithSize( string $user, string $id, string $type, string $dest, int $size - ):void { + ):ResponseInterface { $headers = ['OC-Total-Length' => $size]; if ($type === "asynchronously") { $headers['OC-LazyOps'] = 'true'; } - $this->moveNewDavChunkToFinalFile( + return $this->moveNewDavChunkToFinalFile( $user, $id, $dest, $headers ); + } + + /** + * @When /^user "([^"]*)" moves new chunk file with id "([^"]*)"\s?(asynchronously|) to "([^"]*)" with size (.*) using the WebDAV API$/ + * + * @param string $user + * @param string $id + * @param string $type "asynchronously" or empty + * @param string $dest + * @param int $size + * + * @return void + */ + public function userMovesNewChunkFileWithIdToMychunkedfileWithSize( + string $user, + string $id, + string $type, + string $dest, + int $size + ):void { + $response = $this->userMoveNewChunkFileWithIdToMychunkedfileWithSize( + $user, + $id, + $type, + $dest, + $size + ); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -4273,44 +4464,64 @@ public function userHasMovedNewChunkFileWithIdToMychunkedfileWithSize( string $dest, int $size ):void { - $this->userMovesNewChunkFileWithIdToMychunkedfileWithSize( + $response = $this->userMoveNewChunkFileWithIdToMychunkedfileWithSize( $user, $id, $type, $dest, $size ); - $this->theHTTPStatusCodeShouldBe("201"); + $this->theHTTPStatusCodeShouldBe("201", "", $response); } /** - * @When /^user "([^"]*)" moves new chunk file with id "([^"]*)"\s?(asynchronously|) to "([^"]*)" with checksum "([^"]*)" using the WebDAV API$/ - * * @param string $user * @param string $id * @param string $type "asynchronously" or empty * @param string $dest * @param string $checksum * - * @return void + * @return ResponseInterface */ - public function userMovesNewChunkFileWithIdToMychunkedfileWithChecksum( + public function userMoveNewChunkFileWithIdToMychunkedfileWithChecksum( string $user, string $id, string $type, string $dest, string $checksum - ):void { + ):ResponseInterface { $headers = ['OC-Checksum' => $checksum]; if ($type === "asynchronously") { $headers['OC-LazyOps'] = 'true'; } - $this->moveNewDavChunkToFinalFile( + return $this->moveNewDavChunkToFinalFile( $user, $id, $dest, $headers ); + } + + /** + * @When /^user "([^"]*)" moves new chunk file with id "([^"]*)"\s?(asynchronously|) to "([^"]*)" with checksum "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $id + * @param string $type "asynchronously" or empty + * @param string $dest + * @param string $checksum + * + * @return void + */ + public function userMovesNewChunkFileWithIdToMychunkedfileWithChecksum( + string $user, + string $id, + string $type, + string $dest, + string $checksum + ):void { + $response = $this->userMoveNewChunkFileWithIdToMychunkedfileWithChecksum($user, $id, $type, $dest, $checksum); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -4332,14 +4543,14 @@ public function userHasMovedNewChunkFileWithIdToMychunkedfileWithChecksum( string $dest, string $checksum ):void { - $this->userMovesNewChunkFileWithIdToMychunkedfileWithChecksum( + $response = $this->userMoveNewChunkFileWithIdToMychunkedfileWithChecksum( $user, $id, $type, $dest, $checksum ); - $this->theHTTPStatusCodeShouldBe("201"); + $this->theHTTPStatusCodeShouldBe("201", "", $response); } /** @@ -4351,7 +4562,7 @@ public function userHasMovedNewChunkFileWithIdToMychunkedfileWithChecksum( * @param array $headers extra headers * @param bool|null $isGivenStep * - * @return void + * @return ResponseInterface */ private function moveNewDavChunkToFinalFile( string $user, @@ -4359,7 +4570,7 @@ private function moveNewDavChunkToFinalFile( string $destination, array $headers, ?bool $isGivenStep = false - ):void { + ):ResponseInterface { $user = $this->getActualUsername($user); $source = "/uploads/$user/$id/.file"; $headers['Destination'] = $this->destinationHeaderValue( @@ -4367,7 +4578,7 @@ private function moveNewDavChunkToFinalFile( $destination ); - $this->response = $this->makeDavRequest( + return $this->makeDavRequest( $user, 'MOVE', $source, @@ -4390,11 +4601,11 @@ private function moveNewDavChunkToFinalFile( * @param string $id upload id * @param array $headers extra headers * - * @return void + * @return ResponseInterface */ - private function deleteUpload(string $user, string $id, array $headers) { + private function deleteUpload(string $user, string $id, array $headers):ResponseInterface { $source = "/uploads/$user/$id"; - $this->response = $this->makeDavRequest( + return $this->makeDavRequest( $user, 'DELETE', $source, @@ -4418,12 +4629,12 @@ public function encodePath(string $path):string { } /** - * @When an unauthenticated client connects to the DAV endpoint using the WebDAV API + * an unauthenticated client connects to the DAV endpoint using the WebDAV API * - * @return void + * @return ResponseInterface */ - public function connectingToDavEndpoint():void { - $this->response = $this->makeDavRequest( + public function connectToDavEndpoint():ResponseInterface { + return $this->makeDavRequest( null, 'PROPFIND', '', @@ -4431,14 +4642,23 @@ public function connectingToDavEndpoint():void { ); } + /** + * @When an unauthenticated client connects to the DAV endpoint using the WebDAV API + * + * @return void + */ + public function connectingToDavEndpoint():void { + $this->setResponse($this->connectToDavEndpoint()); + } + /** * @Given an unauthenticated client has connected to the DAV endpoint * * @return void */ public function hasConnectedToDavEndpoint():void { - $this->connectingToDavEndpoint(); - $this->theHTTPStatusCodeShouldBe("401"); + $response = $this->connectToDavEndpoint(); + $this->theHTTPStatusCodeShouldBe("401", "", $response); } /** @@ -4714,7 +4934,7 @@ public function userUploadsFileWithContentSharedResourceToUsingTheWebdavApi(stri if ($this->getDavPathVersion() === 3) { $this->setResponse($this->uploadToSharedFolder($user, $destination, $content)); } else { - $this->uploadFileWithContent($user, $content, $destination); + $this->setResponse($this->uploadFileWithContent($user, $content, $destination)); } } @@ -4865,12 +5085,14 @@ public function imageDimensionsForAUserShouldBe(string $user, string $width, str * * @param string $width * @param string $height + * @param ResponseInterface|null $response * * @return void */ - public function imageDimensionsShouldBe(string $width, string $height): void { + public function imageDimensionsShouldBe(string $width, string $height, ?ResponseInterface $response = null): void { + $response = $response ?? $this->getResponse(); if ($this->responseBodyContent === null) { - $this->responseBodyContent = $this->response->getBody()->getContents(); + $this->responseBodyContent = $response->getBody()->getContents(); } $size = \getimagesizefromstring($this->responseBodyContent); Assert::assertNotFalse($size, "could not get size of image"); @@ -4916,9 +5138,15 @@ public function theDownloadedPreviewContentShouldMatchWithFixturesPreviewContent * @return void */ public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string $path, string $width, string $height):void { - $response = $this->downloadPreviewOfFiles($user, $path, $width, $height); - $this->theHTTPStatusCodeShouldBe(200, '', $response); - $this->imageDimensionsShouldBe($width, $height); + $response = $this->downloadPreviews( + $user, + $path, + null, + $width, + $height + ); + $this->theHTTPStatusCodeShouldBe(200, "", $response); + $this->imageDimensionsShouldBe($width, $height, $response); // save response to user response dictionary for further comparisons $this->userResponseBodyContents[$user] = $this->responseBodyContent; } @@ -4934,9 +5162,15 @@ public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string * @return void */ public function asUserThePreviewOfPathWithHeightAndWidthShouldHaveBeenChanged(string $user, string $path, string $width, string $height):void { - $response = $this->downloadPreviewOfFiles($user, $path, $width, $height); - $this->theHTTPStatusCodeShouldBe(200, '', $response); - $newResponseBodyContents = $this->response->getBody()->getContents(); + $response = $this->downloadPreviews( + $user, + $path, + null, + $width, + $height + ); + $this->theHTTPStatusCodeShouldBe(200, "", $response); + $newResponseBodyContents = $response->getBody()->getContents(); Assert::assertNotEquals( $newResponseBodyContents, // different users can download files before and after an update is made to a file @@ -5679,7 +5913,8 @@ public function theAuthorOfEditedVersionFile(string $index, string $expectedUser */ public function userGetsTheContentOfGeneratedJsonReport(string $user, string $pathToFile): void { $password = $this->getPasswordForUser($user); - $this->downloadFileAsUserUsingPassword($user, $pathToFile, $password); + $response = $this->downloadFileAsUserUsingPassword($user, $pathToFile, $password); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } } diff --git a/tests/acceptance/features/coreApiSharePublicLink2/multilinkSharing.feature b/tests/acceptance/features/coreApiSharePublicLink2/multilinkSharing.feature index d718d9bb3c2..6d2060724ea 100644 --- a/tests/acceptance/features/coreApiSharePublicLink2/multilinkSharing.feature +++ b/tests/acceptance/features/coreApiSharePublicLink2/multilinkSharing.feature @@ -130,7 +130,6 @@ Feature: multi-link sharing | permissions | read | | name | sharedlink2 | And user "Alice" has deleted file "/textfile0.txt" - And the HTTP status code should be "204" When user "Alice" uploads file "filesForUpload/textfile.txt" to "/textfile0.txt" using the WebDAV API Then the HTTP status code should be "201" And as user "Alice" the file "/textfile0.txt" should not have any shares diff --git a/tests/acceptance/features/coreApiWebdavUpload1/uploadFile.feature b/tests/acceptance/features/coreApiWebdavUpload1/uploadFile.feature index b5e4812010e..ab8e4878abe 100644 --- a/tests/acceptance/features/coreApiWebdavUpload1/uploadFile.feature +++ b/tests/acceptance/features/coreApiWebdavUpload1/uploadFile.feature @@ -310,7 +310,7 @@ Feature: upload file Given using DAV path And user "Alice" has uploaded file with content "first time upload content" to "file.txt" When user "Alice" uploads a file with content "Overwrite file" and mtime "Thu, 08 Aug 2019 04:18:13 GMT" to "file.txt" using the WebDAV API - Then the HTTP status code should be "201" + Then the HTTP status code should be "204" And as "Alice" file "file.txt" should exist And as "Alice" the mtime of the file "file.txt" should be "Thu, 08 Aug 2019 04:18:13 GMT" And the content of file "file.txt" for user "Alice" should be "Overwrite file"