Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve detection of "nosec" clause #579

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bandit/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,11 @@ def _parse_file(self, fname, fdata, new_files_list):
lines = data.splitlines()
self.metrics.begin(fname)
self.metrics.count_locs(lines)
if self.ignore_nosec:
nosec_lines = set()
else:

nosec_lines = set()
Copy link
Member

@ericwb ericwb Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here has changed enough after you rebase, that your changes might no longer have an effect. Please rebase and re-assess whether this is still an improvement.

has_nosec = b'nosec' in data

if not self.ignore_nosec and has_nosec:
try:
fdata.seek(0)
if six.PY2:
Expand Down
8 changes: 1 addition & 7 deletions tests/functional/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import subprocess

import six
import testtools


Expand Down Expand Up @@ -103,12 +102,7 @@ def test_example_nonsense2(self):
)
self.assertEqual(0, retcode)
self.assertIn("Files skipped (1):", output)
if six.PY2:
self.assertIn("nonsense2.py (exception while scanning file)",
output)
else:
self.assertIn("nonsense2.py (syntax error while parsing AST",
output)
self.assertIn("nonsense2.py (exception while scanning file)", output)

def test_example_imports(self):
(retcode, output) = self._test_example(['bandit', ], ['imports.py', ])
Expand Down