summaryrefslogtreecommitdiffstats
path: root/Core/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Core/Tests')
-rw-r--r--Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php15
-rw-r--r--Core/Tests/Authorization/AccessDecisionManagerTest.php56
-rw-r--r--Core/Tests/Authorization/DebugAccessDecisionManagerTest.php43
-rw-r--r--Core/Tests/Authorization/Voter/AbstractVoterTest.php129
-rw-r--r--Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php6
-rw-r--r--Core/Tests/Authorization/Voter/ExpressionVoterTest.php9
-rw-r--r--Core/Tests/Authorization/Voter/Fixtures/MyVoter.php27
-rw-r--r--Core/Tests/Authorization/Voter/RoleVoterTest.php7
-rw-r--r--Core/Tests/LegacySecurityContextTest.php132
-rw-r--r--Core/Tests/User/LdapUserProviderTest.php214
-rw-r--r--Core/Tests/Util/ClassUtilsTest.php53
-rw-r--r--Core/Tests/Util/StringUtilsTest.php63
-rw-r--r--Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php26
13 files changed, 248 insertions, 532 deletions
diff --git a/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php
index aae3c76..9359f86 100644
--- a/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php
+++ b/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php
@@ -11,10 +11,13 @@
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
+use Symfony\Component\Ldap\LdapInterface;
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;
+use Symfony\Component\Security\Core\User\UserCheckerInterface;
+use Symfony\Component\Security\Core\User\UserProviderInterface;
/**
* @requires extension ldap
@@ -44,14 +47,14 @@ class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testBindFailureShouldThrowAnException()
{
- $userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
- $ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
+ $userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
+ $ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
$ldap
->expects($this->once())
->method('bind')
->will($this->throwException(new ConnectionException()))
;
- $userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
+ $userChecker = $this->getMockBuilder(UserCheckerInterface::class)->getMock();
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
@@ -62,15 +65,15 @@ class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
public function testRetrieveUser()
{
- $userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
+ $userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
$userProvider
->expects($this->once())
->method('loadUserByUsername')
->with('foo')
;
- $ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
+ $ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
- $userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
+ $userChecker = $this->getMockBuilder(UserCheckerInterface::class)->getMock();
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
$reflection = new \ReflectionMethod($provider, 'retrieveUser');
diff --git a/Core/Tests/Authorization/AccessDecisionManagerTest.php b/Core/Tests/Authorization/AccessDecisionManagerTest.php
index 94b9820..8aace21 100644
--- a/Core/Tests/Authorization/AccessDecisionManagerTest.php
+++ b/Core/Tests/Authorization/AccessDecisionManagerTest.php
@@ -17,42 +17,6 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
{
/**
- * @group legacy
- */
- public function testSupportsClass()
- {
- $manager = new AccessDecisionManager(array(
- $this->getVoterSupportsClass(true),
- $this->getVoterSupportsClass(false),
- ));
- $this->assertTrue($manager->supportsClass('FooClass'));
-
- $manager = new AccessDecisionManager(array(
- $this->getVoterSupportsClass(false),
- $this->getVoterSupportsClass(false),
- ));
- $this->assertFalse($manager->supportsClass('FooClass'));
- }
-
- /**
- * @group legacy
- */
- public function testSupportsAttribute()
- {
- $manager = new AccessDecisionManager(array(
- $this->getVoterSupportsAttribute(true),
- $this->getVoterSupportsAttribute(false),
- ));
- $this->assertTrue($manager->supportsAttribute('foo'));
-
- $manager = new AccessDecisionManager(array(
- $this->getVoterSupportsAttribute(false),
- $this->getVoterSupportsAttribute(false),
- ));
- $this->assertFalse($manager->supportsAttribute('foo'));
- }
-
- /**
* @expectedException \InvalidArgumentException
*/
public function testSetUnsupportedStrategy()
@@ -173,24 +137,4 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
return $voter;
}
-
- protected function getVoterSupportsClass($ret)
- {
- $voter = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface')->getMock();
- $voter->expects($this->any())
- ->method('supportsClass')
- ->will($this->returnValue($ret));
-
- return $voter;
- }
-
- protected function getVoterSupportsAttribute($ret)
- {
- $voter = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface')->getMock();
- $voter->expects($this->any())
- ->method('supportsAttribute')
- ->will($this->returnValue($ret));
-
- return $voter;
- }
}
diff --git a/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php b/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php
new file mode 100644
index 0000000..bbca8ba
--- /dev/null
+++ b/Core/Tests/Authorization/DebugAccessDecisionManagerTest.php
@@ -0,0 +1,43 @@
+<?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;
+
+use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
+use Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager;
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+
+class DebugAccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @dataProvider provideObjectsAndLogs
+ */
+ public function testDecideLog($expectedLog, $object)
+ {
+ $adm = new DebugAccessDecisionManager(new AccessDecisionManager());
+ $adm->decide($this->getMockBuilder(TokenInterface::class)->getMock(), array('ATTRIBUTE_1'), $object);
+
+ $this->assertSame($expectedLog, $adm->getDecisionLog());
+ }
+
+ public function provideObjectsAndLogs()
+ {
+ $object = new \stdClass();
+
+ yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'NULL', 'result' => false)), null);
+ yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'boolean (true)', 'result' => false)), true);
+ yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'string (jolie string)', 'result' => false)), 'jolie string');
+ yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'integer (12345)', 'result' => false)), 12345);
+ yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'resource', 'result' => false)), fopen(__FILE__, 'r'));
+ yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => 'array', 'result' => false)), array());
+ yield array(array(array('attributes' => array('ATTRIBUTE_1'), 'object' => sprintf('stdClass (object hash: %s)', spl_object_hash($object)), 'result' => false)), $object);
+ }
+}
diff --git a/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/Core/Tests/Authorization/Voter/AbstractVoterTest.php
deleted file mode 100644
index 558d4af..0000000
--- a/Core/Tests/Authorization/Voter/AbstractVoterTest.php
+++ /dev/null
@@ -1,129 +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\Authorization\Voter;
-
-use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
-
-/**
- * @group legacy
- */
-class AbstractVoterTest extends \PHPUnit_Framework_TestCase
-{
- /**
- * @var TokenInterface
- */
- protected $token;
-
- protected function setUp()
- {
- $this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
- }
-
- /**
- * @return array
- */
- 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 Fixtures\MyVoter();
-
- $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
- }
-
- /**
- * @return array
- */
- public function getSupportsAttributeData()
- {
- return array(
- 'positive_string_edit' => array(
- 'expected' => true,
- 'attribute' => 'EDIT',
- 'message' => 'expected TRUE given as attribute EDIT is supported',
- ),
- 'positive_string_create' => array(
- 'expected' => true,
- 'attribute' => 'CREATE',
- 'message' => 'expected TRUE as given attribute CREATE is supported',
- ),
-
- 'negative_string_read' => array(
- 'expected' => false,
- 'attribute' => 'READ',
- 'message' => 'expected FALSE as given attribute READ is not supported',
- ),
- 'negative_string_random' => array(
- 'expected' => false,
- 'attribute' => 'random',
- 'message' => 'expected FALSE as given attribute "random" is not supported',
- ),
- 'negative_string_0' => array(
- 'expected' => false,
- 'attribute' => '0',
- 'message' => 'expected FALSE as given attribute "0" is not supported',
- ),
- // this set of data gives false positive if in_array is not used with strict flag set to 'true'
- 'negative_int_0' => array(
- 'expected' => false,
- 'attribute' => 0,
- 'message' => 'expected FALSE as given attribute 0 is not string',
- ),
- 'negative_int_1' => array(
- 'expected' => false,
- 'attribute' => 1,
- 'message' => 'expected FALSE as given attribute 1 is not string',
- ),
- 'negative_int_7' => array(
- 'expected' => false,
- 'attribute' => 7,
- 'message' => 'expected FALSE as attribute 7 is not string',
- ),
- );
- }
-
- /**
- * @dataProvider getSupportsAttributeData
- *
- * @param bool $expected
- * @param string $attribute
- * @param string $message
- */
- public function testSupportsAttribute($expected, $attribute, $message)
- {
- $voter = new Fixtures\MyVoter();
-
- $this->assertEquals($expected, $voter->supportsAttribute($attribute), $message);
- }
-}
diff --git a/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php b/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php
index a59848c..d685f0f 100644
--- a/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php
+++ b/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php
@@ -17,12 +17,6 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
class AuthenticatedVoterTest extends \PHPUnit_Framework_TestCase
{
- public function testSupportsClass()
- {
- $voter = new AuthenticatedVoter($this->getResolver());
- $this->assertTrue($voter->supportsClass('stdClass'));
- }
-
/**
* @dataProvider getVoteTests
*/
diff --git a/Core/Tests/Authorization/Voter/ExpressionVoterTest.php b/Core/Tests/Authorization/Voter/ExpressionVoterTest.php
index 0770039..714e6a0 100644
--- a/Core/Tests/Authorization/Voter/ExpressionVoterTest.php
+++ b/Core/Tests/Authorization/Voter/ExpressionVoterTest.php
@@ -17,15 +17,6 @@ use Symfony\Component\Security\Core\Role\Role;
class ExpressionVoterTest extends \PHPUnit_Framework_TestCase
{
- public function testSupportsAttribute()
- {
- $expression = $this->createExpression();
- $expressionLanguage = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\ExpressionLanguage')->getMock();
- $voter = new ExpressionVoter($expressionLanguage, $this->createTrustResolver(), $this->createRoleHierarchy());
-
- $this->assertTrue($voter->supportsAttribute($expression));
- }
-
/**
* @dataProvider getVoteTests
*/
diff --git a/Core/Tests/Authorization/Voter/Fixtures/MyVoter.php b/Core/Tests/Authorization/Voter/Fixtures/MyVoter.php
deleted file mode 100644
index b75f798..0000000
--- a/Core/Tests/Authorization/Voter/Fixtures/MyVoter.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?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/RoleVoterTest.php b/Core/Tests/Authorization/Voter/RoleVoterTest.php
index ce4f4cf..5918fd8 100644
--- a/Core/Tests/Authorization/Voter/RoleVoterTest.php
+++ b/Core/Tests/Authorization/Voter/RoleVoterTest.php
@@ -17,13 +17,6 @@ use Symfony\Component\Security\Core\Role\Role;
class RoleVoterTest extends \PHPUnit_Framework_TestCase
{
- public function testSupportsClass()
- {
- $voter = new RoleVoter();
-
- $this->assertTrue($voter->supportsClass('Foo'));
- }
-
/**
* @dataProvider getVoteTests
*/
diff --git a/Core/Tests/LegacySecurityContextTest.php b/Core/Tests/LegacySecurityContextTest.php
deleted file mode 100644
index 0c9cc51..0000000
--- a/Core/Tests/LegacySecurityContextTest.php
+++ /dev/null
@@ -1,132 +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\Security;
-use Symfony\Component\Security\Core\SecurityContext;
-use Symfony\Component\Security\Core\SecurityContextInterface;
-
-/**
- * @group legacy
- */
-class LegacySecurityContextTest extends \PHPUnit_Framework_TestCase
-{
- private $tokenStorage;
- private $authorizationChecker;
- private $securityContext;
-
- protected function setUp()
- {
- $this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
- $this->authorizationChecker = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')->getMock();
- $this->securityContext = new SecurityContext($this->tokenStorage, $this->authorizationChecker);
- }
-
- public function testGetTokenDelegation()
- {
- $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
-
- $this->tokenStorage
- ->expects($this->once())
- ->method('getToken')
- ->will($this->returnValue($token));
-
- $this->assertTrue($token === $this->securityContext->getToken());
- }
-
- public function testSetTokenDelegation()
- {
- $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
-
- $this->tokenStorage
- ->expects($this->once())
- ->method('setToken')
- ->with($token);
-
- $this->securityContext->setToken($token);
- }
-
- /**
- * @dataProvider isGrantedDelegationProvider
- */
- public function testIsGrantedDelegation($attributes, $object, $return)
- {
- $this->authorizationChecker
- ->expects($this->once())
- ->method('isGranted')
- ->with($attributes, $object)
- ->will($this->returnValue($return));
-
- $this->assertEquals($return, $this->securityContext->isGranted($attributes, $object));
- }
-
- public function isGrantedDelegationProvider()
- {
- return array(
- array(array(), new \stdClass(), true),
- array(array('henk'), new \stdClass(), false),
- array(null, new \stdClass(), false),
- array('henk', null, true),
- array(array(1), 'henk', true),
- );
- }
-
- /**
- * Test dedicated to check if the backwards compatibility is still working.
- */
- public function testOldConstructorSignature()
- {
- $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock();
- $accessDecisionManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock();
- new SecurityContext($authenticationManager, $accessDecisionManager);
- }
-
- /**
- * @dataProvider oldConstructorSignatureFailuresProvider
- * @expectedException \BadMethodCallException
- */
- public function testOldConstructorSignatureFailures($first, $second)
- {
- new SecurityContext($first, $second);
- }
-
- public function oldConstructorSignatureFailuresProvider()
- {
- $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
- $authorizationChecker = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')->getMock();
- $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock();
- $accessDecisionManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock();
-
- return array(
- array(new \stdClass(), new \stdClass()),
- array($tokenStorage, $accessDecisionManager),
- array($accessDecisionManager, $tokenStorage),
- array($authorizationChecker, $accessDecisionManager),
- array($accessDecisionManager, $authorizationChecker),
- array($tokenStorage, $accessDecisionManager),
- array($authenticationManager, $authorizationChecker),
- array('henk', 'hans'),
- array(null, false),
- 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
index a8fc261..a1ef0bb 100644
--- a/Core/Tests/User/LdapUserProviderTest.php
+++ b/Core/Tests/User/LdapUserProviderTest.php
@@ -11,6 +11,10 @@
namespace Symfony\Component\Security\Core\Tests\User;
+use Symfony\Component\Ldap\Adapter\CollectionInterface;
+use Symfony\Component\Ldap\Adapter\QueryInterface;
+use Symfony\Component\Ldap\Entry;
+use Symfony\Component\Ldap\LdapInterface;
use Symfony\Component\Security\Core\User\LdapUserProvider;
use Symfony\Component\Ldap\Exception\ConnectionException;
@@ -24,7 +28,7 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testLoadUserByUsernameFailsIfCantConnectToLdap()
{
- $ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
+ $ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
$ldap
->expects($this->once())
->method('bind')
@@ -40,12 +44,29 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testLoadUserByUsernameFailsIfNoLdapEntries()
{
- $ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
+ $result = $this->getMockBuilder(CollectionInterface::class)->getMock();
+ $query = $this->getMockBuilder(QueryInterface::class)->getMock();
+ $query
+ ->expects($this->once())
+ ->method('execute')
+ ->will($this->returnValue($result))
+ ;
+ $result
+ ->expects($this->once())
+ ->method('count')
+ ->will($this->returnValue(0))
+ ;
+ $ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
$ldap
->expects($this->once())
->method('escape')
->will($this->returnValue('foo'))
;
+ $ldap
+ ->expects($this->once())
+ ->method('query')
+ ->will($this->returnValue($query))
+ ;
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
$provider->loadUserByUsername('foo');
@@ -56,7 +77,19 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
*/
public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
{
- $ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
+ $result = $this->getMockBuilder(CollectionInterface::class)->getMock();
+ $query = $this->getMockBuilder(QueryInterface::class)->getMock();
+ $query
+ ->expects($this->once())
+ ->method('execute')
+ ->will($this->returnValue($result))
+ ;
+ $result
+ ->expects($this->once())
+ ->method('count')
+ ->will($this->returnValue(2))
+ ;
+ $ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
$ldap
->expects($this->once())
->method('escape')
@@ -64,21 +97,42 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
;
$ldap
->expects($this->once())
- ->method('find')
- ->will($this->returnValue(array(
- array(),
- array(),
- 'count' => 2,
- )))
+ ->method('query')
+ ->will($this->returnValue($query))
;
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
$provider->loadUserByUsername('foo');
}
- public function testSuccessfulLoadUserByUsername()
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
+ */
+ public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
{
- $ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
+ $result = $this->getMockBuilder(CollectionInterface::class)->getMock();
+ $query = $this->getMockBuilder(QueryInterface::class)->getMock();
+ $query
+ ->expects($this->once())
+ ->method('execute')
+ ->will($this->returnValue($result))
+ ;
+ $ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
+ $result
+ ->expects($this->once())
+ ->method('offsetGet')
+ ->with(0)
+ ->will($this->returnValue(new Entry('foo', array(
+ 'sAMAccountName' => array('foo'),
+ 'userpassword' => array('bar', 'baz'),
+ )
+ )))
+ ;
+ $result
+ ->expects($this->once())
+ ->method('count')
+ ->will($this->returnValue(1))
+ ;
$ldap
->expects($this->once())
->method('escape')
@@ -86,15 +140,96 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
;
$ldap
->expects($this->once())
- ->method('find')
- ->will($this->returnValue(array(
- array(
- 'sAMAccountName' => 'foo',
- 'userpassword' => 'bar',
- ),
- 'count' => 1,
+ ->method('query')
+ ->will($this->returnValue($query))
+ ;
+
+ $provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, array(), 'sAMAccountName', '({uid_key}={username})', 'userpassword');
+ $this->assertInstanceOf(
+ 'Symfony\Component\Security\Core\User\User',
+ $provider->loadUserByUsername('foo')
+ );
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
+ */
+ public function testLoadUserByUsernameFailsIfEntryHasNoPasswordAttribute()
+ {
+ $result = $this->getMockBuilder(CollectionInterface::class)->getMock();
+ $query = $this->getMockBuilder(QueryInterface::class)->getMock();
+ $query
+ ->expects($this->once())
+ ->method('execute')
+ ->will($this->returnValue($result))
+ ;
+ $ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
+ $result
+ ->expects($this->once())
+ ->method('offsetGet')
+ ->with(0)
+ ->will($this->returnValue(new Entry('foo', array(
+ 'sAMAccountName' => array('foo'),
+ )
)))
;
+ $result
+ ->expects($this->once())
+ ->method('count')
+ ->will($this->returnValue(1))
+ ;
+ $ldap
+ ->expects($this->once())
+ ->method('escape')
+ ->will($this->returnValue('foo'))
+ ;
+ $ldap
+ ->expects($this->once())
+ ->method('query')
+ ->will($this->returnValue($query))
+ ;
+
+ $provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, array(), 'sAMAccountName', '({uid_key}={username})', 'userpassword');
+ $this->assertInstanceOf(
+ 'Symfony\Component\Security\Core\User\User',
+ $provider->loadUserByUsername('foo')
+ );
+ }
+
+ public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttribute()
+ {
+ $result = $this->getMockBuilder(CollectionInterface::class)->getMock();
+ $query = $this->getMockBuilder(QueryInterface::class)->getMock();
+ $query
+ ->expects($this->once())
+ ->method('execute')
+ ->will($this->returnValue($result))
+ ;
+ $ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
+ $result
+ ->expects($this->once())
+ ->method('offsetGet')
+ ->with(0)
+ ->will($this->returnValue(new Entry('foo', array(
+ 'sAMAccountName' => array('foo'),
+ )
+ )))
+ ;
+ $result
+ ->expects($this->once())
+ ->method('count')
+ ->will($this->returnValue(1))
+ ;
+ $ldap
+ ->expects($this->once())
+ ->method('escape')
+ ->will($this->returnValue('foo'))
+ ;
+ $ldap
+ ->expects($this->once())
+ ->method('query')
+ ->will($this->returnValue($query))
+ ;
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
$this->assertInstanceOf(
@@ -102,4 +237,47 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
$provider->loadUserByUsername('foo')
);
}
+
+ public function testLoadUserByUsernameIsSuccessfulWithPasswordAttribute()
+ {
+ $result = $this->getMockBuilder(CollectionInterface::class)->getMock();
+ $query = $this->getMockBuilder(QueryInterface::class)->getMock();
+ $query
+ ->expects($this->once())
+ ->method('execute')
+ ->will($this->returnValue($result))
+ ;
+ $ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
+ $result
+ ->expects($this->once())
+ ->method('offsetGet')
+ ->with(0)
+ ->will($this->returnValue(new Entry('foo', array(
+ 'sAMAccountName' => array('foo'),
+ 'userpassword' => array('bar'),
+ )
+ )))
+ ;
+ $result
+ ->expects($this->once())
+ ->method('count')
+ ->will($this->returnValue(1))
+ ;
+ $ldap
+ ->expects($this->once())
+ ->method('escape')
+ ->will($this->returnValue('foo'))
+ ;
+ $ldap
+ ->expects($this->once())
+ ->method('query')
+ ->will($this->returnValue($query))
+ ;
+
+ $provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, array(), 'sAMAccountName', '({uid_key}={username})', 'userpassword');
+ $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
deleted file mode 100644
index b048206..0000000
--- a/Core/Tests/Util/ClassUtilsTest.php
+++ /dev/null
@@ -1,53 +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\Util
-{
- use Symfony\Component\Security\Core\Util\ClassUtils;
-
- /**
- * @group legacy
- */
- class ClassUtilsTest extends \PHPUnit_Framework_TestCase
- {
- public static function dataGetClass()
- {
- return array(
- array('stdClass', 'stdClass'),
- array('Symfony\Component\Security\Core\Util\ClassUtils', 'Symfony\Component\Security\Core\Util\ClassUtils'),
- array('MyProject\Proxies\__CG__\stdClass', 'stdClass'),
- array('MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass', 'stdClass'),
- array('MyProject\Proxies\__CG__\Symfony\Component\Security\Core\Tests\Util\ChildObject', 'Symfony\Component\Security\Core\Tests\Util\ChildObject'),
- array(new TestObject(), 'Symfony\Component\Security\Core\Tests\Util\TestObject'),
- array(new \Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Core\Tests\Util\TestObject(), 'Symfony\Component\Security\Core\Tests\Util\TestObject'),
- );
- }
-
- /**
- * @dataProvider dataGetClass
- */
- public function testGetRealClass($object, $expectedClassName)
- {
- $this->assertEquals($expectedClassName, ClassUtils::getRealClass($object));
- }
- }
-
- class TestObject
- {
- }
-}
-
-namespace Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Core\Tests\Util
-{
- class TestObject extends \Symfony\Component\Security\Core\Tests\Util\TestObject
- {
- }
-}
diff --git a/Core/Tests/Util/StringUtilsTest.php b/Core/Tests/Util/StringUtilsTest.php
deleted file mode 100644
index 78d9b05..0000000
--- a/Core/Tests/Util/StringUtilsTest.php
+++ /dev/null
@@ -1,63 +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\Util;
-
-use Symfony\Component\Security\Core\Util\StringUtils;
-
-/**
- * Data from PHP.net's hash_equals tests.
- *
- * @group legacy
- */
-class StringUtilsTest extends \PHPUnit_Framework_TestCase
-{
- public function dataProviderTrue()
- {
- return array(
- array('same', 'same'),
- array('', ''),
- array(123, 123),
- array(null, ''),
- array(null, null),
- );
- }
-
- public function dataProviderFalse()
- {
- return array(
- array('not1same', 'not2same'),
- array('short', 'longer'),
- array('longer', 'short'),
- array('', 'notempty'),
- array('notempty', ''),
- array(123, 'NaN'),
- array('NaN', 123),
- array(null, 123),
- );
- }
-
- /**
- * @dataProvider dataProviderTrue
- */
- public function testEqualsTrue($known, $user)
- {
- $this->assertTrue(StringUtils::equals($known, $user));
- }
-
- /**
- * @dataProvider dataProviderFalse
- */
- public function testEqualsFalse($known, $user)
- {
- $this->assertFalse(StringUtils::equals($known, $user));
- }
-}
diff --git a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php
deleted file mode 100644
index f7da8c0..0000000
--- a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php
+++ /dev/null
@@ -1,26 +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\Validator\Constraints;
-
-use Symfony\Component\Validator\Validation;
-
-/**
- * @author Bernhard Schussek <bschussek@gmail.com>
- * @group legacy
- */
-class LegacyUserPasswordValidatorTest extends UserPasswordValidatorTest
-{
- protected function getApiVersion()
- {
- return Validation::API_VERSION_2_5_BC;
- }
-}