From 50a81d77f25bf5d8a2a4d2c0fac0e3337ef08847 Mon Sep 17 00:00:00 2001 From: Joey Wilhelm Date: Fri, 25 Mar 2022 11:31:41 -0400 Subject: [PATCH] Fixes #336: _issue_file was not defined by default, causing scans to fail (#337) * Default _issue_file to None to ensure it is defined * Version bump for quick bugfix release --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- tartufo/scanner.py | 2 +- tests/test_base_scanner.py | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cddfe902..53573f2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +v3.1.1 - 25 March 2022 +---------------------- + +Bug Fixes: + +* [#336](https://github.com/godaddy/tartufo/issues/336) - `_issue_file` was not defined by default, causing all scans to fail + v3.1.0 - 24 March 2022 ---------------------- diff --git a/pyproject.toml b/pyproject.toml index 19fc6e50..e32ca963 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ maintainers = ["GoDaddy "] name = "tartufo" readme = "README.md" repository = "https://github.com/godaddy/tartufo/" -version = "3.1.0" +version = "3.1.1" [tool.poetry.scripts] tartufo = "tartufo.cli:main" diff --git a/tartufo/scanner.py b/tartufo/scanner.py index f49230e3..fee3e6e8 100755 --- a/tartufo/scanner.py +++ b/tartufo/scanner.py @@ -147,7 +147,7 @@ class ScannerBase(abc.ABC): # pylint: disable=too-many-instance-attributes _excluded_signatures: Optional[Tuple[str, ...]] = None _config_data: MutableMapping[str, Any] = {} _issue_list: List[Issue] = [] - _issue_file: IO + _issue_file: Optional[IO] = None _issue_count: int def __init__(self, options: types.GlobalOptions) -> None: diff --git a/tests/test_base_scanner.py b/tests/test_base_scanner.py index d5bb309a..cfba926e 100644 --- a/tests/test_base_scanner.py +++ b/tests/test_base_scanner.py @@ -107,6 +107,24 @@ def test_scan_checks_regex_if_specified(self, mock_regex: mock.MagicMock): mock_regex.assert_called() +class IssueFileTests(ScannerTestCase): + @mock.patch("tempfile.NamedTemporaryFile") + def test_issue_file_creates_new_temporary_file(self, mock_temp: mock.MagicMock): + self.options.temp_dir = "/foo/bar" + test_scanner = TestScanner(self.options) + issue_file = test_scanner.issue_file + mock_temp.assert_called_once_with(dir="/foo/bar") + self.assertEqual(issue_file, mock_temp.return_value) + + @mock.patch("tempfile.NamedTemporaryFile", mock.MagicMock()) + def test_issue_file_is_cached(self): + self.options.temp_dir = "/foo/bar" + test_scanner = TestScanner(self.options) + file1 = test_scanner.issue_file + file2 = test_scanner.issue_file + self.assertEqual(file1, file2) + + class IssuesTests(ScannerTestCase): @mock.patch("tartufo.scanner.ScannerBase.scan") def test_empty_issue_list_causes_scan(self, mock_scan: mock.MagicMock):