summaryrefslogtreecommitdiffstats
path: root/Core/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Core/Tests')
-rw-r--r--Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php16
-rw-r--r--Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php81
-rw-r--r--Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php10
-rw-r--r--Core/Tests/Authentication/Token/AnonymousTokenTest.php2
-rw-r--r--Core/Tests/Authentication/Token/RememberMeTokenTest.php6
-rw-r--r--Core/Tests/Authorization/AccessDecisionManagerTest.php14
-rw-r--r--Core/Tests/Authorization/Voter/AbstractVoterTest.php24
-rw-r--r--Core/Tests/Authorization/Voter/Fixtures/MyVoter.php27
-rw-r--r--Core/Tests/Authorization/Voter/RoleHierarchyVoterTest.php15
-rw-r--r--Core/Tests/Authorization/Voter/VoterTest.php70
-rw-r--r--Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php26
-rw-r--r--Core/Tests/LegacySecurityContextInterfaceTest.php31
-rw-r--r--Core/Tests/LegacySecurityContextTest.php12
-rw-r--r--Core/Tests/User/LdapUserProviderTest.php105
-rw-r--r--Core/Tests/Util/ClassUtilsTest.php3
-rw-r--r--Core/Tests/Util/StringUtilsTest.php2
16 files changed, 368 insertions, 76 deletions
diff --git a/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php
index 5a189b0..8f4b392 100644
--- a/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php
+++ b/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php
@@ -33,11 +33,11 @@ class AnonymousAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
*/
- public function testAuthenticateWhenKeyIsNotValid()
+ public function testAuthenticateWhenSecretIsNotValid()
{
$provider = $this->getProvider('foo');
- $this->assertNull($provider->authenticate($this->getSupportedToken('bar')));
+ $provider->authenticate($this->getSupportedToken('bar'));
}
public function testAuthenticate()
@@ -48,19 +48,19 @@ class AnonymousAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$this->assertSame($token, $provider->authenticate($token));
}
- protected function getSupportedToken($key)
+ protected function getSupportedToken($secret)
{
- $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', array('getKey'), array(), '', false);
+ $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', array('getSecret'), array(), '', false);
$token->expects($this->any())
- ->method('getKey')
- ->will($this->returnValue($key))
+ ->method('getSecret')
+ ->will($this->returnValue($secret))
;
return $token;
}
- protected function getProvider($key)
+ protected function getProvider($secret)
{
- return new AnonymousAuthenticationProvider($key);
+ return new AnonymousAuthenticationProvider($secret);
}
}
diff --git a/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php
new file mode 100644
index 0000000..fbb4d73
--- /dev/null
+++ b/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php
@@ -0,0 +1,81 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
+
+use Symfony\Component\Security\Core\Authentication\Provider\LdapBindAuthenticationProvider;
+use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
+use Symfony\Component\Security\Core\User\User;
+use Symfony\Component\Ldap\Exception\ConnectionException;
+
+/**
+ * @requires extension ldap
+ */
+class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
+ * @expectedExceptionMessage The presented password must not be empty.
+ */
+ public function testEmptyPasswordShouldThrowAnException()
+ {
+ $userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
+ $ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
+ $userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
+
+ $provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
+ $reflection = new \ReflectionMethod($provider, 'checkAuthentication');
+ $reflection->setAccessible(true);
+
+ $reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', '', 'key'));
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
+ * @expectedExceptionMessage The presented password is invalid.
+ */
+ public function testBindFailureShouldThrowAnException()
+ {
+ $userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
+ $ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
+ $ldap
+ ->expects($this->once())
+ ->method('bind')
+ ->will($this->throwException(new ConnectionException()))
+ ;
+ $userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
+
+ $provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
+ $reflection = new \ReflectionMethod($provider, 'checkAuthentication');
+ $reflection->setAccessible(true);
+
+ $reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', 'bar', 'key'));
+ }
+
+ public function testRetrieveUser()
+ {
+ $userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
+ $userProvider
+ ->expects($this->once())
+ ->method('loadUserByUsername')
+ ->with('foo')
+ ;
+ $ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
+
+ $userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
+
+ $provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
+ $reflection = new \ReflectionMethod($provider, 'retrieveUser');
+ $reflection->setAccessible(true);
+
+ $reflection->invoke($provider, 'foo', new UsernamePasswordToken('foo', 'bar', 'key'));
+ }
+}
diff --git a/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php
index a6fff4b..735d195 100644
--- a/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php
+++ b/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php
@@ -36,10 +36,10 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
*/
- public function testAuthenticateWhenKeysDoNotMatch()
+ public function testAuthenticateWhenSecretsDoNotMatch()
{
- $provider = $this->getProvider(null, 'key1');
- $token = $this->getSupportedToken(null, 'key2');
+ $provider = $this->getProvider(null, 'secret1');
+ $token = $this->getSupportedToken(null, 'secret2');
$provider->authenticate($token);
}
@@ -77,7 +77,7 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('', $authToken->getCredentials());
}
- protected function getSupportedToken($user = null, $key = 'test')
+ protected function getSupportedToken($user = null, $secret = 'test')
{
if (null === $user) {
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
@@ -87,7 +87,7 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(array()));
}
- $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', array('getProviderKey'), array($user, 'foo', $key));
+ $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', array('getProviderKey'), array($user, 'foo', $secret));
$token
->expects($this->once())
->method('getProviderKey')
diff --git a/Core/Tests/Authentication/Token/AnonymousTokenTest.php b/Core/Tests/Authentication/Token/AnonymousTokenTest.php
index b5cf006..cac2039 100644
--- a/Core/Tests/Authentication/Token/AnonymousTokenTest.php
+++ b/Core/Tests/Authentication/Token/AnonymousTokenTest.php
@@ -28,7 +28,7 @@ class AnonymousTokenTest extends \PHPUnit_Framework_TestCase
public function testGetKey()
{
$token = new AnonymousToken('foo', 'bar');
- $this->assertEquals('foo', $token->getKey());
+ $this->assertEquals('foo', $token->getSecret());
}
public function testGetCredentials()
diff --git a/Core/Tests/Authentication/Token/RememberMeTokenTest.php b/Core/Tests/Authentication/Token/RememberMeTokenTest.php
index 7449204..b83de4a 100644
--- a/Core/Tests/Authentication/Token/RememberMeTokenTest.php
+++ b/Core/Tests/Authentication/Token/RememberMeTokenTest.php
@@ -22,7 +22,7 @@ class RememberMeTokenTest extends \PHPUnit_Framework_TestCase
$token = new RememberMeToken($user, 'fookey', 'foo');
$this->assertEquals('fookey', $token->getProviderKey());
- $this->assertEquals('foo', $token->getKey());
+ $this->assertEquals('foo', $token->getSecret());
$this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
$this->assertSame($user, $token->getUser());
$this->assertTrue($token->isAuthenticated());
@@ -31,7 +31,7 @@ class RememberMeTokenTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \InvalidArgumentException
*/
- public function testConstructorKeyCannotBeNull()
+ public function testConstructorSecretCannotBeNull()
{
new RememberMeToken(
$this->getUser(),
@@ -43,7 +43,7 @@ class RememberMeTokenTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \InvalidArgumentException
*/
- public function testConstructorKeyCannotBeEmptyString()
+ public function testConstructorSecretCannotBeEmptyString()
{
new RememberMeToken(
$this->getUser(),
diff --git a/Core/Tests/Authorization/AccessDecisionManagerTest.php b/Core/Tests/Authorization/AccessDecisionManagerTest.php
index 7a9ab08..412af91 100644
--- a/Core/Tests/Authorization/AccessDecisionManagerTest.php
+++ b/Core/Tests/Authorization/AccessDecisionManagerTest.php
@@ -16,6 +16,9 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
{
+ /**
+ * @group legacy
+ */
public function testSupportsClass()
{
$manager = new AccessDecisionManager(array(
@@ -31,6 +34,9 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($manager->supportsClass('FooClass'));
}
+ /**
+ * @group legacy
+ */
public function testSupportsAttribute()
{
$manager = new AccessDecisionManager(array(
@@ -49,14 +55,6 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \InvalidArgumentException
*/
- public function testSetVotersEmpty()
- {
- $manager = new AccessDecisionManager(array());
- }
-
- /**
- * @expectedException \InvalidArgumentException
- */
public function testSetUnsupportedStrategy()
{
new AccessDecisionManager(array($this->getVoter(VoterInterface::ACCESS_GRANTED)), 'fooBar');
diff --git a/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/Core/Tests/Authorization/Voter/AbstractVoterTest.php
index 2ab943b..b537c1b 100644
--- a/Core/Tests/Authorization/Voter/AbstractVoterTest.php
+++ b/Core/Tests/Authorization/Voter/AbstractVoterTest.php
@@ -11,9 +11,11 @@
namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
-use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
+/**
+ * @group legacy
+ */
class AbstractVoterTest extends \PHPUnit_Framework_TestCase
{
protected $token;
@@ -49,26 +51,8 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testVote(array $attributes, $expectedVote, $object, $message)
{
- $voter = new AbstractVoterTest_Voter();
+ $voter = new Fixtures\MyVoter();
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
}
}
-
-class AbstractVoterTest_Voter extends AbstractVoter
-{
- protected function getSupportedClasses()
- {
- return array('stdClass');
- }
-
- protected function getSupportedAttributes()
- {
- return array('EDIT', 'CREATE');
- }
-
- protected function isGranted($attribute, $object, $user = null)
- {
- return 'EDIT' === $attribute;
- }
-}
diff --git a/Core/Tests/Authorization/Voter/Fixtures/MyVoter.php b/Core/Tests/Authorization/Voter/Fixtures/MyVoter.php
new file mode 100644
index 0000000..b75f798
--- /dev/null
+++ b/Core/Tests/Authorization/Voter/Fixtures/MyVoter.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Symfony\Component\Security\Core\Tests\Authorization\Voter\Fixtures;
+
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
+
+/**
+ * @group legacy
+ */
+class MyVoter extends AbstractVoter
+{
+ protected function getSupportedClasses()
+ {
+ return array('stdClass');
+ }
+
+ protected function getSupportedAttributes()
+ {
+ return array('EDIT', 'CREATE');
+ }
+
+ protected function isGranted($attribute, $object, $user = null)
+ {
+ return 'EDIT' === $attribute;
+ }
+}
diff --git a/Core/Tests/Authorization/Voter/RoleHierarchyVoterTest.php b/Core/Tests/Authorization/Voter/RoleHierarchyVoterTest.php
index c50ecf3..4b03bac 100644
--- a/Core/Tests/Authorization/Voter/RoleHierarchyVoterTest.php
+++ b/Core/Tests/Authorization/Voter/RoleHierarchyVoterTest.php
@@ -33,4 +33,19 @@ class RoleHierarchyVoterTest extends RoleVoterTest
array(array('ROLE_FOO'), array('ROLE_FOOBAR'), VoterInterface::ACCESS_GRANTED),
));
}
+
+ /**
+ * @dataProvider getVoteWithEmptyHierarchyTests
+ */
+ public function testVoteWithEmptyHierarchy($roles, $attributes, $expected)
+ {
+ $voter = new RoleHierarchyVoter(new RoleHierarchy(array()));
+
+ $this->assertSame($expected, $voter->vote($this->getToken($roles), null, $attributes));
+ }
+
+ public function getVoteWithEmptyHierarchyTests()
+ {
+ return parent::getVoteTests();
+ }
}
diff --git a/Core/Tests/Authorization/Voter/VoterTest.php b/Core/Tests/Authorization/Voter/VoterTest.php
new file mode 100644
index 0000000..4bac44d
--- /dev/null
+++ b/Core/Tests/Authorization/Voter/VoterTest.php
@@ -0,0 +1,70 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
+
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\Authorization\Voter\Voter;
+use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
+
+class VoterTest extends \PHPUnit_Framework_TestCase
+{
+ protected $token;
+
+ protected function setUp()
+ {
+ $this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ }
+
+ public function getTests()
+ {
+ return array(
+ array(array('EDIT'), VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if attribute and class are supported and attribute grants access'),
+ array(array('CREATE'), VoterInterface::ACCESS_DENIED, new \stdClass(), 'ACCESS_DENIED if attribute and class are supported and attribute does not grant access'),
+
+ array(array('DELETE', 'EDIT'), VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if one attribute is supported and grants access'),
+ array(array('DELETE', 'CREATE'), VoterInterface::ACCESS_DENIED, new \stdClass(), 'ACCESS_DENIED if one attribute is supported and denies access'),
+
+ array(array('CREATE', 'EDIT'), VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if one attribute grants access'),
+
+ array(array('DELETE'), VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if no attribute is supported'),
+
+ array(array('EDIT'), VoterInterface::ACCESS_ABSTAIN, $this, 'ACCESS_ABSTAIN if class is not supported'),
+
+ array(array('EDIT'), VoterInterface::ACCESS_ABSTAIN, null, 'ACCESS_ABSTAIN if object is null'),
+
+ array(array(), VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if no attributes were provided'),
+ );
+ }
+
+ /**
+ * @dataProvider getTests
+ */
+ public function testVote(array $attributes, $expectedVote, $object, $message)
+ {
+ $voter = new VoterTest_Voter();
+
+ $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
+ }
+}
+
+class VoterTest_Voter extends Voter
+{
+ protected function voteOnAttribute($attribute, $object, TokenInterface $token)
+ {
+ return 'EDIT' === $attribute;
+ }
+
+ protected function supports($attribute, $object)
+ {
+ return $object instanceof \stdClass && in_array($attribute, array('EDIT', 'CREATE'));
+ }
+}
diff --git a/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php b/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php
new file mode 100644
index 0000000..408dd2a
--- /dev/null
+++ b/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Exception;
+
+use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
+
+class CustomUserMessageAuthenticationExceptionTest extends \PHPUnit_Framework_TestCase
+{
+ public function testConstructWithSAfeMessage()
+ {
+ $e = new CustomUserMessageAuthenticationException('SAFE MESSAGE', array('foo' => true));
+
+ $this->assertEquals('SAFE MESSAGE', $e->getMessageKey());
+ $this->assertEquals(array('foo' => true), $e->getMessageData());
+ $this->assertEquals('SAFE MESSAGE', $e->getMessage());
+ }
+}
diff --git a/Core/Tests/LegacySecurityContextInterfaceTest.php b/Core/Tests/LegacySecurityContextInterfaceTest.php
deleted file mode 100644
index a45ecf9..0000000
--- a/Core/Tests/LegacySecurityContextInterfaceTest.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Security\Core\Tests;
-
-use Symfony\Component\Security\Core\SecurityContextInterface;
-use Symfony\Component\Security\Core\Security;
-
-/**
- * @group legacy
- */
-class LegacySecurityContextInterfaceTest extends \PHPUnit_Framework_TestCase
-{
- /**
- * Test if the BC Layer is working as intended.
- */
- public function testConstantSync()
- {
- $this->assertSame(Security::ACCESS_DENIED_ERROR, SecurityContextInterface::ACCESS_DENIED_ERROR);
- $this->assertSame(Security::AUTHENTICATION_ERROR, SecurityContextInterface::AUTHENTICATION_ERROR);
- $this->assertSame(Security::LAST_USERNAME, SecurityContextInterface::LAST_USERNAME);
- }
-}
diff --git a/Core/Tests/LegacySecurityContextTest.php b/Core/Tests/LegacySecurityContextTest.php
index fbb847e..4502261 100644
--- a/Core/Tests/LegacySecurityContextTest.php
+++ b/Core/Tests/LegacySecurityContextTest.php
@@ -11,7 +11,9 @@
namespace Symfony\Component\Security\Core\Tests;
+use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\SecurityContext;
+use Symfony\Component\Security\Core\SecurityContextInterface;
/**
* @group legacy
@@ -117,4 +119,14 @@ class LegacySecurityContextTest extends \PHPUnit_Framework_TestCase
array(true, null),
);
}
+
+ /**
+ * Test if the BC Layer is working as intended.
+ */
+ public function testConstantSync()
+ {
+ $this->assertSame(Security::ACCESS_DENIED_ERROR, SecurityContextInterface::ACCESS_DENIED_ERROR);
+ $this->assertSame(Security::AUTHENTICATION_ERROR, SecurityContextInterface::AUTHENTICATION_ERROR);
+ $this->assertSame(Security::LAST_USERNAME, SecurityContextInterface::LAST_USERNAME);
+ }
}
diff --git a/Core/Tests/User/LdapUserProviderTest.php b/Core/Tests/User/LdapUserProviderTest.php
new file mode 100644
index 0000000..9b126e9
--- /dev/null
+++ b/Core/Tests/User/LdapUserProviderTest.php
@@ -0,0 +1,105 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\User;
+
+use Symfony\Component\Security\Core\User\LdapUserProvider;
+use Symfony\Component\Ldap\Exception\ConnectionException;
+
+/**
+ * @requires extension ldap
+ */
+class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
+ */
+ public function testLoadUserByUsernameFailsIfCantConnectToLdap()
+ {
+ $ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
+ $ldap
+ ->expects($this->once())
+ ->method('bind')
+ ->will($this->throwException(new ConnectionException()))
+ ;
+
+ $provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
+ $provider->loadUserByUsername('foo');
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
+ */
+ public function testLoadUserByUsernameFailsIfNoLdapEntries()
+ {
+ $ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
+ $ldap
+ ->expects($this->once())
+ ->method('escape')
+ ->will($this->returnValue('foo'))
+ ;
+
+ $provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
+ $provider->loadUserByUsername('foo');
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
+ */
+ public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
+ {
+ $ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
+ $ldap
+ ->expects($this->once())
+ ->method('escape')
+ ->will($this->returnValue('foo'))
+ ;
+ $ldap
+ ->expects($this->once())
+ ->method('find')
+ ->will($this->returnValue(array(
+ array(),
+ array(),
+ 'count' => 2,
+ )))
+ ;
+
+ $provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
+ $provider->loadUserByUsername('foo');
+ }
+
+ public function testSuccessfulLoadUserByUsername()
+ {
+ $ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
+ $ldap
+ ->expects($this->once())
+ ->method('escape')
+ ->will($this->returnValue('foo'))
+ ;
+ $ldap
+ ->expects($this->once())
+ ->method('find')
+ ->will($this->returnValue(array(
+ array(
+ 'sAMAccountName' => 'foo',
+ 'userpassword' => 'bar',
+ ),
+ 'count' => 1,
+ )))
+ ;
+
+ $provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
+ $this->assertInstanceOf(
+ 'Symfony\Component\Security\Core\User\User',
+ $provider->loadUserByUsername('foo')
+ );
+ }
+}
diff --git a/Core/Tests/Util/ClassUtilsTest.php b/Core/Tests/Util/ClassUtilsTest.php
index e8f0143..b048206 100644
--- a/Core/Tests/Util/ClassUtilsTest.php
+++ b/Core/Tests/Util/ClassUtilsTest.php
@@ -13,6 +13,9 @@ namespace Symfony\Component\Security\Core\Tests\Util
{
use Symfony\Component\Security\Core\Util\ClassUtils;
+ /**
+ * @group legacy
+ */
class ClassUtilsTest extends \PHPUnit_Framework_TestCase
{
public static function dataGetClass()
diff --git a/Core/Tests/Util/StringUtilsTest.php b/Core/Tests/Util/StringUtilsTest.php
index faeaf25..78d9b05 100644
--- a/Core/Tests/Util/StringUtilsTest.php
+++ b/Core/Tests/Util/StringUtilsTest.php
@@ -15,6 +15,8 @@ use Symfony\Component\Security\Core\Util\StringUtils;
/**
* Data from PHP.net's hash_equals tests.
+ *
+ * @group legacy
*/
class StringUtilsTest extends \PHPUnit_Framework_TestCase
{