chore: adjust duplicated use in User_LDAPTest

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2025-10-22 19:22:04 +02:00
parent 7f125551f5
commit c99d27436f

View file

@ -19,7 +19,6 @@ use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\User_LDAP as UserLDAP;
use OCA\User_LDAP\UserPluginManager;
use OCP\HintException;
use OCP\IConfig;
@ -48,7 +47,7 @@ class User_LDAPTest extends TestCase {
protected Manager&MockObject $userManager;
protected LoggerInterface&MockObject $logger;
protected DeletedUsersIndex&MockObject $deletedUsersIndex;
protected UserLDAP $backend;
protected User_LDAP $backend;
protected function setUp(): void {
parent::setUp();
@ -72,7 +71,7 @@ class User_LDAPTest extends TestCase {
$this->deletedUsersIndex = $this->createMock(DeletedUsersIndex::class);
$this->backend = new UserLDAP(
$this->backend = new User_LDAP(
$this->access,
$this->notificationManager,
$this->pluginManager,
@ -178,7 +177,7 @@ class User_LDAPTest extends TestCase {
->method('get')
->willReturn($user);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
@ -188,7 +187,7 @@ class User_LDAPTest extends TestCase {
public function testCheckPasswordWrongPassword(): void {
$this->prepareAccessForCheckPassword();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$result = $backend->checkPassword('roland', 'wrong');
@ -197,7 +196,7 @@ class User_LDAPTest extends TestCase {
public function testCheckPasswordWrongUser(): void {
$this->prepareAccessForCheckPassword();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$result = $backend->checkPassword('mallory', 'evil');
@ -212,7 +211,7 @@ class User_LDAPTest extends TestCase {
->method('get')
->willReturn(null);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
@ -230,7 +229,7 @@ class User_LDAPTest extends TestCase {
->method('get')
->willReturn($user);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$user = Server::get(IUserManager::class)->checkPassword('roland', 'dt19');
@ -243,7 +242,7 @@ class User_LDAPTest extends TestCase {
public function testCheckPasswordPublicAPIWrongPassword(): void {
$this->prepareAccessForCheckPassword();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$user = Server::get(IUserManager::class)->checkPassword('roland', 'wrong');
@ -256,7 +255,7 @@ class User_LDAPTest extends TestCase {
public function testCheckPasswordPublicAPIWrongUser(): void {
$this->prepareAccessForCheckPassword();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$user = Server::get(IUserManager::class)->checkPassword('mallory', 'evil');
@ -268,7 +267,7 @@ class User_LDAPTest extends TestCase {
}
public function testDeleteUserCancel(): void {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->deleteUser('notme');
$this->assertFalse($result);
}
@ -305,7 +304,7 @@ class User_LDAPTest extends TestCase {
->with($uid)
->willReturn(true);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->deleteUser($uid);
$this->assertTrue($result);
@ -394,7 +393,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersNoParam(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers();
$this->assertCount(3, $result);
@ -402,7 +401,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersLimitOffset(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('', 1, 2);
$this->assertCount(1, $result);
@ -410,7 +409,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersLimitOffset2(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('', 2, 1);
$this->assertCount(2, $result);
@ -418,7 +417,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersSearchWithResult(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('yo');
$this->assertCount(2, $result);
@ -426,7 +425,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersSearchEmptyResult(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('nix');
$this->assertCount(0, $result);
@ -442,7 +441,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPINoParam(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers();
@ -451,7 +450,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPILimitOffset(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers('', 1, 2);
@ -460,7 +459,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPILimitOffset2(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers('', 2, 1);
@ -469,7 +468,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPISearchWithResult(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers('yo');
@ -478,7 +477,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPISearchEmptyResult(): void {
$this->prepareAccessForGetUsers();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$result = $this->getUsers('nix');
@ -486,7 +485,7 @@ class User_LDAPTest extends TestCase {
}
public function testUserExists(): void {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->userManager->expects($this->never())
@ -506,7 +505,7 @@ class User_LDAPTest extends TestCase {
}
public function testUserExistsForDeleted(): void {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$mapper = $this->createMock(UserMapping::class);
@ -531,7 +530,7 @@ class User_LDAPTest extends TestCase {
}
public function testUserExistsForNeverExisting(): void {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->access->expects($this->any())
@ -550,7 +549,7 @@ class User_LDAPTest extends TestCase {
}
public function testUserExistsPublicAPI(): void {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
Server::get(IUserManager::class)->registerBackend($backend);
@ -583,7 +582,7 @@ class User_LDAPTest extends TestCase {
}
public function testDeleteUserExisting(): void {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
//we do not support deleting existing users at all
$result = $backend->deleteUser('gunslinger');
@ -591,7 +590,7 @@ class User_LDAPTest extends TestCase {
}
public function testGetHomeAbsolutePath(): void {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
@ -645,7 +644,7 @@ class User_LDAPTest extends TestCase {
}
public function testGetHomeRelative(): void {
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$dataDir = Server::get(IConfig::class)->getSystemValue(
@ -703,7 +702,7 @@ class User_LDAPTest extends TestCase {
public function testGetHomeNoPath(): void {
$this->expectException(\Exception::class);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
@ -748,7 +747,7 @@ class User_LDAPTest extends TestCase {
public function testGetHomeDeletedUser(): void {
$uid = 'newyorker';
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
@ -841,7 +840,7 @@ class User_LDAPTest extends TestCase {
public function testGetDisplayName(): void {
$this->prepareAccessForGetDisplayName();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
@ -932,7 +931,7 @@ class User_LDAPTest extends TestCase {
}
});
$this->prepareAccessForGetDisplayName();
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
@ -1024,7 +1023,7 @@ class User_LDAPTest extends TestCase {
->method('countUsers')
->willReturn(5);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->countUsers();
$this->assertEquals(5, $result);
@ -1035,7 +1034,7 @@ class User_LDAPTest extends TestCase {
->method('countUsers')
->willReturn(false);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->countUsers();
$this->assertFalse($result);
@ -1079,7 +1078,7 @@ class User_LDAPTest extends TestCase {
->method('writeToCache')
->with($this->equalTo('loginName2UserName-' . $loginName), $this->equalTo($username));
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getUsername')
@ -1126,7 +1125,7 @@ class User_LDAPTest extends TestCase {
->method('getAttributes')
->willReturn(['dn', 'uid', 'mail', 'displayname']);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$name = $backend->loginName2UserName($loginName);
$this->assertSame(false, $name);
@ -1163,7 +1162,7 @@ class User_LDAPTest extends TestCase {
->method('getAttributes')
->willReturn(['dn', 'uid', 'mail', 'displayname']);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$name = $backend->loginName2UserName($loginName);
$this->assertSame(false, $name);
@ -1238,7 +1237,7 @@ class User_LDAPTest extends TestCase {
$this->userManager->expects($this->atLeastOnce())
->method('get')
->willReturn($this->createMock(User::class));
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$this->assertTrue(\OC_User::setPassword('roland', 'dt'));
@ -1251,7 +1250,7 @@ class User_LDAPTest extends TestCase {
->method('get')
->willReturn($this->createMock(User::class));
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->userManager->expects($this->any())
->method('get')
->willReturn($this->createMock(User::class));
@ -1267,7 +1266,7 @@ class User_LDAPTest extends TestCase {
->willReturn($this->createMock(User::class));
$this->prepareAccessForSetPassword(false);
$backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$backend = new User_LDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
Server::get(IUserManager::class)->registerBackend($backend);
$this->assertFalse(\OC_User::setPassword('roland', 'dt12234$'));