Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Issue #122: fix scrubbing and provide test coverage #126

Merged
merged 59 commits into from
Apr 21, 2017

Conversation

ArturMoczulski
Copy link
Contributor

@ArturMoczulski ArturMoczulski commented Apr 11, 2017

This pull request covers the following GitHub issues: #122 #52 #31 #15
It's still work in progress but I encourage collaboration.

It includes work on the following:

  • provide test coverage for scrubbing of $_GET, $_POST, query string, request extras, headers, request body context, $_SESSION, server extras, Data::getCustom(), args and kwargs in frames as mentioned in POST_FORMAT.md, ::log() $extra param
  • add recursive scrubbing,
  • add recursive scrubbing of query strings,
  • remove code duplication and use a single point of scrubbing logic,
  • refactor placement of scrubbing logic to follow the Python SDK standard

MichaelMackus and others added 30 commits March 28, 2017 14:00
Uses manual recursion to enable scrubbing of entire array fields like
"Cookie".
This wasn't quite working very well before, and was masking values that
shouldn't have been masked. Turning on strict mode fixes this and should
be fairly backward compatible.
…t's not instance dependent; overwriting a constructor in PHPUnit tests is not common practice and there is no need for it in DataBuilderTest, move initialization to setUp(); cover DataBuilder::scrub with detailed scrubbing test case data
…ill stick with previous approach of testing through makeData()
… testGetRequest; wrote a test for DataBuilder::getUrl
…pty, return an empty array - no need to force nulls
…ramesWithContext so that changing source of tests/DataBuilderTest.php doesn't break PHPUnit test run
…t before sending out the request to Rollbar so all data can be scrubbed; test coverage for the GET arguments
@ArturMoczulski
Copy link
Contributor Author

This is ready for review


protected function scrub($arr, $fields, $replacement = '*')
public function scrubArray(&$arr, $replacement = '*')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these really need to be public?

@ArturMoczulski
Copy link
Contributor Author

@coryvirok Good point. I made them public earlier for unit testing, but since tests for scrub() already cover the same data structures no need to expose those methods. Just pushed a commit with a change fo this.

@coryvirok
Copy link
Contributor

Is there anything blocking this PR from being merged? cc @rokob

$val = str_repeat($replacement, 8);
}

$val = $dataBuilder->scrub($val, $replacement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not have this in an else block? It would seem that it is okay to not have it in an else because $val just ends up as the string '********' which scrub will just ignore, but why not avoid that call to scrub altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

@@ -28,6 +24,9 @@ public function setUp()
public function testMakeData()
{
$output = $this->dataBuilder->makeData(Level::fromName('error'), "testing", array());
/**
* @todo test for scrub data in makeData()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I'm going to clean this up.

@rokob
Copy link
Contributor

rokob commented Apr 19, 2017

LGTM besides some minor comments

@ArturMoczulski ArturMoczulski self-assigned this Apr 19, 2017
@ArturMoczulski ArturMoczulski added this to the v1.0.0 Release milestone Apr 19, 2017
@ArturMoczulski
Copy link
Contributor Author

ArturMoczulski commented Apr 19, 2017

@rokob @coryvirok
code climate brought up this code:
https://github.com/ArturMoczulski/rollbar-php/blob/github-122-scrubbing/src/RollbarLogger.php#L35-L40

with this message:
The method log uses an else expression. Else is never necessary and you can simplify the code to work without else.

Do you guys have any suggestion to how to structure this code to not use the else statement? The only way without an else block I can think of is, but that's worse in my opinion:

$response = new Response(0, "Ignored");     
   
if (!$this->config->checkIgnored($payload, $accessToken, $toLog)) {

            $scrubbed = $this->scrub($payload);

            $response = $this->config->send($scrubbed, $accessToken);

}

Also what do you guys about other items brought up by Code Climate?

@coryvirok
Copy link
Contributor

I would disregard the CodeClimate suggestion in this instance. As for the other items from CC, they're not high priority as long as we have good coverage. i.e. we can do a cleanup round after release.

@rokob
Copy link
Contributor

rokob commented Apr 20, 2017

Also, "never use else" seems like terrible advice.

@ArturMoczulski
Copy link
Contributor Author

ArturMoczulski commented Apr 21, 2017

@coryvirok @rokob All suggestions addressed so if there is nothing more this can be merged into master.

@rokob
Copy link
Contributor

rokob commented Apr 21, 2017

👍

@rokob rokob merged commit dc50f08 into rollbar:master Apr 21, 2017
@ArturMoczulski ArturMoczulski deleted the github-122-scrubbing branch April 29, 2017 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants