Files
recon-pipeline/tests/test_recon/test_amass.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

77 lines
2.5 KiB
Python

import shutil
import tempfile
from pathlib import Path
from unittest.mock import patch, MagicMock
import luigi
from pipeline.recon import AmassScan, ParseAmassOutput, TargetList
amass_json = Path(__file__).parent.parent / "data" / "recon-results" / "amass-results" / "amass.json"
class TestAmassScan:
def setup_method(self):
self.tmp_path = Path(tempfile.mkdtemp())
self.scan = AmassScan(
target_file=__file__, results_dir=str(self.tmp_path), db_location=str(self.tmp_path / "testing.sqlite")
)
def teardown_method(self):
shutil.rmtree(self.tmp_path)
def test_scan_requires(self):
with patch("pipeline.recon.TargetList"):
with patch("pipeline.recon.amass.meets_requirements"):
retval = self.scan.requires()
assert isinstance(retval, TargetList)
def test_scan_run(self):
with patch("subprocess.run") as mocked_run:
self.scan.run()
assert mocked_run.called
def test_scan_run_with_hostnames(self):
with patch("subprocess.run") as mocked_run:
self.scan.db_mgr = MagicMock()
self.scan.db_mgr.get_all_hostnames.return_value = ["google.com"]
self.scan.exempt_list = "stuff"
self.scan.run()
assert mocked_run.called
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(Path(self.tmp_path) / "amass-results" / "amass.json")
class TestParseAmass:
def setup_method(self):
self.tmp_path = Path(tempfile.mkdtemp())
self.scan = ParseAmassOutput(
target_file=__file__, results_dir=str(self.tmp_path), db_location=str(self.tmp_path / "testing.sqlite")
)
self.scan.input = lambda: luigi.LocalTarget(amass_json)
self.scan.run()
def teardown_method(self):
shutil.rmtree(self.tmp_path)
def test_scan_requires(self):
with patch("pipeline.recon.AmassScan"):
retval = self.scan.requires()
assert isinstance(retval, AmassScan)
def test_scan_results(self):
assert self.scan.output().exists()
def test_scan_creates_results_dir(self):
assert self.scan.results_subfolder.exists()
def test_scan_creates_database(self):
assert self.scan.db_mgr.location.exists()
assert self.tmp_path / "testing.sqlite" == self.scan.db_mgr.location