summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Schussek <bschussek@gmail.com>2014-08-14 18:37:29 +0200
committerBernhard Schussek <bschussek@gmail.com>2014-08-14 18:37:29 +0200
commit8ad895b224583c8951cc1a54e598f145e145c309 (patch)
tree05c6877e38d499ffb0e6fac66b058bfc6118c4e6
parentc9c0c03e7130db4affa4f22365189ea4e3677cf2 (diff)
parent79b843690e5ec9df6f0184756c702d96579b41e0 (diff)
downloadsymfony-security-8ad895b224583c8951cc1a54e598f145e145c309.zip
symfony-security-8ad895b224583c8951cc1a54e598f145e145c309.tar.gz
symfony-security-8ad895b224583c8951cc1a54e598f145e145c309.tar.bz2
Merge branch '2.5'
* 2.5: (37 commits) [Validator] Backported constraint validator tests from 2.5 [Validator] Backported constraint validator tests from 2.5 [DIC] Fixed: anonymous services are always private Fix toolbar vertical alignment. [HttpFoundation] MongoDbSessionHandler supports auto expiry via configurable expiry_field [Validator] Fix little typo in ExecutionContextInterface::buildViolation() method comments fix dependencies on HttpFoundation component [FrameworkBundle] add missing attribute to XSD Allow basic auth in url. Improve regex. Add tests. fix typos and syntax in Profiler controller method comments resolve parameters before the configs are processed add symfony/yaml suggestion to composer.json [HttpKernel] added an analyze of environment parameters for built-in server. remove volatile tests [Console] fixed style creation when providing an unknown tag option change command to which available under most unix systems add way to test command under windows fix shell command injection [Form] allowed CallbackTransformer to use callable [Process] Added process synchronization to the incremental output tests ... Conflicts: src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/HttpKernel/composer.json src/Symfony/Component/Validator/Constraints/AllValidator.php src/Symfony/Component/Validator/Constraints/CollectionValidator.php src/Symfony/Component/Validator/Constraints/LegacyAllValidator.php src/Symfony/Component/Validator/Constraints/LegacyCollectionValidator.php src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php
-rw-r--r--Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php26
-rw-r--r--Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorLegacyApiTest.php26
-rw-r--r--Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php129
3 files changed, 125 insertions, 56 deletions
diff --git a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php
new file mode 100644
index 0000000..4cba363
--- /dev/null
+++ b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.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\Validator\Constraints;
+
+use Symfony\Component\Validator\Validation;
+
+/**
+ * @since 2.5.4
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class LegacyUserPasswordValidator2Dot4ApiTest extends UserPasswordValidatorTest
+{
+ protected function getApiVersion()
+ {
+ return Validation::API_VERSION_2_4;
+ }
+}
diff --git a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorLegacyApiTest.php b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorLegacyApiTest.php
new file mode 100644
index 0000000..5092a79
--- /dev/null
+++ b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorLegacyApiTest.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\Validator\Constraints;
+
+use Symfony\Component\Validator\Validation;
+
+/**
+ * @since 2.5.4
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class LegacyUserPasswordValidatorLegacyApiTest extends UserPasswordValidatorTest
+{
+ protected function getApiVersion()
+ {
+ return Validation::API_VERSION_2_5_BC;
+ }
+}
diff --git a/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php b/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php
index 53eeb5f..10f692c 100644
--- a/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php
+++ b/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php
@@ -11,77 +11,102 @@
namespace Symfony\Component\Security\Core\Tests\Validator\Constraints;
+use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
+use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
+use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator;
+use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
+use Symfony\Component\Validator\Validation;
-class UserPasswordValidatorTest extends \PHPUnit_Framework_TestCase
+/**
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class UserPasswordValidatorTest extends AbstractConstraintValidatorTest
{
- const PASSWORD_VALID = true;
- const PASSWORD_INVALID = false;
+ const PASSWORD = 's3Cr3t';
- protected $context;
+ const SALT = '^S4lt$';
- protected function setUp()
+ /**
+ * @var SecurityContextInterface
+ */
+ protected $securityContext;
+
+ /**
+ * @var PasswordEncoderInterface
+ */
+ protected $encoder;
+
+ /**
+ * @var EncoderFactoryInterface
+ */
+ protected $encoderFactory;
+
+ protected function getApiVersion()
{
- $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
+ return Validation::API_VERSION_2_5;
}
- protected function tearDown()
+ protected function createValidator()
{
- $this->context = null;
+ return new UserPasswordValidator($this->securityContext, $this->encoderFactory);
}
- public function testPasswordIsValid()
+ protected function setUp()
{
$user = $this->createUser();
- $securityContext = $this->createSecurityContext($user);
+ $this->securityContext = $this->createSecurityContext($user);
+ $this->encoder = $this->createPasswordEncoder();
+ $this->encoderFactory = $this->createEncoderFactory($this->encoder);
- $encoder = $this->createPasswordEncoder(static::PASSWORD_VALID);
- $encoderFactory = $this->createEncoderFactory($encoder);
+ parent::setUp();
+ }
+
+ public function testPasswordIsValid()
+ {
+ $constraint = new UserPassword(array(
+ 'message' => 'myMessage',
+ ));
- $validator = new UserPasswordValidator($securityContext, $encoderFactory);
- $validator->initialize($this->context);
+ $this->encoder->expects($this->once())
+ ->method('isPasswordValid')
+ ->with(static::PASSWORD, 'secret', static::SALT)
+ ->will($this->returnValue(true));
- $this
- ->context
- ->expects($this->never())
- ->method('addViolation')
- ;
+ $this->validator->validate('secret', $constraint);
- $validator->validate('secret', new UserPassword());
+ $this->assertNoViolation();
}
public function testPasswordIsNotValid()
{
- $user = $this->createUser();
- $securityContext = $this->createSecurityContext($user);
-
- $encoder = $this->createPasswordEncoder(static::PASSWORD_INVALID);
- $encoderFactory = $this->createEncoderFactory($encoder);
+ $constraint = new UserPassword(array(
+ 'message' => 'myMessage',
+ ));
- $validator = new UserPasswordValidator($securityContext, $encoderFactory);
- $validator->initialize($this->context);
+ $this->encoder->expects($this->once())
+ ->method('isPasswordValid')
+ ->with(static::PASSWORD, 'secret', static::SALT)
+ ->will($this->returnValue(false));
- $this
- ->context
- ->expects($this->once())
- ->method('addViolation')
- ;
+ $this->validator->validate('secret', $constraint);
- $validator->validate('secret', new UserPassword());
+ $this->assertViolation('myMessage');
}
+ /**
+ * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
+ */
public function testUserIsNotValid()
{
- $this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
-
$user = $this->getMock('Foo\Bar\User');
- $encoderFactory = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
- $securityContext = $this->createSecurityContext($user);
- $validator = new UserPasswordValidator($securityContext, $encoderFactory);
- $validator->initialize($this->context);
- $validator->validate('secret', new UserPassword());
+ $this->securityContext = $this->createSecurityContext($user);
+ $this->validator = $this->createValidator();
+ $this->validator->initialize($this->context);
+
+ $this->validator->validate('secret', new UserPassword());
}
protected function createUser()
@@ -89,15 +114,15 @@ class UserPasswordValidatorTest extends \PHPUnit_Framework_TestCase
$mock = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$mock
- ->expects($this->once())
+ ->expects($this->any())
->method('getPassword')
- ->will($this->returnValue('s3Cr3t'))
+ ->will($this->returnValue(static::PASSWORD))
;
$mock
- ->expects($this->once())
+ ->expects($this->any())
->method('getSalt')
- ->will($this->returnValue('^S4lt$'))
+ ->will($this->returnValue(static::SALT))
;
return $mock;
@@ -105,15 +130,7 @@ class UserPasswordValidatorTest extends \PHPUnit_Framework_TestCase
protected function createPasswordEncoder($isPasswordValid = true)
{
- $mock = $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
-
- $mock
- ->expects($this->once())
- ->method('isPasswordValid')
- ->will($this->returnValue($isPasswordValid))
- ;
-
- return $mock;
+ return $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
}
protected function createEncoderFactory($encoder = null)
@@ -121,7 +138,7 @@ class UserPasswordValidatorTest extends \PHPUnit_Framework_TestCase
$mock = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
$mock
- ->expects($this->once())
+ ->expects($this->any())
->method('getEncoder')
->will($this->returnValue($encoder))
;
@@ -135,7 +152,7 @@ class UserPasswordValidatorTest extends \PHPUnit_Framework_TestCase
$mock = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
$mock
- ->expects($this->once())
+ ->expects($this->any())
->method('getToken')
->will($this->returnValue($token))
;
@@ -147,7 +164,7 @@ class UserPasswordValidatorTest extends \PHPUnit_Framework_TestCase
{
$mock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$mock
- ->expects($this->once())
+ ->expects($this->any())
->method('getUser')
->will($this->returnValue($user))
;