Skip to content

Commit

Permalink
Adds "Add-Padding" header to not pwned verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Apr 21, 2021
1 parent aa74d01 commit 8d4e5a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Validation/NotPwnedVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ protected function getHash($value)
protected function search($hashPrefix)
{
try {
$response = $this->factory->get(
$response = $this->factory->withHeaders([
'Add-Padding' => true,
])->get(
'https://api.pwnedpasswords.com/range/'.$hashPrefix
);
} catch (Exception $e) {
Expand Down
21 changes: 20 additions & 1 deletion tests/Validation/ValidationNotPwnedVerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public function testApiResponseGoesWrong()
$httpFactory = m::mock(HttpFactory::class);
$response = m::mock(Response::class);

$httpFactory = m::mock(HttpFactory::class);

$httpFactory
->shouldReceive('withHeaders')
->with(['Add-Padding' => true])
->andThrow($httpFactory);

$httpFactory->shouldReceive('get')
->andReturn($response);

Expand All @@ -54,6 +61,11 @@ public function testApiGoesDown()
$httpFactory = m::mock(HttpFactory::class);
$response = m::mock(Response::class);

$httpFactory
->shouldReceive('withHeaders')
->with(['Add-Padding' => true])
->andThrow($httpFactory);

$httpFactory->shouldReceive('get')
->andReturn($response);

Expand All @@ -77,7 +89,14 @@ public function testDnsDown()
});

$httpFactory = m::mock(HttpFactory::class);
$httpFactory->shouldReceive('get')

$httpFactory
->shouldReceive('withHeaders')
->with(['Add-Padding' => true])
->andThrow($httpFactory);

$httpFactory
->shouldReceive('get')
->andThrow($exception);

$verifier = new NotPwnedVerifier($httpFactory);
Expand Down

0 comments on commit 8d4e5a0

Please sign in to comment.