From 1ceaca7364567f81b90db843c8f71c435955debe Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Mon, 28 Nov 2022 14:27:41 +0545 Subject: [PATCH] Add api test for propfind contract testing --- .../features/apiContract/propfind.feature | 24 ++++++ .../features/apiContract/report.feature | 4 +- .../features/bootstrap/SpacesContext.php | 83 +++++++++++++++++-- 3 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 tests/acceptance/features/apiContract/propfind.feature diff --git a/tests/acceptance/features/apiContract/propfind.feature b/tests/acceptance/features/apiContract/propfind.feature new file mode 100644 index 0000000000..53e063a720 --- /dev/null +++ b/tests/acceptance/features/apiContract/propfind.feature @@ -0,0 +1,24 @@ +@api @skipOnOcV10 +Feature: Propfind test + check that the PROPFIND response contains all the relevant values + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + And using spaces DAV path + And the administrator has given "Alice" the role "Space Admin" using the settings api + And user "Alice" has created a space "new-space" with the default quota using the GraphApi + + + Scenario: check the PROPFIND request of a space + Given user "Alice" has uploaded a file inside space "new-space" with content "some content" to "testfile.txt" + When user "Alice" sends PROPFIND request to space "new-space" using the WebDAV API + Then the HTTP status code should be "207" + And for user "Alice" the "PROPFIND" response should contain a space "new-space" with these key and value pairs: + | key | value | + | oc:fileid | UUIDof:new-space | + | oc:name | new-space | + | oc:permissions | SRDNVCKZ | + | oc:privatelink | | + | oc:size | 12 | diff --git a/tests/acceptance/features/apiContract/report.feature b/tests/acceptance/features/apiContract/report.feature index 7f74e9735c..9912598956 100644 --- a/tests/acceptance/features/apiContract/report.feature +++ b/tests/acceptance/features/apiContract/report.feature @@ -23,7 +23,7 @@ Feature: Report test And user "Brian" has accepted share "/folderMain" offered by user "Alice" When user "Brian" searches for "SubFolder1" using the WebDAV API Then the HTTP status code should be "207" - And for user "Brian" the REPORT response should contain a mountpoint "folderMain" with these key and value pairs: + And for user "Brian" the "REPORT" response should contain a mountpoint "folderMain" with these key and value pairs: | key | value | | oc:fileid | UUIDof:SubFolder1 | | oc:file-parent | UUIDof:folderMain | @@ -39,7 +39,7 @@ Feature: Report test And user "Brian" has accepted share "/folderMain" offered by user "Alice" When user "Brian" searches for "insideTheFolder.txt" using the WebDAV API Then the HTTP status code should be "207" - And for user "Brian" the REPORT response should contain a mountpoint "folderMain" with these key and value pairs: + And for user "Brian" the "REPORT" response should contain a mountpoint "folderMain" with these key and value pairs: | key | value | | oc:fileid | UUIDof:SubFolder1/subFOLDER2/insideTheFolder.txt | | oc:file-parent | UUIDof:SubFolder1/subFOLDER2 | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 8af866f917..f40fb43aca 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -355,6 +355,32 @@ class SpacesContext implements Context { return $responseArray[0][0]; } + /** + * @param string $user + * @param string $spaceName + * + * @return string + * @throws GuzzleException + * @throws JsonException + */ + public function getPrivateLink(string $user, string $spaceName): string { + $this->setSpaceIDByName($user, $spaceName); + $response = WebDavHelper::propfind( + $this->featureContext->getBaseUrl(), + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), + "", + ['oc:privatelink'], + "", + "0", + "files", + WebDavHelper::DAV_VERSION_SPACES + ); + $responseArray = json_decode(json_encode($this->featureContext->getResponseXml($response)->xpath("//d:response/d:propstat/d:prop/oc:privatelink")), true, 512, JSON_THROW_ON_ERROR); + Assert::assertNotEmpty($responseArray, "the PROPFIND response for $spaceName is empty"); + return $responseArray[0][0]; + } + /** * The method returns eTag * @@ -1079,7 +1105,7 @@ class SpacesContext implements Context { * Verify that the tableNode contains expected number of columns * * @param TableNode $table - * @param int $count + * @param int $count * * @return void * @@ -2911,37 +2937,76 @@ class SpacesContext implements Context { } /** - * @Then /^for user "([^"]*)" the REPORT response should contain a (?:space|mountpoint) "([^"]*)" with these key and value pairs:$/ + * @When /^user "([^"]*)" sends PROPFIND request to space "([^"]*)" using the WebDAV API$/ * * @param string $user + * @param string $spaceName + * + * @throws GuzzleException + * + * @return void + */ + public function userSendsPropfindRequestToSpace(string $user, string $spaceName): void { + $this->setSpaceIDByName($user, $spaceName); + $properties = ['oc:permissions','oc:fileid','oc:share-types','oc:privatelink','d:resourcetype','oc:size','oc:name','d:getcontenttype']; + $this->featureContext->setResponse( + WebDavHelper::propfind( + $this->featureContext->getBaseUrl(), + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), + "", + $properties, + "", + "0", + "files", + WebDavHelper::DAV_VERSION_SPACES + ) + ); + } + + /** + * @Then /^for user "([^"]*)" the "([^"]*)" response should contain a (?:space|mountpoint) "([^"]*)" with these key and value pairs:$/ + * + * @param string $user + * @param string $method # method should be either PROPFIND or REPORT * @param string $space * @param TableNode $table * * @return void * @throws GuzzleException + * @throws JsonException */ - public function reportResponseShouldContain(string $user, string $space, TableNode $table): void { + public function theResponseShouldContain(string $user, string $method, string $space, TableNode $table): void { $this->featureContext->verifyTableNodeColumns($table, ['key', 'value']); $xmlRes = $this->featureContext->getResponseXml(); - $resourceType = $xmlRes->xpath("//d:response/d:propstat/d:prop/d:getcontenttype")[0]->__toString(); - foreach ($table->getHash() as $row) { $findItem = $row['key']; $responseValue = $xmlRes->xpath("//d:response/d:propstat/d:prop/$findItem")[0]->__toString(); Assert::assertNotEmpty($responseValue, "response doesn't contain $findItem or empty"); $value = str_replace('UUIDof:', '', $row['value']); - switch ($findItem) { case "oc:fileid": - if ($resourceType === 'httpd/unix-directory') { - Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong fileId in the response'); + $resourceType = $xmlRes->xpath("//d:response/d:propstat/d:prop/d:getcontenttype")[0]->__toString(); + if ($method === 'PROPFIND') { + if (!$resourceType) { + Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong fileId in the response'); + } else { + Assert::assertEquals($this->getFileId($user, $space, $value), $responseValue, 'wrong fileId in the response'); + } } else { - Assert::assertEquals($this->getFileId($user, $space, $value), $responseValue, 'wrong fileId in the response'); + if ($resourceType === 'httpd/unix-directory') { + Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong fileId in the response'); + } else { + Assert::assertEquals($this->getFileId($user, $space, $value), $responseValue, 'wrong fileId in the response'); + } } break; case "oc:file-parent": Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong file-parentId in the response'); break; + case "oc:privatelink": + Assert::assertEquals($this->getPrivateLink($user, $space), $responseValue, 'cannot find private link for space or resource in the response'); + break; default: Assert::assertEquals($value, $responseValue, "wrong $findItem in the response"); break;