Example #1
0
 def test_echo_issues_outputs_proper_json_when_requested(self, mock_json):
     issue_1 = scanner.Issue(scanner.IssueType.Entropy, ["foo"])
     issue_2 = scanner.Issue(scanner.IssueType.RegEx, ["bar"])
     util.echo_issues([issue_1, issue_2], True, "/repo", "/output")
     mock_json.dumps.assert_called_once_with(
         {
             "project_path": "/repo",
             "issues_path": "/output",
             "found_issues": [
                 {
                     "issue_type": "High Entropy",
                     "issue_detail": None,
                     "diff": "No diff available.",
                     "strings_found": ["foo"],
                     "commit_time": None,
                     "commit_message": None,
                     "commit_hash": None,
                     "file_path": None,
                     "branch": None,
                 },
                 {
                     "issue_type": "Regular Expression Match",
                     "issue_detail": None,
                     "diff": "No diff available.",
                     "strings_found": ["bar"],
                     "commit_time": None,
                     "commit_message": None,
                     "commit_hash": None,
                     "file_path": None,
                     "branch": None,
                 },
             ],
         }
     )
Example #2
0
 def test_echo_issues_outputs_proper_json_when_requested(self, mock_json):
     issue_1 = scanner.Issue(
         types.IssueType.Entropy, "foo", types.Chunk("foo", "/bar")
     )
     issue_2 = scanner.Issue(
         types.IssueType.RegEx, "bar", types.Chunk("foo", "/bar")
     )
     util.echo_issues([issue_1, issue_2], True, "/repo", "/output")
     mock_json.dumps.assert_called_once_with(
         {
             "project_path": "/repo",
             "output_dir": "/output",
             "found_issues": [
                 {
                     "issue_type": "High Entropy",
                     "issue_detail": None,
                     "diff": "foo",
                     "matched_string": "foo",
                     "signature": "4db0024275a64ac2bf5e7d061e130e283b0b37a44167b605643e06e33177f74e",
                     "file_path": "/bar",
                 },
                 {
                     "issue_type": "Regular Expression Match",
                     "issue_detail": None,
                     "diff": "foo",
                     "matched_string": "bar",
                     "signature": "1516f2c3395943be40811573bb63ed1e2b8fe3a0e6dcc8dbb43351ca90ba6822",
                     "file_path": "/bar",
                 },
             ],
         }
     )
Example #3
0
def process_issues(
    ctx: click.Context,
    result: Tuple[str, List[scanner.Issue]],
    **kwargs: config.OptionTypes,
):
    repo_path, issues = result
    options = types.GlobalOptions(**kwargs)  # type: ignore
    output_dir = None
    if options.output_dir:
        now = datetime.now().isoformat("T", "microseconds")
        output_dir = pathlib.Path(
            options.output_dir) / f"tartufo-scan-results-{now}"
        output_dir.mkdir(parents=True)

    if issues:
        util.echo_issues(issues, options.json, repo_path, output_dir)
        if output_dir:
            util.write_outputs(issues, output_dir)
            if not options.json:
                click.echo(f"Results have been saved in {output_dir}")
        ctx.exit(1)

    ctx.exit(0)
Example #4
0
 def test_echo_issues_echos_all_when_not_json(self, mock_click):
     util.echo_issues([1, 2, 3, 4], False, "", "")
     mock_click.echo.assert_has_calls(
         (mock.call(1), mock.call(2), mock.call(3), mock.call(4)), any_order=False
     )