From bc834a78c3324c8ad0ead1397363fed1aae77b1c Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Fri, 2 Sep 2022 12:35:48 +0545 Subject: [PATCH] test with core branch --- .drone.env | 5 + .../features/apiSpaces/filePreviews.feature | 25 ++-- .../features/apiSpaces/tusUpload.feature | 5 +- .../features/bootstrap/SpacesTusContext.php | 139 ++++-------------- 4 files changed, 48 insertions(+), 126 deletions(-) diff --git a/.drone.env b/.drone.env index 40dc6e21642..476aab69785 100644 --- a/.drone.env +++ b/.drone.env @@ -1,6 +1,11 @@ # The test runner source for API tests +<<<<<<< HEAD CORE_COMMITID=b51fb4c01f08763e023aece4f90308e07a7ac73f CORE_BRANCH=master +======= +CORE_COMMITID=6500d5fd867411fa0ba568b261c695f1b110266f +CORE_BRANCH=adjust-tus-code-to-reuse-on-ocis +>>>>>>> test with core branch # The test runner source for UI tests WEB_COMMITID=4828c892d292dbccd382104c11486bc5d21340b0 diff --git a/tests/acceptance/features/apiSpaces/filePreviews.feature b/tests/acceptance/features/apiSpaces/filePreviews.feature index f6ae9d48480..93f9009cb74 100644 --- a/tests/acceptance/features/apiSpaces/filePreviews.feature +++ b/tests/acceptance/features/apiSpaces/filePreviews.feature @@ -24,17 +24,18 @@ Feature: Preview file in project space Scenario Outline: An user can preview image files in the project space - Given user "Alice" has uploaded a file "" via TUS inside of the space "previews of the files" using the WebDAV API - When user "Alice" downloads the preview of "" of the space "previews of the files" with width "" and height "" using the WebDAV API + Given using spaces DAV path + And user "Alice" has uploaded a file from "" to "" via TUS inside of the space "previews of the files" using the WebDAV API + When user "Alice" downloads the preview of "" of the space "previews of the files" with width "" and height "" using the WebDAV API Then the HTTP status code should be "200" Examples: - | entity | width | height | - | testavatar.png | 36 | 36 | - | testavatar.png | 1200 | 1200 | - | testavatar.png | 1920 | 1920 | - | testavatar.jpg | 36 | 36 | - | testavatar.jpg | 1200 | 1200 | - | testavatar.jpg | 1920 | 1920 | - | example.gif | 36 | 36 | - | example.gif | 1200 | 1200 | - | example.gif | 1280 | 1280 | + | source | destination | width | height | + | filesForUpload/testavatar.png | testavatar.png | 36 | 36 | + | filesForUpload/testavatar.png | testavatar.png | 1200 | 1200 | + | filesForUpload/testavatar.png | testavatar.png | 1920 | 1920 | + | filesForUpload/testavatar.jpg | testavatar.jpg | 36 | 36 | + | filesForUpload/testavatar.jpg | testavatar.jpg | 1200 | 1200 | + | filesForUpload/testavatar.jpg | testavatar.jpg | 1920 | 1920 | + | filesForUpload/example.gif | example.gif | 36 | 36 | + | filesForUpload/example.gif | example.gif | 1200 | 1200 | + | filesForUpload/example.gif | example.gif | 1280 | 1280 | diff --git a/tests/acceptance/features/apiSpaces/tusUpload.feature b/tests/acceptance/features/apiSpaces/tusUpload.feature index 17b959859aa..aadd59acee7 100644 --- a/tests/acceptance/features/apiSpaces/tusUpload.feature +++ b/tests/acceptance/features/apiSpaces/tusUpload.feature @@ -9,12 +9,13 @@ Feature: upload resources using TUS protocol | username | | Alice | And the administrator has given "Alice" the role "Space Admin" using the settings api + And using spaces DAV path Scenario: upload a file within the set quota to a project space Given user "Alice" has created a space "Project Jupiter" of type "project" with quota "10000" - When user "Alice" uploads a file with content "uploaded content" to "upload.txt" via TUS inside of the space "Project Jupiter" using the WebDAV API - Then the HTTP status code should be "204" + When user "Alice" uploads a file with content "uploaded content" to "/upload.txt" via TUS inside of the space "Project Jupiter" using the WebDAV API + Then the HTTP status code should be "200" And for user "Alice" the space "Project Jupiter" should contain these entries: | upload.txt | diff --git a/tests/acceptance/features/bootstrap/SpacesTusContext.php b/tests/acceptance/features/bootstrap/SpacesTusContext.php index f109b8259ad..93a5f257c65 100644 --- a/tests/acceptance/features/bootstrap/SpacesTusContext.php +++ b/tests/acceptance/features/bootstrap/SpacesTusContext.php @@ -13,6 +13,7 @@ use GuzzleHttp\Exception\GuzzleException; use TestHelpers\HttpRequestHelper; use Behat\Gherkin\Node\TableNode; +use TestHelpers\WebDavHelper; require_once 'bootstrap.php'; @@ -62,10 +63,11 @@ public function before(BeforeScenarioScope $scope): void { } /** - * @Given /^user "([^"]*)" has uploaded a file "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/ + * @Given /^user "([^"]*)" has uploaded a file from "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/ * * @param string $user - * @param string $resource + * @param string $source + * @param string $destination * @param string $spaceName * * @return void @@ -73,28 +75,32 @@ public function before(BeforeScenarioScope $scope): void { * @throws Exception * @throws GuzzleException */ - public function uploadFileViaTus(string $user, string $resource, string $spaceName): void { - $this->userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi($user, $resource, $spaceName); - $this->featureContext->theHTTPStatusCodeShouldBe(204, "Expected response status code should be 204"); + public function userHasUploadedFileViaTusInSpace(string $user, string $source, string $destination, string $spaceName): void { + $this->userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi($user, $source, $destination, $spaceName); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "Expected response status code should be 204"); } /** - * @When /^user "([^"]*)" uploads a file "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/ + * @When /^user "([^"]*)" uploads a file from "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/ * * @param string $user - * @param string $resource + * @param string $source * @param string $spaceName - * @param array|null $headers + * @param string $destination + * @param array|null $uploadMetadata * * @return void * * @throws Exception * @throws GuzzleException */ - public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $resource, string $spaceName, ?array $headers = null) { - $this->createTusResource($user, $resource, $spaceName, $headers); - $this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201"); - $this->uploadResourceThroughTUS($user, $resource); + public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $source, string $destination, string $spaceName, ?array $uploadMetadata = null) { + $space = $this->spacesContext->getSpaceByName($user, $spaceName); + if (!WebDavHelper::$SPACE_ID_FROM_OCIS) { + WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id']; + } + $this->tusContext->userUploadsUsingTusAFileTo($user, $source, $destination); + WebDavHelper::$SPACE_ID_FROM_OCIS = null; } /** @@ -110,8 +116,7 @@ public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(string $ * @throws GuzzleException */ public function userHasCreatedANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(string $user, string $spaceName, TableNode $headers):void { - $this->featureContext->verifyTableNodeColumnsCount($headers, 2); - $this->createTusResource($user, "", $spaceName, $headers->getRowsHash()); + $this->userCreatesANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders($user, $spaceName, $headers); $this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201"); } @@ -128,22 +133,11 @@ public function userHasCreatedANewTusResourceForTheSpaceUsingTheWebdavApiWithThe * @throws GuzzleException */ public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(string $user, string $spaceName, TableNode $headers):void { - $this->featureContext->verifyTableNodeColumnsCount($headers, 2); - $this->createTusResource($user, "", $spaceName, $headers->getRowsHash()); - } - - /** - * @When /^user "([^"]*)" creates a new TUS resource "([^"]*)" for the space "([^"]*)" using the WebDAV API$/ - * - * @param string $user - * @param string $resource - * @param string $spaceName - * - * @return void - * @throws Exception|GuzzleException - */ - public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApi(string $user, string $resource, string $spaceName):void { - $this->createTusResource($user, $resource, $spaceName); + $space = $this->spacesContext->getSpaceByName($user, $spaceName); + if (!WebDavHelper::$SPACE_ID_FROM_OCIS) { + WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id']; + } + $this->tusContext->createNewTUSResourceWithHeaders($user, $headers, ''); } /** @@ -158,89 +152,10 @@ public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApi(string $u * @throws Exception|GuzzleException */ public function userUploadsAFileWithContentToViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $content, string $resource, string $spaceName) { - $sourceFile = fopen($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource, "w"); - fwrite($sourceFile, $content); - $this->userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi($user, $resource, $spaceName); - fclose($sourceFile); - \unlink($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource); - } - - /** - * send POST request to create the TUS resource - * - * @param string $user - * @param string|null $resource - * @param string $spaceName - * @param array|null $headers - * - * @return void - * @throws Exception|GuzzleException - */ - public function createTusResource(string $user, ?string $resource, string $spaceName, ?array $headers = null): void { $space = $this->spacesContext->getSpaceByName($user, $spaceName); - $fullUrl = $this->baseUrl . "/remote.php/dav/spaces/" . $space["id"]; - - $tusEndpoint = "tusEndpoint " . base64_encode(str_replace("$", "%", $fullUrl)); - if ($headers === null) { - $fileName = "filename " . base64_encode($resource); - $headers = [ - "Tus-Resumable" => "1.0.0", - "Upload-Metadata" => $tusEndpoint . ',' . $fileName, - "Upload-Length" => filesize($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource) - ]; - } - $this->featureContext->setResponse( - HttpRequestHelper::post( - $fullUrl, - "", - $this->featureContext->getActualUsername($user), - $this->featureContext->getUserPassword($user), - $headers, - '' - ) - ); - } - - /** - * send PATCH request to upload resource through TUS - * - * @param string $user - * @param string $resource - * - * @return void - * @throws Exception|GuzzleException - */ - public function uploadResourceThroughTUS(string $user, string $resource): void { - $resourceLocation = $this->featureContext->getResponse()->getHeader('Location'); - if (\sizeof($resourceLocation) > 0) { - $resourceLocation = $resourceLocation[0]; - } else { - throw new \Exception(__METHOD__ . " Location header could not be found"); + if (!WebDavHelper::$SPACE_ID_FROM_OCIS) { + WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id']; } - $file = \fopen($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource, 'r'); - - $this->featureContext->setResponse( - HttpRequestHelper::sendRequest( - $resourceLocation, - "", - 'HEAD', - $user, - $this->featureContext->getPasswordForUser($user), - [], - "" - ) - ); - $this->featureContext->theHTTPStatusCodeShouldBe(200, "Expected response status code should be 200"); - $this->featureContext->setResponse( - HttpRequestHelper::sendRequest( - $resourceLocation, - "", - 'PATCH', - $user, - $this->featureContext->getPasswordForUser($user), - ["Tus-Resumable" => "1.0.0", "Upload-Offset" => 0, 'Content-Type' => 'application/offset+octet-stream'], - $file - ) - ); + $this->tusContext->userUploadsAFileWithContentToUsingTus($user, $content, $resource); } }