Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #11 from DerManoMann/ldap_excpetion
Browse files Browse the repository at this point in the history
Use correct namespace for LdapException and add test
  • Loading branch information
DerManoMann committed Feb 22, 2016
2 parents 6d3df6c + 8f42ce7 commit c7be63e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/LdapAuthenticationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Zend\Ldap\Exception\LdapException;
use Zend\Ldap\Ldap;
use Radebatz\Silex\LdapAuth\Security\Core\Authentication\Provider\LdapAuthenticationProvider;
use Radebatz\Silex\LdapAuth\Security\Core\User\LdapUserProvider;
Expand Down
1 change: 1 addition & 0 deletions src/Silex1LdapAuthenticationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Silex\Application;
use Silex\ServiceProviderInterface;
use Zend\Ldap\Exception\LdapException;
use Zend\Ldap\Ldap;
use Radebatz\Silex\LdapAuth\Security\Core\Authentication\Provider\LdapAuthenticationProvider;
use Radebatz\Silex\LdapAuth\Security\Core\User\LdapUserProvider;
Expand Down
76 changes: 76 additions & 0 deletions tests/LdapTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/*
* This file is part of the LdapAuthentication service provider.
*
* (c) Martin Rademacher <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Radebatz\Silex\LdapAuth\Tests;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Silex\Application;
use Silex\Provider\SessionServiceProvider;
use Radebatz\Silex\LdapAuth\LdapAuthenticationServiceProvider;

/**
* Test Ldap.
*/
class LdapTest extends LdapAuthTestCase
{

/**
* @expectedException Symfony\Component\Security\Core\Exception\UsernameNotFoundException
*/
public function testLdapExceptionSimple()
{
$app = new Application();
$app['debug'] = true;
$app->register(new SessionServiceProvider());

$app['logger'] = new Logger('CLI');
$app['logger']->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
/*
*/

$serviceName = 'ldap-form';
$app->register(new LdapAuthenticationServiceProvider($serviceName));

// try the user provider with invalid Ldap configuration
$app['security.ldap.'.$serviceName.'.user_provider']()->loadUserByUsername('mano');
}

/**
* @expectedException Symfony\Component\Security\Core\Exception\UsernameNotFoundException
*/
public function testLdapExceptionHosts()
{
$app = new Application();
$app['debug'] = true;
$app->register(new SessionServiceProvider());

$app['logger'] = new Logger('CLI');
$app['logger']->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
/*
*/

$serviceName = 'ldap-form';
$app->register(new LdapAuthenticationServiceProvider($serviceName), array(
'security.ldap.'.$serviceName.'.options' => array(
'ldap' => array(
'hosts' => array(
'host1',
'host2',
),
),
),
));

// try the user provider with invalid Ldap configuration
$app['security.ldap.'.$serviceName.'.user_provider']()->loadUserByUsername('mano');
}
}

0 comments on commit c7be63e

Please sign in to comment.