File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ This plugin searches for NPM tokens
3
+ """
4
+ import re
5
+
6
+ from detect_secrets .plugins .base import RegexBasedDetector
7
+
8
+
9
+ class NpmDetector (RegexBasedDetector ):
10
+ """Scans for NPM tokens."""
11
+ secret_type = 'NPM tokens'
12
+
13
+ denylist = [
14
+ # npmrc authToken
15
+ # ref. https://stackoverflow.com/questions/53099434/using-auth-tokens-in-npmrc
16
+ re .compile (r'\/\/.+\/:_authToken=.+' ),
17
+ ]
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ from detect_secrets .plugins .npm import NpmDetector
4
+
5
+
6
+ class TestNpmDetector :
7
+
8
+ @pytest .mark .parametrize (
9
+ 'payload, should_flag' ,
10
+ [
11
+ ('//registry.npmjs.org/:_authToken=xxxxxxxxxxxxxxxxxxxx' , True ),
12
+ ('//registry.npmjs.org:_authToken=xxxxxxxxxxxxxxxxxxxx' , False ),
13
+ ('registry.npmjs.org/:_authToken=xxxxxxxxxxxxxxxxxxxx' , False ),
14
+ ('///:_authToken=xxxxxxxxxxxxxxxxxxxx' , False ),
15
+ ('_authToken=xxxxxxxxxxxxxxxxxxxx' , False ),
16
+ ('foo' , False ),
17
+ ],
18
+ )
19
+ def test_analyze (self , payload , should_flag ):
20
+ logic = NpmDetector ()
21
+ output = logic .analyze_line (filename = 'mock_filename' , line = payload )
22
+ assert len (output ) == int (should_flag )
You can’t perform that action at this time.
0 commit comments