8000 Renamed NotPwned to NotCompromisedPassword · symfony/symfony@2f648b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f648b0

Browse files
javiereguiluzfabpot
authored andcommitted
Renamed NotPwned to NotCompromisedPassword
1 parent 5fe3701 commit 2f648b0

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
4.3.0
55
-----
66

7-
* added `NotPwned` constraint
7+
* added `NotCompromisedPassword` constraint
88
* added options `iban` and `ibanPropertyPath` to Bic constraint
99
* added UATP cards support to `CardSchemeValidator`
1010
* added option `allowNull` to NotBlank constraint

src/Symfony/Component/Validator/Constraints/NotPwned.php renamed to src/Symfony/Component/Validator/Constraints/NotCompromisedPassword.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
*
2222
* @author Kévin Dunglas <dunglas@gmail.com>
2323
*/
24-
class NotPwned extends Constraint
24+
class NotCompromisedPassword extends Constraint
2525
{
26-
const PWNED_ERROR = 'd9bcdbfe-a9d6-4bfa-a8ff-da5fd93e0f6d';
26+
const COMPROMISED_PASSWORD_ERROR = 'd9bcdbfe-a9d6-4bfa-a8ff-da5fd93e0f6d';
2727

28-
protected static $errorNames = [self::PWNED_ERROR => 'PWNED_ERROR'];
28+
protected static $errorNames = [self::COMPROMISED_PASSWORD_ERROR => 'COMPROMISED_PASSWORD_ERROR'];
2929

3030
public $message = 'This password has been leaked in a data breach, it must not be used. Please use another password.';
3131
public $threshold = 1;

src/Symfony/Component/Validator/Constraints/NotPwnedValidator.php renamed to src/Symfony/Component/Validator/Constraints/NotCompromisedPasswordValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @author Kévin Dunglas <dunglas@gmail.com>
2828
*/
29-
class NotPwnedValidator extends ConstraintValidator
29+
class NotCompromisedPasswordValidator extends ConstraintValidator
3030
{
3131
private const RANGE_API = 'https://api.pwnedpasswords.com/range/%s';
3232

@@ -48,8 +48,8 @@ public function __construct(HttpClientInterface $httpClient = null)
4848
*/
4949
public function validate($value, Constraint $constraint)
5050
{
51-
if (!$constraint instanceof NotPwned) {
52-
throw new UnexpectedTypeException($constraint, NotPwned::class);
51+
if (!$constraint instanceof NotCompromisedPassword) {
52+
throw new UnexpectedTypeException($constraint, NotCompromisedPassword::class);
5353
}
5454

5555
if (null !== $value && !is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
@@ -80,7 +80,7 @@ public function validate($value, Constraint $constraint)
8080

8181
if ($hashPrefix.$hashSuffix === $hash && $constraint->threshold <= (int) $count) {
8282
$this->context->buildViolation($constraint->message)
83-
->setCode(NotPwned::PWNED_ERROR)
83+
->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR)
8484
->addViolation();
8585

8686
return;

src/Symfony/Component/Validator/Tests/Constraints/NotPwnedTest.php renamed to src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Validator\Constraints\NotPwned;
15+
use Symfony\Component\Validator\Constraints\NotCompromisedPassword;
1616

1717
/**
1818
* @author Kévin Dunglas <dunglas@gmail.com>
1919
*/
20-
class NotPwnedTest extends TestCase
20+
class NotCompromisedPasswordTest extends TestCase
2121
{
2222
public function testDefaultValues()
2323
{
24-
$constraint = new NotPwned();
24+
$constraint = new NotCompromisedPassword();
2525
$this->assertSame(1, $constraint->threshold);
2626
$this->assertFalse($constraint->skipOnError);
2727
}

src/Symfony/Component/Validator/Tests/Constraints/NotPwnedValidatorTest.php renamed to src/Symfony/Component/Validator/Tests/Constraints/NotCompromisedPasswordValidatorTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

1414
use Symfony\Component\Validator\Constraints\Luhn;
15-
use Symfony\Component\Validator\Constraints\NotPwned;
16-
use Symfony\Component\Validator\Constraints\NotPwnedValidator;
15+
use Symfony\Component\Validator\Constraints\NotCompromisedPassword;
16+
use Symfony\Component\Validator\Constraints\NotCompromisedPasswordValidator;
1717
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
1818
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
1919
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -22,7 +22,7 @@
2222
/**
2323
* @author Kévin Dunglas <dunglas@gmail.com>
2424
*/
25-
class NotPwnedValidatorTest extends ConstraintValidatorTestCase
25+
class NotCompromisedPasswordValidatorTest extends ConstraintValidatorTestCase
2626
{
2727
private const PASSWORD_TRIGGERING_AN_ERROR = 'apiError';
2828
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
6161
);
6262

6363
// Pass HttpClient::create() instead of this mock to run the tests against the real API
64-
return new NotPwnedValidator($httpClientStub);
64+
return new NotCompromisedPasswordValidator($httpClientStub);
6565
}
6666

6767
public function testNullIsValid()
6868
{
69-
$this->validator->validate(null, new NotPwned());
69+
$this->validator->validate(null, new NotCompromisedPassword());
7070

7171
$this->assertNoViolation();
7272
}
7373

7474
public function testEmptyStringIsValid()
7575
{
76-
$this->validator->validate('', new NotPwned());
76+
$this->validator->validate('', new NotCompromisedPassword());
7777

7878
$this->assertNoViolation();
7979
}
8080

8181
public function testInvalidPassword()
8282
{
83-
$constraint = new NotPwned();
83+
$constraint = new NotCompromisedPassword();
8484
$this->validator->validate(self::PASSWORD_LEAKED, $constraint);
8585

8686
$this->buildViolation($constraint->message)
87-
->setCode(NotPwned::PWNED_ERROR)
87+
->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR)
8888
->assertRaised();
8989
}
9090

9191
public function testThresholdReached()
9292
{
93-
$constraint = new NotPwned(['threshold' => 3]);
93+
$constraint = new NotCompromisedPassword(['threshold' => 3]);
9494
$this->validator->validate(self::PASSWORD_LEAKED, $constraint);
9595

9696
$this->buildViolation($constraint->message)
97-
->setCode(NotPwned::PWNED_ERROR)
97+
->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR)
9898
->assertRaised();
9999
}
100100

101101
public function testThresholdNotReached()
102102
{
103-
$this->validator->validate(self::PASSWORD_LEAKED, new NotPwned(['threshold' => 10]));
103+
$this->validator->validate(self::PASSWORD_LEAKED, new NotCompromisedPassword(['threshold' => 10]));
104104

105105
$this->assertNoViolation();
106106
}
107107

108108
public function testValidPassword()
109109
{
110-
$this->validator->validate(self::PASSWORD_NOT_LEAKED, new NotPwned());
110+
$this->validator->validate(self::PASSWORD_NOT_LEAKED, new NotCompromisedPassword());
111111

112112
$this->assertNoViolation();
113113
}
@@ -125,7 +125,7 @@ public function testInvalidConstraint()
125125
*/
126126
public function testInvalidValue()
127127
{
128-
$this->validator->validate([], new NotPwned());
128+
$this->validator->validate([], new NotCompromisedPassword());
129129
}
130130

131131
/**
@@ -134,12 +134,12 @@ public function testInvalidValue()
134134
*/
135135
public function testApiError()
136136
{
137-
$this->validator->validate(self::PASSWORD_TRIGGERING_AN_ERROR, new NotPwned());
137+
$this->validator->validate(self::PASSWORD_TRIGGERING_AN_ERROR, new NotCompromisedPassword());
138138
}
139139

140140
public function testApiErrorSkipped()
141141
{
142-
$this->validator->validate(self::PASSWORD_TRIGGERING_AN_ERROR, new NotPwned(['skipOnError' => true]));
142+
$this->validator->validate(self::PASSWORD_TRIGGERING_AN_ERROR, new NotCompromisedPassword(['skipOnError' => true]));
143143
$this->assertTrue(true); // No exception have been thrown
144144
}
145145
}

0 commit comments

Comments
 (0)
0