summaryrefslogtreecommitdiffstats
path: root/Tests/Core
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/Core')
-rw-r--r--Tests/Core/Authentication/AuthenticationProviderManagerTest.php4
-rw-r--r--Tests/Core/Authentication/Provider/DaoAuthenticationProviderTest.php23
-rw-r--r--Tests/Core/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php9
-rw-r--r--Tests/Core/Authentication/Provider/RememberMeAuthenticationProviderTest.php4
-rw-r--r--Tests/Core/Authentication/Provider/UserAuthenticationProviderTest.php60
-rw-r--r--Tests/Core/Authentication/Token/AbstractTokenTest.php41
-rw-r--r--Tests/Core/Authentication/Token/RememberMeTokenTest.php (renamed from Tests/Core/Authentication/Token/RememerMeTokenTest.php)2
-rw-r--r--Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php2
-rw-r--r--Tests/Core/Authorization/AccessDecisionManagerTest.php2
-rw-r--r--Tests/Core/Encoder/BCryptPasswordEncoderTest.php17
-rw-r--r--Tests/Core/Encoder/BasePasswordEncoderTest.php18
-rw-r--r--Tests/Core/Encoder/MessageDigestPasswordEncoderTest.php19
-rw-r--r--Tests/Core/Encoder/Pbkdf2PasswordEncoderTest.php19
-rw-r--r--Tests/Core/Encoder/PlaintextPasswordEncoderTest.php17
-rw-r--r--Tests/Core/User/InMemoryUserProviderTest.php (renamed from Tests/Core/User/InMemoryProviderTest.php)2
-rw-r--r--Tests/Core/User/UserCheckerTest.php (renamed from Tests/Core/User/AccountCheckerTest.php)32
-rw-r--r--Tests/Core/User/UserTest.php2
-rw-r--r--Tests/Core/Util/SecureRandomTest.php6
18 files changed, 225 insertions, 54 deletions
diff --git a/Tests/Core/Authentication/AuthenticationProviderManagerTest.php b/Tests/Core/Authentication/AuthenticationProviderManagerTest.php
index 12eb568..32e6cf7 100644
--- a/Tests/Core/Authentication/AuthenticationProviderManagerTest.php
+++ b/Tests/Core/Authentication/AuthenticationProviderManagerTest.php
@@ -20,7 +20,7 @@ use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase
{
/**
- * @expectedException InvalidArgumentException
+ * @expectedException \InvalidArgumentException
*/
public function testAuthenticateWithoutProviders()
{
@@ -129,7 +129,7 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase
} elseif (null !== $exception) {
$provider->expects($this->once())
->method('authenticate')
- ->will($this->throwException($this->getMock($exception, null, array(), '', false)))
+ ->will($this->throwException($this->getMock($exception, null, array(), '', true)))
;
}
diff --git a/Tests/Core/Authentication/Provider/DaoAuthenticationProviderTest.php b/Tests/Core/Authentication/Provider/DaoAuthenticationProviderTest.php
index 8b27061..35b14e8 100644
--- a/Tests/Core/Authentication/Provider/DaoAuthenticationProviderTest.php
+++ b/Tests/Core/Authentication/Provider/DaoAuthenticationProviderTest.php
@@ -14,6 +14,7 @@ namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider;
+use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
{
@@ -37,7 +38,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
$userProvider->expects($this->once())
->method('loadUserByUsername')
- ->will($this->throwException($this->getMock('Symfony\\Component\\Security\\Core\\Exception\\UsernameNotFoundException', null, array(), '', false)))
+ ->will($this->throwException(new UsernameNotFoundException()))
;
$provider = new DaoAuthenticationProvider($userProvider, $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface'), 'key', $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface'));
@@ -55,7 +56,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
$userProvider->expects($this->once())
->method('loadUserByUsername')
- ->will($this->throwException($this->getMock('RuntimeException', null, array(), '', false)))
+ ->will($this->throwException(new \RuntimeException()))
;
$provider = new DaoAuthenticationProvider($userProvider, $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface'), 'key', $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface'));
@@ -115,7 +116,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->method('isPasswordValid')
;
- $provider = $this->getProvider(false, false, $encoder);
+ $provider = $this->getProvider(null, null, $encoder);
$method = new \ReflectionMethod($provider, 'checkAuthentication');
$method->setAccessible(true);
@@ -142,7 +143,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(true))
;
- $provider = $this->getProvider(false, false, $encoder);
+ $provider = $this->getProvider(null, null, $encoder);
$method = new \ReflectionMethod($provider, 'checkAuthentication');
$method->setAccessible(true);
@@ -171,7 +172,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(false))
;
- $provider = $this->getProvider(false, false, $encoder);
+ $provider = $this->getProvider(null, null, $encoder);
$method = new \ReflectionMethod($provider, 'checkAuthentication');
$method->setAccessible(true);
@@ -206,7 +207,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue('newFoo'))
;
- $provider = $this->getProvider(false, false, null);
+ $provider = $this->getProvider();
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
$reflection->setAccessible(true);
$reflection->invoke($provider, $dbUser, $token);
@@ -231,7 +232,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue('foo'))
;
- $provider = $this->getProvider(false, false, null);
+ $provider = $this->getProvider();
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
$reflection->setAccessible(true);
$reflection->invoke($provider, $dbUser, $token);
@@ -245,7 +246,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(true))
;
- $provider = $this->getProvider(false, false, $encoder);
+ $provider = $this->getProvider(null, null, $encoder);
$method = new \ReflectionMethod($provider, 'checkAuthentication');
$method->setAccessible(true);
@@ -270,17 +271,17 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
return $mock;
}
- protected function getProvider($user = false, $userChecker = false, $passwordEncoder = null)
+ protected function getProvider($user = null, $userChecker = null, $passwordEncoder = null)
{
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
- if (false !== $user) {
+ if (null !== $user) {
$userProvider->expects($this->once())
->method('loadUserByUsername')
->will($this->returnValue($user))
;
}
- if (false === $userChecker) {
+ if (null === $userChecker) {
$userChecker = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface');
}
diff --git a/Tests/Core/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php b/Tests/Core/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php
index f7ffb1e..17234b6 100644
--- a/Tests/Core/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php
+++ b/Tests/Core/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php
@@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\PreAuthenticatedAuthenticationProvider;
+use Symfony\Component\Security\Core\Exception\LockedException;
class PreAuthenticatedAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
{
@@ -79,7 +80,7 @@ class PreAuthenticatedAuthenticationProviderTest extends \PHPUnit_Framework_Test
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker->expects($this->once())
->method('checkPostAuth')
- ->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\LockedException', null, array(), '', false)))
+ ->will($this->throwException(new LockedException()))
;
$provider = $this->getProvider($user, $userChecker);
@@ -114,17 +115,17 @@ class PreAuthenticatedAuthenticationProviderTest extends \PHPUnit_Framework_Test
return $token;
}
- protected function getProvider($user = false, $userChecker = false)
+ protected function getProvider($user = null, $userChecker = null)
{
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
- if (false !== $user) {
+ if (null !== $user) {
$userProvider->expects($this->once())
->method('loadUserByUsername')
->will($this->returnValue($user))
;
}
- if (false === $userChecker) {
+ if (null === $userChecker) {
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
}
diff --git a/Tests/Core/Authentication/Provider/RememberMeAuthenticationProviderTest.php b/Tests/Core/Authentication/Provider/RememberMeAuthenticationProviderTest.php
index 5e250e0..88eefbb 100644
--- a/Tests/Core/Authentication/Provider/RememberMeAuthenticationProviderTest.php
+++ b/Tests/Core/Authentication/Provider/RememberMeAuthenticationProviderTest.php
@@ -12,7 +12,7 @@
namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
-use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
+use Symfony\Component\Security\Core\Exception\AccountExpiredException;
use Symfony\Component\Security\Core\Role\Role;
class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
@@ -52,7 +52,7 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker->expects($this->once())
->method('checkPostAuth')
- ->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\AccountExpiredException', null, array(), '', false)))
+ ->will($this->throwException(new AccountExpiredException()))
;
$provider = $this->getProvider($userChecker);
diff --git a/Tests/Core/Authentication/Provider/UserAuthenticationProviderTest.php b/Tests/Core/Authentication/Provider/UserAuthenticationProviderTest.php
index 1516a5f..32f5b10 100644
--- a/Tests/Core/Authentication/Provider/UserAuthenticationProviderTest.php
+++ b/Tests/Core/Authentication/Provider/UserAuthenticationProviderTest.php
@@ -11,9 +11,12 @@
namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
-use Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider;
-use Symfony\Component\Security\Core\Role\Role;
+use Symfony\Component\Security\Core\Exception\AccountExpiredException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
+use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
+use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
+use Symfony\Component\Security\Core\Role\Role;
+use Symfony\Component\Security\Core\Role\SwitchUserRole;
class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
{
@@ -40,7 +43,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$provider = $this->getProvider(false, false);
$provider->expects($this->once())
->method('retrieveUser')
- ->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\UsernameNotFoundException', null, array(), '', false)))
+ ->will($this->throwException(new UsernameNotFoundException()))
;
$provider->authenticate($this->getSupportedToken());
@@ -54,7 +57,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$provider = $this->getProvider(false, true);
$provider->expects($this->once())
->method('retrieveUser')
- ->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\UsernameNotFoundException', null, array(), '', false)))
+ ->will($this->throwException(new UsernameNotFoundException()))
;
$provider->authenticate($this->getSupportedToken());
@@ -82,7 +85,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker->expects($this->once())
->method('checkPreAuth')
- ->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\CredentialsExpiredException', null, array(), '', false)))
+ ->will($this->throwException(new CredentialsExpiredException()))
;
$provider = $this->getProvider($userChecker);
@@ -102,7 +105,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker->expects($this->once())
->method('checkPostAuth')
- ->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\AccountExpiredException', null, array(), '', false)))
+ ->will($this->throwException(new AccountExpiredException()))
;
$provider = $this->getProvider($userChecker);
@@ -127,7 +130,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
;
$provider->expects($this->once())
->method('checkAuthentication')
- ->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\BadCredentialsException', null, array(), '', false)))
+ ->will($this->throwException(new BadCredentialsException()))
;
$provider->authenticate($this->getSupportedToken());
@@ -172,6 +175,11 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue('foo'))
;
+ $token->expects($this->once())
+ ->method('getRoles')
+ ->will($this->returnValue(array()))
+ ;
+
$authToken = $provider->authenticate($token);
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $authToken);
@@ -181,9 +189,45 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('foo' => 'bar'), $authToken->getAttributes(), '->authenticate() copies token attributes');
}
+ public function testAuthenticateWithPreservingRoleSwitchUserRole()
+ {
+ $user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+ $user->expects($this->once())
+ ->method('getRoles')
+ ->will($this->returnValue(array('ROLE_FOO')))
+ ;
+
+ $provider = $this->getProvider();
+ $provider->expects($this->once())
+ ->method('retrieveUser')
+ ->will($this->returnValue($user))
+ ;
+
+ $token = $this->getSupportedToken();
+ $token->expects($this->once())
+ ->method('getCredentials')
+ ->will($this->returnValue('foo'))
+ ;
+
+ $switchUserRole = new SwitchUserRole('foo', $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
+ $token->expects($this->once())
+ ->method('getRoles')
+ ->will($this->returnValue(array($switchUserRole)))
+ ;
+
+ $authToken = $provider->authenticate($token);
+
+ $this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $authToken);
+ $this->assertSame($user, $authToken->getUser());
+ $this->assertContains(new Role('ROLE_FOO'), $authToken->getRoles(), '', false, false);
+ $this->assertContains($switchUserRole, $authToken->getRoles());
+ $this->assertEquals('foo', $authToken->getCredentials());
+ $this->assertEquals(array('foo' => 'bar'), $authToken->getAttributes(), '->authenticate() copies token attributes');
+ }
+
protected function getSupportedToken()
{
- $mock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', array('getCredentials', 'getProviderKey'), array(), '', false);
+ $mock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', array('getCredentials', 'getProviderKey', 'getRoles'), array(), '', false);
$mock
->expects($this->any())
->method('getProviderKey')
diff --git a/Tests/Core/Authentication/Token/AbstractTokenTest.php b/Tests/Core/Authentication/Token/AbstractTokenTest.php
index 783c27e..5683b78 100644
--- a/Tests/Core/Authentication/Token/AbstractTokenTest.php
+++ b/Tests/Core/Authentication/Token/AbstractTokenTest.php
@@ -11,7 +11,9 @@
namespace Symfony\Component\Security\Tests\Core\Authentication\Token;
+use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
use Symfony\Component\Security\Core\Role\Role;
+use Symfony\Component\Security\Core\Role\SwitchUserRole;
class TestUser
{
@@ -28,6 +30,31 @@ class TestUser
}
}
+class ConcreteToken extends AbstractToken
+{
+ private $credentials = 'credentials_value';
+
+ public function __construct($user, array $roles = array())
+ {
+ parent::__construct($roles);
+
+ $this->setUser($user);
+ }
+
+ public function serialize()
+ {
+ return serialize(array($this->credentials, parent::serialize()));
+ }
+
+ public function unserialize($serialized)
+ {
+ list($this->credentials, $parentStr) = unserialize($serialized);
+ parent::unserialize($parentStr);
+ }
+
+ public function getCredentials() {}
+}
+
class AbstractTokenTest extends \PHPUnit_Framework_TestCase
{
public function testGetUsername()
@@ -71,6 +98,20 @@ class AbstractTokenTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($token->getAttributes(), $uToken->getAttributes());
}
+ public function testSerializeParent()
+ {
+ $user = new TestUser('fabien');
+ $token = new ConcreteToken($user, array('ROLE_FOO'));
+
+ $parentToken = new ConcreteToken($user, array(new SwitchUserRole('ROLE_PREVIOUS', $token)));
+ $uToken = unserialize(serialize($parentToken));
+
+ $this->assertEquals(
+ current($parentToken->getRoles())->getSource()->getUser(),
+ current($uToken->getRoles())->getSource()->getUser()
+ );
+ }
+
/**
* @covers Symfony\Component\Security\Core\Authentication\Token\AbstractToken::__construct
*/
diff --git a/Tests/Core/Authentication/Token/RememerMeTokenTest.php b/Tests/Core/Authentication/Token/RememberMeTokenTest.php
index 03275fa..cef3d28 100644
--- a/Tests/Core/Authentication/Token/RememerMeTokenTest.php
+++ b/Tests/Core/Authentication/Token/RememberMeTokenTest.php
@@ -53,7 +53,7 @@ class RememberMeTokenTest extends \PHPUnit_Framework_TestCase
}
/**
- * @expectedException PHPUnit_Framework_Error
+ * @expectedException \PHPUnit_Framework_Error
* @dataProvider getUserArguments
*/
public function testConstructorUserCannotBeNull($user)
diff --git a/Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php b/Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php
index 3da20eb..67f431f 100644
--- a/Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php
+++ b/Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php
@@ -28,7 +28,7 @@ class UsernamePasswordTokenTest extends \PHPUnit_Framework_TestCase
}
/**
- * @expectedException LogicException
+ * @expectedException \LogicException
*/
public function testSetAuthenticatedToTrue()
{
diff --git a/Tests/Core/Authorization/AccessDecisionManagerTest.php b/Tests/Core/Authorization/AccessDecisionManagerTest.php
index 1c706cc..b99423f 100644
--- a/Tests/Core/Authorization/AccessDecisionManagerTest.php
+++ b/Tests/Core/Authorization/AccessDecisionManagerTest.php
@@ -47,7 +47,7 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
}
/**
- * @expectedException InvalidArgumentException
+ * @expectedException \InvalidArgumentException
*/
public function testSetVotersEmpty()
{
diff --git a/Tests/Core/Encoder/BCryptPasswordEncoderTest.php b/Tests/Core/Encoder/BCryptPasswordEncoderTest.php
index 49c1051..dd962fd 100644
--- a/Tests/Core/Encoder/BCryptPasswordEncoderTest.php
+++ b/Tests/Core/Encoder/BCryptPasswordEncoderTest.php
@@ -70,4 +70,21 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('Requires PHP >= 5.3.7');
}
}
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
+ */
+ public function testEncodePasswordLength()
+ {
+ $encoder = new BCryptPasswordEncoder(self::VALID_COST);
+
+ $encoder->encodePassword(str_repeat('a', 5000), 'salt');
+ }
+
+ public function testCheckPasswordLength()
+ {
+ $encoder = new BCryptPasswordEncoder(self::VALID_COST);
+
+ $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), 'salt'));
+ }
}
diff --git a/Tests/Core/Encoder/BasePasswordEncoderTest.php b/Tests/Core/Encoder/BasePasswordEncoderTest.php
index 2ef1dcc..702efb0 100644
--- a/Tests/Core/Encoder/BasePasswordEncoderTest.php
+++ b/Tests/Core/Encoder/BasePasswordEncoderTest.php
@@ -46,13 +46,19 @@ class BasePasswordEncoderTest extends \PHPUnit_Framework_TestCase
}
/**
- * @expectedException InvalidArgumentException
+ * @expectedException \InvalidArgumentException
*/
public function testMergePasswordAndSaltWithException()
{
$this->invokeMergePasswordAndSalt('password', '{foo}');
}
+ public function testIsPasswordTooLong()
+ {
+ $this->assertTrue($this->invokeIsPasswordTooLong(str_repeat('a', 10000)));
+ $this->assertFalse($this->invokeIsPasswordTooLong(str_repeat('a', 10)));
+ }
+
protected function invokeDemergePasswordAndSalt($password)
{
$encoder = new PasswordEncoder();
@@ -82,4 +88,14 @@ class BasePasswordEncoderTest extends \PHPUnit_Framework_TestCase
return $m->invoke($encoder, $p1, $p2);
}
+
+ protected function invokeIsPasswordTooLong($p)
+ {
+ $encoder = new PasswordEncoder();
+ $r = new \ReflectionObject($encoder);
+ $m = $r->getMethod('isPasswordTooLong');
+ $m->setAccessible(true);
+
+ return $m->invoke($encoder, $p);
+ }
}
diff --git a/Tests/Core/Encoder/MessageDigestPasswordEncoderTest.php b/Tests/Core/Encoder/MessageDigestPasswordEncoderTest.php
index 64032c4..f37d3bc 100644
--- a/Tests/Core/Encoder/MessageDigestPasswordEncoderTest.php
+++ b/Tests/Core/Encoder/MessageDigestPasswordEncoderTest.php
@@ -35,11 +35,28 @@ class MessageDigestPasswordEncoderTest extends \PHPUnit_Framework_TestCase
}
/**
- * @expectedException LogicException
+ * @expectedException \LogicException
*/
public function testEncodePasswordAlgorithmDoesNotExist()
{
$encoder = new MessageDigestPasswordEncoder('foobar');
$encoder->encodePassword('password', '');
}
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
+ */
+ public function testEncodePasswordLength()
+ {
+ $encoder = new MessageDigestPasswordEncoder();
+
+ $encoder->encodePassword(str_repeat('a', 5000), 'salt');
+ }
+
+ public function testCheckPasswordLength()
+ {
+ $encoder = new MessageDigestPasswordEncoder();
+
+ $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), 'salt'));
+ }
}
diff --git a/Tests/Core/Encoder/Pbkdf2PasswordEncoderTest.php b/Tests/Core/Encoder/Pbkdf2PasswordEncoderTest.php
index 2c98543..ca16f02 100644
--- a/Tests/Core/Encoder/Pbkdf2PasswordEncoderTest.php
+++ b/Tests/Core/Encoder/Pbkdf2PasswordEncoderTest.php
@@ -35,11 +35,28 @@ class Pbkdf2PasswordEncoderTest extends \PHPUnit_Framework_TestCase
}
/**
- * @expectedException LogicException
+ * @expectedException \LogicException
*/
public function testEncodePasswordAlgorithmDoesNotExist()
{
$encoder = new Pbkdf2PasswordEncoder('foobar');
$encoder->encodePassword('password', '');
}
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
+ */
+ public function testEncodePasswordLength()
+ {
+ $encoder = new Pbkdf2PasswordEncoder('foobar');
+
+ $encoder->encodePassword(str_repeat('a', 5000), 'salt');
+ }
+
+ public function testCheckPasswordLength()
+ {
+ $encoder = new Pbkdf2PasswordEncoder('foobar');
+
+ $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), 'salt'));
+ }
}
diff --git a/Tests/Core/Encoder/PlaintextPasswordEncoderTest.php b/Tests/Core/Encoder/PlaintextPasswordEncoderTest.php
index af0008f..8b1b888 100644
--- a/Tests/Core/Encoder/PlaintextPasswordEncoderTest.php
+++ b/Tests/Core/Encoder/PlaintextPasswordEncoderTest.php
@@ -36,4 +36,21 @@ class PlaintextPasswordEncoderTest extends \PHPUnit_Framework_TestCase
$this->assertSame('foo', $encoder->encodePassword('foo', ''));
}
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
+ */
+ public function testEncodePasswordLength()
+ {
+ $encoder = new PlaintextPasswordEncoder();
+
+ $encoder->encodePassword(str_repeat('a', 5000), 'salt');
+ }
+
+ public function testCheckPasswordLength()
+ {
+ $encoder = new PlaintextPasswordEncoder();
+
+ $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), 'salt'));
+ }
}
diff --git a/Tests/Core/User/InMemoryProviderTest.php b/Tests/Core/User/InMemoryUserProviderTest.php
index 5197a29..275426c 100644
--- a/Tests/Core/User/InMemoryProviderTest.php
+++ b/Tests/Core/User/InMemoryUserProviderTest.php
@@ -42,7 +42,7 @@ class InMemoryUserProviderTest extends \PHPUnit_Framework_TestCase
}
/**
- * @expectedException LogicException
+ * @expectedException \LogicException
*/
public function testCreateUserAlreadyExist()
{
diff --git a/Tests/Core/User/AccountCheckerTest.php b/Tests/Core/User/UserCheckerTest.php
index f28067f..dca6311 100644
--- a/Tests/Core/User/AccountCheckerTest.php
+++ b/Tests/Core/User/UserCheckerTest.php
@@ -15,44 +15,44 @@ use Symfony\Component\Security\Core\User\UserChecker;
class UserCheckerTest extends \PHPUnit_Framework_TestCase
{
- public function testCheckPreAuthNotAdvancedUserInterface()
+ public function testCheckPostAuthNotAdvancedUserInterface()
{
$checker = new UserChecker();
- $this->assertNull($checker->checkPreAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
+ $this->assertNull($checker->checkPostAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
}
- public function testCheckPreAuthPass()
+ public function testCheckPostAuthPass()
{
$checker = new UserChecker();
$account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(true));
- $this->assertNull($checker->checkPreAuth($account));
+ $this->assertNull($checker->checkPostAuth($account));
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\CredentialsExpiredException
*/
- public function testCheckPreAuthCredentialsExpired()
+ public function testCheckPostAuthCredentialsExpired()
{
$checker = new UserChecker();
$account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(false));
- $checker->checkPreAuth($account);
+ $checker->checkPostAuth($account);
}
- public function testCheckPostAuthNotAdvancedUserInterface()
+ public function testCheckPreAuthNotAdvancedUserInterface()
{
$checker = new UserChecker();
- $this->assertNull($checker->checkPostAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
+ $this->assertNull($checker->checkPreAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
}
- public function testCheckPostAuthPass()
+ public function testCheckPreAuthPass()
{
$checker = new UserChecker();
@@ -61,26 +61,26 @@ class UserCheckerTest extends \PHPUnit_Framework_TestCase
$account->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
$account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(true));
- $this->assertNull($checker->checkPostAuth($account));
+ $this->assertNull($checker->checkPreAuth($account));
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException
*/
- public function testCheckPostAuthAccountLocked()
+ public function testCheckPreAuthAccountLocked()
{
$checker = new UserChecker();
$account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
$account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(false));
- $checker->checkPostAuth($account);
+ $checker->checkPreAuth($account);
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
*/
- public function testCheckPostAuthDisabled()
+ public function testCheckPreAuthDisabled()
{
$checker = new UserChecker();
@@ -88,13 +88,13 @@ class UserCheckerTest extends \PHPUnit_Framework_TestCase
$account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(true));
$account->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
- $checker->checkPostAuth($account);
+ $checker->checkPreAuth($account);
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException
*/
- public function testCheckPostAuthAccountExpired()
+ public function testCheckPreAuthAccountExpired()
{
$checker = new UserChecker();
@@ -103,6 +103,6 @@ class UserCheckerTest extends \PHPUnit_Framework_TestCase
$account->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
$account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(false));
- $checker->checkPostAuth($account);
+ $checker->checkPreAuth($account);
}
}
diff --git a/Tests/Core/User/UserTest.php b/Tests/Core/User/UserTest.php
index 26e562f..d05f491 100644
--- a/Tests/Core/User/UserTest.php
+++ b/Tests/Core/User/UserTest.php
@@ -17,7 +17,7 @@ class UserTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Symfony\Component\Security\Core\User\User::__construct
- * @expectedException InvalidArgumentException
+ * @expectedException \InvalidArgumentException
*/
public function testConstructorException()
{
diff --git a/Tests/Core/Util/SecureRandomTest.php b/Tests/Core/Util/SecureRandomTest.php
index c7ed016..05b4b02 100644
--- a/Tests/Core/Util/SecureRandomTest.php
+++ b/Tests/Core/Util/SecureRandomTest.php
@@ -68,7 +68,7 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase
$runs[$i] = 0;
}
- $addRun = function($run) use (&$runs) {
+ $addRun = function ($run) use (&$runs) {
if ($run > 6) {
$run = 6;
}
@@ -111,8 +111,8 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase
{
$b = $this->getBitSequence($secureRandom, 20000);
- $longestRun = 0;
- $currentRun = $lastBit = null;
+ $longestRun = $currentRun = 0;
+ $lastBit = null;
for ($i = 0; $i < 20000; $i++) {
if ($lastBit === $b[$i]) {
$currentRun += 1;