Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Various small improvements#293

Merged
KevinHock merged 6 commits into
masterfrom
various_small_improvements
Apr 16, 2020
Merged

Various small improvements#293
KevinHock merged 6 commits into
masterfrom
various_small_improvements

Conversation

@KevinHock
Copy link
Copy Markdown
Collaborator

@KevinHock KevinHock commented Apr 4, 2020

Hopefully this avoids needing fixes like ca266b1

Note: I excluded the script from `.pre-commit-config.yaml` to use f-strings
We can remove the exclusion when we drop python3.5 support
This fixes issue #269.
Previously we showed an unhelpful stack trace.
Missed a few in 5d0d461

Ran `grep -rnw --include=*.py -e 'future' | grep -v three_six | grep -v .tox` this time.
This fixes issue #244.
Only check the line for allowlist regexes or --exclude-lines if a secret was found.
@KevinHock KevinHock requested a review from OiCMudkips April 7, 2020 05:57
def _is_excluded_line(self, line):
return (
any(
allowlist_regex.search(line)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a test for this? I thought you needed to wrap the X for X in Y syntax in an array, but I might be wrong.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There is a test 👍

@pytest.mark.parametrize(
'content_to_format',
[
# Test inline annotation for allowlisting
"'{secret}' # pragma: allowlist secret",
"'{secret}' # pragma: allowlist secret more text",
"'{secret}' # pragma: allowlist secret",
"'{secret}' // pragma: allowlist secret",
"'{secret}' // pragma: allowlist secret",
"'{secret}' /* pragma: allowlist secret */",
"'{secret}' /* pragma: allowlist secret more text */",
"'{secret}' /* pragma: allowlist secret */",
"'{secret}' ' pragma: allowlist secret",
"'{secret}' ' pragma: allowlist secret",
"'{secret}' -- pragma: allowlist secret",
"'{secret}' -- pragma: allowlist secret",
"'{secret}' <!--pragma: allowlist secret-->",
"'{secret}' <!-- # pragma: allowlist secret -->",
"'{secret}' <!-- pragma: allowlist secret -->",
"'{secret}' <!-- pragma: allowlist secret -->",
# Test old inline annotation for backwards compatibility
"'{secret}' # pragma: whitelist secret",
# Test high entropy exclude regex
'"CanonicalUser": "{secret}"',
# Not a string
'{secret}',
# id occurs before the string, probably a false-positive
'id = "{secret}"',
],
)
def test_ignored_lines(self, content_to_format):
file_content = content_to_format.format(secret=self.secret)
f = mock_file_object(file_content)
results = self.logic.analyze(f, 'does_not_matter')
assert len(results) == 0

>>> san = [True, False, True]
>>> fran = {False}
>>> any(boo for boo in san)
True
>>> any(boo for boo in fran)
False

@KevinHock KevinHock merged commit 0e8925d into master Apr 16, 2020
@KevinHock KevinHock deleted the various_small_improvements branch April 16, 2020 20:54
killuazhu pushed a commit to IBM/detect-secrets that referenced this pull request May 28, 2020
killuazhu pushed a commit to IBM/detect-secrets that referenced this pull request Jul 9, 2020
killuazhu pushed a commit to IBM/detect-secrets that referenced this pull request Sep 17, 2020
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.

2 participants