aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2018-08-14 14:14:22 +0200
committerGitHub <noreply@github.com>2018-08-14 14:14:22 +0200
commitd05c815796152f0d76c459e893f154b3b78005aa (patch)
treea756ff4423b24f8fdcfaa3f90a0138734c6865ca /apps/user_ldap
parentff50ef4b2192800ca7542929e408e67eceae1cef (diff)
parent24ef41454c59ebd17b2fceb336c2a690a854377b (diff)
downloadnextcloud-server-d05c815796152f0d76c459e893f154b3b78005aa.tar.gz
nextcloud-server-d05c815796152f0d76c459e893f154b3b78005aa.zip
Merge pull request #8855 from nextcloud/feature/noid/ldap-integration-autotests
behat integration tests for LDAP
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/Access.php10
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestAccessGroupsMatchFilter.php127
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestBackupServer.php124
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestBatchApplyUserAttributes.php81
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestConnect.php172
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php37
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php186
7 files changed, 6 insertions, 731 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 91089e779a0..a03b4a4cb9c 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -609,23 +609,23 @@ class Access extends LDAPUtility implements IUserTools {
//NOTE: mind, disabling cache affects only this instance! Using it
// outside of core user management will still cache the user as non-existing.
$originalTTL = $this->connection->ldapCacheTTL;
- $this->connection->setConfiguration(array('ldapCacheTTL' => 0));
+ $this->connection->setConfiguration(['ldapCacheTTL' => 0]);
if(($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName))
|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
if($mapper->map($fdn, $intName, $uuid)) {
- $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
- if($this->ncUserManager instanceof PublicEmitter) {
+ $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
+ if($this->ncUserManager instanceof PublicEmitter && $isUser) {
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]);
}
$newlyMapped = true;
return $intName;
}
}
- $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
+ $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
- if($this->ncUserManager instanceof PublicEmitter) {
+ if($this->ncUserManager instanceof PublicEmitter && $isUser) {
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]);
}
$newlyMapped = true;
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAccessGroupsMatchFilter.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAccessGroupsMatchFilter.php
deleted file mode 100644
index 87c2e408424..00000000000
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAccessGroupsMatchFilter.php
+++ /dev/null
@@ -1,127 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @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/>
- *
- */
-
-namespace OCA\User_LDAP\Tests\Integration\Lib;
-
-use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
-
-require_once __DIR__ . '/../Bootstrap.php';
-
-class IntegrationTestAccessGroupsMatchFilter extends AbstractIntegrationTest {
-
- /**
- * prepares the LDAP environment and sets up a test configuration for
- * the LDAP backend.
- */
- public function init() {
- require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
- require(__DIR__ . '/../setup-scripts/createExplicitGroups.php');
- require(__DIR__ . '/../setup-scripts/createExplicitGroupsDifferentOU.php');
- parent::init();
- }
-
- /**
- * tests whether the group filter works with one specific group, while the
- * input is the same.
- *
- * @return bool
- */
- protected function case1() {
- $this->connection->setConfiguration(['ldapGroupFilter' => 'cn=RedGroup']);
-
- $dns = ['cn=RedGroup,ou=Groups,' . $this->base];
- $result = $this->access->groupsMatchFilter($dns);
- return ($dns === $result);
- }
-
- /**
- * Tests whether a filter for limited groups is effective when more existing
- * groups were passed for validation.
- *
- * @return bool
- */
- protected function case2() {
- $this->connection->setConfiguration(['ldapGroupFilter' => '(|(cn=RedGroup)(cn=PurpleGroup))']);
-
- $dns = [
- 'cn=RedGroup,ou=Groups,' . $this->base,
- 'cn=BlueGroup,ou=Groups,' . $this->base,
- 'cn=PurpleGroup,ou=Groups,' . $this->base
- ];
- $result = $this->access->groupsMatchFilter($dns);
-
- $status =
- count($result) === 2
- && in_array('cn=RedGroup,ou=Groups,' . $this->base, $result)
- && in_array('cn=PurpleGroup,ou=Groups,' . $this->base, $result);
-
- return $status;
- }
-
- /**
- * Tests whether a filter for limited groups is effective when more existing
- * groups were passed for validation.
- *
- * @return bool
- */
- protected function case3() {
- $this->connection->setConfiguration(['ldapGroupFilter' => '(objectclass=groupOfNames)']);
-
- $dns = [
- 'cn=RedGroup,ou=Groups,' . $this->base,
- 'cn=PurpleGroup,ou=Groups,' . $this->base,
- 'cn=SquaredCircleGroup,ou=SpecialGroups,' . $this->base
- ];
- $result = $this->access->groupsMatchFilter($dns);
-
- $status =
- count($result) === 2
- && in_array('cn=RedGroup,ou=Groups,' . $this->base, $result)
- && in_array('cn=PurpleGroup,ou=Groups,' . $this->base, $result);
-
- return $status;
- }
-
- /**
- * sets up the LDAP configuration to be used for the test
- */
- protected function initConnection() {
- parent::initConnection();
- $this->connection->setConfiguration([
- 'ldapBaseGroups' => 'ou=Groups,' . $this->base,
- 'ldapUserFilter' => 'objectclass=inetOrgPerson',
- 'ldapUserDisplayName' => 'displayName',
- 'ldapGroupDisplayName' => 'cn',
- 'ldapLoginFilter' => 'uid=%uid',
- ]);
- }
-}
-
-/** @var string $host */
-/** @var int $port */
-/** @var string $adn */
-/** @var string $apwd */
-/** @var string $bdn */
-$test = new IntegrationTestAccessGroupsMatchFilter($host, $port, $adn, $apwd, $bdn);
-$test->init();
-$test->run();
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestBackupServer.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestBackupServer.php
deleted file mode 100644
index 0eef5507538..00000000000
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestBackupServer.php
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @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/>
- *
- */
-
-namespace OCA\User_LDAP\Tests\Integration\Lib;
-
-use OC\ServerNotAvailableException;
-use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
-use OCA\User_LDAP\Mapping\UserMapping;
-use OCA\User_LDAP\User_LDAP;
-
-require_once __DIR__ . '/../Bootstrap.php';
-
-class IntegrationTestBackupServer extends AbstractIntegrationTest {
- /** @var UserMapping */
- protected $mapping;
-
- /** @var User_LDAP */
- protected $backend;
-
- /**
- * sets up the LDAP configuration to be used for the test
- */
- protected function initConnection() {
- parent::initConnection();
- $originalHost = $this->connection->ldapHost;
- $originalPort = $this->connection->ldapPort;
- $this->connection->setConfiguration([
- 'ldapHost' => 'qwertz.uiop',
- 'ldapPort' => '32123',
- 'ldap_backup_host' => $originalHost,
- 'ldap_backup_port' => $originalPort,
- ]);
- }
-
- /**
- * tests that a backup connection is being used when the main LDAP server
- * is offline
- *
- * Beware: after starting docker, the LDAP host might not be ready yet, thus
- * causing a false positive. Retry in that case… or increase the sleep time
- * in run-test.sh
- *
- * @return bool
- */
- protected function case1() {
- try {
- $this->connection->getConnectionResource();
- } catch (ServerNotAvailableException $e) {
- return false;
- }
- return true;
- }
-
- /**
- * ensures that an exception is thrown if LDAP main server and LDAP backup
- * server are not available
- *
- * @return bool
- */
- protected function case2() {
- // reset possible LDAP connection
- $this->initConnection();
- try {
- $this->connection->setConfiguration([
- 'ldap_backup_host' => 'qwertz.uiop',
- 'ldap_backup_port' => '32123',
- ]);
- $this->connection->getConnectionResource();
- } catch (ServerNotAvailableException $e) {
- return true;
- }
- return false;
- }
-
- /**
- * ensures that an exception is thrown if main LDAP server is down and a
- * backup server is not given
- *
- * @return bool
- */
- protected function case3() {
- // reset possible LDAP connection
- $this->initConnection();
- try {
- $this->connection->setConfiguration([
- 'ldap_backup_host' => '',
- 'ldap_backup_port' => '',
- ]);
- $this->connection->getConnectionResource();
- } catch (ServerNotAvailableException $e) {
- return true;
- }
- return false;
- }
-}
-
-/** @var string $host */
-/** @var int $port */
-/** @var string $adn */
-/** @var string $apwd */
-/** @var string $bdn */
-$test = new IntegrationTestBackupServer($host, $port, $adn, $apwd, $bdn);
-$test->init();
-$test->run();
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestBatchApplyUserAttributes.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestBatchApplyUserAttributes.php
deleted file mode 100644
index 24476c9a868..00000000000
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestBatchApplyUserAttributes.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @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/>
- *
- */
-
-namespace OCA\User_LDAP\Tests\Integration\Lib;
-
-use OCA\User_LDAP\Mapping\UserMapping;
-use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
-
-require_once __DIR__ . '/../Bootstrap.php';
-
-class IntegrationTestBatchApplyUserAttributes extends AbstractIntegrationTest {
- /** @var UserMapping */
- protected $mapping;
-
- /**
- * prepares the LDAP environment and sets up a test configuration for
- * the LDAP backend.
- */
- public function init() {
- require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
- require(__DIR__ . '/../setup-scripts/createUsersWithoutDisplayName.php');
- parent::init();
-
- $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
- $this->mapping->clear();
- $this->access->setUserMapper($this->mapping);
- }
-
- /**
- * sets up the LDAP configuration to be used for the test
- */
- protected function initConnection() {
- parent::initConnection();
- $this->connection->setConfiguration([
- 'ldapUserDisplayName' => 'displayname',
- ]);
- }
-
- /**
- * indirectly tests whether batchApplyUserAttributes does it job properly,
- * when a user without display name is included in the result set from LDAP.
- *
- * @return bool
- */
- protected function case1() {
- $result = $this->access->fetchListOfUsers('objectclass=person', 'dn');
- // on the original issue, PHP would emit a fatal error
- // – cannot catch it here, but will render the test as unsuccessful
- return is_array($result) && !empty($result);
- }
-
-}
-
-/** @var string $host */
-/** @var int $port */
-/** @var string $adn */
-/** @var string $apwd */
-/** @var string $bdn */
-$test = new IntegrationTestBatchApplyUserAttributes($host, $port, $adn, $apwd, $bdn);
-$test->init();
-$test->run();
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestConnect.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestConnect.php
deleted file mode 100644
index f4fc0f189b4..00000000000
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestConnect.php
+++ /dev/null
@@ -1,172 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @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/>
- *
- */
-
-namespace OCA\User_LDAP\Tests\Integration\Lib;
-
-use OC\ServerNotAvailableException;
-use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
-use OCA\User_LDAP\Mapping\UserMapping;
-use OCA\User_LDAP\User_LDAP;
-
-require_once __DIR__ . '/../Bootstrap.php';
-
-class IntegrationTestConnect extends AbstractIntegrationTest {
- /** @var UserMapping */
- protected $mapping;
-
- /** @var User_LDAP */
- protected $backend;
-
- /** @var string */
- protected $host;
-
- /** @var int */
- protected $port;
-
- public function __construct($host, $port, $bind, $pwd, $base) {
- // make sure host is a simple host name
- if(strpos($host, '://') !== false) {
- $host = substr_replace($host, '', 0, strpos($host, '://') + 3);
- }
- if(strpos($host, ':') !== false) {
- $host = substr_replace($host, '', strpos($host, ':'));
- }
- $this->host = $host;
- $this->port = $port;
- parent::__construct($host, $port, $bind, $pwd, $base);
- }
-
- /**
- * test that a faulty host will does not connect successfully
- *
- * @return bool
- */
- protected function case1() {
- // reset possible LDAP connection
- $this->initConnection();
- $this->connection->setConfiguration([
- 'ldapHost' => 'qwertz.uiop',
- ]);
- try {
- $this->connection->getConnectionResource();
- } catch (ServerNotAvailableException $e) {
- return true;
- }
- return false;
- }
-
- /**
- * tests that a connect succeeds when only a hostname is provided
- *
- * @return bool
- */
- protected function case2() {
- // reset possible LDAP connection
- $this->initConnection();
- $this->connection->setConfiguration([
- 'ldapHost' => $this->host,
- ]);
- try {
- $this->connection->getConnectionResource();
- } catch (ServerNotAvailableException $e) {
- return false;
- }
- return true;
- }
-
- /**
- * tests that a connect succeeds when an LDAP URL is provided
- *
- * @return bool
- */
- protected function case3() {
- // reset possible LDAP connection
- $this->initConnection();
- $this->connection->setConfiguration([
- 'ldapHost' => 'ldap://' . $this->host,
- ]);
- try {
- $this->connection->getConnectionResource();
- } catch (ServerNotAvailableException $e) {
- return false;
- }
- return true;
- }
-
- /**
- * tests that a connect succeeds when an LDAP URL with port is provided
- *
- * @return bool
- */
- protected function case4() {
- // reset possible LDAP connection
- $this->initConnection();
- $this->connection->setConfiguration([
- 'ldapHost' => 'ldap://' . $this->host . ':' . $this->port,
- ]);
- try {
- $this->connection->getConnectionResource();
- } catch (ServerNotAvailableException $e) {
- return false;
- }
- return true;
- }
-
- /**
- * tests that a connect succeeds when a hostname with port is provided
- *
- * @return bool
- */
- protected function case5() {
- // reset possible LDAP connection
- $this->initConnection();
- $this->connection->setConfiguration([
- 'ldapHost' => $this->host . ':' . $this->port,
- ]);
- try {
- $this->connection->getConnectionResource();
- } catch (ServerNotAvailableException $e) {
- return false;
- }
- return true;
- }
-
- /**
- * repeat case1, only to make sure that not a connection was reused by
- * accident.
- *
- * @return bool
- */
- protected function case6() {
- return $this->case1();
- }
-}
-
-/** @var string $host */
-/** @var int $port */
-/** @var string $adn */
-/** @var string $apwd */
-/** @var string $bdn */
-$test = new IntegrationTestConnect($host, $port, $adn, $apwd, $bdn);
-$test->init();
-$test->run();
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
index d54d001c4ad..fcb2e59b4a9 100644
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
@@ -59,29 +59,11 @@ class IntegrationTestPaging extends AbstractIntegrationTest {
}
/**
- * tests that paging works properly against a simple example (reading all
- * of few users in small steps)
- *
- * @return bool
- */
- protected function case1() {
- $filter = 'objectclass=inetorgperson';
- $attributes = ['cn', 'dn'];
-
- $result = $this->access->searchUsers($filter, $attributes);
- if(count($result) === 7) {
- return true;
- }
-
- return false;
- }
-
- /**
* fetch first three, afterwards all users
*
* @return bool
*/
- protected function case2() {
+ protected function case1() {
$filter = 'objectclass=inetorgperson';
$attributes = ['cn', 'dn'];
@@ -102,23 +84,6 @@ class IntegrationTestPaging extends AbstractIntegrationTest {
return true;
}
-
- /**
- * reads all remaining users starting first page
- *
- * @return bool
- */
- protected function case3() {
- $filter = 'objectclass=inetorgperson';
- $attributes = ['cn', 'dn'];
-
- $result = $this->access->searchUsers($filter, $attributes, null, $this->pagingSize);
- if(count($result) === (7 - $this->pagingSize)) {
- return true;
- }
-
- return false;
- }
}
/** @var string $host */
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php
deleted file mode 100644
index 9ee5a7efac2..00000000000
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php
+++ /dev/null
@@ -1,186 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Vinicius Cubas Brand <vinicius@eita.org.br>
- *
- * @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/>
- *
- */
-
-namespace OCA\User_LDAP\Tests\Integration\Lib;
-
-use OCA\User_LDAP\FilesystemHelper;
-use OCA\User_LDAP\LogWrapper;
-use OCA\User_LDAP\User\Manager as LDAPUserManager;
-use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
-use OCA\User_LDAP\Mapping\UserMapping;
-use OCA\User_LDAP\User_LDAP;
-use OCP\Image;
-
-require_once __DIR__ . '/../Bootstrap.php';
-
-class IntegrationTestUserHome extends AbstractIntegrationTest {
- /** @var UserMapping */
- protected $mapping;
-
- /** @var User_LDAP */
- 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);
- $this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
- }
-
- /**
- * 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(),
- new FilesystemHelper(),
- new LogWrapper(),
- \OC::$server->getAvatarManager(),
- new Image(),
- \OC::$server->getDatabaseConnection(),
- \OC::$server->getUserManager(),
- \OC::$server->getNotificationManager()
- );
- }
-
- /**
- * homeDirectory on LDAP is empty. Return values of getHome should be
- * identical to user name, following Nextcloud default.
- *
- * @return bool
- */
- protected function case1() {
- \OC::$server->getConfig()->setAppValue('user_ldap', 'enforce_home_folder_naming_rule', false);
- $userManager = \OC::$server->getUserManager();
- $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);
- $userManager = \OC::$server->getUserManager();
- // 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.
- * Return values of getHome should be Nextcloud default.
- *
- * @return bool
- */
- protected function case3() {
- \OC::$server->getConfig()->setAppValue('user_ldap', 'enforce_home_folder_naming_rule', true);
- $this->connection->setConfiguration([
- 'homeFolderNamingRule' => 'attr:',
- ]);
- $userManager = \OC::$server->getUserManager();
- $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;
- }
-}
-
-/** @var string $host */
-/** @var int $port */
-/** @var string $adn */
-/** @var string $apwd */
-/** @var string $bdn */
-$test = new IntegrationTestUserHome($host, $port, $adn, $apwd, $bdn);
-$test->init();
-$test->run();