fix LDAP install for systems without ldap extension (#846)
This commit is contained in:
@@ -26,9 +26,11 @@ before_install:
|
|||||||
# - phpenv config-rm xdebug.ini
|
# - phpenv config-rm xdebug.ini
|
||||||
- composer self-update
|
- composer self-update
|
||||||
- php -i
|
- php -i
|
||||||
|
- php -m
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- composer install
|
- composer install
|
||||||
|
- composer require zendframework/zend-ldap
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- composer kimai:codestyle
|
- composer kimai:codestyle
|
||||||
|
|||||||
@@ -60,8 +60,7 @@
|
|||||||
"symfony/webpack-encore-bundle": "^1.5",
|
"symfony/webpack-encore-bundle": "^1.5",
|
||||||
"symfony/yaml": "^4.0",
|
"symfony/yaml": "^4.0",
|
||||||
"twig/extensions": "^1.5",
|
"twig/extensions": "^1.5",
|
||||||
"white-october/pagerfanta-bundle": "^1.1",
|
"white-october/pagerfanta-bundle": "^1.1"
|
||||||
"zendframework/zend-ldap": "^2.10"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"dama/doctrine-test-bundle": "^5.0",
|
"dama/doctrine-test-bundle": "^5.0",
|
||||||
@@ -100,7 +99,8 @@
|
|||||||
"symfony/polyfill-php56": "*"
|
"symfony/polyfill-php56": "*"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-mbstring": "If ext-mbstring is not available you MUST install symfony/polyfill-mbstring"
|
"ext-mbstring": "If ext-mbstring is not available you MUST install symfony/polyfill-mbstring",
|
||||||
|
"zendframework/zend-ldap": "For LDAP authentication with Kimai"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"auto-scripts": {
|
"auto-scripts": {
|
||||||
|
|||||||
55
composer.lock
generated
55
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "ed199b91b3e5eb0b9d2a1eb00ea11cba",
|
"content-hash": "67746acda4894c88c47e3afffab130e4",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "beberlei/DoctrineExtensions",
|
"name": "beberlei/DoctrineExtensions",
|
||||||
@@ -8618,59 +8618,6 @@
|
|||||||
],
|
],
|
||||||
"time": "2018-04-25T15:33:34+00:00"
|
"time": "2018-04-25T15:33:34+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "zendframework/zend-ldap",
|
|
||||||
"version": "2.10.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/zendframework/zend-ldap.git",
|
|
||||||
"reference": "b63c7884a08d3a6bda60ebcf7d6238cf8ad89f49"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/zendframework/zend-ldap/zipball/b63c7884a08d3a6bda60ebcf7d6238cf8ad89f49",
|
|
||||||
"reference": "b63c7884a08d3a6bda60ebcf7d6238cf8ad89f49",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"ext-ldap": "*",
|
|
||||||
"php": "^5.6 || ^7.0"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"php-mock/php-mock-phpunit": "^1.1.2 || ^2.1.1",
|
|
||||||
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2",
|
|
||||||
"zendframework/zend-coding-standard": "~1.0.0",
|
|
||||||
"zendframework/zend-config": "^2.5",
|
|
||||||
"zendframework/zend-eventmanager": "^2.6.3 || ^3.0.1",
|
|
||||||
"zendframework/zend-stdlib": "^2.7 || ^3.0"
|
|
||||||
},
|
|
||||||
"suggest": {
|
|
||||||
"zendframework/zend-eventmanager": "Zend\\EventManager component"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"extra": {
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-master": "2.10.x-dev",
|
|
||||||
"dev-develop": "2.11.x-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Zend\\Ldap\\": "src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"BSD-3-Clause"
|
|
||||||
],
|
|
||||||
"description": "Provides support for LDAP operations including but not limited to binding, searching and modifying entries in an LDAP directory",
|
|
||||||
"keywords": [
|
|
||||||
"ZendFramework",
|
|
||||||
"ldap",
|
|
||||||
"zf"
|
|
||||||
],
|
|
||||||
"time": "2018-07-05T05:05:12+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "zircote/swagger-php",
|
"name": "zircote/swagger-php",
|
||||||
"version": "2.0.14",
|
"version": "2.0.14",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ security:
|
|||||||
providers:
|
providers:
|
||||||
chain_provider:
|
chain_provider:
|
||||||
chain:
|
chain:
|
||||||
providers: [fos_userbundle, kimai_ldap]
|
providers: [fos_userbundle]
|
||||||
kimai_ldap:
|
kimai_ldap:
|
||||||
id: App\Ldap\LdapUserProvider
|
id: App\Ldap\LdapUserProvider
|
||||||
fos_userbundle:
|
fos_userbundle:
|
||||||
@@ -31,9 +31,6 @@ security:
|
|||||||
lifetime: 604800
|
lifetime: 604800
|
||||||
path: /
|
path: /
|
||||||
|
|
||||||
# activate the LdapAuthenticationProvider
|
|
||||||
kimai_ldap: ~
|
|
||||||
|
|
||||||
# activate all configured user provider
|
# activate all configured user provider
|
||||||
provider: chain_provider
|
provider: chain_provider
|
||||||
|
|
||||||
|
|||||||
@@ -132,9 +132,6 @@ services:
|
|||||||
# LDAP
|
# LDAP
|
||||||
# ================================================================================
|
# ================================================================================
|
||||||
|
|
||||||
Zend\Ldap\Ldap:
|
|
||||||
class: App\Ldap\ZendLdap
|
|
||||||
|
|
||||||
kimai_ldap.security.authentication.provider:
|
kimai_ldap.security.authentication.provider:
|
||||||
class: App\Ldap\LdapAuthenticationProvider
|
class: App\Ldap\LdapAuthenticationProvider
|
||||||
arguments: ['@App\Security\UserChecker', '', '', '', '@App\Configuration\LdapConfiguration', '%security.authentication.hide_user_not_found%']
|
arguments: ['@App\Security\UserChecker', '', '', '', '@App\Configuration\LdapConfiguration', '%security.authentication.hide_user_not_found%']
|
||||||
|
|||||||
@@ -18,3 +18,4 @@ parameters:
|
|||||||
- '#Access to an undefined property Faker\\Generator::\$bs.#'
|
- '#Access to an undefined property Faker\\Generator::\$bs.#'
|
||||||
excludes_analyse:
|
excludes_analyse:
|
||||||
- %rootDir%/../../../src/Command/KimaiImporterCommand.php
|
- %rootDir%/../../../src/Command/KimaiImporterCommand.php
|
||||||
|
- %rootDir%/../../../src/Ldap/LdapDriver.php
|
||||||
|
|||||||
@@ -21,11 +21,6 @@ class LdapConfiguration
|
|||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isActivated(): bool
|
|
||||||
{
|
|
||||||
return (bool) $this->settings['active'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRoleParameters(): array
|
public function getRoleParameters(): array
|
||||||
{
|
{
|
||||||
return (array) $this->settings['role'];
|
return (array) $this->settings['role'];
|
||||||
|
|||||||
@@ -494,7 +494,6 @@ class Configuration implements ConfigurationInterface
|
|||||||
$node
|
$node
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
->children()
|
->children()
|
||||||
->booleanNode('active')->defaultFalse()->end()
|
|
||||||
->arrayNode('connection')
|
->arrayNode('connection')
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
->children()
|
->children()
|
||||||
@@ -591,19 +590,13 @@ class Configuration implements ConfigurationInterface
|
|||||||
->end()
|
->end()
|
||||||
->validate()
|
->validate()
|
||||||
->ifTrue(static function ($v) {
|
->ifTrue(static function ($v) {
|
||||||
return $v['active'] && !extension_loaded('ldap');
|
return null !== $v['connection']['host'] && !extension_loaded('ldap');
|
||||||
})
|
})
|
||||||
->thenInvalid('LDAP is activated, but the LDAP PHP extension is not loaded.')
|
->thenInvalid('LDAP is activated, but the LDAP PHP extension is not loaded.')
|
||||||
->end()
|
->end()
|
||||||
->validate()
|
->validate()
|
||||||
->ifTrue(static function ($v) {
|
->ifTrue(static function ($v) {
|
||||||
return $v['active'] && empty($v['connection']['host']);
|
return null !== $v['connection']['host'] && empty($v['user']['baseDn']);
|
||||||
})
|
|
||||||
->thenInvalid('The "ldap.connection.host" config must be set if LDAP is activated.')
|
|
||||||
->end()
|
|
||||||
->validate()
|
|
||||||
->ifTrue(static function ($v) {
|
|
||||||
return $v['active'] && empty($v['user']['baseDn']);
|
|
||||||
})
|
})
|
||||||
->thenInvalid('The "ldap.user.baseDn" config must be set if LDAP is activated.')
|
->thenInvalid('The "ldap.user.baseDn" config must be set if LDAP is activated.')
|
||||||
->end()
|
->end()
|
||||||
|
|||||||
@@ -113,7 +113,27 @@ class Kernel extends BaseKernel
|
|||||||
$container->setParameter('container.autowiring.strict_mode', true);
|
$container->setParameter('container.autowiring.strict_mode', true);
|
||||||
$container->setParameter('container.dumper.inline_class_loader', true);
|
$container->setParameter('container.dumper.inline_class_loader', true);
|
||||||
$confDir = $this->getProjectDir() . '/config';
|
$confDir = $this->getProjectDir() . '/config';
|
||||||
$loader->load($confDir . '/packages/*' . self::CONFIG_EXTS, 'glob');
|
|
||||||
|
// if you want to prepend any config, you can do it here
|
||||||
|
$loader->load($confDir . '/packages/local_before' . self::CONFIG_EXTS, 'glob');
|
||||||
|
|
||||||
|
// using this one instead of $loader->load($confDir . '/packages/*' . self::CONFIG_EXTS, 'glob');
|
||||||
|
// to get rid of the local.yaml from the list, we load it afterwards explicit
|
||||||
|
$finder = (new Finder())
|
||||||
|
->files()
|
||||||
|
->in([$confDir . '/packages/'])
|
||||||
|
->name('*' . self::CONFIG_EXTS)
|
||||||
|
->notName('local*' . self::CONFIG_EXTS)
|
||||||
|
->depth('== 0')
|
||||||
|
->sortByName()
|
||||||
|
->followLinks()
|
||||||
|
;
|
||||||
|
|
||||||
|
/** @var SplFileInfo $file */
|
||||||
|
foreach ($finder as $file) {
|
||||||
|
$loader->load($file->getPathname());
|
||||||
|
}
|
||||||
|
|
||||||
if (is_dir($confDir . '/packages/' . $this->environment)) {
|
if (is_dir($confDir . '/packages/' . $this->environment)) {
|
||||||
$loader->load($confDir . '/packages/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
|
$loader->load($confDir . '/packages/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ namespace App\Ldap;
|
|||||||
use App\Configuration\LdapConfiguration;
|
use App\Configuration\LdapConfiguration;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider;
|
use Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||||
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException;
|
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException;
|
||||||
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||||
@@ -49,15 +48,6 @@ class LdapAuthenticationProvider extends UserAuthenticationProvider
|
|||||||
$this->userProvider = $userProvider;
|
$this->userProvider = $userProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supports(TokenInterface $token)
|
|
||||||
{
|
|
||||||
if (!$this->config->isActivated()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::supports($token);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function retrieveUser($username, UsernamePasswordToken $token)
|
protected function retrieveUser($username, UsernamePasswordToken $token)
|
||||||
{
|
{
|
||||||
$user = $token->getUser();
|
$user = $token->getUser();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
namespace App\Ldap;
|
namespace App\Ldap;
|
||||||
|
|
||||||
|
use App\Configuration\LdapConfiguration;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
use Zend\Ldap\Exception\LdapException;
|
use Zend\Ldap\Exception\LdapException;
|
||||||
@@ -22,20 +23,22 @@ class LdapDriver
|
|||||||
/**
|
/**
|
||||||
* @var Ldap
|
* @var Ldap
|
||||||
*/
|
*/
|
||||||
private $driver;
|
protected $driver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var LoggerInterface
|
* @var LoggerInterface
|
||||||
*/
|
*/
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
/**
|
public function __construct(LdapConfiguration $config, LoggerInterface $logger = null)
|
||||||
* @param Ldap $driver Initialized Zend::Ldap Object
|
|
||||||
* @param LoggerInterface $logger optional logger for write debug messages
|
|
||||||
*/
|
|
||||||
public function __construct(Ldap $driver, LoggerInterface $logger = null)
|
|
||||||
{
|
{
|
||||||
$this->driver = $driver;
|
if (!class_exists('Zend\Ldap\Ldap')) {
|
||||||
|
throw new \Exception(
|
||||||
|
'Zend\Ldap\Ldap is missing, install it with "composer require zendframework/zend-ldap" ' .
|
||||||
|
'or deactivate LDAP, see https://www.kimai.org/documentation/ldap.html'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->driver = new Ldap($config->getConnectionParameters());
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +67,7 @@ class LdapDriver
|
|||||||
// searchEntries don't return 'count' key as specified by php native function ldap_get_entries()
|
// searchEntries don't return 'count' key as specified by php native function ldap_get_entries()
|
||||||
$entries['count'] = count($entries);
|
$entries['count'] = count($entries);
|
||||||
} catch (LdapException $exception) {
|
} catch (LdapException $exception) {
|
||||||
$this->zendExceptionHandler($exception);
|
$this->ldapExceptionHandler($exception);
|
||||||
|
|
||||||
throw new LdapDriverException('An error occurred with the search operation.');
|
throw new LdapDriverException('An error occurred with the search operation.');
|
||||||
}
|
}
|
||||||
@@ -85,16 +88,13 @@ class LdapDriver
|
|||||||
|
|
||||||
return $bind instanceof Ldap;
|
return $bind instanceof Ldap;
|
||||||
} catch (LdapException $exception) {
|
} catch (LdapException $exception) {
|
||||||
$this->zendExceptionHandler($exception, $password);
|
$this->ldapExceptionHandler($exception, $password);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function ldapExceptionHandler(LdapException $exception, string $password = null): void
|
||||||
* Treat a Zend Ldap Exception.
|
|
||||||
*/
|
|
||||||
protected function zendExceptionHandler(LdapException $exception, string $password = null): void
|
|
||||||
{
|
{
|
||||||
$sanitizedException = null !== $password ? new SanitizingException($exception, $password) : $exception;
|
$sanitizedException = null !== $password ? new SanitizingException($exception, $password) : $exception;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
namespace App\Ldap;
|
namespace App\Ldap;
|
||||||
|
|
||||||
use App\Configuration\LdapConfiguration;
|
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
||||||
@@ -37,24 +36,14 @@ class LdapUserProvider implements UserProviderInterface
|
|||||||
*/
|
*/
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
public function __construct(LdapManager $ldapManager, LdapConfiguration $config, LoggerInterface $logger = null)
|
public function __construct(LdapManager $ldapManager, LoggerInterface $logger = null)
|
||||||
{
|
{
|
||||||
$this->ldapManager = $ldapManager;
|
$this->ldapManager = $ldapManager;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->activated = $config->isActivated();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadUserByUsername($username)
|
public function loadUserByUsername($username)
|
||||||
{
|
{
|
||||||
// this method is called at least for unknown user, no matter what supportsClass() returns,
|
|
||||||
// so we have to check if LDAP is activated here as well
|
|
||||||
if (!$this->activated) {
|
|
||||||
$ex = new UsernameNotFoundException(sprintf('LDAP is deactivated, user "%s" not searched', $username));
|
|
||||||
$ex->setUsername($username);
|
|
||||||
|
|
||||||
throw $ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = $this->ldapManager->findUserByUsername($username);
|
$user = $this->ldapManager->findUserByUsername($username);
|
||||||
|
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
@@ -99,10 +88,6 @@ class LdapUserProvider implements UserProviderInterface
|
|||||||
|
|
||||||
public function supportsClass($class)
|
public function supportsClass($class)
|
||||||
{
|
{
|
||||||
if (!$this->activated) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $class === User::class || $class === 'App\Entity\User';
|
return $class === User::class || $class === 'App\Entity\User';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Kimai time-tracking app.
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Ldap;
|
|
||||||
|
|
||||||
use App\Configuration\LdapConfiguration;
|
|
||||||
use Zend\Ldap\Ldap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overwritten to prevent errors in case:
|
|
||||||
* LDAP is deactivated and LDAP extension is not loaded
|
|
||||||
*/
|
|
||||||
class ZendLdap extends Ldap
|
|
||||||
{
|
|
||||||
public function __construct(LdapConfiguration $config)
|
|
||||||
{
|
|
||||||
if (!$config->isActivated()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct($config->getConnectionParameters());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -729,9 +729,6 @@
|
|||||||
"zendframework/zend-eventmanager": {
|
"zendframework/zend-eventmanager": {
|
||||||
"version": "3.2.0"
|
"version": "3.2.0"
|
||||||
},
|
},
|
||||||
"zendframework/zend-ldap": {
|
|
||||||
"version": "2.10.0"
|
|
||||||
},
|
|
||||||
"zircote/swagger-php": {
|
"zircote/swagger-php": {
|
||||||
"version": "2.0.13"
|
"version": "2.0.13"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ class LdapConfigurationTest extends TestCase
|
|||||||
protected function getDefaultSettings()
|
protected function getDefaultSettings()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'active' => true,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'host' => '1.2.3.4',
|
'host' => '1.2.3.4',
|
||||||
],
|
],
|
||||||
@@ -41,12 +40,8 @@ class LdapConfigurationTest extends TestCase
|
|||||||
public function testMapping()
|
public function testMapping()
|
||||||
{
|
{
|
||||||
$sut = $this->getSut($this->getDefaultSettings());
|
$sut = $this->getSut($this->getDefaultSettings());
|
||||||
$this->assertTrue($sut->isActivated());
|
|
||||||
$this->assertEquals(['foo' => 'bar'], $sut->getUserParameters());
|
$this->assertEquals(['foo' => 'bar'], $sut->getUserParameters());
|
||||||
$this->assertEquals(['bar' => 'foo'], $sut->getRoleParameters());
|
$this->assertEquals(['bar' => 'foo'], $sut->getRoleParameters());
|
||||||
$this->assertEquals(['host' => '1.2.3.4'], $sut->getConnectionParameters());
|
$this->assertEquals(['host' => '1.2.3.4'], $sut->getConnectionParameters());
|
||||||
|
|
||||||
$sut = $this->getSut(['active' => false]);
|
|
||||||
$this->assertFalse($sut->isActivated());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,6 @@ class AppExtensionTest extends TestCase
|
|||||||
'kimai.timesheet.rates' => [],
|
'kimai.timesheet.rates' => [],
|
||||||
'kimai.timesheet.rounding' => [],
|
'kimai.timesheet.rounding' => [],
|
||||||
'kimai.ldap' => [
|
'kimai.ldap' => [
|
||||||
'active' => false,
|
|
||||||
'user' => [
|
'user' => [
|
||||||
'baseDn' => null,
|
'baseDn' => null,
|
||||||
'filter' => '',
|
'filter' => '',
|
||||||
@@ -230,7 +229,6 @@ class AppExtensionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$minConfig = $this->getMinConfig();
|
$minConfig = $this->getMinConfig();
|
||||||
$minConfig['kimai']['ldap'] = [
|
$minConfig['kimai']['ldap'] = [
|
||||||
'active' => true,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'host' => '9.9.9.9',
|
'host' => '9.9.9.9',
|
||||||
'baseDn' => 'lkhiuzhkj',
|
'baseDn' => 'lkhiuzhkj',
|
||||||
@@ -257,7 +255,6 @@ class AppExtensionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$minConfig = $this->getMinConfig();
|
$minConfig = $this->getMinConfig();
|
||||||
$minConfig['kimai']['ldap'] = [
|
$minConfig['kimai']['ldap'] = [
|
||||||
'active' => true,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'host' => '9.9.9.9',
|
'host' => '9.9.9.9',
|
||||||
],
|
],
|
||||||
@@ -281,7 +278,6 @@ class AppExtensionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$minConfig = $this->getMinConfig();
|
$minConfig = $this->getMinConfig();
|
||||||
$minConfig['kimai']['ldap'] = [
|
$minConfig['kimai']['ldap'] = [
|
||||||
'active' => true,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'host' => '9.9.9.9',
|
'host' => '9.9.9.9',
|
||||||
'baseDn' => '7658765',
|
'baseDn' => '7658765',
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ class ConfigurationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = $this->getMinConfig();
|
$config = $this->getMinConfig();
|
||||||
$config['ldap'] = [
|
$config['ldap'] = [
|
||||||
'active' => true,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'host' => 'foo'
|
'host' => 'foo'
|
||||||
],
|
],
|
||||||
@@ -78,22 +77,6 @@ class ConfigurationTest extends TestCase
|
|||||||
$this->assertConfig($config, []);
|
$this->assertConfig($config, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
|
||||||
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap": The "ldap.connection.host" config must be set if LDAP is activated.
|
|
||||||
*/
|
|
||||||
public function testValidateLdapConfigConnectionHost()
|
|
||||||
{
|
|
||||||
$config = $this->getMinConfig();
|
|
||||||
$config['ldap'] = [
|
|
||||||
'active' => true,
|
|
||||||
'connection' => [
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->assertConfig($config, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||||
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap.connection": The ldap.connection.useSsl and ldap.connection.useStartTls options are mutually exclusive.
|
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap.connection": The ldap.connection.useSsl and ldap.connection.useStartTls options are mutually exclusive.
|
||||||
@@ -102,7 +85,6 @@ class ConfigurationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = $this->getMinConfig();
|
$config = $this->getMinConfig();
|
||||||
$config['ldap'] = [
|
$config['ldap'] = [
|
||||||
'active' => false,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'useSsl' => true,
|
'useSsl' => true,
|
||||||
'useStartTls' => true,
|
'useStartTls' => true,
|
||||||
@@ -120,7 +102,6 @@ class ConfigurationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = $this->getMinConfig();
|
$config = $this->getMinConfig();
|
||||||
$config['ldap'] = [
|
$config['ldap'] = [
|
||||||
'active' => true,
|
|
||||||
'user' => [
|
'user' => [
|
||||||
'filter' => '(sdfsdfsdf)(uid=%s)',
|
'filter' => '(sdfsdfsdf)(uid=%s)',
|
||||||
],
|
],
|
||||||
@@ -137,7 +118,6 @@ class ConfigurationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = $this->getMinConfig();
|
$config = $this->getMinConfig();
|
||||||
$config['ldap'] = [
|
$config['ldap'] = [
|
||||||
'active' => true,
|
|
||||||
'user' => [
|
'user' => [
|
||||||
'filter' => 's(dfsdfsdf)',
|
'filter' => 's(dfsdfsdf)',
|
||||||
],
|
],
|
||||||
@@ -154,7 +134,6 @@ class ConfigurationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = $this->getMinConfig();
|
$config = $this->getMinConfig();
|
||||||
$config['ldap'] = [
|
$config['ldap'] = [
|
||||||
'active' => true,
|
|
||||||
'user' => [
|
'user' => [
|
||||||
'filter' => '(dfsdfsdf))',
|
'filter' => '(dfsdfsdf))',
|
||||||
],
|
],
|
||||||
@@ -171,7 +150,6 @@ class ConfigurationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = $this->getMinConfig();
|
$config = $this->getMinConfig();
|
||||||
$config['ldap'] = [
|
$config['ldap'] = [
|
||||||
'active' => false,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'accountFilterFormat' => '(sdfsdfsdf)(uid=xx)',
|
'accountFilterFormat' => '(sdfsdfsdf)(uid=xx)',
|
||||||
],
|
],
|
||||||
@@ -188,7 +166,6 @@ class ConfigurationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = $this->getMinConfig();
|
$config = $this->getMinConfig();
|
||||||
$config['ldap'] = [
|
$config['ldap'] = [
|
||||||
'active' => true,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'accountFilterFormat' => 's(dfsdfsdf)',
|
'accountFilterFormat' => 's(dfsdfsdf)',
|
||||||
],
|
],
|
||||||
@@ -205,7 +182,6 @@ class ConfigurationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$config = $this->getMinConfig();
|
$config = $this->getMinConfig();
|
||||||
$config['ldap'] = [
|
$config['ldap'] = [
|
||||||
'active' => true,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'accountFilterFormat' => '(dfsdfsdf))',
|
'accountFilterFormat' => '(dfsdfsdf))',
|
||||||
],
|
],
|
||||||
@@ -218,7 +194,6 @@ class ConfigurationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$finalizedConfig = $this->getCompiledConfig($this->getMinConfig());
|
$finalizedConfig = $this->getCompiledConfig($this->getMinConfig());
|
||||||
$expected = [
|
$expected = [
|
||||||
'active' => false,
|
|
||||||
'user' => [
|
'user' => [
|
||||||
'baseDn' => '',
|
'baseDn' => '',
|
||||||
'filter' => '',
|
'filter' => '',
|
||||||
|
|||||||
@@ -24,44 +24,11 @@ use Symfony\Component\Security\Core\User\UserChecker;
|
|||||||
*/
|
*/
|
||||||
class LdapAuthenticationProviderTest extends TestCase
|
class LdapAuthenticationProviderTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testDeactivatedSupports()
|
|
||||||
{
|
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
||||||
$config = new LdapConfiguration(['active' => false]);
|
|
||||||
$userProvider = new LdapUserProvider($manager, $config);
|
|
||||||
$providerKey = 'secured_area';
|
|
||||||
$userChecker = new UserChecker();
|
|
||||||
|
|
||||||
$token = new UsernamePasswordToken('foo', 'bar', $providerKey);
|
|
||||||
|
|
||||||
$sut = new LdapAuthenticationProvider($userChecker, $providerKey, $userProvider, $manager, $config, false);
|
|
||||||
$result = $sut->supports($token);
|
|
||||||
self::assertFalse($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
|
|
||||||
* @expectedExceptionMessage The token is not supported by this authentication provider.
|
|
||||||
*/
|
|
||||||
public function testDeactivatedAuthenticate()
|
|
||||||
{
|
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
||||||
$config = new LdapConfiguration(['active' => false]);
|
|
||||||
$userProvider = new LdapUserProvider($manager, $config);
|
|
||||||
$providerKey = 'secured_area';
|
|
||||||
$userChecker = new UserChecker();
|
|
||||||
|
|
||||||
$token = new UsernamePasswordToken('foo', 'bar', $providerKey);
|
|
||||||
|
|
||||||
$sut = new LdapAuthenticationProvider($userChecker, $providerKey, $userProvider, $manager, $config, false);
|
|
||||||
$sut->authenticate($token);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSupports()
|
public function testSupports()
|
||||||
{
|
{
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
$config = new LdapConfiguration([]);
|
||||||
$userProvider = new LdapUserProvider($manager, $config);
|
$userProvider = new LdapUserProvider($manager);
|
||||||
$providerKey = 'secured_area';
|
$providerKey = 'secured_area';
|
||||||
$userChecker = new UserChecker();
|
$userChecker = new UserChecker();
|
||||||
|
|
||||||
@@ -76,11 +43,11 @@ class LdapAuthenticationProviderTest extends TestCase
|
|||||||
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
|
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
|
||||||
* @expectedExceptionMessage The password in the token is empty. Check `erase_credentials` in your `security.yaml`
|
* @expectedExceptionMessage The password in the token is empty. Check `erase_credentials` in your `security.yaml`
|
||||||
*/
|
*/
|
||||||
public function testAuthenticateWithTokenUserButEnptyPasswordThrowsException()
|
public function testAuthenticateWithTokenUserButEmptyPasswordThrowsException()
|
||||||
{
|
{
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
$config = new LdapConfiguration([]);
|
||||||
$userProvider = new LdapUserProvider($manager, $config);
|
$userProvider = new LdapUserProvider($manager);
|
||||||
$providerKey = 'secured_area';
|
$providerKey = 'secured_area';
|
||||||
$userChecker = new UserChecker();
|
$userChecker = new UserChecker();
|
||||||
|
|
||||||
@@ -99,7 +66,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|||||||
{
|
{
|
||||||
$user = (new User())->setUsername('foo')->setEnabled(true);
|
$user = (new User())->setUsername('foo')->setEnabled(true);
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
$config = new LdapConfiguration([]);
|
||||||
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
||||||
$userProvider->expects($this->once())->method('loadUserByUsername')->willReturn($user);
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willReturn($user);
|
||||||
$providerKey = 'secured_area';
|
$providerKey = 'secured_area';
|
||||||
@@ -120,7 +87,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|||||||
$user = (new User())->setUsername('foo')->setEnabled(true);
|
$user = (new User())->setUsername('foo')->setEnabled(true);
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock();
|
||||||
$manager->expects($this->once())->method('bind')->willReturn(false);
|
$manager->expects($this->once())->method('bind')->willReturn(false);
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
$config = new LdapConfiguration([]);
|
||||||
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
||||||
$userProvider->expects($this->once())->method('loadUserByUsername')->willReturn($user);
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willReturn($user);
|
||||||
$providerKey = 'secured_area';
|
$providerKey = 'secured_area';
|
||||||
@@ -141,7 +108,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|||||||
$user = (new User())->setUsername('foo')->setEnabled(true);
|
$user = (new User())->setUsername('foo')->setEnabled(true);
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock();
|
||||||
$manager->expects($this->once())->method('bind')->willReturn(false);
|
$manager->expects($this->once())->method('bind')->willReturn(false);
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
$config = new LdapConfiguration([]);
|
||||||
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
||||||
$userProvider->expects($this->never())->method('loadUserByUsername');
|
$userProvider->expects($this->never())->method('loadUserByUsername');
|
||||||
$providerKey = 'secured_area';
|
$providerKey = 'secured_area';
|
||||||
@@ -162,7 +129,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|||||||
$manager->expects($this->once())->method('updateUser')->willReturnCallback(function ($updateUser) use ($user) {
|
$manager->expects($this->once())->method('updateUser')->willReturnCallback(function ($updateUser) use ($user) {
|
||||||
self::assertSame($updateUser, $user);
|
self::assertSame($updateUser, $user);
|
||||||
});
|
});
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
$config = new LdapConfiguration([]);
|
||||||
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
||||||
$userProvider->expects($this->once())->method('loadUserByUsername')->willReturn($user);
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willReturn($user);
|
||||||
$providerKey = 'secured_area';
|
$providerKey = 'secured_area';
|
||||||
@@ -184,7 +151,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|||||||
$manager->expects($this->once())->method('updateUser')->willReturnCallback(function ($updateUser) use ($user) {
|
$manager->expects($this->once())->method('updateUser')->willReturnCallback(function ($updateUser) use ($user) {
|
||||||
self::assertSame($updateUser, $user);
|
self::assertSame($updateUser, $user);
|
||||||
});
|
});
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
$config = new LdapConfiguration([]);
|
||||||
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
||||||
$userProvider->expects($this->never())->method('loadUserByUsername');
|
$userProvider->expects($this->never())->method('loadUserByUsername');
|
||||||
$providerKey = 'secured_area';
|
$providerKey = 'secured_area';
|
||||||
@@ -204,7 +171,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|||||||
public function testAuthenticateThrowsExceptionOnLdapNotFound()
|
public function testAuthenticateThrowsExceptionOnLdapNotFound()
|
||||||
{
|
{
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
$config = new LdapConfiguration([]);
|
||||||
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
||||||
$userProvider->expects($this->once())->method('loadUserByUsername')->willThrowException(new UsernameNotFoundException('blub foo bar'));
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willThrowException(new UsernameNotFoundException('blub foo bar'));
|
||||||
$providerKey = 'secured_area';
|
$providerKey = 'secured_area';
|
||||||
@@ -224,7 +191,7 @@ class LdapAuthenticationProviderTest extends TestCase
|
|||||||
public function testAuthenticateThrowsExceptionOnLdapDown()
|
public function testAuthenticateThrowsExceptionOnLdapDown()
|
||||||
{
|
{
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
$config = new LdapConfiguration([]);
|
||||||
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
$userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock();
|
||||||
$userProvider->expects($this->once())->method('loadUserByUsername')->willThrowException(new \Exception('server away', 1234));
|
$userProvider->expects($this->once())->method('loadUserByUsername')->willThrowException(new \Exception('server away', 1234));
|
||||||
$providerKey = 'secured_area';
|
$providerKey = 'secured_area';
|
||||||
|
|||||||
@@ -20,13 +20,21 @@ use Zend\Ldap\Ldap;
|
|||||||
*/
|
*/
|
||||||
class LdapDriverTest extends TestCase
|
class LdapDriverTest extends TestCase
|
||||||
{
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
if (!class_exists('Zend\Ldap\Ldap')) {
|
||||||
|
$this->markTestSkipped('LDAP is not installed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testBindSuccess()
|
public function testBindSuccess()
|
||||||
{
|
{
|
||||||
$zendLdap = $this->getMockBuilder(Ldap::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock();
|
$zendLdap = $this->getMockBuilder(Ldap::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock();
|
||||||
$zendLdap->expects($this->once())->method('bind')->willReturnSelf();
|
$zendLdap->expects($this->once())->method('bind')->willReturnSelf();
|
||||||
|
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$sut = new LdapDriver($zendLdap);
|
$sut = new TestLdapDriver($zendLdap);
|
||||||
$result = $sut->bind($user, 'test123');
|
$result = $sut->bind($user, 'test123');
|
||||||
self::assertTrue($result);
|
self::assertTrue($result);
|
||||||
}
|
}
|
||||||
@@ -37,7 +45,7 @@ class LdapDriverTest extends TestCase
|
|||||||
$zendLdap->expects($this->once())->method('bind')->willThrowException(new LdapException());
|
$zendLdap->expects($this->once())->method('bind')->willThrowException(new LdapException());
|
||||||
|
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$sut = new LdapDriver($zendLdap);
|
$sut = new TestLdapDriver($zendLdap);
|
||||||
$result = $sut->bind($user, 'test123');
|
$result = $sut->bind($user, 'test123');
|
||||||
self::assertFalse($result);
|
self::assertFalse($result);
|
||||||
}
|
}
|
||||||
@@ -48,7 +56,7 @@ class LdapDriverTest extends TestCase
|
|||||||
$zendLdap->expects($this->once())->method('bind');
|
$zendLdap->expects($this->once())->method('bind');
|
||||||
$zendLdap->expects($this->once())->method('searchEntries')->willReturn([1, 2, 3]);
|
$zendLdap->expects($this->once())->method('searchEntries')->willReturn([1, 2, 3]);
|
||||||
|
|
||||||
$sut = new LdapDriver($zendLdap);
|
$sut = new TestLdapDriver($zendLdap);
|
||||||
$result = $sut->search('', '', []);
|
$result = $sut->search('', '', []);
|
||||||
self::assertEquals(['count' => 3, 1, 2, 3], $result);
|
self::assertEquals(['count' => 3, 1, 2, 3], $result);
|
||||||
}
|
}
|
||||||
@@ -65,7 +73,15 @@ class LdapDriverTest extends TestCase
|
|||||||
new LdapException($zendLdap, '', LdapException::LDAP_SERVER_DOWN)
|
new LdapException($zendLdap, '', LdapException::LDAP_SERVER_DOWN)
|
||||||
);
|
);
|
||||||
|
|
||||||
$sut = new LdapDriver($zendLdap);
|
$sut = new TestLdapDriver($zendLdap);
|
||||||
$sut->search('', '', []);
|
$sut->search('', '', []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestLdapDriver extends LdapDriver
|
||||||
|
{
|
||||||
|
public function __construct(Ldap $ldap)
|
||||||
|
{
|
||||||
|
$this->driver = $ldap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ class LdapUserHydratorTest extends TestCase
|
|||||||
public function testEmptyHydrate()
|
public function testEmptyHydrate()
|
||||||
{
|
{
|
||||||
$config = new LdapConfiguration([
|
$config = new LdapConfiguration([
|
||||||
'active' => false,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'host' => '1.1.1.1'
|
'host' => '1.1.1.1'
|
||||||
],
|
],
|
||||||
@@ -44,7 +43,6 @@ class LdapUserHydratorTest extends TestCase
|
|||||||
public function testHydrate()
|
public function testHydrate()
|
||||||
{
|
{
|
||||||
$config = new LdapConfiguration([
|
$config = new LdapConfiguration([
|
||||||
'active' => false,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'host' => '1.1.1.1'
|
'host' => '1.1.1.1'
|
||||||
],
|
],
|
||||||
@@ -88,7 +86,6 @@ class LdapUserHydratorTest extends TestCase
|
|||||||
public function testHydrateUser()
|
public function testHydrateUser()
|
||||||
{
|
{
|
||||||
$config = new LdapConfiguration([
|
$config = new LdapConfiguration([
|
||||||
'active' => false,
|
|
||||||
'connection' => [
|
'connection' => [
|
||||||
'host' => '1.1.1.1'
|
'host' => '1.1.1.1'
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
namespace App\Tests\Ldap;
|
namespace App\Tests\Ldap;
|
||||||
|
|
||||||
use App\Configuration\LdapConfiguration;
|
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Ldap\LdapManager;
|
use App\Ldap\LdapManager;
|
||||||
use App\Ldap\LdapUserProvider;
|
use App\Ldap\LdapUserProvider;
|
||||||
@@ -20,41 +19,6 @@ use PHPUnit\Framework\TestCase;
|
|||||||
*/
|
*/
|
||||||
class LdapUserProviderTest extends TestCase
|
class LdapUserProviderTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testDeactivatedSupportsClass()
|
|
||||||
{
|
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
||||||
$config = new LdapConfiguration(['active' => false]);
|
|
||||||
|
|
||||||
$sut = new LdapUserProvider($manager, $config);
|
|
||||||
self::assertFalse($sut->supportsClass(User::class));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
|
|
||||||
* @expectedExceptionMessage LDAP is deactivated, user "test" not searched
|
|
||||||
*/
|
|
||||||
public function testDeactivatedLoadUserByUsername()
|
|
||||||
{
|
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
||||||
$config = new LdapConfiguration(['active' => false]);
|
|
||||||
|
|
||||||
$sut = new LdapUserProvider($manager, $config);
|
|
||||||
$sut->loadUserByUsername('test');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Symfony\Component\Security\Core\Exception\UnsupportedUserException
|
|
||||||
* @expectedExceptionMessage Instances of "App\Entity\User" are not supported.
|
|
||||||
*/
|
|
||||||
public function testDeactivatedRefreshUser()
|
|
||||||
{
|
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock();
|
|
||||||
$config = new LdapConfiguration(['active' => false]);
|
|
||||||
|
|
||||||
$sut = new LdapUserProvider($manager, $config);
|
|
||||||
$sut->refreshUser(new User());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
|
* @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
|
||||||
* @expectedExceptionMessage User "test" not found
|
* @expectedExceptionMessage User "test" not found
|
||||||
@@ -63,9 +27,8 @@ class LdapUserProviderTest extends TestCase
|
|||||||
{
|
{
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['findUserByUsername'])->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['findUserByUsername'])->getMock();
|
||||||
$manager->expects($this->once())->method('findUserByUsername')->willReturn(null);
|
$manager->expects($this->once())->method('findUserByUsername')->willReturn(null);
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
|
||||||
|
|
||||||
$sut = new LdapUserProvider($manager, $config);
|
$sut = new LdapUserProvider($manager);
|
||||||
$sut->loadUserByUsername('test');
|
$sut->loadUserByUsername('test');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,9 +39,8 @@ class LdapUserProviderTest extends TestCase
|
|||||||
|
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['findUserByUsername'])->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['findUserByUsername'])->getMock();
|
||||||
$manager->expects($this->once())->method('findUserByUsername')->willReturn($user);
|
$manager->expects($this->once())->method('findUserByUsername')->willReturn($user);
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
|
||||||
|
|
||||||
$sut = new LdapUserProvider($manager, $config);
|
$sut = new LdapUserProvider($manager);
|
||||||
$actual = $sut->loadUserByUsername('test');
|
$actual = $sut->loadUserByUsername('test');
|
||||||
self::assertInstanceOf(User::class, $actual);
|
self::assertInstanceOf(User::class, $actual);
|
||||||
self::assertSame($user, $actual);
|
self::assertSame($user, $actual);
|
||||||
@@ -91,9 +53,8 @@ class LdapUserProviderTest extends TestCase
|
|||||||
$user->setPreferenceValue('ldap.dn', 'sdfdsf');
|
$user->setPreferenceValue('ldap.dn', 'sdfdsf');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['updateUser'])->getMock();
|
$manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['updateUser'])->getMock();
|
||||||
$config = new LdapConfiguration(['active' => true]);
|
|
||||||
|
|
||||||
$sut = new LdapUserProvider($manager, $config);
|
$sut = new LdapUserProvider($manager);
|
||||||
$actual = $sut->refreshUser($user);
|
$actual = $sut->refreshUser($user);
|
||||||
|
|
||||||
self::assertInstanceOf(User::class, $actual);
|
self::assertInstanceOf(User::class, $actual);
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Kimai time-tracking app.
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Tests\Ldap;
|
|
||||||
|
|
||||||
use App\Configuration\LdapConfiguration;
|
|
||||||
use App\Ldap\ZendLdap;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \App\Ldap\ZendLdap
|
|
||||||
*/
|
|
||||||
class ZendLdapTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testConstructDeactivated()
|
|
||||||
{
|
|
||||||
$config = new LdapConfiguration([
|
|
||||||
'active' => false,
|
|
||||||
'connection' => [
|
|
||||||
'host' => '1.1.1.1'
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
$sut = new ZendLdap($config);
|
|
||||||
$options = $sut->getOptions();
|
|
||||||
self::assertNull($options['host']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testConstructActivatedPassesOptions()
|
|
||||||
{
|
|
||||||
$config = new LdapConfiguration([
|
|
||||||
'active' => true,
|
|
||||||
'connection' => [
|
|
||||||
'host' => '1.1.1.1'
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
$sut = new ZendLdap($config);
|
|
||||||
$options = $sut->getOptions();
|
|
||||||
self::assertEquals('1.1.1.1', $options['host']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,3 +8,5 @@ parameters:
|
|||||||
- '#Access to an undefined property Faker\\Generator::\$stateAbbr.#'
|
- '#Access to an undefined property Faker\\Generator::\$stateAbbr.#'
|
||||||
- '#Access to an undefined property Faker\\Generator::\$catchPhrase.#'
|
- '#Access to an undefined property Faker\\Generator::\$catchPhrase.#'
|
||||||
- '#Access to an undefined property Faker\\Generator::\$bs.#'
|
- '#Access to an undefined property Faker\\Generator::\$bs.#'
|
||||||
|
excludes_analyse:
|
||||||
|
- %rootDir%/../../../tests/Ldap/LdapDriverTest.php
|
||||||
|
|||||||
Reference in New Issue
Block a user