@@ -165,6 +165,31 @@ public function testInvalidPasswordCustomEndpoint()
165
165
->assertRaised ();
166
166
}
167
167
168
+ public function testEndpointWithInvalidValueInReturn ()
169
+ {
170
+ $ returnValue = implode (
171
+ "\r\n" ,
172
+ [
173
+ '36039744C253F9B2A4E90CBEDB02EBFB82D:5 ' ,
174
+ 'This should not break the validator ' ,
175
+ '3686792BBC66A72D40D928ED15621124CFE:7 ' ,
176
+ '36EEC709091B810AA240179A44317ED415C:2 ' ,
177
+ '' ,
178
+ ]
179
+ );
180
+
181
+ $ validator = new NotCompromisedPasswordValidator (
182
+ $ this ->createHttpClientStub ($ returnValue ),
183
+ 'UTF-8 ' ,
184
+ true ,
185
+ 'https://password-check.internal.example.com/range/%s '
186
+ );
187
+
188
+ $ validator ->validate (self ::PASSWORD_NOT_LEAKED , new NotCompromisedPassword ());
189
+
190
+ $ this ->assertNoViolation ();
191
+ }
192
+
168
193
public function testInvalidConstraint ()
169
194
{
170
195
$ this ->expectException (UnexpectedTypeException::class);
@@ -202,11 +227,11 @@ public function provideErrorSkippingConstraints(): iterable
202
227
}
203
228
}
204
229
205
- private function createHttpClientStub (): HttpClientInterface
230
+ private function createHttpClientStub (? string $ returnValue = null ): HttpClientInterface
206
231
{
207
232
$ httpClientStub = $ this ->createMock (HttpClientInterface::class);
208
233
$ httpClientStub ->method ('request ' )->willReturnCallback (
209
- function (string $ method , string $ url ): ResponseInterface {
234
+ function (string $ method , string $ url ) use ( $ returnValue ) : ResponseInterface {
210
235
if (self ::PASSWORD_TRIGGERING_AN_ERROR_RANGE_URL === $ url<
8488
/span>) {
211
236
throw new class ('Problem contacting the Have I been Pwned API. ' ) extends \Exception implements ServerExceptionInterface {
212
237
public function getResponse (): ResponseInterface
@@ -219,7 +244,7 @@ public function getResponse(): ResponseInterface
219
244
$ responseStub = $ this ->createMock (ResponseInterface::class);
220
245
$ responseStub
221
246
->method ('getContent ' )
222
- ->willReturn (implode ("\r\n" , self ::RETURN ));
247
+ ->willReturn ($ returnValue ?? implode ("\r\n" , self ::RETURN ));
223
248
224
249
return $ responseStub ;
225
250
}
0 commit comments