2015-08-06 10:31:07 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Vinicius Cubas Brand <vinicius@eita.org.br>
|
2015-10-05 21:54:56 +03: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-08-06 10:31:07 +03:00
|
|
|
*/
|
|
|
|
|
2016-05-12 18:14:59 +03:00
|
|
|
namespace OCA\User_LDAP\Tests\Integration\Lib;
|
2015-08-06 10:31:07 +03:00
|
|
|
|
2017-05-26 12:30:43 +03:00
|
|
|
use OCA\User_LDAP\FilesystemHelper;
|
|
|
|
use OCA\User_LDAP\LogWrapper;
|
2016-05-12 12:25:50 +03:00
|
|
|
use OCA\User_LDAP\User\Manager as LDAPUserManager;
|
2016-05-12 18:14:59 +03:00
|
|
|
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
|
2015-08-06 10:31:07 +03:00
|
|
|
use OCA\User_LDAP\Mapping\UserMapping;
|
2016-05-12 12:01:29 +03:00
|
|
|
use OCA\User_LDAP\User_LDAP;
|
2017-05-26 12:30:43 +03:00
|
|
|
use OCP\Image;
|
2015-08-06 10:31:07 +03:00
|
|
|
|
2016-07-25 11:58:03 +03:00
|
|
|
require_once __DIR__ . '/../Bootstrap.php';
|
2015-08-06 10:31:07 +03:00
|
|
|
|
|
|
|
class IntegrationTestUserHome extends AbstractIntegrationTest {
|
|
|
|
/** @var UserMapping */
|
|
|
|
protected $mapping;
|
|
|
|
|
2016-05-12 12:01:29 +03:00
|
|
|
/** @var User_LDAP */
|
2015-08-06 10:31:07 +03:00
|
|
|
protected $backend;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* prepares the LDAP environment and sets up a test configuration for
|
|
|
|
* the LDAP backend.
|
|
|
|
*/
|
|
|
|
public function init() {
|
|
|
|
require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
|
|
|
|
parent::init();
|
|
|
|
|
|
|
|
$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
|
|
|
|
$this->mapping->clear();
|
|
|
|
$this->access->setUserMapper($this->mapping);
|
2017-11-02 15:40:38 +03:00
|
|
|
$this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
|
2015-08-06 10:31:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sets up the LDAP configuration to be used for the test
|
|
|
|
*/
|
|
|
|
protected function initConnection() {
|
|
|
|
parent::initConnection();
|
|
|
|
$this->connection->setConfiguration([
|
|
|
|
'homeFolderNamingRule' => 'homeDirectory',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* initializes an LDAP user manager instance
|
|
|
|
* @return LDAPUserManager
|
|
|
|
*/
|
|
|
|
protected function initUserManager() {
|
|
|
|
$this->userManager = new LDAPUserManager(
|
|
|
|
\OC::$server->getConfig(),
|
2017-05-26 12:30:43 +03:00
|
|
|
new FilesystemHelper(),
|
|
|
|
new LogWrapper(),
|
2015-08-06 10:31:07 +03:00
|
|
|
\OC::$server->getAvatarManager(),
|
2017-05-26 12:30:43 +03:00
|
|
|
new Image(),
|
2016-05-12 17:16:06 +03:00
|
|
|
\OC::$server->getDatabaseConnection(),
|
2017-05-26 12:25:54 +03:00
|
|
|
\OC::$server->getUserManager(),
|
|
|
|
\OC::$server->getNotificationManager()
|
2015-08-06 10:31:07 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* homeDirectory on LDAP is empty. Return values of getHome should be
|
2017-04-12 07:16:27 +03:00
|
|
|
* identical to user name, following Nextcloud default.
|
2015-08-06 10:31:07 +03:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function case1() {
|
|
|
|
\OC::$server->getConfig()->setAppValue('user_ldap', 'enforce_home_folder_naming_rule', false);
|
2016-05-12 17:16:06 +03:00
|
|
|
$userManager = \OC::$server->getUserManager();
|
2015-08-06 10:31:07 +03:00
|
|
|
$userManager->clearBackends();
|
|
|
|
$userManager->registerBackend($this->backend);
|
|
|
|
$users = $userManager->search('', 5, 0);
|
|
|
|
|
|
|
|
foreach($users as $user) {
|
|
|
|
$home = $user->getHome();
|
|
|
|
$uid = $user->getUID();
|
|
|
|
$posFound = strpos($home, '/' . $uid);
|
|
|
|
$posExpected = strlen($home) - (strlen($uid) + 1);
|
|
|
|
if($posFound === false || $posFound !== $posExpected) {
|
|
|
|
print('"' . $user->getUID() . '" was not found in "' . $home . '" or does not end with it.' . PHP_EOL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* homeDirectory on LDAP is empty. Having the attributes set is enforced.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function case2() {
|
|
|
|
\OC::$server->getConfig()->setAppValue('user_ldap', 'enforce_home_folder_naming_rule', true);
|
2016-08-17 10:46:54 +03:00
|
|
|
$userManager = \OC::$server->getUserManager();
|
2015-08-06 10:31:07 +03:00
|
|
|
// clearing backends is critical, otherwise the userManager will have
|
|
|
|
// the user objects cached and the value from case1 returned
|
|
|
|
$userManager->clearBackends();
|
|
|
|
$userManager->registerBackend($this->backend);
|
|
|
|
$users = $userManager->search('', 5, 0);
|
|
|
|
|
|
|
|
try {
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$user->getHome();
|
|
|
|
print('User home was retrieved without throwing an Exception!' . PHP_EOL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
if(strpos($e->getMessage(), 'Home dir attribute') === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* homeDirectory on LDAP is set to "attr:" which is effectively empty.
|
2017-04-12 07:16:27 +03:00
|
|
|
* Return values of getHome should be Nextcloud default.
|
2015-08-06 10:31:07 +03:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function case3() {
|
|
|
|
\OC::$server->getConfig()->setAppValue('user_ldap', 'enforce_home_folder_naming_rule', true);
|
|
|
|
$this->connection->setConfiguration([
|
|
|
|
'homeFolderNamingRule' => 'attr:',
|
|
|
|
]);
|
2016-08-17 10:46:54 +03:00
|
|
|
$userManager = \OC::$server->getUserManager();
|
2015-08-06 10:31:07 +03:00
|
|
|
$userManager->clearBackends();
|
|
|
|
$userManager->registerBackend($this->backend);
|
|
|
|
$users = $userManager->search('', 5, 0);
|
|
|
|
|
|
|
|
try {
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$home = $user->getHome();
|
|
|
|
$uid = $user->getUID();
|
|
|
|
$posFound = strpos($home, '/' . $uid);
|
|
|
|
$posExpected = strlen($home) - (strlen($uid) + 1);
|
|
|
|
if ($posFound === false || $posFound !== $posExpected) {
|
|
|
|
print('"' . $user->getUID() . '" was not found in "' . $home . '" or does not end with it.' . PHP_EOL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
print("Unexpected Exception: " . $e->getMessage() . PHP_EOL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 12:30:43 +03:00
|
|
|
/** @var string $host */
|
|
|
|
/** @var int $port */
|
|
|
|
/** @var string $adn */
|
|
|
|
/** @var string $apwd */
|
|
|
|
/** @var string $bdn */
|
2015-08-06 10:31:07 +03:00
|
|
|
$test = new IntegrationTestUserHome($host, $port, $adn, $apwd, $bdn);
|
|
|
|
$test->init();
|
|
|
|
$test->run();
|