Skip to content

Commit

Permalink
:fix: Fix TypeError thrown when Yaml was all comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinHock committed Sep 23, 2019
1 parent ef5d000 commit 2cd5a2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions detect_secrets/plugins/high_entropy_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ def _analyze_yaml_file(self, file, filename):
exclude_lines_regex=self.exclude_lines_regex,
)
data = parser.json()
# If the file is all comments
if not data:
raise yaml.YAMLError

ignored_lines = parser.get_ignored_lines()
potential_secrets = {}

Expand Down
6 changes: 5 additions & 1 deletion tests/plugins/high_entropy_strings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_ini_file(self, filename, secrets):

assert count == len(secrets)

def test_yaml_file(self):
def test_yaml_files(self):
plugin = Base64HighEntropyString(
base64_limit=3,
exclude_lines_regex='CanonicalUser',
Expand All @@ -220,6 +220,10 @@ def test_yaml_file(self):
'Location: test_data/config.yaml:15',
)

with open('test_data/only_comments.yaml') as f:
secrets = plugin.analyze(f, 'test_data/only_comments.yaml')
assert not secrets.values()

def test_env_file(self):
plugin = Base64HighEntropyString(4.5)
with open('test_data/config.env') as f:
Expand Down

0 comments on commit 2cd5a2b

Please sign in to comment.