-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support duplicate volume names in target-mount (#397)
- Loading branch information
Showing
2 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from io import BytesIO | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from dissect.target.filesystem import VirtualFilesystem | ||
from dissect.target.target import Target | ||
from dissect.target.tools.mount import main as target_mount | ||
from dissect.target.volume import Volume | ||
|
||
|
||
def test_duplicate_volume_name(mock_target: Target, monkeypatch: pytest.MonkeyPatch) -> None: | ||
with monkeypatch.context() as m: | ||
m.setattr("sys.argv", ["target-mount", "mock-target", "mock-mount"]) | ||
m.setattr("dissect.target.tools.mount.HAS_FUSE", True) | ||
|
||
with patch("dissect.target.tools.mount.Target") as MockTarget, patch( | ||
"dissect.target.tools.mount.FUSE", create=True | ||
) as MockFUSE, patch("dissect.target.tools.mount.DissectMount", create=True) as MockDissectMount: | ||
MockTarget.open.return_value = mock_target | ||
|
||
mock_target.volumes.add(Volume(BytesIO(), 1, 0, 0, None, name="first")) | ||
mock_target.volumes.add(Volume(BytesIO(), 2, 0, 0, None, name="second")) | ||
mock_target.volumes.add(Volume(BytesIO(), 3, 0, 0, None, name="second_1")) | ||
mock_target.volumes.add(Volume(BytesIO(), 4, 0, 0, None, name="second")) | ||
|
||
mock_fs = VirtualFilesystem() | ||
mock_fs.volume = mock_target.volumes[1] | ||
mock_target.filesystems.add(mock_fs) | ||
mock_fs = VirtualFilesystem() | ||
mock_fs.volume = mock_target.volumes[2] | ||
mock_target.filesystems.add(mock_fs) | ||
mock_fs = VirtualFilesystem() | ||
mock_fs.volume = mock_target.volumes[3] | ||
mock_target.filesystems.add(mock_fs) | ||
|
||
target_mount() | ||
|
||
MockFUSE.assert_called_once() | ||
MockDissectMount.assert_called_once() | ||
vfs = MockDissectMount.call_args[0][0] | ||
|
||
assert vfs.listdir("/volumes") == ["first", "second", "second_1", "second_2"] | ||
assert vfs.listdir("/filesystems") == ["second", "second_1", "second_2"] |