diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index 70528f35117e9..c44c49bee8c33 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 4.3.0 ----- - * added `NotPwned` constraint + * added `NotCompromisedPassword` constraint * added options `iban` and `ibanPropertyPath` to Bic constraint * added UATP cards support to `CardSchemeValidator` * added option `allowNull` to NotBlank constraint diff --git a/src/Symfony/Component/Validator/Constraints/NotPwned.php b/src/Symfony/Component/Validator/Constraints/NotCompromisedPassword.php similarity index 75% rename from src/Symfony/Component/Validator/Constraints/NotPwned.php rename to src/Symfony/Component/Validator/Constraints/NotCompromisedPassword.php index 9872076b73546..d38cab1a92a21 100644 --- a/src/Symfony/Component/Validator/Constraints/NotPwned.php +++ b/src/Symfony/Component/Validator/Constraints/NotCompromisedPassword.php @@ -21,11 +21,11 @@ * * @author Kévin Dunglas */ -class NotPwned extends Constraint +class NotCompromisedPassword extends Constraint { - const PWNED_ERROR = 'd9bcdbfe-a9d6-4bfa-a8ff-da5fd93e0f6d'; + const COMPROMISED_PASSWORD_ERROR = 'd9bcdbfe-a9d6-4bfa-a8ff-da5fd93e0f6d'; - protected static $errorNames = [self::PWNED_ERROR => 'PWNED_ERROR']; + protected static $errorNames = [self::COMPROMISED_PASSWORD_ERROR => 'COMPROMISED_PASSWORD_ERROR']; public $message = 'This password has been leaked in a data breach, it must not be used. Please use another password.'; public $threshold = 1; diff --git a/src/Symfony/Component/Validator/Constraints/NotPwnedValidator.php b/src/Symfony/Component/Validator/Constraints/NotCompromisedPasswordValidator.php similarity index 89% rename from src/Symfony/Component/Validator/Constraints/NotPwnedValidator.php rename to src/Symfony/Component/Validator/Constraints/NotCompromisedPasswordValidator.php index d0beffb4f285b..7abdbf23b26e8 100644 --- a/src/Symfony/Component/Validator/Constraints/NotPwnedValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotCompromisedPasswordValidator.php @@ -26,7 +26,7 @@ * * @author Kévin Dunglas */ -class NotPwnedValidator extends ConstraintValidator +class NotCompromisedPasswordValidator extends ConstraintValidator { private const RANGE_API = 'https://api.pwnedpasswords.com/range/%s'; @@ -48,8 +48,8 @@ public function __construct(HttpClientInterface $httpClient = null) */ public function validate($value, Constraint $constraint) { - if (!$constraint instanceof NotPwned) { - throw new UnexpectedTypeException($constraint, NotPwned::class); + if (!$constraint instanceof NotCompromisedPassword) { + throw new UnexpectedTypeException($constraint, NotCompromisedPassword::class); } if (null !== $value && !is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) { @@ -80,7 +80,7 @@ public function validate($value, Constraint $constraint) if ($hashPrefix.$hashSuffix === $hash && $constraint->threshold <= (int) $count) { $this->context->buildViolation($constraint->message) - ->setCode(NotPwned::PWNED_ERROR) + ->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR) ->addViolation(); return; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotPwnedTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordTest.php similarity index 76% rename from src/Symfony/Component/Validator/Tests/Constraints/NotPwnedTest.php rename to src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordTest.php index 7d312d828190b..4ae9b8e852b06 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotPwnedTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordTest.php @@ -12,16 +12,16 @@ namespace Symfony\Component\Validator\Tests\Constraints; use PHPUnit\Framework\TestCase; -use Symfony\Component\Validator\Constraints\NotPwned; +use Symfony\Component\Validator\Constraints\NotCompromisedPassword; /** * @author Kévin Dunglas */ -class NotPwnedTest extends TestCase +class NotCompromisedPasswordTest extends TestCase { public function testDefaultValues() { - $constraint = new NotPwned(); + $constraint = new NotCompromisedPassword(); $this->assertSame(1, $constraint->threshold); $this->assertFalse($constraint->skipOnError); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotPwnedValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordValidatorTest.php similarity index 81% rename from src/Symfony/Component/Validator/Tests/Constraints/NotPwnedValidatorTest.php rename to src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordValidatorTest.php index 845ddbde3959f..d80ed94b52d6d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotPwnedValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordValidatorTest.php @@ -12,8 +12,8 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Luhn; -use Symfony\Component\Validator\Constraints\NotPwned; -use Symfony\Component\Validator\Constraints\NotPwnedValidator; +use Symfony\Component\Validator\Constraints\NotCompromisedPassword; +use Symfony\Component\Validator\Constraints\NotCompromisedPasswordValidator; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -22,7 +22,7 @@ /** * @author Kévin Dunglas */ -class NotPwnedValidatorTest extends ConstraintValidatorTestCase +class NotCompromisedPasswordValidatorTest extends ConstraintValidatorTestCase { private const PASSWORD_TRIGGERING_AN_ERROR = 'apiError'; private const PASSWORD_TRIGGERING_AN_ERROR_RANGE_URL = 'https://api.pwnedpasswords.com/range/3EF27'; // https://api.pwnedpasswords.com/range/3EF27 is the range for the value "apiError" @@ -61,53 +61,53 @@ public function getResponse(): ResponseInterface ); // Pass HttpClient::create() instead of this mock to run the tests against the real API - return new NotPwnedValidator($httpClientStub); + return new NotCompromisedPasswordValidator($httpClientStub); } public function testNullIsValid() { - $this->validator->validate(null, new NotPwned()); + $this->validator->validate(null, new NotCompromisedPassword()); $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->validator->validate('', new NotPwned()); + $this->validator->validate('', new NotCompromisedPassword()); $this->assertNoViolation(); } public function testInvalidPassword() { - $constraint = new NotPwned(); + $constraint = new NotCompromisedPassword(); $this->validator->validate(self::PASSWORD_LEAKED, $constraint); $this->buildViolation($constraint->message) - ->setCode(NotPwned::PWNED_ERROR) + ->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR) ->assertRaised(); } public function testThresholdReached() { - $constraint = new NotPwned(['threshold' => 3]); + $constraint = new NotCompromisedPassword(['threshold' => 3]); $this->validator->validate(self::PASSWORD_LEAKED, $constraint); $this->buildViolation($constraint->message) - ->setCode(NotPwned::PWNED_ERROR) + ->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR) ->assertRaised(); } public function testThresholdNotReached() { - $this->validator->validate(self::PASSWORD_LEAKED, new NotPwned(['threshold' => 10])); + $this->validator->validate(self::PASSWORD_LEAKED, new NotCompromisedPassword(['threshold' => 10])); $this->assertNoViolation(); } public function testValidPassword() { - $this->validator->validate(self::PASSWORD_NOT_LEAKED, new NotPwned()); + $this->validator->validate(self::PASSWORD_NOT_LEAKED, new NotCompromisedPassword()); $this->assertNoViolation(); } @@ -125,7 +125,7 @@ public function testInvalidConstraint() */ public function testInvalidValue() { - $this->validator->validate([], new NotPwned()); + $this->validator->validate([], new NotCompromisedPassword()); } /** @@ -134,12 +134,12 @@ public function testInvalidValue() */ public function testApiError() { - $this->validator->validate(self::PASSWORD_TRIGGERING_AN_ERROR, new NotPwned()); + $this->validator->validate(self::PASSWORD_TRIGGERING_AN_ERROR, new NotCompromisedPassword()); } public function testApiErrorSkipped() { - $this->validator->validate(self::PASSWORD_TRIGGERING_AN_ERROR, new NotPwned(['skipOnError' => true])); + $this->validator->validate(self::PASSWORD_TRIGGERING_AN_ERROR, new NotCompromisedPassword(['skipOnError' => true])); $this->assertTrue(true); // No exception have been thrown } }