From c40ba04c341f71d29feb2cb2e65794c1d0aca6fb Mon Sep 17 00:00:00 2001 From: ddash-ct Date: Fri, 3 Feb 2023 08:28:52 -0500 Subject: [PATCH 1/3] Fix bug with version comparison in test_parsers --- CHANGELOG.md | 9 +++++++++ mwcp/tests/test_parsers.py | 21 +++++++++++---------- setup.py | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0187054..164a52e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ # Changelog All notable changes to this project will be documented in this file. +## Unreleased + +### 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 diff --git a/mwcp/tests/test_parsers.py b/mwcp/tests/test_parsers.py index a793a9d..0c52f4a 100644 --- a/mwcp/tests/test_parsers.py +++ b/mwcp/tests/test_parsers.py @@ -1,6 +1,7 @@ import json import pytest +from packaging import version try: import dragodis @@ -64,17 +65,17 @@ 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": @@ -82,7 +83,7 @@ def _fixup_test_cases(expected_results, actual_results): # 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")] @@ -90,7 +91,7 @@ def _fixup_test_cases(expected_results, actual_results): # 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 @@ -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"] @@ -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"]) @@ -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. @@ -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" diff --git a/setup.py b/setup.py index 9e697d3..d5049bb 100755 --- a/setup.py +++ b/setup.py @@ -43,6 +43,7 @@ 'future', 'jinja2', # For construct.html_hex() 'jsonschema_extractor>=1.0', + 'packaging', 'pandas', 'pefile>=2019.4.18', 'pyasn1', From 3ff8eeb138d9cbf24b567fae21aaef5cba2be38b Mon Sep 17 00:00:00 2001 From: ddash-ct Date: Fri, 3 Feb 2023 08:35:01 -0500 Subject: [PATCH 2/3] Update version for hotfix --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 164a52e..ca449e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog All notable changes to this project will be documented in this file. -## Unreleased +## [3.10.1] - 2023-02-03 ### Added - [packaging](https://pypi.org/project/packaging/) dependency @@ -584,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 From 28ffe28d5b112987720b8263e4dc9f2b9b09d4eb Mon Sep 17 00:00:00 2001 From: ddash-ct Date: Fri, 3 Feb 2023 08:36:16 -0500 Subject: [PATCH 3/3] Update version --- mwcp/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mwcp/__init__.py b/mwcp/__init__.py index 7b0e6bd..f240aec 100644 --- a/mwcp/__init__.py +++ b/mwcp/__init__.py @@ -24,4 +24,4 @@ from mwcp.exceptions import * -__version__ = "3.10.0" +__version__ = "3.10.1"