Flush duplicate usernames for integration tests

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Lukas Reschke 2021-05-26 17:57:04 +02:00
parent 4abf1226ba
commit 1d5cbd3e04
5 changed files with 73 additions and 0 deletions

View File

@ -48,6 +48,11 @@ return [
'url' => '/api/v1/app/{appid}/{configkey}',
'verb' => 'DELETE',
],
[
'name' => 'FlushUsedUserNames#executeFlush',
'url' => '/api/v1/flushDupeUsernames',
'verb' => 'POST',
],
[
'name' => 'Locking#isLockingEnabled',
'url' => '/api/v1/lockprovisioning',

View File

@ -10,6 +10,7 @@ return array(
'OCA\\Testing\\AlternativeHomeUserBackend' => $baseDir . '/../lib/AlternativeHomeUserBackend.php',
'OCA\\Testing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Testing\\Controller\\ConfigController' => $baseDir . '/../lib/Controller/ConfigController.php',
'OCA\\Testing\\Controller\\FlushUsedUserNamesController' => $baseDir . '/../lib/Controller/FlushUsedUserNamesController.php',
'OCA\\Testing\\Controller\\LockingController' => $baseDir . '/../lib/Controller/LockingController.php',
'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir . '/../lib/Controller/RateLimitTestController.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => $baseDir . '/../lib/Locking/FakeDBLockingProvider.php',

View File

@ -25,6 +25,7 @@ class ComposerStaticInitTesting
'OCA\\Testing\\AlternativeHomeUserBackend' => __DIR__ . '/..' . '/../lib/AlternativeHomeUserBackend.php',
'OCA\\Testing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Testing\\Controller\\ConfigController' => __DIR__ . '/..' . '/../lib/Controller/ConfigController.php',
'OCA\\Testing\\Controller\\FlushUsedUserNamesController' => __DIR__ . '/..' . '/../lib/Controller/FlushUsedUserNamesController.php',
'OCA\\Testing\\Controller\\LockingController' => __DIR__ . '/..' . '/../lib/Controller/LockingController.php',
'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__ . '/..' . '/../lib/Controller/RateLimitTestController.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => __DIR__ . '/..' . '/../lib/Locking/FakeDBLockingProvider.php',

View File

@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Lukas Reschke <lukas@statuscode.ch>
*
* @author Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Testing\Controller;
use OC\User\UsernameDuplicationPreventionManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
class FlushUsedUserNamesController extends OCSController {
/** @var UsernameDuplicationPreventionManager */
private $usernameDuplicationPreventionManager;
/**
* @param string $appName
* @param IRequest $request
* @param UsernameDuplicationPreventionManager $usernameDuplicationPreventionManager
*/
public function __construct($appName,
IRequest $request,
UsernameDuplicationPreventionManager $usernameDuplicationPreventionManager) {
parent::__construct($appName, $request);
$this->usernameDuplicationPreventionManager = $usernameDuplicationPreventionManager;
}
public function executeFlush() : DataResponse {
$this->usernameDuplicationPreventionManager->cleanUp();
return new DataResponse();
}
}

View File

@ -414,6 +414,15 @@ trait Provisioning {
$this->response = $client->put($fullUrl, $options);
}
private function flushDeletedUserList() {
$previousUser = $this->currentUser;
$this->currentUser = 'admin';
$this->sendingTo('POST', "/cloud/apps/testing");
$this->sendingTo('POST', "/apps/testing/api/v1/flushDupeUsernames");
$this->sendingTo('DELETE', "/cloud/apps/testing");
$this->currentUser = $previousUser;
}
/**
* @When /^Deleting the user "([^"]*)"$/
* @param string $user
@ -908,6 +917,8 @@ trait Provisioning {
* @AfterScenario
*/
public function cleanupUsers() {
$this->flushDeletedUserList();
$previousServer = $this->currentServer;
$this->usingServer('LOCAL');
foreach ($this->createdUsers as $user) {