@@ -62,9 +62,9 @@ public function testEmptyStringIsValid()
6262
6363 public function testInvalidPasswordButDisabled ()
6464 {
65- $ r = new \ReflectionProperty ($ this ->validator , 'disabled ' );
65+ $ r = new \ReflectionProperty ($ this ->validator , 'enabled ' );
6666 $ r ->setAccessible (true );
67- $ r ->setValue ($ this ->validator , true );
67+ $ r ->setValue ($ this ->validator , false );
6868
6969 $ this ->validator ->validate (self ::PASSWORD_LEAKED , new NotCompromisedPassword ());
7070
@@ -128,6 +128,29 @@ public function testNonUtf8CharsetInvalid()
128128 ->assertRaised ();
129129 }
130130
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+
131154 /**
132155 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
133156 */
@@ -184,4 +207,21 @@ public function getResponse(): ResponseInterface
184207
185208 return $ httpClientStub ;
186209 }
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+ }
187227}
0 commit comments