From e05dc0e57e3d832e7538e19805b0e0a56758d656 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Tue, 20 Dec 2022 17:57:18 +0100 Subject: [PATCH 1/2] add test --- .../features/apiContract/copy.feature | 22 ++++++++++++ .../features/bootstrap/SpacesContext.php | 34 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/acceptance/features/apiContract/copy.feature diff --git a/tests/acceptance/features/apiContract/copy.feature b/tests/acceptance/features/apiContract/copy.feature new file mode 100644 index 000000000..d99e86056 --- /dev/null +++ b/tests/acceptance/features/apiContract/copy.feature @@ -0,0 +1,22 @@ +@api @skipOnOcV10 +Feature: Copy test + check that the Copy 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 COPY response headers + Given user "Alice" has uploaded a file inside space "new-space" with content "some content" to "testfile.txt" + And user "Alice" has created a folder "new" in space "new-space" + When user "Alice" copies file "testfile.txt" from space "new-space" to "/new/testfile.txt" inside space "new-space" using the WebDAV API + Then the HTTP status code should be "201" + And for user "Alice" the COPY response headers for the space "new-space" should contain these key and value pairs: + | key | value | + | Access-Control-Allow-Origin | * | + | Oc-Fileid | UUIDof:/new/testfile.txt | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 7a5733593..12912eddd 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3088,4 +3088,38 @@ class SpacesContext implements Context { } } } + + /** + * @Then /^for user "([^"]*)" the (?:COPY|MOVE) response headers for the (?:space|mountpoint) "([^"]*)" should contain these key and value pairs:$/ + * + * @param string $user + * @param string $space + * @param TableNode $table + * + * @return void + * @throws GuzzleException + * @throws JsonException + */ + public function theCopyResponseHeadersShouldContain(string $user, string $space, TableNode $table): void { + $this->featureContext->verifyTableNodeColumns($table, ['key', 'value']); + $headers = $this->featureContext->getResponse()->getHeaders(); + + foreach ($table->getHash() as $row) { + $findItem = $row['key']; + $value = str_replace('UUIDof:', '', $row['value']); + + foreach ($headers as $headerName => $headerValues) { + if ($headerName === $findItem) { + switch ($findItem) { + case "Oc-Fileid": + Assert::assertEquals($this->getFileId($user, $space, $value), $headerValues[0], 'wrong fileId in the response header'); + break; + default: + Assert::assertEquals($value, $headerValues[0], "wrong $findItem in the response header"); + break; + } + } + } + } + } } From 1ff8665b7888602341a5d0846ace7be4fa1a984b Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Thu, 22 Dec 2022 10:29:36 +0100 Subject: [PATCH 2/2] fix after review --- .../features/apiContract/copy.feature | 9 +++-- .../features/bootstrap/SpacesContext.php | 34 ------------------- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/tests/acceptance/features/apiContract/copy.feature b/tests/acceptance/features/apiContract/copy.feature index d99e86056..984812a61 100644 --- a/tests/acceptance/features/apiContract/copy.feature +++ b/tests/acceptance/features/apiContract/copy.feature @@ -9,14 +9,13 @@ Feature: Copy test 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 COPY response headers Given user "Alice" has uploaded a file inside space "new-space" with content "some content" to "testfile.txt" And user "Alice" has created a folder "new" in space "new-space" When user "Alice" copies file "testfile.txt" from space "new-space" to "/new/testfile.txt" inside space "new-space" using the WebDAV API Then the HTTP status code should be "201" - And for user "Alice" the COPY response headers for the space "new-space" should contain these key and value pairs: - | key | value | - | Access-Control-Allow-Origin | * | - | Oc-Fileid | UUIDof:/new/testfile.txt | + And the following headers should match these regular expressions + | Oc-Fileid | /^[a-f0-9!\$\-]{110}$/ | + | Access-Control-Allow-Origin | /^[*]{1}$/ | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 12912eddd..7a5733593 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3088,38 +3088,4 @@ class SpacesContext implements Context { } } } - - /** - * @Then /^for user "([^"]*)" the (?:COPY|MOVE) response headers for the (?:space|mountpoint) "([^"]*)" should contain these key and value pairs:$/ - * - * @param string $user - * @param string $space - * @param TableNode $table - * - * @return void - * @throws GuzzleException - * @throws JsonException - */ - public function theCopyResponseHeadersShouldContain(string $user, string $space, TableNode $table): void { - $this->featureContext->verifyTableNodeColumns($table, ['key', 'value']); - $headers = $this->featureContext->getResponse()->getHeaders(); - - foreach ($table->getHash() as $row) { - $findItem = $row['key']; - $value = str_replace('UUIDof:', '', $row['value']); - - foreach ($headers as $headerName => $headerValues) { - if ($headerName === $findItem) { - switch ($findItem) { - case "Oc-Fileid": - Assert::assertEquals($this->getFileId($user, $space, $value), $headerValues[0], 'wrong fileId in the response header'); - break; - default: - Assert::assertEquals($value, $headerValues[0], "wrong $findItem in the response header"); - break; - } - } - } - } - } }