From ccb9da0ad48075ebbc9d0b1cc99b13c6250965aa Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 8 Jun 2019 21:48:19 +0200 Subject: [PATCH] Added default ini file and targets --- bandit/cli/main.py | 7 ++++--- bandit/core/utils.py | 2 +- tests/functional/test_runtime.py | 8 ++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/bandit/cli/main.py b/bandit/cli/main.py index 98afc9048..488ee0f77 100644 --- a/bandit/cli/main.py +++ b/bandit/cli/main.py @@ -246,7 +246,7 @@ def main(): '(only JSON-formatted files are accepted)' ) parser.add_argument( - '--ini', dest='ini_path', action='store', default=None, + '--ini', dest='ini_path', action='store', default='.bandit', help='path to a .bandit file that supplies command line arguments' ) python_ver = sys.version.replace('\n', '') @@ -334,9 +334,10 @@ def main(): 'recursive') # TODO(tmcpeak): any other useful options to pass from .bandit? + # If no target has been set through args or ini file, then use a default if not args.targets: - LOG.error("No targets found in CLI or ini files, exiting.") - sys.exit(2) + args.targets = '.' + # if the log format string was set in the options, reinitialize if b_conf.get_option('log_format'): log_format = b_conf.get_option('log_format') diff --git a/bandit/core/utils.py b/bandit/core/utils.py index 694d322a8..004778087 100644 --- a/bandit/core/utils.py +++ b/bandit/core/utils.py @@ -320,7 +320,7 @@ def parse_ini_file(f_loc): return {k: v for k, v in config.items('bandit')} except (configparser.Error, KeyError, TypeError): - LOG.warning("Unable to parse config file %s or missing [bandit] " + LOG.warning("Config file %s not found or missing [bandit] " "section", f_loc) return None diff --git a/tests/functional/test_runtime.py b/tests/functional/test_runtime.py index c5cb3f707..8547d5225 100644 --- a/tests/functional/test_runtime.py +++ b/tests/functional/test_runtime.py @@ -38,11 +38,6 @@ def _test_example(self, cmdlist, targets): cmdlist.append(os.path.join(os.getcwd(), 'examples', t)) return self._test_runtime(cmdlist) - def test_no_arguments(self): - (retcode, output) = self._test_runtime(['bandit', ]) - self.assertEqual(2, retcode) - self.assertIn("No targets found in CLI or ini files", output) - def test_piped_input(self): with open('examples/imports.py', 'r') as infile: (retcode, output) = self._test_runtime(['bandit', '-'], infile) @@ -102,7 +97,8 @@ def test_example_okay(self): self.assertIn("No issues identified.", output) def test_recurse(self): - (retcode, output) = self._test_runtime(['bandit', '-r', 'examples/recursive1']) + (retcode, output) = self._test_runtime(['bandit', '-r', + 'examples/recursive1']) self.assertEqual(0, retcode) self.assertIn("Total lines of code: 2", output) self.assertIn("Files skipped (0):", output)