2013-09-11 16:51:45 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
|
*
|
2016-05-26 17:56:05 +00:00
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-07-21 14:49:16 +00:00
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-06-25 09:43:55 +00:00
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 17:56:05 +00:00
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 10:44:34 +00:00
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-01-12 14:02:16 +00:00
|
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2017-11-06 14:56:42 +00:00
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-08-30 09:43:29 +00:00
|
|
|
|
* @author Roger Szabo <roger.szabo@web.de>
|
2017-11-06 14:56:42 +00:00
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
|
* @author Vinicius Cubas Brand <vinicius@eita.org.br>
|
2015-03-26 10:44:34 +00:00
|
|
|
|
*
|
|
|
|
|
* @license AGPL-3.0
|
|
|
|
|
*
|
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* 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, version 3,
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
|
2016-05-12 09:01:29 +00:00
|
|
|
|
namespace OCA\User_LDAP\Tests;
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
use OC\User\Backend;
|
2017-09-15 14:01:54 +00:00
|
|
|
|
use OC\User\Session;
|
2016-10-06 20:52:45 +00:00
|
|
|
|
use OCA\User_LDAP\Access;
|
|
|
|
|
use OCA\User_LDAP\Connection;
|
2016-09-02 09:02:12 +00:00
|
|
|
|
use OCA\User_LDAP\FilesystemHelper;
|
2016-10-06 20:52:45 +00:00
|
|
|
|
use OCA\User_LDAP\Helper;
|
2016-09-02 09:02:12 +00:00
|
|
|
|
use OCA\User_LDAP\ILDAPWrapper;
|
|
|
|
|
use OCA\User_LDAP\LogWrapper;
|
2017-07-13 12:32:52 +00:00
|
|
|
|
use OCA\User_LDAP\Mapping\UserMapping;
|
2016-10-06 20:52:45 +00:00
|
|
|
|
use OCA\User_LDAP\User\Manager;
|
2016-10-06 23:39:57 +00:00
|
|
|
|
use OCA\User_LDAP\User\OfflineUser;
|
2016-08-30 09:43:29 +00:00
|
|
|
|
use OC\HintException;
|
2016-11-23 18:58:43 +00:00
|
|
|
|
use OCA\User_LDAP\User\User;
|
2016-05-12 09:01:29 +00:00
|
|
|
|
use OCA\User_LDAP\User_LDAP as UserLDAP;
|
2016-11-23 18:58:43 +00:00
|
|
|
|
use OCA\User_LDAP\User_LDAP;
|
2016-09-02 09:02:12 +00:00
|
|
|
|
use OCP\IAvatarManager;
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\Image;
|
2017-09-15 14:01:54 +00:00
|
|
|
|
use OCP\IUser;
|
2016-09-02 09:02:12 +00:00
|
|
|
|
use OCP\IUserManager;
|
2016-10-06 20:52:45 +00:00
|
|
|
|
use Test\TestCase;
|
2017-03-31 07:16:22 +00:00
|
|
|
|
use OCP\Notification\IManager as INotificationManager;
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2015-11-25 15:58:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* Class Test_User_Ldap_Direct
|
|
|
|
|
*
|
|
|
|
|
* @group DB
|
|
|
|
|
*
|
2016-05-12 09:01:29 +00:00
|
|
|
|
* @package OCA\User_LDAP\Tests
|
2015-11-25 15:58:54 +00:00
|
|
|
|
*/
|
2016-10-06 20:52:45 +00:00
|
|
|
|
class User_LDAPTest extends TestCase {
|
2013-09-11 16:51:45 +00:00
|
|
|
|
protected $backend;
|
2014-04-01 10:28:23 +00:00
|
|
|
|
protected $access;
|
2017-07-13 12:32:52 +00:00
|
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2015-08-20 22:55:42 +00:00
|
|
|
|
protected $configMock;
|
2017-07-13 12:32:52 +00:00
|
|
|
|
/** @var OfflineUser|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
|
protected $offlineUser;
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2014-11-10 21:28:12 +00:00
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
\OC_User::clearBackends();
|
2017-03-03 07:24:27 +00:00
|
|
|
|
\OC::$server->getGroupManager()->clearBackends();
|
2013-09-11 16:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 23:39:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|Access
|
|
|
|
|
*/
|
2013-09-11 16:51:45 +00:00
|
|
|
|
private function getAccessMock() {
|
2016-09-02 09:02:12 +00:00
|
|
|
|
$this->configMock = $this->createMock(IConfig::class);
|
2015-12-11 16:25:57 +00:00
|
|
|
|
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$this->offlineUser = $this->createMock(OfflineUser::class);
|
2015-12-11 16:25:57 +00:00
|
|
|
|
|
2017-07-13 12:32:52 +00:00
|
|
|
|
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject $um */
|
2016-10-06 20:52:45 +00:00
|
|
|
|
$um = $this->getMockBuilder(Manager::class)
|
2015-12-11 16:25:57 +00:00
|
|
|
|
->setMethods(['getDeletedUser'])
|
|
|
|
|
->setConstructorArgs([
|
2015-08-20 22:55:42 +00:00
|
|
|
|
$this->configMock,
|
2016-09-02 09:02:12 +00:00
|
|
|
|
$this->createMock(FilesystemHelper::class),
|
|
|
|
|
$this->createMock(LogWrapper::class),
|
|
|
|
|
$this->createMock(IAvatarManager::class),
|
|
|
|
|
$this->createMock(Image::class),
|
|
|
|
|
$this->createMock(IDBConnection::class),
|
2017-03-31 07:16:22 +00:00
|
|
|
|
$this->createMock(IUserManager::class),
|
|
|
|
|
$this->createMock(INotificationManager::class)
|
2015-12-11 16:25:57 +00:00
|
|
|
|
])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
/** @var Connection|\PHPUnit_Framework_MockObject_MockObject $connection */
|
|
|
|
|
$connection = $this->createMock(Connection::class);
|
2014-04-01 10:28:23 +00:00
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject $userManager */
|
|
|
|
|
$userManager = $this->createMock(Manager::class);
|
2016-10-06 20:52:45 +00:00
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
/** @var Access|\PHPUnit_Framework_MockObject_MockObject $access */
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$access->connection = $connection;
|
|
|
|
|
$access->userManager = $userManager;
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
return $access;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
private function getDefaultPluginManagerMock() {
|
|
|
|
|
return $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
private function prepareMockForUserExists(&$access) {
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('username2dn')
|
|
|
|
|
->will($this->returnCallback(function($uid) {
|
|
|
|
|
switch ($uid) {
|
|
|
|
|
case 'gunslinger':
|
2014-04-01 10:28:23 +00:00
|
|
|
|
return 'dnOfRoland,dc=test';
|
2013-09-11 16:51:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'formerUser':
|
2014-04-01 10:28:23 +00:00
|
|
|
|
return 'dnOfFormerUser,dc=test';
|
2013-09-11 16:51:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'newyorker':
|
2014-04-01 10:28:23 +00:00
|
|
|
|
return 'dnOfNewYorker,dc=test';
|
2013-09-11 16:51:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'ladyofshadows':
|
2014-04-01 10:28:23 +00:00
|
|
|
|
return 'dnOfLadyOfShadows,dc=test';
|
2013-09-11 16:51:45 +00:00
|
|
|
|
break;
|
2014-05-11 13:24:42 +00:00
|
|
|
|
default:
|
2013-09-11 16:51:45 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}));
|
2017-08-09 14:43:40 +00:00
|
|
|
|
|
|
|
|
|
$access->method('fetchUsersByLoginName')
|
|
|
|
|
->willReturn([]);
|
2013-09-11 16:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
|
* Prepares the Access mock for checkPassword tests
|
2016-10-06 23:39:57 +00:00
|
|
|
|
* @param Access|\PHPUnit_Framework_MockObject_MockObject $access mock
|
2016-05-12 14:42:57 +00:00
|
|
|
|
* @param bool $noDisplayName
|
2013-09-25 20:14:02 +00:00
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2014-10-27 14:58:23 +00:00
|
|
|
|
private function prepareAccessForCheckPassword(&$access, $noDisplayName = false) {
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('__get')
|
|
|
|
|
->will($this->returnCallback(function($name) {
|
|
|
|
|
if($name === 'ldapLoginFilter') {
|
|
|
|
|
return '%uid';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('fetchListOfUsers')
|
|
|
|
|
->will($this->returnCallback(function($filter) {
|
|
|
|
|
if($filter === 'roland') {
|
2015-10-09 12:30:49 +00:00
|
|
|
|
return array(array('dn' => ['dnOfRoland,dc=test']));
|
2013-09-11 16:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
return array();
|
|
|
|
|
}));
|
|
|
|
|
|
2015-04-09 10:00:11 +00:00
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('fetchUsersByLoginName')
|
|
|
|
|
->will($this->returnCallback(function($uid) {
|
|
|
|
|
if($uid === 'roland') {
|
2015-10-09 12:30:49 +00:00
|
|
|
|
return array(array('dn' => ['dnOfRoland,dc=test']));
|
2015-04-09 10:00:11 +00:00
|
|
|
|
}
|
|
|
|
|
return array();
|
|
|
|
|
}));
|
|
|
|
|
|
2014-10-27 14:58:23 +00:00
|
|
|
|
$retVal = 'gunslinger';
|
|
|
|
|
if($noDisplayName === true) {
|
|
|
|
|
$retVal = false;
|
|
|
|
|
}
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('dn2username')
|
2014-04-01 10:28:23 +00:00
|
|
|
|
->with($this->equalTo('dnOfRoland,dc=test'))
|
2014-10-27 14:58:23 +00:00
|
|
|
|
->will($this->returnValue($retVal));
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2014-08-12 14:13:17 +00:00
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('stringResemblesDN')
|
|
|
|
|
->with($this->equalTo('dnOfRoland,dc=test'))
|
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('areCredentialsValid')
|
|
|
|
|
->will($this->returnCallback(function($dn, $pwd) {
|
|
|
|
|
if($pwd === 'dt19') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}));
|
2013-09-25 20:14:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 13:05:45 +00:00
|
|
|
|
public function testCheckPasswordUidReturn() {
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user = $this->createMock(User::class);
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getUsername')
|
|
|
|
|
->willReturn('gunslinger');
|
2014-02-20 13:05:45 +00:00
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access = $this->getAccessMock();
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->prepareAccessForCheckPassword($access);
|
2017-11-07 12:19:08 +00:00
|
|
|
|
$access->userManager->expects($this->any())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($user);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
|
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2017-11-03 16:40:05 +00:00
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->checkPassword('roland', 'dt19');
|
|
|
|
|
$this->assertEquals('gunslinger', $result);
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCheckPasswordWrongPassword() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
|
|
|
|
|
$this->prepareAccessForCheckPassword($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-02-20 13:05:45 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->checkPassword('roland', 'wrong');
|
|
|
|
|
$this->assertFalse($result);
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCheckPasswordWrongUser() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
|
|
|
|
|
$this->prepareAccessForCheckPassword($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-02-20 13:05:45 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->checkPassword('mallory', 'evil');
|
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 14:58:23 +00:00
|
|
|
|
public function testCheckPasswordNoDisplayName() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForCheckPassword($access, true);
|
2017-11-03 16:40:05 +00:00
|
|
|
|
|
|
|
|
|
$this->prepareAccessForCheckPassword($access);
|
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn(null);
|
2014-10-27 14:58:23 +00:00
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-10-27 14:58:23 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
|
|
|
|
|
|
$result = $backend->checkPassword('roland', 'dt19');
|
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
public function testCheckPasswordPublicAPI() {
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user = $this->createMock(User::class);
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getUsername')
|
|
|
|
|
->willReturn('gunslinger');
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$access = $this->getAccessMock();
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->prepareAccessForCheckPassword($access);
|
2017-11-07 12:19:08 +00:00
|
|
|
|
$access->userManager->expects($this->any())
|
2017-11-03 16:40:05 +00:00
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
2017-11-07 12:19:08 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-25 20:14:02 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2018-01-16 12:27:45 +00:00
|
|
|
|
$user = \OC::$server->getUserManager()->checkPassword('roland', 'dt19');
|
|
|
|
|
$result = false;
|
|
|
|
|
if ($user !== false) {
|
|
|
|
|
$result = $user->getUID();
|
|
|
|
|
}
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertEquals('gunslinger', $result);
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCheckPasswordPublicAPIWrongPassword() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForCheckPassword($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-02-20 13:05:45 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
|
2018-01-16 12:27:45 +00:00
|
|
|
|
$user = \OC::$server->getUserManager()->checkPassword('roland', 'wrong');
|
|
|
|
|
$result = false;
|
|
|
|
|
if ($user !== false) {
|
|
|
|
|
$result = $user->getUID();
|
|
|
|
|
}
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertFalse($result);
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCheckPasswordPublicAPIWrongUser() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForCheckPassword($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-02-20 13:05:45 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
|
2018-01-16 12:27:45 +00:00
|
|
|
|
$user = \OC::$server->getUserManager()->checkPassword('mallory', 'evil');
|
|
|
|
|
$result = false;
|
|
|
|
|
if ($user !== false) {
|
|
|
|
|
$result = $user->getUID();
|
|
|
|
|
}
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 15:59:13 +00:00
|
|
|
|
public function testDeleteUserCancel() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-08-21 15:59:13 +00:00
|
|
|
|
$result = $backend->deleteUser('notme');
|
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDeleteUserSuccess() {
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$uid = 'jeremy';
|
|
|
|
|
$home = '/var/vhome/jdings/';
|
|
|
|
|
|
2014-08-21 15:59:13 +00:00
|
|
|
|
$access = $this->getAccessMock();
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$mapping = $this->createMock(UserMapping::class);
|
2014-12-20 15:09:04 +00:00
|
|
|
|
$mapping->expects($this->once())
|
|
|
|
|
->method('unmap')
|
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
$access->expects($this->once())
|
|
|
|
|
->method('getUserMapper')
|
|
|
|
|
->will($this->returnValue($mapping));
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('getConnectionResource')
|
|
|
|
|
->willReturn('this is an ldap link');
|
2014-12-20 15:09:04 +00:00
|
|
|
|
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$this->configMock->expects($this->any())
|
2015-01-06 22:28:49 +00:00
|
|
|
|
->method('getUserValue')
|
2017-07-13 12:32:52 +00:00
|
|
|
|
->with($uid, 'user_ldap', 'isDeleted')
|
|
|
|
|
->willReturn('1');
|
2014-08-21 15:59:13 +00:00
|
|
|
|
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$this->offlineUser->expects($this->once())
|
|
|
|
|
->method('getHomePath')
|
|
|
|
|
->willReturn($home);
|
2017-09-15 14:01:54 +00:00
|
|
|
|
$this->offlineUser->expects($this->once())
|
|
|
|
|
->method('getOCName')
|
|
|
|
|
->willReturn($uid);
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($this->offlineUser);
|
2014-08-21 15:59:13 +00:00
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->configMock, $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2017-09-15 14:01:54 +00:00
|
|
|
|
|
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
|
$user->expects($this->once())
|
|
|
|
|
->method('getUID')
|
|
|
|
|
->willReturn($uid);
|
2015-06-17 12:13:01 +00:00
|
|
|
|
|
2017-09-15 14:01:54 +00:00
|
|
|
|
$backend->preDeleteUser($user);
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$result = $backend->deleteUser($uid);
|
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
$this->assertSame($backend->getHome($uid), $home);
|
2014-08-21 15:59:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
public function testDeleteUserWithPlugin() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['canDeleteUser','deleteUser'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('canDeleteUser')
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('deleteUser')
|
|
|
|
|
->with('uid')
|
|
|
|
|
->willReturn('result');
|
|
|
|
|
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($ldap->deleteUser('uid'),'result');
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
/**
|
2014-05-19 15:50:53 +00:00
|
|
|
|
* Prepares the Access mock for getUsers tests
|
2016-10-06 20:52:45 +00:00
|
|
|
|
* @param Access $access mock
|
2013-09-25 20:14:02 +00:00
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private function prepareAccessForGetUsers(&$access) {
|
2014-02-20 13:05:45 +00:00
|
|
|
|
$access->expects($this->once())
|
|
|
|
|
->method('escapeFilterPart')
|
|
|
|
|
->will($this->returnCallback(function($search) {
|
|
|
|
|
return $search;
|
|
|
|
|
}));
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('getFilterPartForUserSearch')
|
|
|
|
|
->will($this->returnCallback(function($search) {
|
|
|
|
|
return $search;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('combineFilterWithAnd')
|
|
|
|
|
->will($this->returnCallback(function($param) {
|
2015-11-27 22:46:26 +00:00
|
|
|
|
return $param[2];
|
2013-09-11 16:51:45 +00:00
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('fetchListOfUsers')
|
|
|
|
|
->will($this->returnCallback(function($search, $a, $l, $o) {
|
|
|
|
|
$users = array('gunslinger', 'newyorker', 'ladyofshadows');
|
|
|
|
|
if(empty($search)) {
|
|
|
|
|
$result = $users;
|
|
|
|
|
} else {
|
|
|
|
|
$result = array();
|
|
|
|
|
foreach($users as $user) {
|
|
|
|
|
if(stripos($user, $search) !== false) {
|
|
|
|
|
$result[] = $user;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!is_null($l) || !is_null($o)) {
|
|
|
|
|
$result = array_slice($result, $o, $l);
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
2017-04-12 04:21:04 +00:00
|
|
|
|
->method('nextcloudUserNames')
|
2013-09-11 16:51:45 +00:00
|
|
|
|
->will($this->returnArgument(0));
|
2017-08-09 14:43:40 +00:00
|
|
|
|
|
|
|
|
|
$access->method('fetchUsersByLoginName')
|
|
|
|
|
->willReturn([]);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 13:05:45 +00:00
|
|
|
|
public function testGetUsersNoParam() {
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->getUsers();
|
|
|
|
|
$this->assertEquals(3, count($result));
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUsersLimitOffset() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->getUsers('', 1, 2);
|
|
|
|
|
$this->assertEquals(1, count($result));
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUsersLimitOffset2() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->getUsers('', 2, 1);
|
|
|
|
|
$this->assertEquals(2, count($result));
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUsersSearchWithResult() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->getUsers('yo');
|
|
|
|
|
$this->assertEquals(2, count($result));
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUsersSearchEmptyResult() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->getUsers('nix');
|
|
|
|
|
$this->assertEquals(0, count($result));
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-25 18:33:24 +00:00
|
|
|
|
private function getUsers($search = '', $limit = null, $offset = null) {
|
|
|
|
|
$users = \OC::$server->getUserManager()->search($search, $limit, $offset);
|
|
|
|
|
$uids = [];
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
$uids[] = $user->getUID();
|
|
|
|
|
}
|
|
|
|
|
return $uids;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 13:05:45 +00:00
|
|
|
|
public function testGetUsersViaAPINoParam() {
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-25 20:14:02 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
|
|
2018-03-25 18:33:24 +00:00
|
|
|
|
$result = $this->getUsers();
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertEquals(3, count($result));
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUsersViaAPILimitOffset() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-02-20 13:05:45 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
|
2018-03-25 18:33:24 +00:00
|
|
|
|
$result = $this->getUsers('', 1, 2);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertEquals(1, count($result));
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUsersViaAPILimitOffset2() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-02-20 13:05:45 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
|
2018-03-25 18:33:24 +00:00
|
|
|
|
$result = $this->getUsers('', 2, 1);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertEquals(2, count($result));
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUsersViaAPISearchWithResult() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-02-20 13:05:45 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
|
2018-03-25 18:33:24 +00:00
|
|
|
|
$result = $this->getUsers('yo');
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertEquals(2, count($result));
|
2014-02-20 13:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUsersViaAPISearchEmptyResult() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetUsers($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-02-20 13:05:45 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
|
2018-03-25 18:33:24 +00:00
|
|
|
|
$result = $this->getUsers('nix');
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertEquals(0, count($result));
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
public function testUserExists() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user = $this->createMock(User::class);
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getDN')
|
|
|
|
|
->willReturn('dnOfRoland,dc=test');
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$access->expects($this->any())
|
2015-03-31 13:33:44 +00:00
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn) {
|
|
|
|
|
if($dn === 'dnOfRoland,dc=test') {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}));
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('getUserMapper')
|
|
|
|
|
->willReturn($this->createMock(UserMapping::class));
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
//test for existing user
|
|
|
|
|
$result = $backend->userExists('gunslinger');
|
|
|
|
|
$this->assertTrue($result);
|
2015-03-31 13:33:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @expectedException \Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUserExistsForDeleted() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn) {
|
|
|
|
|
if($dn === 'dnOfRoland,dc=test') {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}));
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->userManager = $this->createMock(Manager::class);
|
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($this->createMock(User::class));
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
//test for deleted user
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$backend->userExists('formerUser');
|
2015-03-31 13:33:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUserExistsForNeverExisting() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn) {
|
|
|
|
|
if($dn === 'dnOfRoland,dc=test') {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}));
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
//test for never-existing user
|
|
|
|
|
$result = $backend->userExists('mallory');
|
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
public function testUserExistsPublicAPI() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user = $this->createMock(User::class);
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getDN')
|
|
|
|
|
->willReturn('dnOfRoland,dc=test');
|
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$access->expects($this->any())
|
2015-03-31 13:33:44 +00:00
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn) {
|
|
|
|
|
if($dn === 'dnOfRoland,dc=test') {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}));
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('getUserMapper')
|
|
|
|
|
->willReturn($this->createMock(UserMapping::class));
|
2013-09-25 20:14:02 +00:00
|
|
|
|
|
|
|
|
|
//test for existing user
|
2018-01-16 12:27:45 +00:00
|
|
|
|
$result = \OC::$server->getUserManager()->userExists('gunslinger');
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertTrue($result);
|
2015-03-31 13:33:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @expectedException \Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUserExistsPublicAPIForDeleted() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn) {
|
|
|
|
|
if($dn === 'dnOfRoland,dc=test') {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}));
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->userManager = $this->createMock(Manager::class);
|
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($this->createMock(User::class));
|
2013-09-25 20:14:02 +00:00
|
|
|
|
|
|
|
|
|
//test for deleted user
|
2018-01-16 12:27:45 +00:00
|
|
|
|
\OC::$server->getUserManager()->userExists('formerUser');
|
2015-03-31 13:33:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUserExistsPublicAPIForNeverExisting() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn) {
|
|
|
|
|
if($dn === 'dnOfRoland,dc=test') {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}));
|
2013-09-25 20:14:02 +00:00
|
|
|
|
|
|
|
|
|
//test for never-existing user
|
2018-01-16 12:27:45 +00:00
|
|
|
|
$result = \OC::$server->getUserManager()->userExists('mallory');
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 12:32:52 +00:00
|
|
|
|
public function testDeleteUserExisting() {
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2017-07-13 12:32:52 +00:00
|
|
|
|
//we do not support deleting existing users at all
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$result = $backend->deleteUser('gunslinger');
|
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-31 13:33:44 +00:00
|
|
|
|
public function testGetHomeAbsolutePath() {
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$access = $this->getAccessMock();
|
2016-09-02 09:02:12 +00:00
|
|
|
|
$config = $this->createMock(IConfig::class);
|
2017-03-31 07:16:22 +00:00
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $config, $noti, $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
|
|
|
|
|
$access->connection->expects($this->any())
|
2015-03-31 13:33:44 +00:00
|
|
|
|
->method('__get')
|
|
|
|
|
->will($this->returnCallback(function($name) {
|
|
|
|
|
if($name === 'homeFolderNamingRule') {
|
|
|
|
|
return 'attr:testAttribute';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}));
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
2015-03-31 13:33:44 +00:00
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn, $attr) {
|
|
|
|
|
switch ($dn) {
|
|
|
|
|
case 'dnOfRoland,dc=test':
|
|
|
|
|
if($attr === 'testAttribute') {
|
|
|
|
|
return array('/tmp/rolandshome/');
|
|
|
|
|
}
|
|
|
|
|
return array();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}));
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user = $this->createMock(User::class);
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getUsername')
|
|
|
|
|
->willReturn('gunslinger');
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getDN')
|
|
|
|
|
->willReturn('dnOfRoland,dc=test');
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getHomePath')
|
|
|
|
|
->willReturn('/tmp/rolandshome/');
|
|
|
|
|
|
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
|
|
//absolute path
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$result = $backend->getHome('gunslinger');
|
|
|
|
|
$this->assertEquals('/tmp/rolandshome/', $result);
|
2015-03-31 13:33:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 12:03:30 +00:00
|
|
|
|
public function testGetHomeRelative() {
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$access = $this->getAccessMock();
|
2016-09-02 09:02:12 +00:00
|
|
|
|
$config = $this->createMock(IConfig::class);
|
2017-03-31 07:16:22 +00:00
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $config, $noti, $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
|
2015-08-20 22:55:42 +00:00
|
|
|
|
$dataDir = \OC::$server->getConfig()->getSystemValue(
|
|
|
|
|
'datadirectory', \OC::$SERVERROOT.'/data');
|
|
|
|
|
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('__get')
|
|
|
|
|
->will($this->returnCallback(function($name) {
|
|
|
|
|
if($name === 'homeFolderNamingRule') {
|
|
|
|
|
return 'attr:testAttribute';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}));
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn, $attr) {
|
|
|
|
|
switch ($dn) {
|
|
|
|
|
case 'dnOfLadyOfShadows,dc=test':
|
|
|
|
|
if($attr === 'testAttribute') {
|
|
|
|
|
return array('susannah/');
|
|
|
|
|
}
|
|
|
|
|
return array();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}));
|
2015-04-09 12:03:30 +00:00
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user = $this->createMock(User::class);
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getUsername')
|
|
|
|
|
->willReturn('ladyofshadows');
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getDN')
|
|
|
|
|
->willReturn('dnOfLadyOfShadows,dc=test');
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getHomePath')
|
|
|
|
|
->willReturn($dataDir.'/susannah/');
|
|
|
|
|
|
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$result = $backend->getHome('ladyofshadows');
|
2015-08-20 22:55:42 +00:00
|
|
|
|
$this->assertEquals($dataDir.'/susannah/', $result);
|
2015-03-31 13:33:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @expectedException \Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetHomeNoPath() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
|
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('__get')
|
|
|
|
|
->will($this->returnCallback(function($name) {
|
|
|
|
|
if($name === 'homeFolderNamingRule') {
|
|
|
|
|
return 'attr:testAttribute';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn, $attr) {
|
|
|
|
|
switch ($dn) {
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}));
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user = $this->createMock(User::class);
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getUsername')
|
|
|
|
|
->willReturn('newyorker');
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getHomePath')
|
|
|
|
|
->willThrowException(new \Exception());
|
|
|
|
|
|
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
//no path at all – triggers OC default behaviour
|
|
|
|
|
$result = $backend->getHome('newyorker');
|
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-11 16:25:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* @expectedException \OC\User\NoUserException
|
|
|
|
|
*/
|
|
|
|
|
public function testGetHomeDeletedUser() {
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$uid = 'newyorker';
|
|
|
|
|
|
2015-12-11 16:25:57 +00:00
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->configMock, $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2015-12-11 16:25:57 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
|
|
|
|
|
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('__get')
|
|
|
|
|
->will($this->returnCallback(function($name) {
|
|
|
|
|
if($name === 'homeFolderNamingRule') {
|
|
|
|
|
return 'attr:testAttribute';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnValue([]));
|
|
|
|
|
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$userMapper = $this->createMock(UserMapping::class);
|
2015-12-11 16:25:57 +00:00
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('getUserMapper')
|
|
|
|
|
->will($this->returnValue($userMapper));
|
|
|
|
|
|
|
|
|
|
$this->configMock->expects($this->any())
|
|
|
|
|
->method('getUserValue')
|
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$this->offlineUser->expects($this->never())
|
|
|
|
|
->method('getHomePath');
|
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($this->offlineUser);
|
|
|
|
|
|
2017-07-13 12:32:52 +00:00
|
|
|
|
$backend->getHome($uid);
|
2015-12-11 16:25:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
public function testGetHomeWithPlugin() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['implementsActions','getHome'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('implementsActions')
|
|
|
|
|
->with(Backend::GET_HOME)
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('getHome')
|
|
|
|
|
->with('uid')
|
|
|
|
|
->willReturn('result');
|
|
|
|
|
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('getFromCache')
|
|
|
|
|
->will($this->returnCallback(function($uid) {
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($ldap->getHome('uid'),'result');
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
private function prepareAccessForGetDisplayName(&$access) {
|
2013-09-11 16:51:45 +00:00
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('__get')
|
|
|
|
|
->will($this->returnCallback(function($name) {
|
|
|
|
|
if($name === 'ldapUserDisplayName') {
|
|
|
|
|
return 'displayname';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('readAttribute')
|
|
|
|
|
->will($this->returnCallback(function($dn, $attr) {
|
|
|
|
|
switch ($dn) {
|
2014-04-01 10:28:23 +00:00
|
|
|
|
case 'dnOfRoland,dc=test':
|
2013-09-11 16:51:45 +00:00
|
|
|
|
if($attr === 'displayname') {
|
|
|
|
|
return array('Roland Deschain');
|
|
|
|
|
}
|
|
|
|
|
return array();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}));
|
2015-12-11 11:52:12 +00:00
|
|
|
|
|
2017-08-09 14:43:40 +00:00
|
|
|
|
$access->method('fetchUsersByLoginName')
|
|
|
|
|
->willReturn([]);
|
2013-09-25 20:14:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetDisplayName() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$this->prepareAccessForGetDisplayName($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
2013-09-11 16:51:45 +00:00
|
|
|
|
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('getConnectionResource')
|
|
|
|
|
->will($this->returnCallback(function() {
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user1 = $this->createMock(User::class);
|
|
|
|
|
$user1->expects($this->once())
|
|
|
|
|
->method('composeAndStoreDisplayName')
|
|
|
|
|
->willReturn('Roland Deschain');
|
|
|
|
|
$user1->expects($this->any())
|
|
|
|
|
->method('getDN')
|
|
|
|
|
->willReturn('dnOfRoland,dc=test');
|
|
|
|
|
|
|
|
|
|
$user2 = $this->createMock(User::class);
|
|
|
|
|
$user2->expects($this->never())
|
|
|
|
|
->method('composeAndStoreDisplayName');
|
|
|
|
|
$user2->expects($this->any())
|
|
|
|
|
->method('getDN')
|
|
|
|
|
->willReturn('another DN');
|
|
|
|
|
|
|
|
|
|
$mapper = $this->createMock(UserMapping::class);
|
|
|
|
|
$mapper->expects($this->any())
|
|
|
|
|
->method('getUUIDByDN')
|
|
|
|
|
->willReturnCallback(function($dn) { return $dn; });
|
|
|
|
|
|
|
|
|
|
$access->userManager->expects($this->any())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturnCallback(function($uid) use ($user1, $user2) {
|
|
|
|
|
if($uid === 'gunslinger') {
|
|
|
|
|
return $user1;
|
|
|
|
|
} else if($uid === 'newyorker') {
|
|
|
|
|
return $user2;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('getUserMapper')
|
|
|
|
|
->willReturn($mapper);
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('getUserDnByUuid')
|
|
|
|
|
->willReturnCallback(function($uuid) { return $uuid . '1'; });
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
//with displayName
|
|
|
|
|
$result = $backend->getDisplayName('gunslinger');
|
|
|
|
|
$this->assertEquals('Roland Deschain', $result);
|
|
|
|
|
|
|
|
|
|
//empty displayname retrieved
|
|
|
|
|
$result = $backend->getDisplayName('newyorker');
|
|
|
|
|
$this->assertEquals(null, $result);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
public function testGetDisplayNamePublicAPI() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2015-03-31 13:33:44 +00:00
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('username2dn')
|
|
|
|
|
->will($this->returnCallback(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;
|
|
|
|
|
}
|
|
|
|
|
}));
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->prepareAccessForGetDisplayName($access);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2013-09-25 20:14:02 +00:00
|
|
|
|
$this->prepareMockForUserExists($access);
|
2015-03-31 13:33:44 +00:00
|
|
|
|
|
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('getConnectionResource')
|
|
|
|
|
->will($this->returnCallback(function() {
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user1 = $this->createMock(User::class);
|
|
|
|
|
$user1->expects($this->once())
|
|
|
|
|
->method('composeAndStoreDisplayName')
|
|
|
|
|
->willReturn('Roland Deschain');
|
|
|
|
|
$user1->expects($this->any())
|
|
|
|
|
->method('getDN')
|
|
|
|
|
->willReturn('dnOfRoland,dc=test');
|
|
|
|
|
|
|
|
|
|
$user2 = $this->createMock(User::class);
|
|
|
|
|
$user2->expects($this->never())
|
|
|
|
|
->method('composeAndStoreDisplayName');
|
|
|
|
|
$user2->expects($this->any())
|
|
|
|
|
->method('getDN')
|
|
|
|
|
->willReturn('another DN');
|
|
|
|
|
|
|
|
|
|
$mapper = $this->createMock(UserMapping::class);
|
|
|
|
|
$mapper->expects($this->any())
|
|
|
|
|
->method('getUUIDByDN')
|
|
|
|
|
->willReturnCallback(function($dn) { return $dn; });
|
|
|
|
|
|
|
|
|
|
$access->userManager->expects($this->any())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturnCallback(function($uid) use ($user1, $user2) {
|
|
|
|
|
if($uid === 'gunslinger') {
|
|
|
|
|
return $user1;
|
|
|
|
|
} else if($uid === 'newyorker') {
|
|
|
|
|
return $user2;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('getUserMapper')
|
|
|
|
|
->willReturn($mapper);
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('getUserDnByUuid')
|
|
|
|
|
->willReturnCallback(function($uuid) { return $uuid . '1'; });
|
|
|
|
|
|
2013-09-25 20:14:02 +00:00
|
|
|
|
//with displayName
|
|
|
|
|
$result = \OCP\User::getDisplayName('gunslinger');
|
|
|
|
|
$this->assertEquals('Roland Deschain', $result);
|
|
|
|
|
|
|
|
|
|
//empty displayname retrieved
|
|
|
|
|
$result = \OCP\User::getDisplayName('newyorker');
|
|
|
|
|
$this->assertEquals('newyorker', $result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
public function testGetDisplayNameWithPlugin() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['implementsActions','getDisplayName'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('implementsActions')
|
|
|
|
|
->with(Backend::GET_DISPLAYNAME)
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('getDisplayName')
|
|
|
|
|
->with('uid')
|
|
|
|
|
->willReturn('result');
|
|
|
|
|
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($ldap->getDisplayName('uid'),'result');
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 16:51:45 +00:00
|
|
|
|
//no test for getDisplayNames, because it just invokes getUsers and
|
|
|
|
|
//getDisplayName
|
2014-01-08 11:24:29 +00:00
|
|
|
|
|
|
|
|
|
public function testCountUsers() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
|
|
|
|
|
$access->expects($this->once())
|
|
|
|
|
->method('countUsers')
|
2014-10-27 22:39:30 +00:00
|
|
|
|
->will($this->returnValue(5));
|
2014-01-08 11:24:29 +00:00
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-01-08 11:24:29 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->countUsers();
|
|
|
|
|
$this->assertEquals(5, $result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCountUsersFailing() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
|
|
|
|
|
$access->expects($this->once())
|
|
|
|
|
->method('countUsers')
|
2014-10-27 22:39:30 +00:00
|
|
|
|
->will($this->returnValue(false));
|
2014-01-08 11:24:29 +00:00
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2014-01-08 11:24:29 +00:00
|
|
|
|
|
|
|
|
|
$result = $backend->countUsers();
|
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
}
|
2016-10-06 23:39:57 +00:00
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
public function testCountUsersWithPlugin() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['implementsActions','countUsers'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('implementsActions')
|
|
|
|
|
->with(Backend::COUNT_USERS)
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('countUsers')
|
|
|
|
|
->willReturn(42);
|
|
|
|
|
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($ldap->countUsers(),42);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 23:39:57 +00:00
|
|
|
|
public function testLoginName2UserNameSuccess() {
|
|
|
|
|
$loginName = 'Alice';
|
|
|
|
|
$username = 'alice';
|
|
|
|
|
$dn = 'uid=alice,dc=what,dc=ever';
|
|
|
|
|
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$access->expects($this->once())
|
|
|
|
|
->method('fetchUsersByLoginName')
|
|
|
|
|
->with($this->equalTo($loginName))
|
|
|
|
|
->willReturn([['dn' => [$dn]]]);
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->expects($this->any())
|
2016-10-06 23:39:57 +00:00
|
|
|
|
->method('stringResemblesDN')
|
|
|
|
|
->with($this->equalTo($dn))
|
|
|
|
|
->willReturn(true);
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->expects($this->any())
|
2016-10-06 23:39:57 +00:00
|
|
|
|
->method('dn2username')
|
|
|
|
|
->with($this->equalTo($dn))
|
|
|
|
|
->willReturn($username);
|
|
|
|
|
|
|
|
|
|
$access->connection->expects($this->exactly(2))
|
|
|
|
|
->method('getFromCache')
|
|
|
|
|
->with($this->equalTo('loginName2UserName-'.$loginName))
|
|
|
|
|
->willReturnOnConsecutiveCalls(null, $username);
|
|
|
|
|
$access->connection->expects($this->once())
|
|
|
|
|
->method('writeToCache')
|
|
|
|
|
->with($this->equalTo('loginName2UserName-'.$loginName), $this->equalTo($username));
|
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2017-11-07 12:19:08 +00:00
|
|
|
|
$user = $this->createMock(User::class);
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getUsername')
|
|
|
|
|
->willReturn('alice');
|
|
|
|
|
|
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->with($dn)
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
2016-10-06 23:39:57 +00:00
|
|
|
|
$name = $backend->loginName2UserName($loginName);
|
|
|
|
|
$this->assertSame($username, $name);
|
|
|
|
|
|
|
|
|
|
// and once again to verify that caching works
|
|
|
|
|
$backend->loginName2UserName($loginName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testLoginName2UserNameNoUsersOnLDAP() {
|
|
|
|
|
$loginName = 'Loki';
|
|
|
|
|
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$access->expects($this->once())
|
|
|
|
|
->method('fetchUsersByLoginName')
|
|
|
|
|
->with($this->equalTo($loginName))
|
|
|
|
|
->willReturn([]);
|
|
|
|
|
$access->expects($this->never())
|
|
|
|
|
->method('stringResemblesDN');
|
|
|
|
|
$access->expects($this->never())
|
|
|
|
|
->method('dn2username');
|
|
|
|
|
|
|
|
|
|
$access->connection->expects($this->exactly(2))
|
|
|
|
|
->method('getFromCache')
|
|
|
|
|
->with($this->equalTo('loginName2UserName-'.$loginName))
|
|
|
|
|
->willReturnOnConsecutiveCalls(null, false);
|
|
|
|
|
$access->connection->expects($this->once())
|
|
|
|
|
->method('writeToCache')
|
|
|
|
|
->with($this->equalTo('loginName2UserName-'.$loginName), false);
|
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2016-10-06 23:39:57 +00:00
|
|
|
|
$name = $backend->loginName2UserName($loginName);
|
|
|
|
|
$this->assertSame(false, $name);
|
|
|
|
|
|
|
|
|
|
// and once again to verify that caching works
|
|
|
|
|
$backend->loginName2UserName($loginName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testLoginName2UserNameOfflineUser() {
|
|
|
|
|
$loginName = 'Alice';
|
|
|
|
|
$dn = 'uid=alice,dc=what,dc=ever';
|
|
|
|
|
|
|
|
|
|
$offlineUser = $this->getMockBuilder(OfflineUser::class)
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
$access->expects($this->once())
|
|
|
|
|
->method('fetchUsersByLoginName')
|
|
|
|
|
->with($this->equalTo($loginName))
|
|
|
|
|
->willReturn([['dn' => [$dn]]]);
|
|
|
|
|
|
|
|
|
|
$access->connection->expects($this->exactly(2))
|
|
|
|
|
->method('getFromCache')
|
|
|
|
|
->with($this->equalTo('loginName2UserName-'.$loginName))
|
|
|
|
|
->willReturnOnConsecutiveCalls(null, false);
|
|
|
|
|
$access->connection->expects($this->once())
|
|
|
|
|
->method('writeToCache')
|
|
|
|
|
->with($this->equalTo('loginName2UserName-'.$loginName), $this->equalTo(false));
|
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->userManager->expects($this->any())
|
|
|
|
|
->method('get')
|
|
|
|
|
->with($dn)
|
|
|
|
|
->willReturn($offlineUser);
|
2016-10-06 23:39:57 +00:00
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2016-10-06 23:39:57 +00:00
|
|
|
|
$name = $backend->loginName2UserName($loginName);
|
|
|
|
|
$this->assertSame(false, $name);
|
|
|
|
|
|
|
|
|
|
// and once again to verify that caching works
|
|
|
|
|
$backend->loginName2UserName($loginName);
|
|
|
|
|
}
|
2016-08-30 09:43:29 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepares the Access mock for setPassword tests
|
|
|
|
|
* @param \OCA\User_LDAP\Access|\PHPUnit_Framework_MockObject_MockObject $access mock
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private function prepareAccessForSetPassword(&$access, $enablePasswordChange = true) {
|
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('__get')
|
|
|
|
|
->will($this->returnCallback(function($name) use (&$enablePasswordChange) {
|
|
|
|
|
if($name === 'ldapLoginFilter') {
|
|
|
|
|
return '%uid';
|
|
|
|
|
}
|
|
|
|
|
if($name === 'turnOnPasswordChange') {
|
|
|
|
|
return $enablePasswordChange?1:0;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}));
|
2017-11-02 12:40:38 +00:00
|
|
|
|
|
2016-08-30 09:43:29 +00:00
|
|
|
|
$access->connection->expects($this->any())
|
|
|
|
|
->method('getFromCache')
|
|
|
|
|
->will($this->returnCallback(function($uid) {
|
|
|
|
|
if($uid === 'userExists'.'roland') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('fetchListOfUsers')
|
|
|
|
|
->will($this->returnCallback(function($filter) {
|
|
|
|
|
if($filter === 'roland') {
|
|
|
|
|
return array(array('dn' => ['dnOfRoland,dc=test']));
|
|
|
|
|
}
|
|
|
|
|
return array();
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('fetchUsersByLoginName')
|
|
|
|
|
->will($this->returnCallback(function($uid) {
|
|
|
|
|
if($uid === 'roland') {
|
|
|
|
|
return array(array('dn' => ['dnOfRoland,dc=test']));
|
|
|
|
|
}
|
|
|
|
|
return array();
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('dn2username')
|
|
|
|
|
->with($this->equalTo('dnOfRoland,dc=test'))
|
|
|
|
|
->will($this->returnValue('roland'));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('stringResemblesDN')
|
|
|
|
|
->with($this->equalTo('dnOfRoland,dc=test'))
|
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
|
|
$access->expects($this->any())
|
|
|
|
|
->method('setPassword')
|
|
|
|
|
->will($this->returnCallback(function($uid, $password) {
|
|
|
|
|
if(strlen($password) <= 5) {
|
|
|
|
|
throw new HintException('Password fails quality checking policy', '', 19);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @expectedException \OC\HintException
|
|
|
|
|
* @expectedExceptionMessage Password fails quality checking policy
|
|
|
|
|
*/
|
|
|
|
|
public function testSetPasswordInvalid() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2016-10-06 23:39:57 +00:00
|
|
|
|
|
2016-08-30 09:43:29 +00:00
|
|
|
|
$this->prepareAccessForSetPassword($access);
|
2018-01-03 20:44:30 +00:00
|
|
|
|
$access->userManager->expects($this->atLeastOnce())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($this->createMock(User::class));
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2016-08-30 09:43:29 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(\OC_User::setPassword('roland', 'dt'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetPasswordValid() {
|
|
|
|
|
$access = $this->getAccessMock();
|
|
|
|
|
|
|
|
|
|
$this->prepareAccessForSetPassword($access);
|
2017-11-07 12:19:08 +00:00
|
|
|
|
|
|
|
|
|
$access->userManager->expects($this->any())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($this->createMock(User::class));
|
|
|
|
|
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->userManager->expects($this->any())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($this->createMock(User::class));
|
|
|
|
|
|
2016-08-30 09:43:29 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(\OC_User::setPassword('roland', 'dt12234$'));
|
|
|
|
|
}
|
2017-03-31 07:16:22 +00:00
|
|
|
|
|
2016-08-30 09:43:29 +00:00
|
|
|
|
public function testSetPasswordValidDisabled() {
|
|
|
|
|
$access = $this->getAccessMock();
|
2017-11-03 16:40:05 +00:00
|
|
|
|
$access->userManager->expects($this->any())
|
|
|
|
|
->method('get')
|
|
|
|
|
->willReturn($this->createMock(User::class));
|
2016-08-30 09:43:29 +00:00
|
|
|
|
|
|
|
|
|
$this->prepareAccessForSetPassword($access, false);
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
|
2016-08-30 09:43:29 +00:00
|
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
|
|
|
|
|
|
$this->assertFalse(\OC_User::setPassword('roland', 'dt12234$'));
|
|
|
|
|
}
|
2016-11-23 18:58:43 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @expectedException \Exception
|
|
|
|
|
* @expectedExceptionMessage LDAP setPassword: Could not get user object for uid NotExistingUser. Maybe the LDAP entry has no set display name attribute?
|
|
|
|
|
*/
|
|
|
|
|
public function testSetPasswordWithInvalidUser() {
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$access->userManager = $this->createMock(IUserManager::class);
|
|
|
|
|
$access->userManager
|
|
|
|
|
->expects($this->once())
|
|
|
|
|
->method('get')
|
|
|
|
|
->with('NotExistingUser')
|
|
|
|
|
->willReturn(null);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
2017-03-31 07:16:22 +00:00
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
2017-09-15 14:01:54 +00:00
|
|
|
|
$userSession = $this->createMock(Session::class);
|
2016-11-23 18:58:43 +00:00
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
2017-03-31 07:16:22 +00:00
|
|
|
|
$config,
|
2017-09-15 14:01:54 +00:00
|
|
|
|
$noti,
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$userSession,
|
|
|
|
|
$this->getDefaultPluginManagerMock()
|
2016-11-23 18:58:43 +00:00
|
|
|
|
);
|
|
|
|
|
$ldap->setPassword('NotExistingUser', 'Password');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetPasswordWithUsernameFalse() {
|
|
|
|
|
$user = $this->createMock(User::class);
|
|
|
|
|
$user
|
|
|
|
|
->expects($this->once())
|
|
|
|
|
->method('getUsername')
|
|
|
|
|
->willReturn(false);
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$access->userManager = $this->createMock(IUserManager::class);
|
|
|
|
|
$access->userManager
|
|
|
|
|
->expects($this->once())
|
|
|
|
|
->method('get')
|
|
|
|
|
->with('NotExistingUser')
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
2017-03-31 07:16:22 +00:00
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
2017-09-15 14:01:54 +00:00
|
|
|
|
$userSession = $this->createMock(Session::class);
|
2016-11-23 18:58:43 +00:00
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
2017-03-31 07:16:22 +00:00
|
|
|
|
$config,
|
2017-09-15 14:01:54 +00:00
|
|
|
|
$noti,
|
2017-11-02 12:40:38 +00:00
|
|
|
|
$userSession,
|
|
|
|
|
$this->getDefaultPluginManagerMock()
|
2016-11-23 18:58:43 +00:00
|
|
|
|
);
|
|
|
|
|
$this->assertFalse($ldap->setPassword('NotExistingUser', 'Password'));
|
|
|
|
|
}
|
2017-11-02 12:40:38 +00:00
|
|
|
|
|
|
|
|
|
public function testSetPasswordWithPlugin() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['implementsActions','setPassword'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('implementsActions')
|
|
|
|
|
->with(Backend::SET_PASSWORD)
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('setPassword')
|
|
|
|
|
->with('uid','password')
|
|
|
|
|
->willReturn('result');
|
|
|
|
|
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($ldap->setPassword('uid', 'password'),'result');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCanChangeAvatarWithPlugin() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['implementsActions','canChangeAvatar'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('implementsActions')
|
|
|
|
|
->with(Backend::PROVIDE_AVATAR)
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('canChangeAvatar')
|
|
|
|
|
->with('uid')
|
|
|
|
|
->willReturn('result');
|
|
|
|
|
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($ldap->canChangeAvatar('uid'),'result');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetDisplayNameWithPlugin() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['implementsActions','setDisplayName'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('implementsActions')
|
|
|
|
|
->with(Backend::SET_DISPLAYNAME)
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('setDisplayName')
|
|
|
|
|
->with('uid','displayName')
|
|
|
|
|
->willReturn('result');
|
|
|
|
|
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($ldap->setDisplayName('uid', 'displayName'),'result');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetDisplayNameFailing() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['implementsActions','setDisplayName'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('implementsActions')
|
|
|
|
|
->with(Backend::SET_DISPLAYNAME)
|
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertFalse($ldap->setDisplayName('uid', 'displayName'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateUserWithPlugin() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['implementsActions','createUser'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('implementsActions')
|
|
|
|
|
->with(Backend::CREATE_USER)
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('createUser')
|
|
|
|
|
->with('uid','password')
|
|
|
|
|
->willReturn('result');
|
|
|
|
|
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($ldap->createUser('uid', 'password'),'result');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateUserFailing() {
|
|
|
|
|
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\UserPluginManager')
|
|
|
|
|
->setMethods(['implementsActions', 'createUser'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$pluginManager->expects($this->once())
|
|
|
|
|
->method('implementsActions')
|
|
|
|
|
->with(Backend::CREATE_USER)
|
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
|
|
$access = $this->createMock(Access::class);
|
|
|
|
|
$config = $this->createMock(IConfig::class);
|
|
|
|
|
$noti = $this->createMock(INotificationManager::class);
|
|
|
|
|
$session = $this->createMock(Session::class);
|
|
|
|
|
|
|
|
|
|
$ldap = new User_LDAP(
|
|
|
|
|
$access,
|
|
|
|
|
$config,
|
|
|
|
|
$noti,
|
|
|
|
|
$session,
|
|
|
|
|
$pluginManager
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertFalse($ldap->createUser('uid', 'password'));
|
|
|
|
|
}
|
2014-05-13 11:29:25 +00:00
|
|
|
|
}
|