-
Notifications
You must be signed in to change notification settings - Fork 448
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 #169 from dgzlopes/add-stripe-plugin
Add Stripe detector to plugins
- Loading branch information
Showing
7 changed files
with
82 additions
and
0 deletions.
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,18 @@ | ||
""" | ||
This plugin searches for Stripe keys | ||
""" | ||
from __future__ import absolute_import | ||
|
||
import re | ||
|
||
from .base import RegexBasedDetector | ||
|
||
|
||
class StripeDetector(RegexBasedDetector): | ||
|
||
secret_type = 'Stripe Access Key' | ||
|
||
blacklist = ( | ||
# stripe standard keys begin with sk_live and restricted with rk_live | ||
re.compile(r'(r|s)k_live_[0-9a-zA-Z]{24}'), | ||
) |
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,40 @@ | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
import pytest | ||
|
||
from detect_secrets.plugins.stripe import StripeDetector | ||
from testing.mocks import mock_file_object | ||
|
||
|
||
class TestStripeKeyDetector(object): | ||
|
||
@pytest.mark.parametrize( | ||
'file_content,should_flag', | ||
[ | ||
( | ||
'sk_live_ReTllpYQYfIZu2Jnf2lAPFjD', | ||
True, | ||
), | ||
( | ||
'rk_live_5TcWfjKmJgpql9hjpRnwRXbT', | ||
True, | ||
), | ||
( | ||
'pk_live_j5krY8XTgIcDaHDb3YrsAfCl', | ||
False, | ||
), | ||
( | ||
'sk_live_', | ||
False, | ||
), | ||
], | ||
) | ||
def test_analyze(self, file_content, should_flag): | ||
logic = StripeDetector() | ||
|
||
f = mock_file_object(file_content) | ||
output = logic.analyze(f, 'mock_filename') | ||
assert len(output) == (1 if should_flag else 0) | ||
for potential_secret in output: | ||
assert 'mock_filename' == potential_secret.filename |
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