Guard probe_target against creating phantom local dirs when mount_root is unmounted
This commit is contained in:
@@ -595,6 +595,51 @@ class TestPlaceIntoPloudSameFileIsNoop:
|
||||
assert test_file.stat().st_size > 0
|
||||
|
||||
|
||||
class TestMountRootGuard:
|
||||
"""Test probe_target() mount-root verification (phantom-dir regression guard)."""
|
||||
|
||||
def test_no_mount_root_configured_unchanged_behavior(self, mock_paths, setup_logging, monkeypatch):
|
||||
"""MOUNT_ROOT None + writable TARGET_DIR -> True (unchanged behavior)."""
|
||||
monkeypatch.setattr(coe_mirror, "MOUNT_ROOT", None)
|
||||
|
||||
assert coe_mirror.probe_target() is True
|
||||
|
||||
def test_mount_root_live_target_under_it_returns_true(self, mock_paths, setup_logging, monkeypatch, tmp_path):
|
||||
"""MOUNT_ROOT set, live mount, TARGET_DIR a subdir of it -> True."""
|
||||
mount_root = tmp_path / "pCloudDrive"
|
||||
mount_root.mkdir()
|
||||
target_dir = mount_root / "Hacking" / "ChurchOfMalware"
|
||||
monkeypatch.setattr(coe_mirror, "MOUNT_ROOT", mount_root)
|
||||
monkeypatch.setattr(coe_mirror, "TARGET_DIR", target_dir)
|
||||
monkeypatch.setattr(coe_mirror.os.path, "ismount", lambda p: True)
|
||||
|
||||
assert coe_mirror.probe_target() is True
|
||||
|
||||
def test_mount_not_live_does_not_create_phantom_dir(self, mock_paths, setup_logging, monkeypatch, tmp_path):
|
||||
"""MOUNT_ROOT set but not mounted -> False, and TARGET_DIR is never created."""
|
||||
mount_root = tmp_path / "pCloudDrive"
|
||||
mount_root.mkdir()
|
||||
target_dir = mount_root / "Hacking" / "ChurchOfMalware"
|
||||
monkeypatch.setattr(coe_mirror, "MOUNT_ROOT", mount_root)
|
||||
monkeypatch.setattr(coe_mirror, "TARGET_DIR", target_dir)
|
||||
monkeypatch.setattr(coe_mirror.os.path, "ismount", lambda p: False)
|
||||
|
||||
assert coe_mirror.probe_target() is False
|
||||
assert not target_dir.exists()
|
||||
|
||||
def test_target_dir_not_under_mount_root_returns_false(self, mock_paths, setup_logging, monkeypatch, tmp_path):
|
||||
"""MOUNT_ROOT set, live mount, but TARGET_DIR is unrelated -> False, no dir created."""
|
||||
mount_root = tmp_path / "pCloudDrive"
|
||||
mount_root.mkdir()
|
||||
target_dir = tmp_path / "unrelated" / "target"
|
||||
monkeypatch.setattr(coe_mirror, "MOUNT_ROOT", mount_root)
|
||||
monkeypatch.setattr(coe_mirror, "TARGET_DIR", target_dir)
|
||||
monkeypatch.setattr(coe_mirror.os.path, "ismount", lambda p: True)
|
||||
|
||||
assert coe_mirror.probe_target() is False
|
||||
assert not target_dir.exists()
|
||||
|
||||
|
||||
# Tests for Matrix notification implementation.
|
||||
# Note: Tests requiring monkeypatched subprocess.run must use raising=False because
|
||||
# subprocess.run is not a class attribute on the coe_mirror module by default
|
||||
|
||||
Reference in New Issue
Block a user