Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for ScanIso #239

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ opencv-python==4.6.0.66
opencv-contrib-python==4.6.0.66
pefile==2019.4.18
pgpdump3==1.5.2
pycdlib==1.13.0
pyelftools==0.27
pygments==2.9.0
pylzma==0.5.0
Expand Down
Binary file added src/python/strelka/tests/fixtures/test.iso
Binary file not shown.
47 changes: 47 additions & 0 deletions src/python/strelka/tests/test_scan_iso.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import datetime
from pathlib import Path
from unittest import TestCase, mock

from strelka.scanners.scan_iso import ScanIso


def test_scan_iso(mocker):
"""
This tests the ScanIso scanner.
It attempts to validate several given ISO metadata values.

Pass: Sample event matches output of ScanIso.
Failure: Unable to load file or sample event fails to match.
"""

test_scan_iso_event = {
"elapsed": mock.ANY,
"flags": [],
"total": {"files": 1, "extracted": 1},
"files": [
{"filename": "/lorem.txt", "size": 4015, "date_utc": "2022-12-11T18:44:49Z"}
],
"hidden_dirs": [],
"meta": {
"date_created": "2022-12-11T18:42:00Z",
"date_effective": None,
"date_expiration": None,
"date_modification": "2022-12-11T18:42:00Z",
"volume_identifier": "NEW_VOLUME ",
},
}

scanner = ScanIso(
{"name": "ScanIso", "key": "scan_iso", "limits": {"scanner": 10}},
"test_coordinate",
)

mocker.patch.object(ScanIso, "upload_to_coordinator", return_value=None)
scanner.scan_wrapper(
Path(Path(__file__).parent / "fixtures/test.iso").read_bytes(),
{"uid": "12345", "name": "somename"},
{"scanner_timeout": 5},
datetime.date.today(),
)

TestCase().assertDictEqual(test_scan_iso_event, scanner.event)