-
Notifications
You must be signed in to change notification settings - Fork 6
Fix Database Installation Path and Prevent Duplicate Database #36
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
Changes from all commits
22f71ef
7b08be3
6331517
19de9ff
8cdfb45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,8 @@ def test_constants(): | |
| assert die.dielib_version | ||
|
|
||
| # validate die database | ||
| assert isinstance(die.database_path, pathlib.Path) | ||
| assert isinstance(die.database_path, die._DatabasePath) | ||
| assert die.database_path.exists() | ||
|
Comment on lines
21
to
23
|
||
| assert die.database_path.is_dir() | ||
|
|
||
| # validate scan flags | ||
| assert die._DieFlags.Deepscan.value == die.ScanFlags.DEEP_SCAN | ||
|
|
@@ -156,3 +155,82 @@ def test_basic_databases(): | |
| assert isinstance(db, pathlib.Path) | ||
| assert db.exists() | ||
| assert db.is_file() | ||
|
|
||
|
|
||
| def test_database_path_backward_compatibility(): | ||
| """Test backward compatibility for database_path usage.""" | ||
| import warnings | ||
|
|
||
| # Test 1: New usage should work without warnings | ||
| with warnings.catch_warnings(record=True) as w: | ||
| warnings.simplefilter("always") | ||
| path_new = str(die.database_path) | ||
| assert len(w) == 0, "New usage should not produce warnings" | ||
|
|
||
| # Test 2: database_path should resolve to a valid location with PE/ directory | ||
| db_path = pathlib.Path(path_new) | ||
| assert db_path.exists(), f"Database path does not exist: {db_path}" | ||
| assert (db_path / 'PE').exists(), f"PE directory not found at {db_path}" | ||
|
|
||
| # Test 3: Old usage with /'db' should work through smart path resolution | ||
| # The smart path should detect the version and handle accordingly | ||
| with warnings.catch_warnings(record=True) as w: | ||
| warnings.simplefilter("always") | ||
| path_old = str(die.database_path / 'db') | ||
|
|
||
| # The path should exist in both old and new versions | ||
| assert pathlib.Path(path_old).exists(), f"Old usage path doesn't exist: {path_old}" | ||
|
|
||
| if len(w) > 0: | ||
| # New fixed version: got deprecation warning | ||
| assert len(w) == 1 | ||
| assert issubclass(w[0].category, DeprecationWarning) | ||
| assert "database_path" in str(w[0].message).lower() | ||
| # In new version, both should resolve to same location | ||
| assert pathlib.Path(path_new) == pathlib.Path(path_old) | ||
| else: | ||
| # Old buggy version: no warning, /'db' is necessary | ||
| # In old version, path_old should be die/db/db and path_new should also be die/db/db | ||
| assert path_new == path_old | ||
|
|
||
|
|
||
| def test_database_path_resolves_correctly(): | ||
| """Test that database_path resolves to the actual database location.""" | ||
| # The resolved path should contain PE/ directory | ||
| db_path = pathlib.Path(str(die.database_path)) | ||
|
|
||
| # Check for PE directory (main signature database) | ||
| assert (db_path / 'PE').exists(), f"PE directory not found at {db_path}" | ||
|
|
||
| # Check for other expected directories | ||
| expected_dirs = ['PE', 'ELF', 'MACH'] | ||
| for dir_name in expected_dirs: | ||
| assert (db_path / dir_name).exists(), \ | ||
| f"Expected directory {dir_name} not found at {db_path}" | ||
|
|
||
|
|
||
| def test_scan_with_explicit_database_path(target_binary: pathlib.Path): | ||
| """Test that scan_file works with explicit database path.""" | ||
| import warnings | ||
|
|
||
| # Test with new usage (no /'db') | ||
| with warnings.catch_warnings(record=True): | ||
| warnings.simplefilter("always") | ||
| res = die.scan_file( | ||
| target_binary, | ||
| die.ScanFlags.DEEP_SCAN, | ||
| database=str(die.database_path), | ||
| ) | ||
|
Comment on lines
+219
to
+223
|
||
| assert res | ||
| assert isinstance(res, str) | ||
|
|
||
| # Test with old usage (with /'db') | ||
| with warnings.catch_warnings(record=True): | ||
| warnings.simplefilter("always") | ||
| res = die.scan_file( | ||
| target_binary, | ||
| die.ScanFlags.DEEP_SCAN, | ||
| database=str(die.database_path / 'db'), | ||
| ) | ||
| assert res | ||
| assert isinstance(res, str) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m.attr("__version__")is bumped to 0.5.1 here, but the build/package versions still appear to be 0.5.0 (e.g.,pyproject.tomlandpython/CMakeLists.txt). This will lead to inconsistent version reporting (wheel metadata vsdie.__version__). Please update all version sources in the repo together or derive the extension version from the project/package version to keep them in sync.