2015-07-07 00:07:33 +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 Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
* @author root <root@localhost.localdomain>
|
|
|
|
* @author Vinicius Cubas Brand <vinicius@eita.org.br>
|
2015-07-07 00:07:33 +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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-07-07 00:07:33 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-12 18:14:59 +03:00
|
|
|
namespace OCA\User_LDAP\Tests\Integration;
|
2015-07-07 00:07:33 +03:00
|
|
|
|
2016-05-12 17:42:57 +03:00
|
|
|
use OCA\User_LDAP\Access;
|
2016-05-12 17:35:33 +03:00
|
|
|
use OCA\User_LDAP\Connection;
|
2017-02-17 04:04:42 +03:00
|
|
|
use OCA\User_LDAP\FilesystemHelper;
|
2016-07-22 11:46:29 +03:00
|
|
|
use OCA\User_LDAP\Helper;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\User_LDAP\LDAP;
|
2017-02-17 04:04:42 +03:00
|
|
|
use OCA\User_LDAP\LogWrapper;
|
2016-05-12 12:25:50 +03:00
|
|
|
use OCA\User_LDAP\User\Manager;
|
2015-07-07 00:07:33 +03:00
|
|
|
|
|
|
|
abstract class AbstractIntegrationTest {
|
|
|
|
/** @var LDAP */
|
|
|
|
protected $ldap;
|
|
|
|
|
|
|
|
/** @var Connection */
|
|
|
|
protected $connection;
|
|
|
|
|
|
|
|
/** @var Access */
|
|
|
|
protected $access;
|
|
|
|
|
2015-07-08 03:16:01 +03:00
|
|
|
/** @var Manager */
|
|
|
|
protected $userManager;
|
2016-07-22 11:46:29 +03:00
|
|
|
|
|
|
|
/** @var Helper */
|
|
|
|
protected $helper;
|
2015-07-08 03:16:01 +03:00
|
|
|
|
2015-07-07 00:07:33 +03:00
|
|
|
/** @var string */
|
|
|
|
protected $base;
|
|
|
|
|
|
|
|
/** @var string[] */
|
|
|
|
protected $server;
|
|
|
|
|
|
|
|
public function __construct($host, $port, $bind, $pwd, $base) {
|
|
|
|
$this->base = $base;
|
|
|
|
$this->server = [
|
|
|
|
'host' => $host,
|
|
|
|
'port' => $port,
|
|
|
|
'dn' => $bind,
|
|
|
|
'pwd' => $pwd
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* prepares the LDAP environment and sets up a test configuration for
|
|
|
|
* the LDAP backend.
|
|
|
|
*/
|
|
|
|
public function init() {
|
2020-04-09 14:53:40 +03:00
|
|
|
\OC::$server->registerService('LDAPUserPluginManager', function () {
|
2017-11-03 01:19:03 +03:00
|
|
|
return new \OCA\User_LDAP\UserPluginManager();
|
|
|
|
});
|
2020-04-09 14:53:40 +03:00
|
|
|
\OC::$server->registerService('LDAPGroupPluginManager', function () {
|
2017-11-03 01:19:03 +03:00
|
|
|
return new \OCA\User_LDAP\GroupPluginManager();
|
|
|
|
});
|
|
|
|
|
2015-07-07 00:07:33 +03:00
|
|
|
$this->initLDAPWrapper();
|
|
|
|
$this->initConnection();
|
2015-07-08 03:16:01 +03:00
|
|
|
$this->initUserManager();
|
2016-07-22 11:46:29 +03:00
|
|
|
$this->initHelper();
|
2015-07-07 00:07:33 +03:00
|
|
|
$this->initAccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* initializes the test LDAP wrapper
|
|
|
|
*/
|
|
|
|
protected function initLDAPWrapper() {
|
|
|
|
$this->ldap = new LDAP();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sets up the LDAP configuration to be used for the test
|
|
|
|
*/
|
|
|
|
protected function initConnection() {
|
|
|
|
$this->connection = new Connection($this->ldap, '', null);
|
|
|
|
$this->connection->setConfiguration([
|
|
|
|
'ldapHost' => $this->server['host'],
|
|
|
|
'ldapPort' => $this->server['port'],
|
|
|
|
'ldapBase' => $this->base,
|
|
|
|
'ldapAgentName' => $this->server['dn'],
|
|
|
|
'ldapAgentPassword' => $this->server['pwd'],
|
|
|
|
'ldapUserFilter' => 'objectclass=inetOrgPerson',
|
|
|
|
'ldapUserDisplayName' => 'cn',
|
|
|
|
'ldapGroupDisplayName' => 'cn',
|
|
|
|
'ldapLoginFilter' => '(|(uid=%uid)(samaccountname=%uid))',
|
|
|
|
'ldapCacheTTL' => 0,
|
|
|
|
'ldapConfigurationActive' => 1,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-07-08 03:16:01 +03:00
|
|
|
/**
|
|
|
|
* initializes an LDAP user manager instance
|
|
|
|
*/
|
|
|
|
protected function initUserManager() {
|
2017-02-17 04:04:42 +03:00
|
|
|
$this->userManager = new Manager(
|
|
|
|
\OC::$server->getConfig(),
|
|
|
|
new FilesystemHelper(),
|
|
|
|
new LogWrapper(),
|
|
|
|
\OC::$server->getAvatarManager(),
|
|
|
|
new \OCP\Image(),
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
2017-05-26 12:25:54 +03:00
|
|
|
\OC::$server->getUserManager(),
|
|
|
|
\OC::$server->getNotificationManager()
|
2017-02-17 04:04:42 +03:00
|
|
|
);
|
2015-07-08 03:16:01 +03:00
|
|
|
}
|
2016-07-22 11:46:29 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* initializes the test Helper
|
|
|
|
*/
|
|
|
|
protected function initHelper() {
|
2016-10-10 11:18:18 +03:00
|
|
|
$this->helper = new Helper(\OC::$server->getConfig());
|
2016-07-22 11:46:29 +03:00
|
|
|
}
|
2015-07-08 03:16:01 +03:00
|
|
|
|
2015-07-07 00:07:33 +03:00
|
|
|
/**
|
|
|
|
* initializes the Access test instance
|
|
|
|
*/
|
|
|
|
protected function initAccess() {
|
2017-11-08 03:51:14 +03:00
|
|
|
$this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server->getConfig());
|
2015-07-07 00:07:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* runs the test cases while outputting progress and result information
|
|
|
|
*
|
|
|
|
* If a test failed, the script is exited with return code 1.
|
|
|
|
*/
|
|
|
|
public function run() {
|
|
|
|
$methods = get_class_methods($this);
|
|
|
|
$atLeastOneCaseRan = false;
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($methods as $method) {
|
|
|
|
if (strpos($method, 'case') === 0) {
|
2015-07-07 00:07:33 +03:00
|
|
|
print("running $method " . PHP_EOL);
|
2017-09-15 17:01:54 +03:00
|
|
|
try {
|
2020-04-10 15:19:56 +03:00
|
|
|
if (!$this->$method()) {
|
2017-09-15 17:01:54 +03:00
|
|
|
print(PHP_EOL . '>>> !!! Test ' . $method . ' FAILED !!! <<<' . PHP_EOL . PHP_EOL);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
$atLeastOneCaseRan = true;
|
2020-04-10 15:19:56 +03:00
|
|
|
} catch (\Exception $e) {
|
2017-09-15 17:01:54 +03:00
|
|
|
print(PHP_EOL . '>>> !!! Test ' . $method . ' RAISED AN EXCEPTION !!! <<<' . PHP_EOL);
|
|
|
|
print($e->getMessage() . PHP_EOL . PHP_EOL);
|
2015-07-07 00:07:33 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($atLeastOneCaseRan) {
|
2015-07-07 00:07:33 +03:00
|
|
|
print('Tests succeeded' . PHP_EOL);
|
|
|
|
} else {
|
|
|
|
print('No Test was available.' . PHP_EOL);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|