mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
3bed6d8890
Signed-off-by: phernandez <paul@basicmachines.co>
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""Tests for secure rclone installer fallbacks."""
|
|
|
|
import pytest
|
|
|
|
from basic_memory.cli.commands.cloud import rclone_installer
|
|
|
|
|
|
def test_macos_installer_does_not_fallback_to_remote_script(monkeypatch):
|
|
"""Homebrew failure should produce manual guidance, not curl-piped sudo bash."""
|
|
commands: list[list[str]] = []
|
|
|
|
def fake_which(command: str) -> str | None:
|
|
return "/opt/homebrew/bin/brew" if command == "brew" else None
|
|
|
|
def fake_run(command: list[str], check: bool = True):
|
|
commands.append(command)
|
|
raise rclone_installer.RcloneInstallError("brew failed")
|
|
|
|
monkeypatch.setattr(rclone_installer.shutil, "which", fake_which)
|
|
monkeypatch.setattr(rclone_installer, "run_command", fake_run)
|
|
|
|
with pytest.raises(rclone_installer.RcloneInstallError) as exc_info:
|
|
rclone_installer.install_rclone_macos()
|
|
|
|
assert commands == [["brew", "install", "rclone"]]
|
|
assert "curl" not in str(exc_info.value)
|
|
assert "sudo bash" not in str(exc_info.value)
|
|
assert "brew install rclone" in str(exc_info.value)
|
|
|
|
|
|
def test_linux_installer_uses_package_managers_only(monkeypatch):
|
|
"""Linux package-manager failures should not fall through to remote script execution."""
|
|
commands: list[list[str]] = []
|
|
|
|
def fake_which(command: str) -> str | None:
|
|
return f"/usr/bin/{command}" if command in {"apt", "snap"} else None
|
|
|
|
def fake_run(command: list[str], check: bool = True):
|
|
commands.append(command)
|
|
raise rclone_installer.RcloneInstallError("install failed")
|
|
|
|
monkeypatch.setattr(rclone_installer.shutil, "which", fake_which)
|
|
monkeypatch.setattr(rclone_installer, "run_command", fake_run)
|
|
|
|
with pytest.raises(rclone_installer.RcloneInstallError) as exc_info:
|
|
rclone_installer.install_rclone_linux()
|
|
|
|
assert commands == [
|
|
["sudo", "apt", "update"],
|
|
["sudo", "snap", "install", "rclone"],
|
|
]
|
|
assert all("curl" not in token for command in commands for token in command)
|
|
assert "sudo bash" not in str(exc_info.value)
|
|
assert "sudo apt install rclone" in str(exc_info.value)
|