From 53172d2796ab78a729371da95e9a157bdfe494d1 Mon Sep 17 00:00:00 2001 From: Schamper <1254028+Schamper@users.noreply.github.com> Date: Tue, 5 Mar 2024 14:12:38 +0100 Subject: [PATCH] Fix consistency in `HAVE_`/`HAS_` constants --- dissect/target/helpers/fsutil.py | 18 +++++++++--------- tests/plugins/os/windows/test_sam.py | 8 ++++---- tests/volumes/test_bde.py | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dissect/target/helpers/fsutil.py b/dissect/target/helpers/fsutil.py index b299b9dd4..4d738608f 100644 --- a/dissect/target/helpers/fsutil.py +++ b/dissect/target/helpers/fsutil.py @@ -16,23 +16,23 @@ try: import lzma - HAVE_XZ = True + HAS_XZ = True except ImportError: - HAVE_XZ = False + HAS_XZ = False try: import bz2 - HAVE_BZ2 = True + HAS_BZ2 = True except ImportError: - HAVE_BZ2 = False + HAS_BZ2 = False try: import zstandard - HAVE_ZSTD = True + HAS_ZSTD = True except ImportError: - HAVE_ZSTD = False + HAS_ZSTD = False import dissect.target.filesystem as filesystem from dissect.target.exceptions import FileNotFoundError, SymlinkRecursionError @@ -511,14 +511,14 @@ def open_decompress( if magic[:2] == b"\x1f\x8b": return gzip.open(file, mode, encoding=encoding, errors=errors, newline=newline) - if HAVE_XZ and magic[:5] == b"\xfd7zXZ": + if HAS_XZ and magic[:5] == b"\xfd7zXZ": return lzma.open(file, mode, encoding=encoding, errors=errors, newline=newline) - if HAVE_BZ2 and magic[:3] == b"BZh" and 0x31 <= magic[3] <= 0x39: + if HAS_BZ2 and magic[:3] == b"BZh" and 0x31 <= magic[3] <= 0x39: # In a valid bz2 header the 4th byte is in the range b'1' ... b'9'. return bz2.open(file, mode, encoding=encoding, errors=errors, newline=newline) - if HAVE_ZSTD and magic[:4] in [b"\xfd\x2f\xb5\x28", b"\x28\xb5\x2f\xfd"]: + if HAS_ZSTD and magic[:4] in [b"\xfd\x2f\xb5\x28", b"\x28\xb5\x2f\xfd"]: # stream_reader is not seekable, so we have to resort to the less # efficient decompressor which returns bytes. return io.BytesIO(zstandard.decompress(file.read())) diff --git a/tests/plugins/os/windows/test_sam.py b/tests/plugins/os/windows/test_sam.py index bb952b628..ab770b3fe 100644 --- a/tests/plugins/os/windows/test_sam.py +++ b/tests/plugins/os/windows/test_sam.py @@ -8,15 +8,15 @@ from dissect.target.plugins.os.windows.sam import SamPlugin - HAVE_CRYPTO = True + HAS_CRYPTO = True except ImportError: - HAVE_CRYPTO = False + HAS_CRYPTO = False SAM_KEY_PATH = "SAM\\SAM\\Domains\\Account" SYSTEM_KEY_PATH = "SYSTEM\\ControlSet001\\Control\\LSA" -@pytest.mark.skipif(not HAVE_CRYPTO, reason="requires pycryptodome") +@pytest.mark.skipif(not HAS_CRYPTO, reason="requires pycryptodome") def test_sam_plugin_rev1(target_win_users, hive_hklm): sam_key = VirtualKey(hive_hklm, SAM_KEY_PATH) sam_key.add_value( @@ -143,7 +143,7 @@ def test_sam_plugin_rev1(target_win_users, hive_hklm): assert results[2].nt == MD4.new("L0ngLiv3LM!".encode("utf-16-le")).digest().hex() -@pytest.mark.skipif(not HAVE_CRYPTO, reason="requires pycryptodome") +@pytest.mark.skipif(not HAS_CRYPTO, reason="requires pycryptodome") def test_sam_plugin_rev2(target_win_users, hive_hklm): sam_key = VirtualKey(hive_hklm, SAM_KEY_PATH) sam_key.add_value( diff --git a/tests/volumes/test_bde.py b/tests/volumes/test_bde.py index 1d89932ec..ff9a2586d 100644 --- a/tests/volumes/test_bde.py +++ b/tests/volumes/test_bde.py @@ -6,9 +6,9 @@ try: from dissect.target.volumes.bde import BitlockerVolumeSystem - HAVE_DISSECT_FVE = True + HAS_DISSECT_FVE = True except ModuleNotFoundError: - HAVE_DISSECT_FVE = False + HAS_DISSECT_FVE = False from tests._utils import absolute_path @@ -21,7 +21,7 @@ def encrypted_volume(): yield f -@pytest.mark.skipif(not HAVE_DISSECT_FVE, reason="requires dissect.fve") +@pytest.mark.skipif(not HAS_DISSECT_FVE, reason="requires dissect.fve") def test_bde_volume_failure(target_win, encrypted_volume): enc_vol = volume.Volume(encrypted_volume, 1, 0, None, None, None, disk=encrypted_volume) target_win.volumes.add(enc_vol) @@ -31,7 +31,7 @@ def test_bde_volume_failure(target_win, encrypted_volume): assert enc_vol in target_win.volumes -@pytest.mark.skipif(not HAVE_DISSECT_FVE, reason="requires dissect.fve") +@pytest.mark.skipif(not HAS_DISSECT_FVE, reason="requires dissect.fve") def test_bde_volume_with_recovery_key(target_win, encrypted_volume): recovery_key = "272316-265804-640728-713570-509047-503305-045837-324731" @@ -58,7 +58,7 @@ def test_bde_volume_with_recovery_key(target_win, encrypted_volume): assert target_win.fs.path("e:/test-folder/test-file-2.txt").exists() -@pytest.mark.skipif(not HAVE_DISSECT_FVE, reason="requires dissect.fve") +@pytest.mark.skipif(not HAS_DISSECT_FVE, reason="requires dissect.fve") def test_bde_volume_with_passphrase(target_win, encrypted_volume): identifier = "B6AD258A-2725-4A42-93C6-844478BF7A90" passphrase = "Password1234" @@ -86,7 +86,7 @@ def test_bde_volume_with_passphrase(target_win, encrypted_volume): assert target_win.fs.path("e:/test-folder/test-file-2.txt").exists() -@pytest.mark.skipif(not HAVE_DISSECT_FVE, reason="requires dissect.fve") +@pytest.mark.skipif(not HAS_DISSECT_FVE, reason="requires dissect.fve") def test_bde_volume_with_wildcard_key(target_win, encrypted_volume): keychain.register_wildcard_value("Password1234")