@@ -62,9 +62,9 @@ public function testEmptyStringIsValid()
62
62
63
63
public function testInvalidPasswordButDisabled ()
64
64
{
65
- $ r = new \ReflectionProperty ($ this ->validator , 'disabled ' );
65
+ $ r = new \ReflectionProperty ($ this ->validator , 'enabled ' );
66
66
$ r ->setAccessible (true );
67
- $ r ->setValue ($ this ->validator , true );
67
+ $ r ->setValue ($ this ->validator , false );
68
68
69
69
$ this ->validator ->validate (self ::PASSWORD_LEAKED , new NotCompromisedPassword ());
70
70
@@ -128,6 +128,29 @@ public function testNonUtf8CharsetInvalid()
128
128
->assertRaised ();
129
129
}
130
130
131
+ public function testInvalidPasswordCustomEndpoint ()
132
+ {
133
+ $ endpoint = 'https://password-check.internal.example.com/range/%s ' ;
134
+ // 50D74 - first 5 bytes of uppercase SHA1 hash of self::PASSWORD_LEAKED
135
+ $ expectedEndpointUrl = 'https://password-check.internal.example.com/range/50D74 ' ;
136
+ $ constraint = new NotCompromisedPassword ();
137
+
138
+ $ this ->context = $ this ->createContext ();
139
+
140
+ $ validator = new NotCompromisedPasswordValidator (
141
+ $ this ->createHttpClientStubCustomEndpoint ($ expectedEndpointUrl ),
142
+ 'UTF-8 ' ,
143
+ true ,
144
+ $ endpoint
145
+ );
146
+ $ validator ->initialize ($ this ->context );
147
+ $ validator ->validate (self ::PASSWORD_LEAKED , $ constraint );
148
+
149
+ $ this ->buildViolation ($ constraint ->message )
150
+ ->setCode (NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR )
151
+ ->assertRaised ();
152
+ }
153
+
131
154
/**
132
155
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
133
156
*/
@@ -184,4 +207,21 @@ public function getResponse(): ResponseInterface
184
207
185
208
return $ httpClientStub ;
186
209
}
210
+
211
+ private function createHttpClientStubCustomEndpoint ($ expectedEndpoint ): HttpClientInterface
212
+ {
213
+ $ httpClientStub = $ this ->createMock (HttpClientInterface::class);
214
+ $ httpClientStub ->method ('request ' )->with ('GET ' , $ expectedEndpoint )->will (
215
+ $ this ->returnCallback (function (string $ method , string $ url ): ResponseInterface {
216
+ $ responseStub = $ this ->createMock (ResponseInterface::class);
217
+ $ responseStub
218
+ ->method ('getContent ' )
219
+ ->willReturn (implode ("\r\n" , self ::RETURN ));
220
+
221
+ return $ responseStub ;
222
+ })
223
+ );
224
+
225
+ return $ httpClientStub ;
226
+ }
187
227
}
0 commit comments