80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import os
|
||
|
|
import subprocess
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
LAUNCHER = (
|
||
|
|
Path(__file__).parents[1] / "scripts" / "run-mealie-mcp-read-only-for-buzz"
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def _fake_uv(tmp_path: Path) -> Path:
|
||
|
|
executable = tmp_path / "fake-uv"
|
||
|
|
executable.write_text(
|
||
|
|
"#!/usr/bin/env bash\n"
|
||
|
|
"printf '%s\\n' \"${MEALIE_API_TOKEN}|${MEALIE_BASE_URL}|"
|
||
|
|
"${MEALIE_USER_AGENT}|${UNRELATED_SECRET-unset}|$*\"\n",
|
||
|
|
encoding="utf-8",
|
||
|
|
)
|
||
|
|
executable.chmod(0o755)
|
||
|
|
return executable
|
||
|
|
|
||
|
|
|
||
|
|
def test_launcher_reads_only_mealie_values_and_clears_unrelated_secrets(
|
||
|
|
tmp_path: Path,
|
||
|
|
) -> None:
|
||
|
|
env_file = tmp_path / "hermes.env"
|
||
|
|
env_file.write_text(
|
||
|
|
"OTHER_PROVIDER_TOKEN=must-not-leak\n"
|
||
|
|
"MEALIE_API_TOKEN='test-token'\n"
|
||
|
|
"MEALIE_BASE_URL=https://mealie.example\n"
|
||
|
|
'MEALIE_USER_AGENT="Test-Agent/1.0"\n',
|
||
|
|
encoding="utf-8",
|
||
|
|
)
|
||
|
|
env = {
|
||
|
|
**os.environ,
|
||
|
|
"MEALIE_ENV_FILE": str(env_file),
|
||
|
|
"MEALIE_MCP_REPO_DIR": "/tmp/test-repo",
|
||
|
|
"MEALIE_UV_BIN": str(_fake_uv(tmp_path)),
|
||
|
|
"UNRELATED_SECRET": "must-not-leak",
|
||
|
|
}
|
||
|
|
|
||
|
|
result = subprocess.run(
|
||
|
|
[str(LAUNCHER)],
|
||
|
|
check=False,
|
||
|
|
capture_output=True,
|
||
|
|
text=True,
|
||
|
|
env=env,
|
||
|
|
)
|
||
|
|
|
||
|
|
assert result.returncode == 0
|
||
|
|
assert result.stdout.strip() == (
|
||
|
|
"test-token|https://mealie.example|Test-Agent/1.0|unset|"
|
||
|
|
"--directory /tmp/test-repo run mealie-mcp-read-only"
|
||
|
|
)
|
||
|
|
assert "must-not-leak" not in result.stdout
|
||
|
|
|
||
|
|
|
||
|
|
def test_launcher_fails_without_mealie_token(tmp_path: Path) -> None:
|
||
|
|
env_file = tmp_path / "empty.env"
|
||
|
|
env_file.write_text("MEALIE_BASE_URL=https://mealie.example\n", encoding="utf-8")
|
||
|
|
env = {
|
||
|
|
"HOME": str(tmp_path),
|
||
|
|
"PATH": os.environ["PATH"],
|
||
|
|
"MEALIE_ENV_FILE": str(env_file),
|
||
|
|
"MEALIE_UV_BIN": str(_fake_uv(tmp_path)),
|
||
|
|
}
|
||
|
|
|
||
|
|
result = subprocess.run(
|
||
|
|
[str(LAUNCHER)],
|
||
|
|
check=False,
|
||
|
|
capture_output=True,
|
||
|
|
text=True,
|
||
|
|
env=env,
|
||
|
|
)
|
||
|
|
|
||
|
|
assert result.returncode == 1
|
||
|
|
assert "MEALIE_API_TOKEN is not set" in result.stderr
|