Skip to content
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

Fix consistency in HAVE_/HAS_ constants #564

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 21 in dissect/target/helpers/fsutil.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/helpers/fsutil.py#L21

Added line #L21 was not covered by tests

try:
import bz2

HAVE_BZ2 = True
HAS_BZ2 = True
except ImportError:
HAVE_BZ2 = False
HAS_BZ2 = False

Check warning on line 28 in dissect/target/helpers/fsutil.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/helpers/fsutil.py#L28

Added line #L28 was not covered by tests

try:
import zstandard

HAVE_ZSTD = True
HAS_ZSTD = True
except ImportError:
HAVE_ZSTD = False
HAS_ZSTD = False

Check warning on line 35 in dissect/target/helpers/fsutil.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/helpers/fsutil.py#L35

Added line #L35 was not covered by tests

import dissect.target.filesystem as filesystem
from dissect.target.exceptions import FileNotFoundError, SymlinkRecursionError
Expand Down Expand Up @@ -511,14 +511,14 @@
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
Loading