summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/Integration/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/tests/Integration/Lib')
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestAccessGroupsMatchFilter.php122
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestBackupServer.php117
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestBatchApplyUserAttributes.php72
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestConnect.php165
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestCountUsersByLoginName.php65
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php78
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php80
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php173
-rw-r--r--apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php152
-rw-r--r--apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php104
10 files changed, 1128 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAccessGroupsMatchFilter.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAccessGroupsMatchFilter.php
new file mode 100644
index 00000000000..d058540bd4c
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAccessGroupsMatchFilter.php
@@ -0,0 +1,122 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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__ . '/../../../../../lib/base.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',
+ ]);
+ }
+}
+
+require_once(__DIR__ . '/../setup-scripts/config.php');
+$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
new file mode 100644
index 00000000000..ccd9b251bfc
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestBackupServer.php
@@ -0,0 +1,117 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\User_LDAP;
+
+require_once __DIR__ . '/../../../../../lib/base.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 (\OC\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 (\OC\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 (\OC\ServerNotAvailableException $e) {
+ return true;
+ }
+ return false;
+ }
+}
+
+require_once(__DIR__ . '/../setup-scripts/config.php');
+$test = new IntegrationBackupServer($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
new file mode 100644
index 00000000000..89afcaa4b90
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestBatchApplyUserAttributes.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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__ . '/../../../../../lib/base.php';
+
+class IntegrationTestBatchApplyUserAttributes 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/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);
+ }
+
+}
+
+require_once(__DIR__ . '/../setup-scripts/config.php');
+$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
new file mode 100644
index 00000000000..3ada556bbea
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestConnect.php
@@ -0,0 +1,165 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\User_LDAP;
+
+require_once __DIR__ . '/../../../../../lib/base.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 (\OC\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 (\OC\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 (\OC\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 (\OC\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 (\OC\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();
+ }
+}
+
+require_once(__DIR__ . '/../setup-scripts/config.php');
+$test = new IntegrationConnect($host, $port, $adn, $apwd, $bdn);
+$test->init();
+$test->run();
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestCountUsersByLoginName.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestCountUsersByLoginName.php
new file mode 100644
index 00000000000..5f4fd6f572f
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestCountUsersByLoginName.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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__ . '/../../../../../lib/base.php';
+
+class IntegrationTestCountUsersByLoginName 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');
+ parent::init();
+ }
+
+ /**
+ * tests countUsersByLoginName where it is expected that the login name does
+ * not match any LDAP user
+ *
+ * @return bool
+ */
+ protected function case1() {
+ $result = $this->access->countUsersByLoginName('nothere');
+ return $result === 0;
+ }
+
+ /**
+ * tests countUsersByLoginName where it is expected that the login name does
+ * match one LDAP user
+ *
+ * @return bool
+ */
+ protected function case2() {
+ $result = $this->access->countUsersByLoginName('alice');
+ return $result === 1;
+ }
+}
+
+require_once(__DIR__ . '/../setup-scripts/config.php');
+$test = new IntegrationTestUserHome($host, $port, $adn, $apwd, $bdn);
+$test->init();
+$test->run();
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php
new file mode 100644
index 00000000000..f2dbd7393f3
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\User_LDAP;
+
+require_once __DIR__ . '/../../../../../lib/base.php';
+
+class IntegrationTestFetchUsersByLoginName 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 \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
+ }
+
+ /**
+ * tests fetchUserByLoginName where it is expected that the login name does
+ * not match any LDAP user
+ *
+ * @return bool
+ */
+ protected function case1() {
+ $result = $this->access->fetchUsersByLoginName('nothere');
+ return $result === [];
+ }
+
+ /**
+ * tests fetchUserByLoginName where it is expected that the login name does
+ * match one LDAP user
+ *
+ * @return bool
+ */
+ protected function case2() {
+ $result = $this->access->fetchUsersByLoginName('alice');
+ return count($result) === 1;
+ }
+
+}
+
+require_once(__DIR__ . '/../setup-scripts/config.php');
+$test = new IntegrationTestUserHome($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
new file mode 100644
index 00000000000..72cc3e459b7
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\User_LDAP;
+
+require_once __DIR__ . '/../../../../../lib/base.php';
+
+class IntegrationTestPaging 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->backend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
+ }
+
+ /**
+ * tests that paging works properly against a simple example (reading all
+ * of few users in smallest steps)
+ *
+ * @return bool
+ */
+ protected function case1() {
+ $limit = 1;
+ $offset = 0;
+
+ $filter = 'objectclass=inetorgperson';
+ $attributes = ['cn', 'dn'];
+ $users = [];
+ do {
+ $result = $this->access->searchUsers($filter, $attributes, $limit, $offset);
+ foreach($result as $user) {
+ $users[] = $user['cn'];
+ }
+ $offset += $limit;
+ } while ($this->access->hasMoreResults());
+
+ if(count($users) === 2) {
+ return true;
+ }
+
+ return false;
+ }
+}
+
+require_once(__DIR__ . '/../setup-scripts/config.php');
+$test = new IntegrationTestPaging($host, $port, $adn, $apwd, $bdn);
+$test->init();
+$test->run();
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php
new file mode 100644
index 00000000000..8538fd2f964
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php
@@ -0,0 +1,173 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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\User\Manager as LDAPUserManager;
+use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\User_LDAP;
+
+require_once __DIR__ . '/../../../../../lib/base.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 \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
+ }
+
+ /**
+ * 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 \OCA\User_LDAP\FilesystemHelper(),
+ new \OCA\User_LDAP\LogWrapper(),
+ \OC::$server->getAvatarManager(),
+ new \OCP\Image(),
+ \OC::$server->getDatabaseConnection(),
+ \OC::$server->getUserManager()
+ );
+ }
+
+ /**
+ * homeDirectory on LDAP is empty. Return values of getHome should be
+ * identical to user name, following ownCloud 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 ownCloud 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;
+ }
+}
+
+require_once(__DIR__ . '/../setup-scripts/config.php');
+$test = new IntegrationTestUserHome($host, $port, $adn, $apwd, $bdn);
+$test->init();
+$test->run();
diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
new file mode 100644
index 00000000000..5f555956ea2
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
@@ -0,0 +1,152 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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\User;
+
+use OCA\User_LDAP\User\User;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
+
+require_once __DIR__ . '/../../../../../../lib/base.php';
+
+class IntegrationTestUserAvatar 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');
+ parent::init();
+ $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
+ $this->mapping->clear();
+ $this->access->setUserMapper($this->mapping);
+ $userBackend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
+ \OC_User::useBackend($userBackend);
+ }
+
+ /**
+ * A method that does the common steps of test cases 1 and 2. The evaluation
+ * is not happening here.
+ *
+ * @param string $dn
+ * @param string $username
+ * @param string $image
+ */
+ private function execFetchTest($dn, $username, $image) {
+ $this->setJpegPhotoAttribute($dn, $image);
+
+ // assigns our self-picked oc username to the dn
+ $this->mapping->map($dn, $username, 'fakeUUID-' . $username);
+
+ // initialize home folder and make sure that the user will update
+ // also remove an possibly existing avatar
+ \OC_Util::tearDownFS();
+ \OC_Util::setupFS($username);
+ \OC::$server->getUserFolder($username);
+ \OC::$server->getConfig()->deleteUserValue($username, 'user_ldap', User::USER_PREFKEY_LASTREFRESH);
+ if(\OC::$server->getAvatarManager()->getAvatar($username)->exists()) {
+ \OC::$server->getAvatarManager()->getAvatar($username)->remove();
+ }
+
+ // finally attempt to get the avatar set
+ $user = $this->userManager->get($dn);
+ $user->updateAvatar();
+ }
+
+ /**
+ * tests whether an avatar can be retrieved from LDAP and stored correctly
+ *
+ * @return bool
+ */
+ protected function case1() {
+ $image = file_get_contents(__DIR__ . '/../../data/avatar-valid.jpg');
+ $dn = 'uid=alice,ou=Users,' . $this->base;
+ $username = 'alice1337';
+
+ $this->execFetchTest($dn, $username, $image);
+
+ return \OC::$server->getAvatarManager()->getAvatar($username)->exists();
+ }
+
+ /**
+ * tests whether an image received from LDAP which is of an invalid file
+ * type is dealt with properly (i.e. not set and not dying).
+ *
+ * @return bool
+ */
+ protected function case2() {
+ // gif by Pmspinner from https://commons.wikimedia.org/wiki/File:Avatar2469_3.gif
+ $image = file_get_contents(__DIR__ . '/../../data/avatar-invalid.gif');
+ $dn = 'uid=boris,ou=Users,' . $this->base;
+ $username = 'boris7844';
+
+ $this->execFetchTest($dn, $username, $image);
+
+ return !\OC::$server->getAvatarManager()->getAvatar($username)->exists();
+ }
+
+ /**
+ * This writes an image to the 'jpegPhoto' attribute on LDAP.
+ *
+ * @param string $dn
+ * @param string $image An image read via file_get_contents
+ * @throws \OC\ServerNotAvailableException
+ */
+ private function setJpegPhotoAttribute($dn, $image) {
+ $changeSet = ['jpegphoto' => $image];
+ ldap_mod_add($this->connection->getConnectionResource(), $dn, $changeSet);
+ }
+
+ protected function initUserManager() {
+ $this->userManager = new \OCA\User_LDAP\User\Manager(
+ \OC::$server->getConfig(),
+ new \OCA\User_LDAP\FilesystemHelper(),
+ new \OCA\User_LDAP\LogWrapper(),
+ \OC::$server->getAvatarManager(),
+ new \OCP\Image(),
+ \OC::$server->getDatabaseConnection(),
+ \OC::$server->getUserManager()
+ );
+ }
+
+ /**
+ * sets up the LDAP configuration to be used for the test
+ */
+ protected function initConnection() {
+ parent::initConnection();
+ $this->connection->setConfiguration([
+ 'ldapUserFilter' => 'objectclass=inetOrgPerson',
+ 'ldapUserDisplayName' => 'displayName',
+ 'ldapGroupDisplayName' => 'cn',
+ 'ldapLoginFilter' => 'uid=%uid',
+ ]);
+ }
+}
+
+require_once(__DIR__ . '/../../setup-scripts/config.php');
+$test = new IntegrationTestUserAvatar($host, $port, $adn, $apwd, $bdn);
+$test->init();
+$test->run();
diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
new file mode 100644
index 00000000000..07ab2e287ca
--- /dev/null
+++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
@@ -0,0 +1,104 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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\User;
+
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
+
+require_once __DIR__ . '/../../../../../../lib/base.php';
+
+class IntegrationTestUserDisplayName 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');
+ parent::init();
+ $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
+ $this->mapping->clear();
+ $this->access->setUserMapper($this->mapping);
+ $userBackend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
+ \OC_User::useBackend($userBackend);
+ }
+
+ /**
+ * adds a map entry for the user, so we know the username
+ *
+ * @param $dn
+ * @param $username
+ */
+ private function prepareUser($dn, $username) {
+ // assigns our self-picked oc username to the dn
+ $this->mapping->map($dn, $username, 'fakeUUID-' . $username);
+ }
+
+ /**
+ * tests whether a display name consisting of two parts is created correctly
+ *
+ * @return bool
+ */
+ protected function case1() {
+ $username = 'alice1337';
+ $dn = 'uid=alice,ou=Users,' . $this->base;
+ $this->prepareUser($dn, $username);
+ $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
+
+ return strpos($displayName, '(Alice@example.com)') !== false;
+ }
+
+ /**
+ * tests whether a display name consisting of one part is created correctly
+ *
+ * @return bool
+ */
+ protected function case2() {
+ $this->connection->setConfiguration([
+ 'ldapUserDisplayName2' => '',
+ ]);
+ $username = 'boris23421';
+ $dn = 'uid=boris,ou=Users,' . $this->base;
+ $this->prepareUser($dn, $username);
+ $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
+
+ return strpos($displayName, '(Boris@example.com)') === false;
+ }
+
+ /**
+ * sets up the LDAP configuration to be used for the test
+ */
+ protected function initConnection() {
+ parent::initConnection();
+ $this->connection->setConfiguration([
+ 'ldapUserDisplayName' => 'displayName',
+ 'ldapUserDisplayName2' => 'mail',
+ ]);
+ }
+}
+
+require_once(__DIR__ . '/../../setup-scripts/config.php');
+$test = new IntegrationTestUserDisplayName($host, $port, $adn, $apwd, $bdn);
+$test->init();
+$test->run();