Skip to content

Commit

Permalink
Fix consistency in HAVE_/HAS_ constants (fox-it#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper authored Mar 5, 2024
1 parent 3ba3eec commit 08b6ec3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions dissect/target/helpers/fsutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Expand Down
8 changes: 4 additions & 4 deletions tests/plugins/os/windows/test_sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions tests/volumes/test_bde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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"

Expand All @@ -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"
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 08b6ec3

Please sign in to comment.