File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ This plugin searches for SendGrid API keys
3
+ """
4
+ import re
5
+
6
+ from detect_secrets .plugins .base import RegexBasedDetector
7
+
8
+
9
+ class SendGridDetector (RegexBasedDetector ):
10
+ """Scans for SendGrid API keys."""
11
+ secret_type = 'SendGrid API key'
12
+
13
+ denylist = [
14
+ # SendGrid API key
15
+ # ref. https://d2w67tjf43xwdp.cloudfront.net/Classroom/Basics/API/what_is_my_api_key.html
16
+ re .compile (r'SG\.[a-zA-Z0-9_-]{22}\.[a-zA-Z0-9_-]{43}' ),
17
+ ]
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ from detect_secrets .plugins .sendgrid import SendGridDetector
4
+
5
+
6
+ class TestSendGridDetector :
7
+
8
+ @pytest .mark .parametrize (
9
+ 'payload, should_flag' ,
10
+ [
11
+ ('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' , True ),
12
+ ('SG.ngeVfQFYQlKU0ufo8x5d1A..TwL2iGABf9DHoTf-09kqeF8tAmbihYzrnopKc-1s5cr' , False ),
13
+ ('AG.ngeVfQFYQlKU0ufo8x5d1A.TwL2iGABf9DHoTf-09kqeF8tAmbihYzrnopKc-1s5cr' , False ),
14
+ ('foo' , False ),
15
+ ],
16
+ )
17
+ def test_analyze (self , payload , should_flag ):
18
+ logic = SendGridDetector ()
19
+ output = logic .analyze_line (filename = 'mock_filename' , line = payload )
20
+ assert len (output ) == int (should_flag )
You can’t perform that action at this time.
0 commit comments