Skip to content

Commit

Permalink
Fix windows tests in acquire (#111)
Browse files Browse the repository at this point in the history
- also remove references to __fstype__
Fixes (DIS-2430, DIS-2089)
  • Loading branch information
Miauwkeru authored Dec 6, 2023
1 parent e879310 commit a0c062f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions acquire/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ def iter_esxi_filesystems(target: Target) -> Iterator[tuple[str, str, Filesystem

uuid = mount[len("/vmfs/volumes/") :] # strip /vmfs/volumes/
name = None
if fs.__fstype__ == "fat":
if fs.__type__ == "fat":
name = fs.volume.name
elif fs.__fstype__ == "vmfs":
elif fs.__type__ == "vmfs":
name = fs.vmfs.label

yield uuid, name, fs
Expand Down Expand Up @@ -1597,7 +1597,7 @@ class VMFS(Module):
@classmethod
def _run(cls, target: Target, cli_args: argparse.Namespace, collector: Collector) -> None:
for uuid, name, fs in iter_esxi_filesystems(target):
if not fs.__fstype__ == "vmfs":
if not fs.__type__ == "vmfs":
continue

log.info("Acquiring /vmfs/volumes/%s (%s)", uuid, name)
Expand Down
2 changes: 1 addition & 1 deletion acquire/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def serialize_path(path: Any) -> str:
# Naive way to serialize TargetPath filesystem's metadata is
# to rely on uniqueness of `path._fs` object
fs_id = id(path._fs)
return f"{path._fs.__fstype__}:{fs_id}:{path}"
return f"{path._fs.__type__}:{fs_id}:{path}"


@dataclass
Expand Down
5 changes: 0 additions & 5 deletions tests/test_collector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import errno
import platform
from pathlib import Path
from unittest.mock import MagicMock, Mock, patch

Expand Down Expand Up @@ -329,10 +328,6 @@ def collect_report(
return collector.report


@pytest.mark.skipif(
platform.system() == "Windows",
reason="No files are collected on Windows. Needs to be fixed.",
)
@pytest.mark.parametrize(
"function_name, collection_point, expected_results, create_paths",
[
Expand Down
12 changes: 6 additions & 6 deletions tests/test_outputs_dir.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import platform
import os
from pathlib import Path

import pytest
from dissect.target.filesystem import VirtualFilesystem
from dissect.target.helpers.fsutil import normalize

from acquire.outputs import DirectoryOutput

Expand Down Expand Up @@ -30,10 +31,6 @@ def leaves(path: Path) -> list[Path]:
return leave_paths


@pytest.mark.skipif(
platform.system() == "Windows",
reason="entry_name comparison uses the wrong path separators on Windows. Needs to befixed.",
)
@pytest.mark.parametrize(
"entry_name",
[
Expand All @@ -53,7 +50,10 @@ def test_dir_output_write_entry(mock_fs: VirtualFilesystem, dir_output: Director
assert len(files) == 1

file = files[0]
assert str(file)[len(str(path)) :] == entry_name

# Convert a os seperated file to the entry name.
file_path = f"/{normalize(str(file.relative_to(path)), alt_separator=os.sep)}"
assert file_path == entry_name

if entry.is_dir():
assert file.is_dir()
Expand Down
13 changes: 9 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ def test_check_and_set_acquire_args_cagent():
),
],
)
@pytest.mark.skipif(platform.system() == "Windows", reason="Compares Posix Paths. Needs to be fixed.")
def test_utils_normalize_path(
mock_target: Target,
path: pathlib.Path,
Expand All @@ -379,6 +378,12 @@ def test_utils_normalize_path(
case_sensitive: bool,
os: str,
) -> None:
with patch.object(mock_target, "os", new=os):
with patch.object(mock_target.fs, "_case_sensitive", new=case_sensitive):
assert normalize_path(mock_target, path, resolve=resolve) == norm_path
with patch.object(mock_target, "os", new=os), patch.object(mock_target.fs, "_case_sensitive", new=case_sensitive):
resolved_path = normalize_path(mock_target, path, resolve=resolve)

if platform.system() == "Windows":
# A resolved path on windows adds a C:\ prefix. So we check if it ends with our expected
# path string
assert resolved_path.endswith(norm_path)
else:
assert resolved_path == norm_path

0 comments on commit a0c062f

Please sign in to comment.