Skip to content

Commit

Permalink
Merge pull request #36 from ciphertechsolutions/test-parsers-version
Browse files Browse the repository at this point in the history
Fix bug with version comparison in test_parsers
  • Loading branch information
dc3-tsd committed Feb 3, 2023
2 parents 0cd5ae0 + 28ffe28 commit 79ce5fe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.

## [3.10.1] - 2023-02-03

### Added
- [packaging](https://pypi.org/project/packaging/) dependency

### Fixed
- Use `packaging.version` for version comparison with test results


## [3.10.0] - 2023-01-25

### Added
Expand Down Expand Up @@ -575,7 +584,8 @@ It is assumed if you are not updating/adding tests.
- Fixed broken markdown headings from @bryant1410


[Unreleased]: https://github.com/Defense-Cyber-Crime-Center/DC3-MWCP/compare/3.10.0...HEAD
[Unreleased]: https://github.com/Defense-Cyber-Crime-Center/DC3-MWCP/compare/3.10.1...HEAD
[3.10.1]: https://github.com/Defense-Cyber-Crime-Center/DC3-MWCP/compare/3.10.0...3.10.1
[3.10.0]: https://github.com/Defense-Cyber-Crime-Center/DC3-MWCP/compare/3.9.0...3.10.0
[3.9.0]: https://github.com/Defense-Cyber-Crime-Center/DC3-MWCP/compare/3.8.0...3.9.0
[3.8.0]: https://github.com/Defense-Cyber-Crime-Center/DC3-MWCP/compare/3.7.0...3.8.0
Expand Down
2 changes: 1 addition & 1 deletion mwcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
from mwcp.exceptions import *


__version__ = "3.10.0"
__version__ = "3.10.1"
21 changes: 11 additions & 10 deletions mwcp/tests/test_parsers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

import pytest
from packaging import version

try:
import dragodis
Expand Down Expand Up @@ -64,33 +65,33 @@ def _fixup_test_cases(expected_results, actual_results):

# Remove mwcp version since we don't want to be updating our tests cases every time
# there is a new version.
expected_results_version = expected_results.pop("mwcp_version")
actual_results_version = actual_results.pop("mwcp_version")
expected_results_version = version.parse(expected_results.pop("mwcp_version"))
actual_results_version = version.parse(actual_results.pop("mwcp_version"))

# Version 3.3.2 introduced "mode" property in encryption_key. Remove property for older tests.
if expected_results_version < "3.3.2":
if expected_results_version < version.parse("3.3.2"):
for item in actual_results["metadata"]:
if item["type"] == "encryption_key":
del item["mode"]

# Version 3.3.3 set "residual_file" and "input_file" types to just "file".
if expected_results_version < "3.3.3":
if expected_results_version < version.parse("3.3.3"):
actual_results["input_file"]["type"] = "input_file"
for item in actual_results["metadata"]:
if item["type"] == "file":
item["type"] = "residual_file"

# Version 3.3.3 also changed the types for legacy interval and uuid to
# "interval_legacy" and "uuid_legacy" respectively.
if expected_results_version < "3.3.3":
if expected_results_version < version.parse("3.3.3"):
for item in actual_results["metadata"]:
if item["type"].endswith("_legacy"):
item["type"] = item["type"][:-len("_legacy")]

# Version 3.3.3 no longer automatically adds tcp into a socket for url,
# therefore just clear the network_protocol when it's set to tcp for
# older versions
if expected_results_version < "3.3.3":
if expected_results_version < version.parse("3.3.3"):
for item in actual_results["metadata"] + expected_results["metadata"]:
if item["type"] == "socket" and item["network_protocol"] == "tcp":
item["network_protocol"] = None
Expand All @@ -110,7 +111,7 @@ def _fixup_test_cases(expected_results, actual_results):

# Version 3.5.0 adds "value_format" to Other metadata elements
# and allows for new value types.
if expected_results_version < "3.5.0":
if expected_results_version < version.parse("3.5.0"):
for item in actual_results["metadata"]:
if item["type"] == "other":
del item["value_format"]
Expand Down Expand Up @@ -144,7 +145,7 @@ def _fixup_test_cases(expected_results, actual_results):
# "path" has been removed.
# "key" has been replaced with a "hive"/"subkey" combo.
# Update registry entries in expected results to account for new schema.
if expected_results_version < "3.6.0":
if expected_results_version < version.parse("3.6.0"):
for item in expected_results["metadata"]:
if item["type"] == "registry":
reg = mwcp.metadata.Registry2.from_path(item["path"] or "", data=item["data"]).add_tag(*item["tags"])
Expand All @@ -155,7 +156,7 @@ def _fixup_test_cases(expected_results, actual_results):
# Version 3.7.0 changes schema for Path
# "directory_path", and "name" as been removed in exchange for just a "path" element.
# Update path entries in expected results to account for new schema.
if expected_results_version < "3.7.0":
if expected_results_version < version.parse("3.7.0"):
for item in expected_results["metadata"]:
if item["type"] == "path":
# Recreate path using backwards compatibility wrapper.
Expand Down Expand Up @@ -186,7 +187,7 @@ def _fixup_test_cases(expected_results, actual_results):
# For now, we are going to remove any supplemental generated files created by IDA or Ghidra.
# These are not deterministic, changing the md5 on each run. Plus the backend disassembler
# could be different based what the user setup as their default backend disassembler.
if expected_results_version >= "3.7.0":
if expected_results_version >= version.parse("3.7.0"):
# TODO: make this check less hardcoded.
is_supplemental = lambda item: (
item["type"] == "file"
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'future',
'jinja2', # For construct.html_hex()
'jsonschema_extractor>=1.0',
'packaging',
'pandas',
'pefile>=2019.4.18',
'pyasn1',
Expand Down

0 comments on commit 79ce5fe

Please sign in to comment.