Skip to content

Commit

Permalink
Relabel plugin to test to avoid confusion
Browse files Browse the repository at this point in the history
The original code considered plugins, but not blacklists.
Since the code now correctly considers both types of tests,
the function and variables should be renamed to avoid confusion.
  • Loading branch information
costaparas committed Aug 17, 2023
1 parent 8d07ba0 commit 05bd875
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions bandit/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ def convert_names_to_ids(self):
# sometimes explicity 'None', for example when the list if given in
# yaml but not populated with any values.
include = {
(extman.get_plugin_id(i) or i)
(extman.get_test_id(i) or i)
for i in (profile.get("include") or [])
}
exclude = {
(extman.get_plugin_id(i) or i)
(extman.get_test_id(i) or i)
for i in (profile.get("exclude") or [])
}
updated_profiles[name] = {"include": include, "exclude": exclude}
Expand Down
10 changes: 5 additions & 5 deletions bandit/core/extension_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def test_has_id(plugin):
self.plugins_by_id = {p.plugin._test_id: p for p in self.plugins}
self.plugins_by_name = {p.name: p for p in self.plugins}

def get_plugin_id(self, plugin_name):
if plugin_name in self.plugins_by_name:
return self.plugins_by_name[plugin_name].plugin._test_id
if plugin_name in self.blacklist_by_name:
return self.blacklist_by_name[plugin_name]["id"]
def get_test_id(self, test_name):
if test_name in self.plugins_by_name:
return self.plugins_by_name[test_name].plugin._test_id
if test_name in self.blacklist_by_name:
return self.blacklist_by_name[test_name]["id"]
return None

def load_blacklists(self, blacklist_namespace):
Expand Down
12 changes: 6 additions & 6 deletions bandit/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,17 +460,17 @@ def _find_candidate_matches(unmatched_issues, results_list):


def _find_test_id_from_nosec_string(extman, match):
plugin_id = extman.check_id(match)
if plugin_id:
test_id = extman.check_id(match)
if test_id:
return match
# Finding by short_id didn't work, let's check the plugin name
plugin_id = extman.get_plugin_id(match)
if not plugin_id:
# Finding by short_id didn't work, let's check the test name
test_id = extman.get_test_id(match)
if not test_id:
# Name and short id didn't work:
LOG.warning(
"Test in comment: %s is not a test name or id, ignoring", match
)
return plugin_id # We want to return None or the string here regardless
return test_id # We want to return None or the string here regardless


def _parse_nosec_comment(comment):
Expand Down

0 comments on commit 05bd875

Please sign in to comment.