Skip to content

Commit

Permalink
Merge pull request #347 from ninoseki/add-npm-detector
Browse files Browse the repository at this point in the history
Add npm detector
  • Loading branch information
domanchi committed Nov 12, 2020
2 parents 2d300cb + f92bb41 commit 9b4ec6d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
17 changes: 17 additions & 0 deletions detect_secrets/plugins/npm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
This plugin searches for NPM tokens
"""
import re

from detect_secrets.plugins.base import RegexBasedDetector


class NpmDetector(RegexBasedDetector):
"""Scans for NPM tokens."""
secret_type = 'NPM tokens'

denylist = [
# npmrc authToken
# ref. https://stackoverflow.com/questions/53099434/using-auth-tokens-in-npmrc
re.compile(r'\/\/.+\/:_authToken=.+'),
]
22 changes: 22 additions & 0 deletions tests/plugins/npm_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest

from detect_secrets.plugins.npm import NpmDetector


class TestNpmDetector:

@pytest.mark.parametrize(
'payload, should_flag',
[
('//registry.npmjs.org/:_authToken=xxxxxxxxxxxxxxxxxxxx', True),
('//registry.npmjs.org:_authToken=xxxxxxxxxxxxxxxxxxxx', False),
('registry.npmjs.org/:_authToken=xxxxxxxxxxxxxxxxxxxx', False),
('///:_authToken=xxxxxxxxxxxxxxxxxxxx', False),
('_authToken=xxxxxxxxxxxxxxxxxxxx', False),
('foo', False),
],
)
def test_analyze(self, payload, should_flag):
logic = NpmDetector()
output = logic.analyze_line(filename='mock_filename', line=payload)
assert len(output) == int(should_flag)

0 comments on commit 9b4ec6d

Please sign in to comment.