From 6977855ac02de07b632cc04f4b47e21c2d4f0654 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Thu, 28 Nov 2024 11:12:29 +0100 Subject: [PATCH] test(ExternalStorage): Send basic auth during integrations tests Signed-off-by: Louis Chemineau [skip ci] --- .../features/bootstrap/ExternalStorage.php | 23 +++++++++++-- .../files_features/external-storage.feature | 34 +++++++++---------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/build/integration/features/bootstrap/ExternalStorage.php b/build/integration/features/bootstrap/ExternalStorage.php index 2a73f22c1b44c..b1e4c92810b16 100644 --- a/build/integration/features/bootstrap/ExternalStorage.php +++ b/build/integration/features/bootstrap/ExternalStorage.php @@ -48,7 +48,7 @@ private function deleteStorage(string $storageId): void { * @param TableNode $fields */ public function loggedInUserCreatesExternalGlobalStorage(TableNode $fields): void { - $this->sendJsonWithRequestToken('POST', '/index.php/apps/files_external/globalstorages', $fields); + $this->sendJsonWithRequestTokenAndBasicAuth('POST', '/index.php/apps/files_external/globalstorages', $fields); $this->theHTTPStatusCodeShouldBe('201'); $this->lastExternalStorageData = json_decode($this->response->getBody(), $asAssociativeArray = true); @@ -62,7 +62,7 @@ public function loggedInUserCreatesExternalGlobalStorage(TableNode $fields): voi * @param TableNode $fields */ public function loggedInUserUpdatesLastExternalUserglobalStorage(TableNode $fields): void { - $this->sendJsonWithRequestToken('PUT', '/index.php/apps/files_external/userglobalstorages/' . $this->lastExternalStorageData['id'], $fields); + $this->sendJsonWithRequestTokenAndBasicAuth('PUT', '/index.php/apps/files_external/userglobalstorages/' . $this->lastExternalStorageData['id'], $fields); $this->theHTTPStatusCodeShouldBe('200'); $this->lastExternalStorageData = json_decode($this->response->getBody(), $asAssociativeArray = true); @@ -100,4 +100,23 @@ private function sendJsonWithRequestToken(string $method, string $url, TableNode ]; $this->sendingAToWithRequesttoken($method, $url, $body); } + + private function sendJsonWithRequestTokenAndBasicAuth(string $method, string $url, TableNode $fields): void { + $isFirstField = true; + $fieldsAsJsonString = '{'; + foreach ($fields->getRowsHash() as $key => $value) { + $fieldsAsJsonString .= ($isFirstField ? '' : ',') . '"' . $key . '":' . $value; + $isFirstField = false; + } + $fieldsAsJsonString .= '}'; + + $body = [ + 'headers' => [ + 'Content-Type' => 'application/json', + 'Authorization' => 'Basic ' . base64_encode('admin:admin'), + ], + 'body' => $fieldsAsJsonString, + ]; + $this->sendingAToWithRequesttoken($method, $url, $body); + } } diff --git a/build/integration/files_features/external-storage.feature b/build/integration/files_features/external-storage.feature index 2b724be44b03c..c158b0e3634a9 100644 --- a/build/integration/files_features/external-storage.feature +++ b/build/integration/files_features/external-storage.feature @@ -14,14 +14,14 @@ Feature: external-storage And As an "user1" And accepting last share When creating a share with - | path | foo | - | shareType | 3 | + | path | foo | + | shareType | 3 | Then the OCS status code should be "100" And the HTTP status code should be "200" And Share fields of last share match with - | id | A_NUMBER | - | url | AN_URL | - | token | A_TOKEN | + | id | A_NUMBER | + | url | AN_URL | + | token | A_TOKEN | | mimetype | httpd/unix-directory | Scenario: Shares don't overwrite external storage @@ -66,9 +66,9 @@ Feature: external-storage Scenario: Save an external storage with password provided by user Given Logging in using web as "admin" And logged in user creates external global storage - | mountPoint | "ExternalStorageTest" | - | backend | "owncloud" | - | authMechanism | "password::userprovided" | + | mountPoint | "ExternalStorageTest" | + | backend | "owncloud" | + | authMechanism | "password::userprovided" | | backendOptions | {"host":"http://localhost:8080","secure":false} | And fields of last external storage match with | status | 2 | @@ -80,9 +80,9 @@ Feature: external-storage Scenario: Save an external storage again with an unmodified password provided by user Given Logging in using web as "admin" And logged in user creates external global storage - | mountPoint | "ExternalStorageTest" | - | backend | "owncloud" | - | authMechanism | "password::userprovided" | + | mountPoint | "ExternalStorageTest" | + | backend | "owncloud" | + | authMechanism | "password::userprovided" | | backendOptions | {"host":"http://localhost:8080","secure":false} | And fields of last external storage match with | status | 2 | @@ -96,9 +96,9 @@ Feature: external-storage Scenario: Save an external storage with global credentials provided by user Given Logging in using web as "admin" And logged in user creates external global storage - | mountPoint | "ExternalStorageTest" | - | backend | "owncloud" | - | authMechanism | "password::global::user" | + | mountPoint | "ExternalStorageTest" | + | backend | "owncloud" | + | authMechanism | "password::global::user" | | backendOptions | {"host":"http://localhost:8080","secure":false} | And fields of last external storage match with | status | 2 | @@ -110,9 +110,9 @@ Feature: external-storage Scenario: Save an external storage again with unmodified global credentials provided by user Given Logging in using web as "admin" And logged in user creates external global storage - | mountPoint | "ExternalStorageTest" | - | backend | "owncloud" | - | authMechanism | "password::global::user" | + | mountPoint | "ExternalStorageTest" | + | backend | "owncloud" | + | authMechanism | "password::global::user" | | backendOptions | {"host":"http://localhost:8080","secure":false} | And fields of last external storage match with | status | 2 |