Skip to content

Commit 2d300cb

Browse files
author
Aaron Loo
committed
tests pass
1 parent 9aaae64 commit 2d300cb

34 files changed

+134
-770
lines changed

.coveragerc

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ exclude_lines =
2222
2323
# Need to redefine this, as per documentation
2424
pragma: no cover
25+
26+
# Don't complain for skipped tests
27+
^@pytest.mark.skip

detect_secrets/audit/io.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(self, allow_labelling: bool, allow_backstep: bool) -> None:
115115
self.options = [option.name.lower() for option in options]
116116

117117
def __str__(self) -> str:
118-
if 'y' in self.valid_input:
118+
if 'Y' in self.valid_input:
119119
output = 'Is this a valid secret (not a false-positive)?'
120120
else:
121121
output = 'What would you like to do?'

detect_secrets/core/upgrades/v1_0.py

-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ def _migrate_filters(baseline: Dict[str, Any]) -> None:
1818
contain the default filters used before this version upgrade.
1919
"""
2020
baseline['filters_used'] = [
21-
{
22-
'path': 'detect_secrets.filters.allowlist.is_line_allowlisted',
23-
},
24-
{
25-
'path': 'detect_secrets.filters.common.is_invalid_file',
26-
},
27-
{
28-
'path': 'detect_secrets.filters.heuristic.is_non_text_file',
29-
},
3021
{
3122
'path': 'detect_secrets.filters.heuristic.is_sequential_string',
3223
},

detect_secrets/core/usage/scan.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ def parse_args(args: argparse.Namespace) -> None:
6565

6666
# NOTE: This is assumed to run *after* the baseline argument processor, and before
6767
# the plugin argument processor.
68-
if args.baseline and args.force_use_all_plugins:
68+
if args.baseline is not None and args.force_use_all_plugins:
6969
get_settings().plugins.clear()
7070
initialize_plugin_settings(args)

detect_secrets/filters/heuristic.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ def _get_uuid_regex() -> Pattern:
5858

5959

6060
def is_likely_id_string(secret: str, line: str) -> bool:
61-
index = line.index(secret)
61+
try:
62+
index = line.index(secret)
63+
except ValueError:
64+
return False
65+
6266
return bool(_get_id_detector_regex().search(line, pos=0, endpos=index))
6367

6468

detect_secrets/plugins/common/__init__.py

Whitespace-only changes.

detect_secrets/plugins/common/ini_file_parser.py

-160
This file was deleted.

detect_secrets/settings.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class Settings:
6666
}
6767

6868
def __init__(self) -> None:
69+
self.clear()
70+
71+
def clear(self) -> None:
6972
# mapping of class names to initialization variables
7073
self.plugins: Dict[str, Dict[str, Any]] = {}
7174

@@ -89,7 +92,6 @@ def configure_plugins(self, config: List[Dict[str, Any]]) -> 'Settings':
8992
]
9093
"""
9194
for plugin in config:
92-
# TODO: Can we remove this, once we fix up SecretsCollection?
9395
plugin = {**plugin}
9496
name = plugin.pop('name')
9597
self.plugins[name] = plugin

detect_secrets/types.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
from typing import Optional
55
from typing import Set
66

7+
from .audit.exceptions import SecretNotFoundOnSpecifiedLineError
8+
from .core.potential_secret import PotentialSecret
9+
from .util.code_snippet import CodeSnippet
10+
711

812
class SelfAwareCallable:
913
"""
@@ -28,11 +32,11 @@ class SecretContext(NamedTuple):
2832
current_index: int
2933
num_total_secrets: int
3034

31-
secret: 'PotentialSecret' # noqa: F821
35+
secret: PotentialSecret
3236
header: Optional[str] = None
3337

3438
# Either secret context is provided...
35-
snippet: Optional['CodeSnippet'] = None
39+
snippet: Optional[CodeSnippet] = None
3640

3741
# ...or error information. But it has an XOR relationship.
38-
error: Optional['SecretNotFoundOnSpecifiedLineError'] = None
42+
error: Optional[SecretNotFoundOnSpecifiedLineError] = None

detect_secrets/util/__init__.py

-95
Original file line numberDiff line numberDiff line change
@@ -1,95 +0,0 @@
1-
import hashlib
2-
import os
3-
import subprocess
4-
5-
6-
def build_automaton(word_list):
7-
"""
8-
:type word_list: str
9-
:param word_list: optional word list file for ignoring certain words.
10-
11-
:rtype: (ahocorasick.Automaton, str)
12-
:returns: an automaton, and an iterated sha1 hash of the words in the word list.
13-
"""
14-
# Dynamic import due to optional-dependency
15-
try:
16-
import ahocorasick
17-
except ImportError: # pragma: no cover
18-
print('Please install the `pyahocorasick` package to use --word-list')
19-
raise
20-
21-
# See https://pyahocorasick.readthedocs.io/en/latest/
22-
# for more information.
23-
automaton = ahocorasick.Automaton()
24-
word_list_hash = hashlib.sha1()
25-
26-
with open(word_list) as f:
27-
for line in f.readlines():
28-
# .lower() to make everything case-insensitive
29-
line = line.lower().strip()
30-
if len(line) > 3:
31-
word_list_hash.update(line.encode('utf-8'))
32-
automaton.add_word(line, line)
33-
34-
automaton.make_automaton()
35-
36-
return (
37-
automaton,
38-
word_list_hash.hexdigest(),
39-
)
40-
41-
42-
def get_root_directory(): # pragma: no cover
43-
return os.path.realpath(
44-
os.path.join(
45-
os.path.dirname(__file__),
46-
'../../',
47-
),
48-
)
49-
50-
51-
def get_git_sha(path):
52-
"""Returns the sha of the git checkout at the input path.
53-
54-
:type path: str
55-
:param path: directory of the git checkout
56-
57-
:rtype: str|None
58-
:returns: git sha of the input path
59-
"""
60-
try:
61-
with open(os.devnull, 'w') as fnull:
62-
return subprocess.check_output(
63-
['git', 'rev-parse', '--verify', 'HEAD'],
64-
stderr=fnull,
65-
cwd=path,
66-
).decode('utf-8').split()[0]
67-
except (subprocess.CalledProcessError, OSError, IndexError): # pragma: no cover
68-
return None
69-
70-
71-
def get_git_remotes(path):
72-
"""Returns a list of unique git remotes of the checkout
73-
at the input path.
74-
75-
:type path: str
76-
:param path: directory of the git checkout
77-
78-
:rtype: List<str>|None
79-
:returns: A list of unique git urls
80-
"""
81-
try:
82-
with open(os.devnull, 'w') as fnull:
83-
git_remotes = subprocess.check_output(
84-
['git', 'remote', '-v'],
85-
stderr=fnull,
86-
cwd=path,
87-
).decode('utf-8').split('\n')
88-
return list({
89-
git_remote.split()[1]
90-
for git_remote
91-
in git_remotes
92-
if len(git_remote) > 2 # split('\n') produces an empty list
93-
})
94-
except (subprocess.CalledProcessError, OSError): # pragma: no cover
95-
return None

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# on python 3.6.0 (xenial)
33
coverage<5
44
flake8==3.5.0
5-
mock
65
monotonic
6+
mypy
77
pre-commit==1.11.2
88
pyahocorasick
99
pytest

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import find_packages
22
from setuptools import setup
33

4-
from detect_secrets import VERSION
4+
from detect_secrets.__version__ import VERSION
55

66

77
setup(

0 commit comments

Comments
 (0)