aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-09-04 11:33:30 +0200
committerGitHub <noreply@github.com>2024-09-04 11:33:30 +0200
commitf1706df3676574dd63e7b34aff50d3e4fe136377 (patch)
tree43ffc695ebf11f5289f0275eba18b0b88ee34174 /build
parentab511e8d9454cceb8387ad84923570a3598649e1 (diff)
parentfa0862c656d4fbe381a418015a16b5dc2e85408c (diff)
downloadnextcloud-server-f1706df3676574dd63e7b34aff50d3e4fe136377.tar.gz
nextcloud-server-f1706df3676574dd63e7b34aff50d3e4fe136377.zip
Merge pull request #46859 from nextcloud/fix-status-check-and-saving-of-external-storages
Diffstat (limited to 'build')
-rw-r--r--build/integration/features/bootstrap/BasicStructure.php2
-rw-r--r--build/integration/features/bootstrap/ExternalStorage.php103
-rw-r--r--build/integration/features/bootstrap/FeatureContext.php1
-rw-r--r--build/integration/files_features/external-storage.feature62
-rwxr-xr-xbuild/integration/run.sh2
5 files changed, 168 insertions, 2 deletions
diff --git a/build/integration/features/bootstrap/BasicStructure.php b/build/integration/features/bootstrap/BasicStructure.php
index e4aad79858c..8500eca6b0f 100644
--- a/build/integration/features/bootstrap/BasicStructure.php
+++ b/build/integration/features/bootstrap/BasicStructure.php
@@ -327,7 +327,7 @@ trait BasicStructure {
$fd = $body->getRowsHash();
$options['form_params'] = $fd;
} elseif ($body) {
- $options = array_merge($options, $body);
+ $options = array_merge_recursive($options, $body);
}
$client = new Client();
diff --git a/build/integration/features/bootstrap/ExternalStorage.php b/build/integration/features/bootstrap/ExternalStorage.php
new file mode 100644
index 00000000000..2a73f22c1b4
--- /dev/null
+++ b/build/integration/features/bootstrap/ExternalStorage.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+use Behat\Gherkin\Node\TableNode;
+use PHPUnit\Framework\Assert;
+
+require __DIR__ . '/../../vendor/autoload.php';
+
+trait ExternalStorage {
+ private array $storageIds = [];
+
+ private array $lastExternalStorageData;
+
+ /**
+ * @AfterScenario
+ **/
+ public function deleteCreatedStorages(): void {
+ foreach ($this->storageIds as $storageId) {
+ $this->deleteStorage($storageId);
+ }
+ $this->storageIds = [];
+ }
+
+ private function deleteStorage(string $storageId): void {
+ // Based on "runOcc" from CommandLine trait
+ $args = ['files_external:delete', '--yes', $storageId];
+ $args = array_map(function ($arg) {
+ return escapeshellarg($arg);
+ }, $args);
+ $args[] = '--no-ansi --no-warnings';
+ $args = implode(' ', $args);
+
+ $descriptor = [
+ 0 => ['pipe', 'r'],
+ 1 => ['pipe', 'w'],
+ 2 => ['pipe', 'w'],
+ ];
+ $process = proc_open('php console.php ' . $args, $descriptor, $pipes, $ocPath = '../..');
+ $lastStdOut = stream_get_contents($pipes[1]);
+ proc_close($process);
+ }
+
+ /**
+ * @When logged in user creates external global storage
+ *
+ * @param TableNode $fields
+ */
+ public function loggedInUserCreatesExternalGlobalStorage(TableNode $fields): void {
+ $this->sendJsonWithRequestToken('POST', '/index.php/apps/files_external/globalstorages', $fields);
+ $this->theHTTPStatusCodeShouldBe('201');
+
+ $this->lastExternalStorageData = json_decode($this->response->getBody(), $asAssociativeArray = true);
+
+ $this->storageIds[] = $this->lastExternalStorageData['id'];
+ }
+
+ /**
+ * @When logged in user updates last external userglobal storage
+ *
+ * @param TableNode $fields
+ */
+ public function loggedInUserUpdatesLastExternalUserglobalStorage(TableNode $fields): void {
+ $this->sendJsonWithRequestToken('PUT', '/index.php/apps/files_external/userglobalstorages/' . $this->lastExternalStorageData['id'], $fields);
+ $this->theHTTPStatusCodeShouldBe('200');
+
+ $this->lastExternalStorageData = json_decode($this->response->getBody(), $asAssociativeArray = true);
+ }
+
+ /**
+ * @Then fields of last external storage match with
+ *
+ * @param TableNode $fields
+ */
+ public function fieldsOfLastExternalStorageMatchWith(TableNode $fields): void {
+ foreach ($fields->getRowsHash() as $expectedField => $expectedValue) {
+ if (!array_key_exists($expectedField, $this->lastExternalStorageData)) {
+ Assert::fail("$expectedField was not found in response");
+ }
+
+ Assert::assertEquals($expectedValue, $this->lastExternalStorageData[$expectedField], "Field '$expectedField' does not match ({$this->lastExternalStorageData[$expectedField]})");
+ }
+ }
+
+ private function sendJsonWithRequestToken(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',
+ ],
+ 'body' => $fieldsAsJsonString,
+ ];
+ $this->sendingAToWithRequesttoken($method, $url, $body);
+ }
+}
diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php
index 638772da0b7..893dc3094ba 100644
--- a/build/integration/features/bootstrap/FeatureContext.php
+++ b/build/integration/features/bootstrap/FeatureContext.php
@@ -15,6 +15,7 @@ require __DIR__ . '/../../vendor/autoload.php';
*/
class FeatureContext implements Context, SnippetAcceptingContext {
use ContactsMenu;
+ use ExternalStorage;
use Search;
use WebDav;
use Trashbin;
diff --git a/build/integration/files_features/external-storage.feature b/build/integration/files_features/external-storage.feature
index 111b5686e0e..d313cfb3287 100644
--- a/build/integration/files_features/external-storage.feature
+++ b/build/integration/files_features/external-storage.feature
@@ -63,3 +63,65 @@ Feature: external-storage
Then as "user1" the file "/local_storage/foo2/textfile0.txt" does not exist
And as "user0" the file "/local_storage/foo2/textfile0.txt" does not exist
And as "user1" the file "/local.txt" exists
+
+
+
+ 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" |
+ | backendOptions | {"host":"http://localhost:8080","secure":false} |
+ And fields of last external storage match with
+ | status | 2 |
+ When logged in user updates last external userglobal storage
+ | backendOptions | {"user":"admin","password":"admin"} |
+ Then fields of last external storage match with
+ | status | 0 |
+
+ 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" |
+ | backendOptions | {"host":"http://localhost:8080","secure":false} |
+ And fields of last external storage match with
+ | status | 2 |
+ And logged in user updates last external userglobal storage
+ | backendOptions | {"user":"admin","password":"admin"} |
+ When logged in user updates last external userglobal storage
+ | backendOptions | {"user":"admin","password":"__unmodified__"} |
+ Then fields of last external storage match with
+ | status | 0 |
+
+ 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" |
+ | backendOptions | {"host":"http://localhost:8080","secure":false} |
+ And fields of last external storage match with
+ | status | 2 |
+ When logged in user updates last external userglobal storage
+ | backendOptions | {"user":"admin","password":"admin"} |
+ Then fields of last external storage match with
+ | status | 0 |
+
+ 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" |
+ | backendOptions | {"host":"http://localhost:8080","secure":false} |
+ And fields of last external storage match with
+ | status | 2 |
+ And logged in user updates last external userglobal storage
+ | backendOptions | {"user":"admin","password":"admin"} |
+ When logged in user updates last external userglobal storage
+ | backendOptions | {"user":"admin","password":"__unmodified__"} |
+ Then fields of last external storage match with
+ | status | 0 |
diff --git a/build/integration/run.sh b/build/integration/run.sh
index cef59c976af..8f5320af8f5 100755
--- a/build/integration/run.sh
+++ b/build/integration/run.sh
@@ -41,7 +41,7 @@ echo $PORT
echo "" > phpserver.log
-php -S localhost:$PORT -t ../.. &> phpserver.log &
+PHP_CLI_SERVER_WORKERS=2 php -S localhost:$PORT -t ../.. &> phpserver.log &
PHPPID=$!
echo $PHPPID