From b15de3105ec1733297bdc1ceaafa6a0ee70b1dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 27 Mar 2024 04:55:10 +0100 Subject: [PATCH] fix: Clear remote shares between scenarios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Although groups are removed after each scenario it seems that their remote group shares are not, so there might be dangling remote group shares that could interfere with the following scenarios. To solve that a new endpoint is added to the "testing" app to explicitly clear the remote shares. Note that any dangling remote storage was already removed with the OCC command, so only the "share_external" table is cleared. Signed-off-by: Daniel Calviño Sánchez --- apps/testing/appinfo/routes.php | 5 ++ .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + .../lib/Controller/RemoteSharesController.php | 64 +++++++++++++++++++ .../features/bootstrap/FederationContext.php | 18 +++++- 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 apps/testing/lib/Controller/RemoteSharesController.php diff --git a/apps/testing/appinfo/routes.php b/apps/testing/appinfo/routes.php index 1ab36a4e826..a461bd98b66 100644 --- a/apps/testing/appinfo/routes.php +++ b/apps/testing/appinfo/routes.php @@ -80,5 +80,10 @@ return [ 'type' => null ] ], + [ + 'name' => 'RemoteShares#delete', + 'url' => '/api/v1/remote_shares', + 'verb' => 'DELETE', + ], ], ]; diff --git a/apps/testing/composer/composer/autoload_classmap.php b/apps/testing/composer/composer/autoload_classmap.php index 079f8877881..7898144672b 100644 --- a/apps/testing/composer/composer/autoload_classmap.php +++ b/apps/testing/composer/composer/autoload_classmap.php @@ -12,6 +12,7 @@ return array( 'OCA\\Testing\\Controller\\ConfigController' => $baseDir . '/../lib/Controller/ConfigController.php', 'OCA\\Testing\\Controller\\LockingController' => $baseDir . '/../lib/Controller/LockingController.php', 'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir . '/../lib/Controller/RateLimitTestController.php', + 'OCA\\Testing\\Controller\\RemoteSharesController' => $baseDir . '/../lib/Controller/RemoteSharesController.php', 'OCA\\Testing\\Listener\\GetDeclarativeSettingsValueListener' => $baseDir . '/../lib/Listener/GetDeclarativeSettingsValueListener.php', 'OCA\\Testing\\Listener\\RegisterDeclarativeSettingsListener' => $baseDir . '/../lib/Listener/RegisterDeclarativeSettingsListener.php', 'OCA\\Testing\\Listener\\SetDeclarativeSettingsValueListener' => $baseDir . '/../lib/Listener/SetDeclarativeSettingsValueListener.php', diff --git a/apps/testing/composer/composer/autoload_static.php b/apps/testing/composer/composer/autoload_static.php index 2332da70da9..e2819e61b82 100644 --- a/apps/testing/composer/composer/autoload_static.php +++ b/apps/testing/composer/composer/autoload_static.php @@ -27,6 +27,7 @@ class ComposerStaticInitTesting 'OCA\\Testing\\Controller\\ConfigController' => __DIR__ . '/..' . '/../lib/Controller/ConfigController.php', 'OCA\\Testing\\Controller\\LockingController' => __DIR__ . '/..' . '/../lib/Controller/LockingController.php', 'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__ . '/..' . '/../lib/Controller/RateLimitTestController.php', + 'OCA\\Testing\\Controller\\RemoteSharesController' => __DIR__ . '/..' . '/../lib/Controller/RemoteSharesController.php', 'OCA\\Testing\\Listener\\GetDeclarativeSettingsValueListener' => __DIR__ . '/..' . '/../lib/Listener/GetDeclarativeSettingsValueListener.php', 'OCA\\Testing\\Listener\\RegisterDeclarativeSettingsListener' => __DIR__ . '/..' . '/../lib/Listener/RegisterDeclarativeSettingsListener.php', 'OCA\\Testing\\Listener\\SetDeclarativeSettingsValueListener' => __DIR__ . '/..' . '/../lib/Listener/SetDeclarativeSettingsValueListener.php', diff --git a/apps/testing/lib/Controller/RemoteSharesController.php b/apps/testing/lib/Controller/RemoteSharesController.php new file mode 100644 index 00000000000..90fe4dd229e --- /dev/null +++ b/apps/testing/lib/Controller/RemoteSharesController.php @@ -0,0 +1,64 @@ + + * + * @author Daniel Calviño Sánchez + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\Testing\Controller; + +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCSController; +use OCP\IDBConnection; +use OCP\IRequest; + +class RemoteSharesController extends OCSController { + + /** @var IDBConnection */ + protected $connection; + + /** + * @param string $appName + * @param IRequest $request + */ + public function __construct($appName, + IRequest $request, + IDBConnection $connection) { + parent::__construct($appName, $request); + $this->connection = $connection; + } + + /** + * Deletes all remote shares. + * + * Note that neither storages nor mountpoints are deleted. This is meant to + * be used to get rid of dangling group shares after the users and groups + * were deleted. + * + * @return DataResponse + */ + public function delete() { + // For simplicity the database table is cleared directly in the + // controller :see-no-evil: + $query = $this->connection->getQueryBuilder(); + $query->delete('share_external'); + + $query->executeStatement(); + + return new DataResponse(); + } +} diff --git a/build/integration/features/bootstrap/FederationContext.php b/build/integration/features/bootstrap/FederationContext.php index 3ff83de7b91..409c5f3ca1e 100644 --- a/build/integration/features/bootstrap/FederationContext.php +++ b/build/integration/features/bootstrap/FederationContext.php @@ -70,7 +70,7 @@ class FederationContext implements Context, SnippetAcceptingContext { /** * @BeforeScenario */ - public function cleanupRemoteStorages() { + public function cleanupRemoteStoragesAndShares() { // Ensure that dangling remote storages from previous tests will not // interfere with the current scenario. // The storages must be cleaned before each scenario; they can not be @@ -78,6 +78,22 @@ class FederationContext implements Context, SnippetAcceptingContext { // that removes the users, so the shares would be still valid and thus // the storages would not be dangling yet. $this->runOcc(['sharing:cleanup-remote-storages']); + + // Even if the groups are removed after each scenario there might be + // dangling remote group shares that could interfere with the current + // scenario, so the remote shares need to be explicitly cleared. + $this->runOcc(['app:enable', 'testing']); + + $user = $this->currentUser; + $this->currentUser = 'admin'; + + $this->sendingTo('DELETE', "/apps/testing/api/v1/remote_shares"); + $this->theHTTPStatusCodeShouldBe('200'); + if ($this->apiVersion === 1) { + $this->theOCSStatusCodeShouldBe('100'); + } + + $this->currentUser = $user; } /**