$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'wrong');
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('mallory', 'evil');
->method('username2dn')
->will($this->returnValue(false));
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
public function testCheckPasswordPublicAPI() {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('roland', 'dt19');
public function testCheckPasswordPublicAPIWrongPassword() {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('roland', 'wrong');
public function testCheckPasswordPublicAPIWrongUser() {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('mallory', 'evil');
public function testDeleteUserCancel() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$result = $backend->deleteUser('notme');
$this->assertFalse($result);
}
->method('getUserMapper')
->will($this->returnValue($mapping));
- $backend = new UserLDAP($access);
+ $config = $this->getMock('\OCP\IConfig');
+ $config->expects($this->exactly(2))
+ ->method('getUserValue')
+ ->will($this->returnValue(1));
- $pref = \OC::$server->getConfig();
- $pref->setUserValue('jeremy', 'user_ldap', 'isDeleted', 1);
+ $backend = new UserLDAP($access, $config);
$result = $backend->deleteUser('jeremy');
$this->assertTrue($result);
public function testGetUsersNoParam() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$result = $backend->getUsers();
$this->assertEquals(3, count($result));
public function testGetUsersLimitOffset() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$result = $backend->getUsers('', 1, 2);
$this->assertEquals(1, count($result));
public function testGetUsersLimitOffset2() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$result = $backend->getUsers('', 2, 1);
$this->assertEquals(2, count($result));
public function testGetUsersSearchWithResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$result = $backend->getUsers('yo');
$this->assertEquals(2, count($result));
public function testGetUsersSearchEmptyResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$result = $backend->getUsers('nix');
$this->assertEquals(0, count($result));
public function testGetUsersViaAPINoParam() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers();
public function testGetUsersViaAPILimitOffset() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('', 1, 2);
public function testGetUsersViaAPILimitOffset2() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('', 2, 1);
public function testGetUsersViaAPISearchWithResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('yo');
public function testGetUsersViaAPISearchEmptyResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('nix');
public function testUserExists() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$this->prepareMockForUserExists($access);
$access->expects($this->any())
public function testUserExistsPublicAPI() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);
public function testDeleteUser() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
//we do not support deleting users at all
$result = $backend->deleteUser('gunslinger');
public function testGetHome() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access);
+ $config = $this->getMock('\OCP\IConfig');
+ $backend = new UserLDAP($access, $config);
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
}
}));
+ $datadir = '/my/data/dir';
+ $config->expects($this->once())
+ ->method('getSystemValue')
+ ->will($this->returnValue($datadir));
+
//absolut path
$result = $backend->getHome('gunslinger');
$this->assertEquals('/tmp/rolandshome/', $result);
//datadir-relativ path
$result = $backend->getHome('ladyofshadows');
- $datadir = \OCP\Config::getSystemValue('datadirectory',
- \OC::$SERVERROOT.'/data');
$this->assertEquals($datadir.'/susannah/', $result);
//no path at all – triggers OC default behaviour
public function testGetDisplayName() {
$access = $this->getAccessMock();
$this->prepareAccessForGetDisplayName($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$this->prepareMockForUserExists($access);
//with displayName
public function testGetDisplayNamePublicAPI() {
$access = $this->getAccessMock();
$this->prepareAccessForGetDisplayName($access);
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);
->method('countUsers')
->will($this->returnValue(5));
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$result = $backend->countUsers();
$this->assertEquals(5, $result);
->method('countUsers')
->will($this->returnValue(false));
- $backend = new UserLDAP($access);
+ $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$result = $backend->countUsers();
$this->assertFalse($result);
namespace OCA\user_ldap;
use OCA\user_ldap\lib\BackendUtility;
+use OCA\user_ldap\lib\Access;
use OCA\user_ldap\lib\user\OfflineUser;
use OCA\User_LDAP\lib\User\User;
+use OCP\IConfig;
class USER_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserInterface {
+ /** @var string[] $homesToKill */
+ protected $homesToKill = array();
+
+ /** @var \OCP\IConfig */
+ protected $ocConfig;
+
/**
- * @var string[] $homesToKill
+ * @param \OCA\user_ldap\lib\Access $access
+ * @param \OCP\IConfig $ocConfig
*/
- protected $homesToKill = array();
+ public function __construct(Access $access, IConfig $ocConfig) {
+ parent::__construct($access);
+ $this->ocConfig = $ocConfig;
+ }
/**
* checks whether the user is allowed to change his avatar in ownCloud
* @return bool
*/
public function deleteUser($uid) {
- $pref = \OC::$server->getConfig();
- $marked = $pref->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
+ $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
if(intval($marked) === 0) {
\OC::$server->getLogger()->notice(
'User '.$uid . ' is not marked as deleted, not cleaning up.',
//Get Home Directory out of user preferences so we can return it later,
//necessary for removing directories as done by OC_User.
- $home = $pref->getUserValue($uid, 'user_ldap', 'homePath', '');
+ $home = $this->ocConfig->getUserValue($uid, 'user_ldap', 'homePath', '');
$this->homesToKill[$uid] = $home;
$this->access->getUserMapper()->unmap($uid);
if($this->access->connection->isCached($cacheKey)) {
return $this->access->connection->getFromCache($cacheKey);
}
- $pref = \OC::$server->getConfig();
if(strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0) {
$attr = substr($this->access->connection->homeFolderNamingRule, strlen('attr:'));
$homedir = $this->access->readAttribute(
) {
$homedir = $path;
} else {
- $homedir = \OC::$server->getConfig()->getSystemValue('datadirectory',
+ $homedir = $this->ocConfig->getSystemValue('datadirectory',
\OC::$SERVERROOT.'/data' ) . '/' . $homedir[0];
}
$this->access->connection->writeToCache($cacheKey, $homedir);
//we need it to store it in the DB as well in case a user gets
//deleted so we can clean up afterwards
- $pref->setUserValue($uid, 'user_ldap', 'homePath', $homedir);
+ $this->ocConfig->setUserValue(
+ $uid, 'user_ldap', 'homePath', $homedir
+ );
//TODO: if home directory changes, the old one needs to be removed.
return $homedir;
}
//false will apply default behaviour as defined and done by OC_User
$this->access->connection->writeToCache($cacheKey, false);
- $pref->setUserValue($uid, 'user_ldap', 'homePath', '');
+ $this->ocConfig->setUserValue($uid, 'user_ldap', 'homePath', '');
return false;
}