-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from facade/censor-request-body
Add ability to censor request body fields
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Facade\FlareClient\Middleware; | ||
|
||
use Facade\FlareClient\Report; | ||
|
||
class CensorRequestBodyFields | ||
{ | ||
protected $fieldNames = []; | ||
|
||
public function __construct(array $fieldNames) | ||
{ | ||
$this->fieldNames = $fieldNames; | ||
} | ||
|
||
public function handle(Report $report, $next) | ||
{ | ||
$context = $report->allContext(); | ||
|
||
foreach ($this->fieldNames as $fieldName) { | ||
if (isset($context['request_data']['body'][$fieldName])) { | ||
$context['request_data']['body'][$fieldName] = '<CENSORED>'; | ||
} | ||
} | ||
|
||
$report->userProvidedContext($context); | ||
|
||
return $next($report); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,23 @@ public function it_can_anonymize_the_ip() | |
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_censor_request_data() | ||
{ | ||
$_ENV['FLARE_FAKE_WEB_REQUEST'] = true; | ||
$_POST['user'] = '[email protected]'; | ||
$_POST['password'] = 'secret'; | ||
|
||
$this->flare->censorRequestBodyFields(['user', 'password']); | ||
|
||
$this->reportException(); | ||
|
||
$this->fakeClient->assertLastRequestContains('context.request_data.body', [ | ||
'user' => '<CENSORED>', | ||
'password' => '<CENSORED>', | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_merge_user_provided_context() | ||
{ | ||
|