fix: Clear remote shares between scenarios

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 <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2024-03-27 04:55:10 +01:00
parent 2b1cc55247
commit b15de3105e
5 changed files with 88 additions and 1 deletions

View file

@ -80,5 +80,10 @@ return [
'type' => null
]
],
[
'name' => 'RemoteShares#delete',
'url' => '/api/v1/remote_shares',
'verb' => 'DELETE',
],
],
];

View file

@ -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',

View file

@ -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',

View file

@ -0,0 +1,64 @@
<?php
/**
* @copyright Copyright (c) 2024, Daniel Calviño Sánchez <danxuliu@gmail.com>
*
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
*
* @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 <http://www.gnu.org/licenses/>
*
*/
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();
}
}

View file

@ -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;
}
/**