File tree 7 files changed +82
-0
lines changed
7 files changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,11 @@ class PluginOptions(object):
295
295
disable_flag_text = '--no-artifactory-scan' ,
296
296
disable_help_text = 'Disable scanning for Artifactory credentials' ,
297
297
),
298
+ PluginDescriptor (
299
+ classname = 'StripeDetector' ,
300
+ disable_flag_text = '--no-stripe-scan' ,
301
+ disable_help_text = 'Disable scanning for Stripe keys' ,
302
+ ),
298
303
]
299
304
300
305
def __init__ (self , parser ):
Original file line number Diff line number Diff line change 13
13
from ..keyword import KeywordDetector # noqa: F401
14
14
from ..private_key import PrivateKeyDetector # noqa: F401
15
15
from ..slack import SlackDetector # noqa: F401
16
+ from ..stripe import StripeDetector # noqa: F401
16
17
from detect_secrets .core .log import log
17
18
from detect_secrets .core .usage import PluginOptions
18
19
Original file line number Diff line number Diff line change
1
+ """
2
+ This plugin searches for Stripe keys
3
+ """
4
+ from __future__ import absolute_import
5
+
6
+ import re
7
+
8
+ from .base import RegexBasedDetector
9
+
10
+
11
+ class StripeDetector (RegexBasedDetector ):
12
+
13
+ secret_type = 'Stripe Access Key'
14
+
15
+ blacklist = (
16
+ # stripe standard keys begin with sk_live and restricted with rk_live
17
+ re .compile (r'(r|s)k_live_[0-9a-zA-Z]{24}' ),
18
+ )
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ def test_consolidates_output_basic(self):
40
40
'AWSKeyDetector' : {},
41
41
'SlackDetector' : {},
42
42
'ArtifactoryDetector' : {},
43
+ 'StripeDetector' : {},
43
44
}
44
45
assert not hasattr (args , 'no_private_key_scan' )
45
46
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ def test_scan_string_basic(
96
96
KeywordDetector : False
97
97
PrivateKeyDetector : False
98
98
SlackDetector : False
99
+ StripeDetector : False
99
100
""" .format (
100
101
expected_base64_result ,
101
102
expected_hex_result ,
@@ -119,6 +120,7 @@ def test_scan_string_cli_overrides_stdin(self):
119
120
KeywordDetector : False
120
121
PrivateKeyDetector : False
121
122
SlackDetector : False
123
+ StripeDetector : False
122
124
""" )[1 :]
123
125
124
126
def test_scan_with_all_files_flag (self , mock_baseline_initialize ):
@@ -257,6 +259,9 @@ def test_old_baseline_ignored_with_update_flag(
257
259
{
258
260
"name" : "SlackDetector" ,
259
261
},
262
+ {
263
+ "name" : "StripeDetector" ,
264
+ },
260
265
],
261
266
),
262
267
( # remove some plugins from all plugins
@@ -288,6 +293,9 @@ def test_old_baseline_ignored_with_update_flag(
288
293
{
289
294
"name" : "SlackDetector" ,
290
295
},
296
+ {
297
+ "name" : "StripeDetector" ,
298
+ },
291
299
],
292
300
),
293
301
( # use same plugin list from baseline
@@ -375,6 +383,9 @@ def test_old_baseline_ignored_with_update_flag(
375
383
{
376
384
"name" : "SlackDetector" ,
377
385
},
386
+ {
387
+ "name" : "StripeDetector" ,
388
+ },
378
389
],
379
390
),
380
391
( # use plugin limit from baseline when using --use-all-plugins and no input limit
@@ -408,6 +419,9 @@ def test_old_baseline_ignored_with_update_flag(
408
419
{
409
420
"name" : "SlackDetector" ,
410
421
},
422
+ {
423
+ "name" : "StripeDetector" ,
424
+ },
411
425
],
412
426
),
413
427
],
Original file line number Diff line number Diff line change
1
+ from __future__ import absolute_import
2
+ from __future__ import unicode_literals
3
+
4
+ import pytest
5
+
6
+ from detect_secrets .plugins .stripe import StripeDetector
7
+ from testing .mocks import mock_file_object
8
+
9
+
10
+ class TestStripeKeyDetector (object ):
11
+
12
+ @pytest .mark .parametrize (
13
+ 'file_content,should_flag' ,
14
+ [
15
+ (
16
+ 'sk_live_ReTllpYQYfIZu2Jnf2lAPFjD' ,
17
+ True ,
18
+ ),
19
+ (
20
+ 'rk_live_5TcWfjKmJgpql9hjpRnwRXbT' ,
21
+ True ,
22
+ ),
23
+ (
24
+ 'pk_live_j5krY8XTgIcDaHDb3YrsAfCl' ,
25
+ False ,
26
+ ),
27
+ (
28
+ 'sk_live_' ,
29
+ False ,
30
+ ),
31
+ ],
32
+ )
33
+ def test_analyze (self , file_content , should_flag ):
34
+ logic = StripeDetector ()
35
+
36
+ f = mock_file_object (file_content )
37
+ output = logic .analyze (f , 'mock_filename' )
38
+ assert len (output ) == (1 if should_flag else 0 )
39
+ for potential_secret in output :
40
+ assert 'mock_filename' == potential_secret .filename
Original file line number Diff line number Diff line change @@ -194,6 +194,9 @@ def test_that_baseline_gets_updated(
194
194
{
195
195
'name' : 'SlackDetector' ,
196
196
},
197
+ {
198
+ 'name' : 'StripeDetector' ,
199
+ },
197
200
]
198
201
199
202
def test_writes_new_baseline_if_modified (self ):
You can’t perform that action at this time.
0 commit comments