Skip to content

Commit

Permalink
Flush duplicate usernames for integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
  • Loading branch information
LukasReschke committed May 26, 2021
1 parent 80421c5 commit 99a2b22
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/testing/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
'url' => '/api/v1/app/{appid}/{configkey}',
'verb' => 'DELETE',
],
[
'name' => 'FlushUsedUserNames#executeFlush',
'url' => '/api/v1/flushDupeUsernames',
'verb' => 'POST',
],
[
'name' => 'Locking#isLockingEnabled',
'url' => '/api/v1/lockprovisioning',
Expand Down
1 change: 1 addition & 0 deletions apps/testing/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'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',
Expand Down
1 change: 1 addition & 0 deletions apps/testing/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
55 changes: 55 additions & 0 deletions apps/testing/lib/Controller/FlushUsedUserNamesController.php
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 4 additions & 0 deletions build/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ class FeatureContext implements Context, SnippetAcceptingContext {
use Search;
use WebDav;
use Trashbin;

protected function resetAppConfigs() {
// not implemented
}
}
12 changes: 12 additions & 0 deletions build/integration/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

trait Provisioning {
use BasicStructure;
use AppConfiguration;

/** @var array */
private $createdUsers = [];
Expand Down Expand Up @@ -384,6 +385,15 @@ public function assureUserIsDisabled($user) {
$this->response = $client->put($fullUrl, $options);
}

private function flushDeletedUserList() {
$previousUser = $this->currentUser;
$this->currentUser = 'admin';
$this->setStatusTestingApp(true);
$this->sendingTo('POST', "/apps/testing/api/v1/flushDupeUsernames");
$this->setStatusTestingApp(true);
$this->currentUser = $previousUser;
}

/**
* @When /^Deleting the user "([^"]*)"$/
* @param string $user
Expand Down Expand Up @@ -878,6 +888,8 @@ public function getUserHome($user) {
* @AfterScenario
*/
public function cleanupUsers() {
$this->flushDeletedUserList();

$previousServer = $this->currentServer;
$this->usingServer('LOCAL');
foreach ($this->createdUsers as $user) {
Expand Down

0 comments on commit 99a2b22

Please sign in to comment.