12
12
namespace Symfony \Component \Validator \Tests \Constraints ;
13
13
14
14
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 ;
17
17
use Symfony \Component \Validator \Test \ConstraintValidatorTestCase ;
18
18
use Symfony \Contracts \HttpClient \Exception \ServerExceptionInterface ;
19
19
use Symfony \Contracts \HttpClient \HttpClientInterface ;
22
22
/**
23
23
* @author Kévin Dunglas <dunglas@gmail.com>
24
24
*/
25
- class NotPwnedValidatorTest extends ConstraintValidatorTestCase
25
+ class NotCompromisedPasswordValidatorTest extends ConstraintValidatorTestCase
26
26
{
27
27
private const PASSWORD_TRIGGERING_AN_ERROR = 'apiError ' ;
28
28
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
61
61
);
62
62
63
63
// 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 );
65
65
}
66
66
67
67
public function testNullIsValid ()
68
68
{
69
- $ this ->validator ->validate (null , new NotPwned ());
69
+ $ this ->validator ->validate (null , new NotCompromisedPassword ());
70
70
71
71
$ this ->assertNoViolation ();
72
72
}
73
73
74
74
public function testEmptyStringIsValid ()
75
75
{
76
- $ this ->validator ->validate ('' , new NotPwned ());
76
+ $ this ->validator ->validate ('' , new NotCompromisedPassword ());
77
77
78
78
$ this ->assertNoViolation ();
79
79
}
80
80
81
81
public function testInvalidPassword ()
82
82
{
83
- $ constraint = new NotPwned ();
83
+ $ constraint = new NotCompromisedPassword ();
84
84
$ this ->validator ->validate (self ::PASSWORD_LEAKED , $ constraint );
85
85
86
86
$ this ->buildViolation ($ constraint ->message )
87
- ->setCode (NotPwned:: PWNED_ERROR )
87
+ ->setCode (NotCompromisedPassword:: COMPROMISED_PASSWORD_ERROR )
88
88
->assertRaised ();
89
89
}
90
90
91
91
public function testThresholdReached ()
92
92
{
93
- $ constraint = new NotPwned (['threshold ' => 3 ]);
93
+ $ constraint = new NotCompromisedPassword (['threshold ' => 3 ]);
94
94
$ this ->validator ->validate (self ::PASSWORD_LEAKED , $ constraint );
95
95
96
96
$ this ->buildViolation ($ constraint ->message )
97
- ->setCode (NotPwned:: PWNED_ERROR )
97
+ ->setCode (NotCompromisedPassword:: COMPROMISED_PASSWORD_ERROR )
98
98
->assertRaised ();
99
99
}
100
100
101
101
public function testThresholdNotReached ()
102
102
{
103
- $ this ->validator ->validate (self ::PASSWORD_LEAKED , new NotPwned (['threshold ' => 10 ]));
103
+ $ this ->validator ->validate (self ::PASSWORD_LEAKED , new NotCompromisedPassword (['threshold ' => 10 ]));
104
104
105
105
$ this ->assertNoViolation ();
106
106
}
107
107
108
108
public function testValidPassword ()
109
109
{
110
- $ this ->validator ->validate (self ::PASSWORD_NOT_LEAKED , new NotPwned ());
110
+ $ this ->validator ->validate (self ::PASSWORD_NOT_LEAKED , new NotCompromisedPassword ());
111
111
112
112
$ this ->assertNoViolation ();
113
113
}
@@ -125,7 +125,7 @@ public function testInvalidConstraint()
125
125
*/
126
126
public function testInvalidValue ()
127
127
{
128
- $ this ->validator ->validate ([], new NotPwned ());
128
+ $ this ->validator ->validate ([], new NotCompromisedPassword ());
129
129
}
130
130
131
131
/**
@@ -134,12 +134,12 @@ public function testInvalidValue()
134
134
*/
135
135
public function testApiError ()
136
136
{
137
- $ this ->validator ->validate (self ::PASSWORD_TRIGGERING_AN_ERROR , new NotPwned ());
137
+ $ this ->validator ->validate (self ::PASSWORD_TRIGGERING_AN_ERROR , new NotCompromisedPassword ());
138
138
}
139
139
140
140
public function testApiErrorSkipped ()
141
141
{
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 ]));
143
143
$ this ->assertTrue (true ); // No exception have been thrown
144
144
}
145
145
}
0 commit comments