diff --git a/tests/acceptance/features/apiAntivirus/antivirus.feature b/tests/acceptance/features/apiAntivirus/antivirus.feature index fd7083c3b2..01c4a060cc 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 45ff6e2f2a..8ec303b4c9 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -3189,7 +3189,7 @@ class FeatureContext extends BehatVariablesContext { */ 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 d25d7ec6a6..b51ad35e17 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -2525,8 +2525,8 @@ trait Sharing { */ 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 790db850fa..1164ec3b79 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -1083,6 +1083,7 @@ class SpacesContext implements Context { string $folder, string $spaceName ): void { + $folder = \trim($folder, '/'); $exploded = explode('/', $folder); $path = ''; for ($i = 0; $i < \count($exploded); $i++) { @@ -1121,19 +1122,48 @@ class SpacesContext implements Context { * * @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 @@ class SpacesContext implements Context { 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 @@ class SpacesContext implements Context { * @param string $content * @param string $destination * - * @return string[] + * @return void * @throws GuzzleException * @throws Exception */ @@ -1177,9 +1203,10 @@ class SpacesContext implements Context { 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 @@ class SpacesContext implements Context { 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 @@ class SpacesContext implements Context { 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 @@ class SpacesContext implements Context { 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 @@ class SpacesContext implements Context { * @param string $fileContent * @param string $destination * - * @return string[] + * @return array * @throws GuzzleException */ public function userHasUploadedFile( @@ -1840,9 +1869,10 @@ class SpacesContext implements Context { 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 @@ class SpacesContext implements Context { 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 1b940499db..dfdb122ebd 100644 --- a/tests/acceptance/features/bootstrap/TrashbinContext.php +++ b/tests/acceptance/features/bootstrap/TrashbinContext.php @@ -889,11 +889,11 @@ class TrashbinContext implements Context { ):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 482ceefc7f..23e838fbd5 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -603,20 +603,14 @@ trait WebDav { $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); } /** @@ -837,6 +831,31 @@ trait WebDav { $this->usingServer($previousServer); } + /** + * @param string $user + * @param string $fileSource + * @param string $fileDestination + * + * @return ResponseInterface + */ + public function copyFile( + string $user, + string $fileSource, + string $fileDestination + ):ResponseInterface { + $user = $this->getActualUsername($user); + $headers['Destination'] = $this->destinationHeaderValue( + $user, + $fileDestination + ); + return $this->makeDavRequest( + $user, + "COPY", + $fileSource, + $headers + ); + } + /** * @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" to "([^"]*)" using the WebDAV API$/ * @@ -851,23 +870,9 @@ trait WebDav { string $fileSource, string $fileDestination ):void { - $user = $this->getActualUsername($user); - $headers['Destination'] = $this->destinationHeaderValue( - $user, - $fileDestination - ); - $this->response = $this->makeDavRequest( - $user, - "COPY", - $fileSource, - $headers - ); - $this->setResponseXml( - HttpRequestHelper::parseResponseAsXml($this->response) - ); - $this->pushToLastHttpStatusCodesArray( - (string) $this->getResponse()->getStatusCode() - ); + $response = $this->copyFile($user, $fileSource, $fileDestination); + $this->setResponse($response); + $this->pushToLastHttpStatusCodesArray(); } /** @@ -884,12 +889,12 @@ trait WebDav { 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 @@ trait WebDav { * @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,14 +934,32 @@ trait WebDav { * * @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 ); } + /** + * @param string $user + * @param string $fileSource + * @param string $range + * + * @return ResponseInterface + */ + public function downloadFileWithRange(string $user, string $fileSource, string $range):ResponseInterface { + $user = $this->getActualUsername($user); + $headers['Range'] = $range; + return $this->makeDavRequest( + $user, + "GET", + $fileSource, + $headers + ); + } + /** * @When /^user "([^"]*)" downloads file "([^"]*)" with range "([^"]*)" using the WebDAV API$/ * @@ -945,15 +969,8 @@ trait WebDav { * * @return void */ - public function userDownloadsFileWithRange(string $user, string $fileSource, string $range):void { - $user = $this->getActualUsername($user); - $headers['Range'] = $range; - $this->response = $this->makeDavRequest( - $user, - "GET", - $fileSource, - $headers - ); + public function userDownloadsFileWithRangeUsingWebDavApi(string $user, string $fileSource, string $range):void { + $this->setResponse($this->downloadFileWithRange($user, $fileSource, $range)); } /** @@ -972,19 +989,19 @@ trait WebDav { ):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 @@ trait WebDav { ):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 @@ trait WebDav { // 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 @@ trait WebDav { * @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 @@ trait WebDav { */ 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 @@ trait WebDav { ):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 @@ trait WebDav { 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 @@ trait WebDav { * @return void */ public function theUserDownloadsTheFileUsingTheAPI(string $fileName):void { - $this->downloadFileAsUserUsingPassword($this->currentUser, $fileName); + $this->setResponse($this->downloadFileAsUserUsingPassword($this->currentUser, $fileName)); } /** @@ -1474,7 +1491,7 @@ trait WebDav { string $user, string $fileName ):void { - $this->downloadFileAsUserUsingPassword($user, $fileName); + $this->setResponse($this->downloadFileAsUserUsingPassword($user, $fileName)); } /** @@ -1491,7 +1508,7 @@ trait WebDav { ?string $password, string $fileName ):void { - $this->downloadFileAsUserUsingPassword($user, $fileName, $password); + $this->setResponse($this->downloadFileAsUserUsingPassword($user, $fileName, $password)); } /** @@ -1500,17 +1517,17 @@ trait WebDav { * @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 @@ trait WebDav { } /** - * @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 @@ trait WebDav { $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 @@ trait WebDav { * @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 @@ trait WebDav { * * @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 @@ trait WebDav { * @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 @@ trait WebDav { * @param string $server * @param string $source * @param string $destination - * @param bool|null $isGivenStep * * @return void */ @@ -2178,11 +2210,10 @@ trait WebDav { 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 @@ trait WebDav { */ 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 @@ trait WebDav { $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 @@ trait WebDav { 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 @@ trait WebDav { * @param string $destination * @param string $text * @param string $bytes - * @param bool|null $isGivenStep * * @return void */ @@ -2921,17 +2952,15 @@ trait WebDav { 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 @@ trait WebDav { * @param string $destination * @param bool|null $isGivenStep * - * @return string[] + * @return ResponseInterface * @throws JsonException * @throws GuzzleException */ @@ -2986,10 +3015,10 @@ trait WebDav { ?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 @@ trait WebDav { null, $isGivenStep ); - $this->setResponseXml( - HttpRequestHelper::parseResponseAsXml($this->response) - ); $this->lastUploadDeleteTime = \time(); - return $this->response->getHeader('oc-fileid'); + return $response; } /** @@ -3016,13 +3042,16 @@ trait WebDav { * @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 @@ trait WebDav { * @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 @@ trait WebDav { ?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 @@ trait WebDav { $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 @@ trait WebDav { * @param string|null $content * @param string $destination * - * @return string[] + * @return array + * @throws GuzzleException + * @throws JsonException */ public function userHasUploadedAFileWithContentTo( string $user, @@ -3278,13 +3313,13 @@ trait WebDav { 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 @@ trait WebDav { * @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 @@ trait WebDav { $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 @@ trait WebDav { $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 @@ trait WebDav { $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 @@ trait WebDav { ?string $content, string $destination ):void { - $this->userUploadsAFileWithChecksumAndContentTo( + $response = $this->uploadFileWithChecksumAndContent( $user, $checksum, $content, @@ -3430,7 +3478,8 @@ trait WebDav { ); $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 @@ trait WebDav { 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 @@ trait WebDav { */ 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); } @@ -3479,6 +3528,20 @@ trait WebDav { $this->userHasDeletedResource($user, "deleted", "file", $file); } + /** + * @param string $user + * @param string $resource + * + * @return void + */ + public function deleteFile(string $user, string $resource):ResponseInterface { + $user = $this->getActualUsername($user); + $this->pauseUploadDelete(); + $response = $this->makeDavRequest($user, 'DELETE', $resource, []); + $this->lastUploadDeleteTime = \time(); + return $response; + } + /** * @When user :user deletes file/folder :resource using the WebDAV API * @@ -3488,11 +3551,9 @@ trait WebDav { * @return void */ public function userDeletesFile(string $user, string $resource):void { - $user = $this->getActualUsername($user); - $this->pauseUploadDelete(); - $this->response = $this->makeDavRequest($user, 'DELETE', $resource, []); - $this->lastUploadDeleteTime = \time(); - $this->pushToLastHttpStatusCodesArray((string) $this->getResponse()->getStatusCode()); + $response = $this->deleteFile($user, $resource); + $this->setResponse($response); + $this->pushToLastStatusCodesArrays(); } /** @@ -3506,7 +3567,7 @@ trait WebDav { */ 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 @@ trait WebDav { $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 @@ trait WebDav { * @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 @@ trait WebDav { */ 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 @@ trait WebDav { * @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 @@ trait WebDav { * @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 @@ trait WebDav { } } + /** + * @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 @@ trait WebDav { 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 @@ trait WebDav { /** * 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 @@ trait WebDav { * @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 @@ trait WebDav { $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 @@ trait WebDav { 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 @@ trait WebDav { 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 @@ trait WebDav { ); } + /** + * @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 @@ trait WebDav { * @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 @@ trait WebDav { 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 @@ trait WebDav { * @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 @@ trait WebDav { 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 @@ trait WebDav { 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 @@ trait WebDav { string $user, string $id ):void { - $this->deleteUpload($user, $id, []); + $response = $this->deleteUpload($user, $id, []); + $this->setResponse($response); } /** @@ -4220,8 +4385,36 @@ trait WebDav { string $user, string $id ):void { - $this->userCancelsUploadWithId($user, $id); - $this->theHTTPStatusCodeShouldBe("201"); + $response = $this->deleteUpload($user, $id, []); + $this->theHTTPStatusCodeShouldBe("201", "", $response); + } + + /** + * @param string $user + * @param string $id + * @param string $type "asynchronously" or empty + * @param string $dest + * @param int $size + * + * @return ResponseInterface + */ + public function userMoveNewChunkFileWithIdToMychunkedfileWithSize( + string $user, + string $id, + string $type, + string $dest, + int $size + ):ResponseInterface { + $headers = ['OC-Total-Length' => $size]; + if ($type === "asynchronously") { + $headers['OC-LazyOps'] = 'true'; + } + return $this->moveNewDavChunkToFinalFile( + $user, + $id, + $dest, + $headers + ); } /** @@ -4242,16 +4435,14 @@ trait WebDav { string $dest, int $size ):void { - $headers = ['OC-Total-Length' => $size]; - if ($type === "asynchronously") { - $headers['OC-LazyOps'] = 'true'; - } - $this->moveNewDavChunkToFinalFile( + $response = $this->userMoveNewChunkFileWithIdToMychunkedfileWithSize( $user, $id, + $type, $dest, - $headers + $size ); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -4273,14 +4464,42 @@ trait WebDav { string $dest, int $size ):void { - $this->userMovesNewChunkFileWithIdToMychunkedfileWithSize( + $response = $this->userMoveNewChunkFileWithIdToMychunkedfileWithSize( $user, $id, $type, $dest, $size ); - $this->theHTTPStatusCodeShouldBe("201"); + $this->theHTTPStatusCodeShouldBe("201", "", $response); + } + + /** + * @param string $user + * @param string $id + * @param string $type "asynchronously" or empty + * @param string $dest + * @param string $checksum + * + * @return ResponseInterface + */ + public function userMoveNewChunkFileWithIdToMychunkedfileWithChecksum( + string $user, + string $id, + string $type, + string $dest, + string $checksum + ):ResponseInterface { + $headers = ['OC-Checksum' => $checksum]; + if ($type === "asynchronously") { + $headers['OC-LazyOps'] = 'true'; + } + return $this->moveNewDavChunkToFinalFile( + $user, + $id, + $dest, + $headers + ); } /** @@ -4301,16 +4520,8 @@ trait WebDav { string $dest, string $checksum ):void { - $headers = ['OC-Checksum' => $checksum]; - if ($type === "asynchronously") { - $headers['OC-LazyOps'] = 'true'; - } - $this->moveNewDavChunkToFinalFile( - $user, - $id, - $dest, - $headers - ); + $response = $this->userMoveNewChunkFileWithIdToMychunkedfileWithChecksum($user, $id, $type, $dest, $checksum); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -4332,14 +4543,14 @@ trait WebDav { 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 @@ trait WebDav { * @param array $headers extra headers * @param bool|null $isGivenStep * - * @return void + * @return ResponseInterface */ private function moveNewDavChunkToFinalFile( string $user, @@ -4359,7 +4570,7 @@ trait WebDav { 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 @@ trait WebDav { $destination ); - $this->response = $this->makeDavRequest( + return $this->makeDavRequest( $user, 'MOVE', $source, @@ -4390,11 +4601,11 @@ trait WebDav { * @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 @@ trait WebDav { } /** - * @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 @@ trait WebDav { ); } + /** + * @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); } /** @@ -4676,12 +4896,14 @@ trait WebDav { * * @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"); @@ -4727,9 +4949,15 @@ trait WebDav { * @return void */ public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string $path, string $width, string $height):void { - $this->downloadPreviewOfFiles($user, $path, $width, $height); - $this->theHTTPStatusCodeShouldBe(200); - $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; } @@ -4745,9 +4973,15 @@ trait WebDav { * @return void */ public function asUserThePreviewOfPathWithHeightAndWidthShouldHaveBeenChanged(string $user, string $path, string $width, string $height):void { - $this->downloadPreviewOfFiles($user, $path, $width, $height); - $this->theHTTPStatusCodeShouldBe(200); - $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 @@ -5490,7 +5724,8 @@ trait WebDav { */ 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 d718d9bb3c..6d2060724e 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 b5e4812010..ab8e4878ab 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"