From 878198cefae028386c6dc800ccbf18f2b9cbff3f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 14 Jul 2017 16:01:02 +0200 Subject: [PATCH] [Security] validate empty passwords again --- .../Constraints/UserPasswordValidatorTest.php | 23 +++++++++++++++++++ .../Constraints/UserPasswordValidator.php | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php b/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php index 7ebe65c647..942a4a6350 100644 --- a/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php @@ -90,6 +90,29 @@ abstract class UserPasswordValidatorTest extends AbstractConstraintValidatorTest ->assertRaised(); } + /** + * @dataProvider emptyPasswordData + */ + public function testEmptyPasswordsAreNotValid($password) + { + $constraint = new UserPassword(array( + 'message' => 'myMessage', + )); + + $this->validator->validate($password, $constraint); + + $this->buildViolation('myMessage') + ->assertRaised(); + } + + public function emptyPasswordData() + { + return array( + array(null), + array(''), + ); + } + /** * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException */ diff --git a/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php b/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php index 5f4c146cab..c2ab13b2f6 100644 --- a/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php +++ b/src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php @@ -40,6 +40,8 @@ class UserPasswordValidator extends ConstraintValidator } if (null === $password || '' === $password) { + $this->context->addViolation($constraint->message); + return; }