Skip to content

Commit

Permalink
Fixes #336: _issue_file was not defined by default, causing scans to …
Browse files Browse the repository at this point in the history
…fail (#337)

* Default _issue_file to None to ensure it is defined

* Version bump for quick bugfix release
  • Loading branch information
tarkatronic authored Mar 25, 2022
1 parent 34cb015 commit 50a81d7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
----------------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ maintainers = ["GoDaddy <oss@godaddy.com>"]
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"
Expand Down
2 changes: 1 addition & 1 deletion tartufo/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 50a81d7

Please sign in to comment.