use OCA\User_LDAP\Connection;
use OCA\User_LDAP\Mapping\AbstractMapping;
use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
use OCP\IUser;
use OCP\Notification\IManager as INotificationManager;
use Test\TestCase;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
/**
* Class Test_User_Ldap_Direct
class User_LDAPTest extends TestCase {
/** @var User_LDAP */
protected $backend;
- /** @var Access|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var Access|MockObject */
protected $access;
- /** @var OfflineUser|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var OfflineUser|MockObject */
protected $offlineUser;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
protected $config;
- /** @var INotificationManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var INotificationManager|MockObject */
protected $notificationManager;
- /** @var Session|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var Session|MockObject */
protected $session;
- /** @var UserPluginManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var UserPluginManager|MockObject */
protected $pluginManager;
- /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var Connection|MockObject */
protected $connection;
- /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var Manager|MockObject */
protected $userManager;
+ /** @var LoggerInterface|MockObject */
+ protected $logger;
+ /** @var DeletedUsersIndex|MockObject */
+ protected $deletedUsersIndex;
protected function setUp(): void {
parent::setUp();
$this->session = $this->createMock(Session::class);
$this->pluginManager = $this->createMock(UserPluginManager::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+
+ $this->deletedUsersIndex = $this->createMock(DeletedUsersIndex::class);
+
$this->backend = new User_LDAP(
$this->access,
$this->config,
$this->notificationManager,
$this->session,
- $this->pluginManager
+ $this->pluginManager,
+ $this->logger,
+ $this->deletedUsersIndex,
);
}
->method('username2dn')
->willReturnCallback(function ($uid) {
switch ($uid) {
- case 'gunslinger':
- return 'dnOfRoland,dc=test';
- break;
- case 'formerUser':
- return 'dnOfFormerUser,dc=test';
- break;
- case 'newyorker':
- return 'dnOfNewYorker,dc=test';
- break;
- case 'ladyofshadows':
- return 'dnOfLadyOfShadows,dc=test';
- break;
- default:
- return false;
- }
+ case 'gunslinger':
+ return 'dnOfRoland,dc=test';
+ break;
+ case 'formerUser':
+ return 'dnOfFormerUser,dc=test';
+ break;
+ case 'newyorker':
+ return 'dnOfNewYorker,dc=test';
+ break;
+ case 'ladyofshadows':
+ return 'dnOfLadyOfShadows,dc=test';
+ break;
+ default:
+ return false;
+ }
});
$this->access->method('fetchUsersByLoginName')
->method('get')
->willReturn($user);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
public function testCheckPasswordWrongPassword() {
$this->prepareAccessForCheckPassword();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'wrong');
public function testCheckPasswordWrongUser() {
$this->prepareAccessForCheckPassword();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$result = $backend->checkPassword('mallory', 'evil');
->method('get')
->willReturn(null);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
->method('get')
->willReturn($user);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$user = \OC::$server->getUserManager()->checkPassword('roland', 'dt19');
public function testCheckPasswordPublicAPIWrongPassword() {
$this->prepareAccessForCheckPassword();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$user = \OC::$server->getUserManager()->checkPassword('roland', 'wrong');
public function testCheckPasswordPublicAPIWrongUser() {
$this->prepareAccessForCheckPassword();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$user = \OC::$server->getUserManager()->checkPassword('mallory', 'evil');
}
public function testDeleteUserCancel() {
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->deleteUser('notme');
$this->assertFalse($result);
}
->method('getConnectionResource')
->willReturn('this is an ldap link');
- $this->config->expects($this->any())
- ->method('getUserValue')
- ->with($uid, 'user_ldap', 'isDeleted')
- ->willReturn('1');
+ $this->deletedUsersIndex->expects($this->once())
+ ->method('isUserMarked')
+ ->with($uid)
+ ->willReturn(true);
$offlineUser = $this->createMock(OfflineUser::class);
$offlineUser->expects($this->once())
->method('get')
->willReturn($offlineUser);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->deleteUser($uid);
$this->assertTrue($result);
->with('uid')
->willReturn(true);
- $this->config->expects($this->once())
- ->method('getUserValue')
- ->with('uid', 'user_ldap', 'isDeleted', 0)
- ->willReturn(1);
+ $this->deletedUsersIndex->expects($this->once())
+ ->method('isUserMarked')
+ ->with('uid')
+ ->willReturn(true);
$mapper = $this->createMock(UserMapping::class);
$mapper->expects($this->once())
} else {
$result = [];
foreach ($users as $user) {
- if (stripos($user, $search) !== false) {
+ if (stripos($user, $search) !== false) {
$result[] = $user;
}
}
public function testGetUsersNoParam() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers();
$this->assertEquals(3, count($result));
public function testGetUsersLimitOffset() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('', 1, 2);
$this->assertEquals(1, count($result));
public function testGetUsersLimitOffset2() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('', 2, 1);
$this->assertEquals(2, count($result));
public function testGetUsersSearchWithResult() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('yo');
$this->assertEquals(2, count($result));
public function testGetUsersSearchEmptyResult() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->getUsers('nix');
$this->assertEquals(0, count($result));
public function testGetUsersViaAPINoParam() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$result = $this->getUsers();
public function testGetUsersViaAPILimitOffset() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$result = $this->getUsers('', 1, 2);
public function testGetUsersViaAPILimitOffset2() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$result = $this->getUsers('', 2, 1);
public function testGetUsersViaAPISearchWithResult() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$result = $this->getUsers('yo');
public function testGetUsersViaAPISearchEmptyResult() {
$this->prepareAccessForGetUsers();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$result = $this->getUsers('nix');
}
public function testUserExists() {
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$user = $this->createMock(User::class);
}
public function testUserExistsForDeleted() {
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$mapper = $this->createMock(UserMapping::class);
}
public function testUserExistsForNeverExisting() {
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->access->expects($this->any())
}
public function testUserExistsPublicAPI() {
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
\OC_User::useBackend($backend);
}
public function testDeleteUserExisting() {
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
//we do not support deleting existing users at all
$result = $backend->deleteUser('gunslinger');
}
public function testGetHomeAbsolutePath() {
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
}
public function testGetHomeRelative() {
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$dataDir = \OC::$server->getConfig()->getSystemValue(
public function testGetHomeNoPath() {
$this->expectException(\Exception::class);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
public function testGetHomeDeletedUser() {
$uid = 'newyorker';
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
});
/** @noinspection PhpUnhandledExceptionInspection */
- $this->assertEquals($this->backend->getHome('uid'),'result');
+ $this->assertEquals($this->backend->getHome('uid'), 'result');
}
private function prepareAccessForGetDisplayName() {
->method('readAttribute')
->willReturnCallback(function ($dn, $attr) {
switch ($dn) {
- case 'dnOfRoland,dc=test':
- if ($attr === 'displayname') {
- return ['Roland Deschain'];
- }
- return [];
- break;
-
- default:
- return false;
- }
+ case 'dnOfRoland,dc=test':
+ if ($attr === 'displayname') {
+ return ['Roland Deschain'];
+ }
+ return [];
+ break;
+
+ default:
+ return false;
+ }
});
$this->access->method('fetchUsersByLoginName')
->willReturn([]);
public function testGetDisplayName() {
$this->prepareAccessForGetDisplayName();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
}
});
$this->prepareAccessForGetDisplayName();
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->prepareMockForUserExists();
$this->connection->expects($this->any())
->with('uid')
->willReturn('result');
- $this->assertEquals($this->backend->getDisplayName('uid'),'result');
+ $this->assertEquals($this->backend->getDisplayName('uid'), 'result');
}
//no test for getDisplayNames, because it just invokes getUsers and
->method('countUsers')
->willReturn(5);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->countUsers();
$this->assertEquals(5, $result);
->method('countUsers')
->willReturn(false);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$result = $backend->countUsers();
$this->assertFalse($result);
->method('countUsers')
->willReturn(42);
- $this->assertEquals($this->backend->countUsers(),42);
+ $this->assertEquals($this->backend->countUsers(), 42);
}
public function testLoginName2UserNameSuccess() {
->method('writeToCache')
->with($this->equalTo('loginName2UserName-'.$loginName), $this->equalTo($username));
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getUsername')
->method('getAttributes')
->willReturn(['dn', 'uid', 'mail', 'displayname']);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$name = $backend->loginName2UserName($loginName);
$this->assertSame(false, $name);
->method('getAttributes')
->willReturn(['dn', 'uid', 'mail', 'displayname']);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$name = $backend->loginName2UserName($loginName);
$this->assertSame(false, $name);
$this->userManager->expects($this->atLeastOnce())
->method('get')
->willReturn($this->createMock(User::class));
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$this->assertTrue(\OC_User::setPassword('roland', 'dt'));
->method('get')
->willReturn($this->createMock(User::class));
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
$this->userManager->expects($this->any())
->method('get')
->willReturn($this->createMock(User::class));
->willReturn($this->createMock(User::class));
$this->prepareAccessForSetPassword(false);
- $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
+ $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager, $this->logger, $this->deletedUsersIndex);
\OC_User::useBackend($backend);
$this->assertFalse(\OC_User::setPassword('roland', 'dt12234$'));
->willReturn(true);
$this->pluginManager->expects($this->once())
->method('setPassword')
- ->with('uid','password')
+ ->with('uid', 'password')
->willReturn('result');
/** @noinspection PhpUnhandledExceptionInspection */
- $this->assertEquals($this->backend->setPassword('uid', 'password'),'result');
+ $this->assertEquals($this->backend->setPassword('uid', 'password'), 'result');
}
public function avatarDataProvider() {
->with('uid')
->willReturn('result');
- $this->assertEquals($this->backend->canChangeAvatar('uid'),'result');
+ $this->assertEquals($this->backend->canChangeAvatar('uid'), 'result');
}
public function testSetDisplayNameWithPlugin() {
->method('getUserMapper')
->willReturn($this->createMock(UserMapping::class));
- $this->assertEquals($this->backend->createUser($uid, $pwd),true);
+ $this->assertEquals($this->backend->createUser($uid, $pwd), true);
}
public function testCreateUserFailing() {