85 lines
4.5 KiB
Python
85 lines
4.5 KiB
Python
# #region Test.Tooling.FullFlowArtifactPaths [C:3] [TYPE Module] [SEMANTICS evidence,path,negative]
|
|
# @TEST_INVARIANT Forbidden repository paths refuse before private inputs, directory creation or network construction.
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
|
|
|
|
# #region Test.Tooling.FullFlowArtifactPaths.Load [C:1] [TYPE Function]
|
|
def load(name, path):
|
|
spec = importlib.util.spec_from_file_location(name, path)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
# #endregion Test.Tooling.FullFlowArtifactPaths.Load
|
|
|
|
|
|
# #region Test.Tooling.FullFlowArtifactPaths.Admission [C:2] [TYPE Function]
|
|
def test_artifact_external_and_symlink_admission_is_readonly(tmp_path, monkeypatch):
|
|
common = load("synthetic_full_flow_paths", ROOT / "scripts/full_flow/common.py")
|
|
repo, external = tmp_path / "worktree", tmp_path / "external"
|
|
(repo / "scripts/full_flow").mkdir(parents=True)
|
|
(repo / "specs").mkdir()
|
|
external.mkdir()
|
|
monkeypatch.setattr(common, "__file__", str(repo / "scripts/full_flow/common.py"))
|
|
assert common.artifact_path(repo / "artifacts/new/report.json") == repo / "artifacts/new/report.json"
|
|
assert common.artifact_path(external / "report.json") == external / "report.json"
|
|
for forbidden in (repo, repo / "specs/report.json", repo / "backend/report.json"):
|
|
with pytest.raises(common.Blocked, match="EVIDENCE_OUTPUT_PATH_FORBIDDEN"):
|
|
common.artifact_path(forbidden)
|
|
(external / "alias").symlink_to(repo / "specs", target_is_directory=True)
|
|
(repo / "artifacts").symlink_to(repo / "specs", target_is_directory=True)
|
|
for alias in (external / "alias/report.json", repo / "artifacts/report.json"):
|
|
with pytest.raises(common.Blocked, match="EVIDENCE_OUTPUT_PATH_FORBIDDEN"):
|
|
common.artifact_path(alias)
|
|
(external / "loop").symlink_to(external / "loop")
|
|
with pytest.raises(common.Blocked, match="EVIDENCE_OUTPUT_PATH_UNAVAILABLE"):
|
|
common.artifact_path(external / "loop/report.json")
|
|
assert list((repo / "specs").iterdir()) == []
|
|
assert not (external / "report.json").exists()
|
|
# #endregion Test.Tooling.FullFlowArtifactPaths.Admission
|
|
|
|
|
|
# #region Test.Tooling.FullFlowArtifactPaths.Driver [C:2] [TYPE Function]
|
|
def test_driver_refuses_before_mkdir_credentials_or_client(monkeypatch):
|
|
common = load("driver_full_flow_paths", ROOT / "scripts/full_flow/common.py")
|
|
monkeypatch.setitem(sys.modules, "common", common)
|
|
client = load("synthetic_full_flow_client", ROOT / "scripts/full_flow/client.py")
|
|
monkeypatch.delenv("FIXTURE_PASSWORD", raising=False)
|
|
calls = []
|
|
monkeypatch.setattr(client.httpx, "Client", lambda **kwargs: calls.append(kwargs))
|
|
forbidden = ROOT / "specs/synthetic-output-must-not-exist"
|
|
assert not forbidden.exists()
|
|
with pytest.raises(common.Blocked, match="EVIDENCE_OUTPUT_PATH_FORBIDDEN"):
|
|
client.HttpDriver({}, forbidden)
|
|
assert calls == []
|
|
assert not forbidden.exists()
|
|
# #endregion Test.Tooling.FullFlowArtifactPaths.Driver
|
|
|
|
|
|
# #region Test.Tooling.FullFlowArtifactPaths.Cli [C:2] [TYPE Function]
|
|
@pytest.mark.parametrize("script,arguments", [
|
|
("full_flow/verify.py", ["--fixture", "missing", "--env-file", "missing", "--output"]),
|
|
("full_flow/extract_revision.py", ["--fixture", "missing", "--env-file", "missing", "--evidence"]),
|
|
("full_flow_v2/verify.py", ["--fixture", "missing", "--env-file", "missing", "--output"]),
|
|
("full_flow_v2/extract_revision.py", ["--fixture", "missing", "--env-file", "missing", "--evidence"]),
|
|
("full_flow_v2/audit_results.py", ["--output"]),
|
|
("full_flow_finance/verify.py", ["--fixture", "missing", "--env-file", "missing",
|
|
"--capture-output", "missing", "--phase", "manual", "--output"]),
|
|
])
|
|
def test_actual_cli_refuses_path_before_missing_private_inputs(script, arguments):
|
|
result = subprocess.run([sys.executable, str(ROOT / "scripts" / script), *arguments,
|
|
str(ROOT / "specs/synthetic-output-must-not-exist")],
|
|
cwd=ROOT, capture_output=True, text=True, timeout=10)
|
|
assert result.returncode != 0
|
|
assert "EVIDENCE_OUTPUT_PATH_FORBIDDEN" in result.stderr
|
|
assert "FileNotFoundError" not in result.stderr
|
|
assert not (ROOT / "specs/synthetic-output-must-not-exist").exists()
|
|
# #endregion Test.Tooling.FullFlowArtifactPaths.Cli
|
|
# #endregion Test.Tooling.FullFlowArtifactPaths
|