1212namespace Symfony \Component \Validator \Tests \Constraints ;
1313
1414use 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 ;
1717use Symfony \Component \Validator \Test \ConstraintValidatorTestCase ;
1818use Symfony \Contracts \HttpClient \Exception \ServerExceptionInterface ;
1919use Symfony \Contracts \HttpClient \HttpClientInterface ;
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