Skip to content

Commit

Permalink
Make tests more flexible to path changes
Browse files Browse the repository at this point in the history
  • Loading branch information
felddy committed May 21, 2019
1 parent c2b4dd2 commit 7f5978f
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions tests/test_ioc_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def test_version(capsys):
@pytest.mark.parametrize("level", log_levels)
def test_log_levels(level):
"""Validate commandline log-level arguments."""
with patch.object(sys, "argv", ["bogus", f"--log-level={level}", "--target=."]):
with patch.object(
sys, "argv", ["bogus", f"--log-level={level}", "--target=tests/targets"]
):
with patch.object(logging.root, "handlers", []):
assert (
logging.root.hasHandlers() is False
Expand All @@ -51,27 +53,38 @@ def test_log_levels(level):
def test_scan_file(capsys):
"""Test running the scanner with an input target file."""
with patch.object(
sys, "argv", ["bogus", "--file=tests/testblob.txt", "--target=tests/eicar.txt"]
sys,
"argv",
[
"bogus",
"--log-level=debug",
"--file=tests/testblob.txt",
"--target=tests/targets",
],
):
ioc_scan_cli.main()
captured = capsys.readouterr()
print(captured.out)
assert (
captured.out.count("69630e4574ec6798239b091cda43dca0 tests/eicar.txt") == 1
captured.out.count("eicar.txt") == 1
), "standard out should contain eicar detection with filename"
assert (
captured.out.count("69630e4574ec6798239b091cda43dca0 1") == 1
), "standard out should contain eicar detection and tally"
captured.out.count("69630e4574ec6798239b091cda43dca0") == 2
), "standard out should detection and tally should match hash"


def test_scan_stdin(capsys):
"""Test running the scanner with an input target file."""
with patch.object(sys, "argv", ["bogus", "--stdin", "--target=tests/eicar.txt"]):
with patch.object(
sys, "argv", ["bogus", "--log-level=debug", "--stdin", "--target=tests/targets"]
):
with patch("sys.stdin", StringIO("69630e4574ec6798239b091cda43dca0")):
ioc_scan_cli.main()
captured = capsys.readouterr()
print(captured.out)
assert (
captured.out.count("69630e4574ec6798239b091cda43dca0 tests/eicar.txt") == 1
captured.out.count("eicar.txt") == 1
), "standard out should contain eicar detection with filename"
assert (
captured.out.count("69630e4574ec6798239b091cda43dca0 1") == 1
), "standard out should contain eicar detection and tally"
captured.out.count("69630e4574ec6798239b091cda43dca0") == 2
), "standard out should detection and tally should match hash"

0 comments on commit 7f5978f

Please sign in to comment.