Files
recon-pipeline/tests/test_recon/test_masscan.py
Ryan Good d7dbd1e7b3 Dependency Checking (#75)
* Adds req testing methodology, needs fixes

* Improves dependency exception handling

* Better meets_requirements implementation

Still need to adjust tests to fake installation

* Changes to exception boolean to enable tool check

tests and class variables modified for new tool check

* Adjust test_get_scans to use appropriate variable

* Adds Go requirement where relevant

* Adds missing scan dependencies

* Add clarification to error message
2020-08-07 08:48:49 -05:00

69 lines
2.4 KiB
Python

import shutil
import tempfile
from pathlib import Path
from unittest.mock import patch
import luigi
from pipeline.recon import MasscanScan, ParseMasscanOutput
masscan_results = Path(__file__).parent.parent / "data" / "recon-results" / "masscan-results" / "masscan.json"
class TestMasscanScan:
# can't test run method due to yields from TargetList and ParseAmassOutput
def setup_method(self):
self.tmp_path = Path(tempfile.mkdtemp())
self.scan = MasscanScan(
target_file=__file__, results_dir=str(self.tmp_path), db_location=str(self.tmp_path / "testing.sqlite")
)
self.scan.exception = False
def teardown_method(self):
shutil.rmtree(self.tmp_path)
def test_scan_creates_results_dir(self):
assert self.scan.results_subfolder == self.tmp_path / "masscan-results"
def test_scan_creates_database(self):
assert self.scan.db_mgr.location.exists()
assert self.tmp_path / "testing.sqlite" == self.scan.db_mgr.location
def test_scan_output_location(self):
assert self.scan.output().path == str(self.scan.results_subfolder / "masscan.json")
class TestParseMasscanOutput:
def setup_method(self):
self.tmp_path = Path(tempfile.mkdtemp())
self.scan = ParseMasscanOutput(
target_file=__file__, results_dir=str(self.tmp_path), db_location=str(self.tmp_path / "testing.sqlite")
)
self.scan.input = lambda: luigi.LocalTarget(masscan_results)
def teardown_method(self):
shutil.rmtree(self.tmp_path)
def test_scan_creates_results_dir(self):
assert self.scan.results_subfolder == self.tmp_path / "masscan-results"
def test_scan_creates_database(self):
assert self.scan.db_mgr.location.exists()
assert self.tmp_path / "testing.sqlite" == self.scan.db_mgr.location
def test_scan_creates_results(self):
self.scan.run()
assert self.scan.output().exists()
def test_scan_bad_json(self, capsys):
not_json = self.tmp_path / "not-json"
not_json.write_text("I'm definitely not json")
self.scan.input = lambda: luigi.LocalTarget(not_json)
self.scan.run()
assert "Expecting value: line 1 column 1" in capsys.readouterr().out
def test_scan_requires(self):
with patch("pipeline.recon.MasscanScan"):
retval = self.scan.requires()
assert isinstance(retval, MasscanScan)