namespace OCA\User_LDAP\Tests;
+use OC\User\Session;
use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
use OCA\User_LDAP\FilesystemHelper;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Image;
+use OCP\IUser;
use OCP\IUserManager;
use Test\TestCase;
use OCP\Notification\IManager as INotificationManager;
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'wrong');
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('mallory', 'evil');
->method('username2dn')
->will($this->returnValue(false));
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
public function testCheckPasswordPublicAPI() {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('roland', 'dt19');
public function testCheckPasswordPublicAPIWrongPassword() {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('roland', 'wrong');
public function testCheckPasswordPublicAPIWrongUser() {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('mallory', 'evil');
public function testDeleteUserCancel() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$result = $backend->deleteUser('notme');
$this->assertFalse($result);
}
$this->offlineUser->expects($this->once())
->method('getHomePath')
->willReturn($home);
+ $this->offlineUser->expects($this->once())
+ ->method('getOCName')
+ ->willReturn($uid);
- $backend = new UserLDAP($access, $this->configMock, $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->configMock, $this->createMock(INotificationManager::class), $this->createMock(Session::class));
+
+ $user = $this->createMock(IUser::class);
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn($uid);
+ $backend->preDeleteUser($user);
$result = $backend->deleteUser($uid);
$this->assertTrue($result);
$this->assertSame($backend->getHome($uid), $home);
public function testGetUsersNoParam() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$result = $backend->getUsers();
$this->assertEquals(3, count($result));
public function testGetUsersLimitOffset() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$result = $backend->getUsers('', 1, 2);
$this->assertEquals(1, count($result));
public function testGetUsersLimitOffset2() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$result = $backend->getUsers('', 2, 1);
$this->assertEquals(2, count($result));
public function testGetUsersSearchWithResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$result = $backend->getUsers('yo');
$this->assertEquals(2, count($result));
public function testGetUsersSearchEmptyResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$result = $backend->getUsers('nix');
$this->assertEquals(0, count($result));
public function testGetUsersViaAPINoParam() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers();
public function testGetUsersViaAPILimitOffset() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('', 1, 2);
public function testGetUsersViaAPILimitOffset2() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('', 2, 1);
public function testGetUsersViaAPISearchWithResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('yo');
public function testGetUsersViaAPISearchEmptyResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('nix');
public function testUserExists() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
$access->expects($this->any())
*/
public function testUserExistsForDeleted() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
$access->expects($this->any())
public function testUserExistsForNeverExisting() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
$access->expects($this->any())
public function testUserExistsPublicAPI() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);
*/
public function testUserExistsPublicAPIForDeleted() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);
public function testUserExistsPublicAPIForNeverExisting() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);
public function testDeleteUserExisting() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
//we do not support deleting existing users at all
$result = $backend->deleteUser('gunslinger');
$access = $this->getAccessMock();
$config = $this->createMock(IConfig::class);
$noti = $this->createMock(INotificationManager::class);
- $backend = new UserLDAP($access, $config, $noti);
+ $backend = new UserLDAP($access, $config, $noti, $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
$access = $this->getAccessMock();
$config = $this->createMock(IConfig::class);
$noti = $this->createMock(INotificationManager::class);
- $backend = new UserLDAP($access, $config, $noti);
+ $backend = new UserLDAP($access, $config, $noti, $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
$dataDir = \OC::$server->getConfig()->getSystemValue(
*/
public function testGetHomeNoPath() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
$uid = 'newyorker';
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->configMock, $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->configMock, $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
$this->offlineUser->expects($this->never())
->method('getHomePath');
- $this->offlineUser->expects($this->once())
- ->method('getUID')
- ->willReturn($uid);
$backend->getHome($uid);
}
public function testGetDisplayName() {
$access = $this->getAccessMock();
$this->prepareAccessForGetDisplayName($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
}
}));
$this->prepareAccessForGetDisplayName($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
->method('countUsers')
->will($this->returnValue(5));
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$result = $backend->countUsers();
$this->assertEquals(5, $result);
->method('countUsers')
->will($this->returnValue(false));
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$result = $backend->countUsers();
$this->assertFalse($result);
->method('writeToCache')
->with($this->equalTo('loginName2UserName-'.$loginName), $this->equalTo($username));
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$name = $backend->loginName2UserName($loginName);
$this->assertSame($username, $name);
->method('writeToCache')
->with($this->equalTo('loginName2UserName-'.$loginName), false);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$name = $backend->loginName2UserName($loginName);
$this->assertSame(false, $name);
->method('getUserValue')
->willReturn(1);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
$name = $backend->loginName2UserName($loginName);
$this->assertSame(false, $name);
$access = $this->getAccessMock();
$this->prepareAccessForSetPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$this->assertTrue(\OC_User::setPassword('roland', 'dt'));
$access = $this->getAccessMock();
$this->prepareAccessForSetPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$this->assertTrue(\OC_User::setPassword('roland', 'dt12234$'));
$access = $this->getAccessMock();
$this->prepareAccessForSetPassword($access, false);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class));
\OC_User::useBackend($backend);
$this->assertFalse(\OC_User::setPassword('roland', 'dt12234$'));
->willReturn(null);
$config = $this->createMock(IConfig::class);
$noti = $this->createMock(INotificationManager::class);
+ $userSession = $this->createMock(Session::class);
$ldap = new User_LDAP(
$access,
$config,
- $noti
+ $noti,
+ $userSession
);
$ldap->setPassword('NotExistingUser', 'Password');
}
->willReturn($user);
$config = $this->createMock(IConfig::class);
$noti = $this->createMock(INotificationManager::class);
+ $userSession = $this->createMock(Session::class);
$ldap = new User_LDAP(
$access,
$config,
- $noti
+ $noti,
+ $userSession
);
$this->assertFalse($ldap->setPassword('NotExistingUser', 'Password'));
}