Publish curated Unraid-AppOps-Gateway source from 945a919d1a3bbd2bb5bd21eb221fc9b58d795d80

This commit is contained in:
Public Source Publisher committed 2026-10-12 03:57:24 +00:00
1 parent aa9f7d178c
commit fd4b962bdd
10 files changed
+884 -37

No files matched your search

+52 -1
View File
@@ -5,6 +5,7 @@ import importlib
import io
import json
import contextlib
import os
import stat
import struct
import sys
@@ -119,6 +120,20 @@ def _private_file(path: Path, data: bytes) -> None:
path.chmod(0o600)
def _candidate_directory_link_count(monkeypatch, directory: Path, count: int) -> None:
original_lstat = Path.lstat
def candidate_lstat(path: Path, *args, **kwargs):
info = original_lstat(path, *args, **kwargs)
if path == directory:
values = list(info)
values[3] = count
return os.stat_result(values)
return info
monkeypatch.setattr(Path, "lstat", candidate_lstat)
def _synthetic_scan_reports(
services, images, *, created_at: str, finding_service: str | None = None
) -> dict[str, bytes]:
@@ -590,8 +605,10 @@ def test_unfixable_vulnerability_finding_is_bound_to_fixed_image_reference(modul
@pytest.mark.parametrize("finding_present", [False, True])
@pytest.mark.parametrize("rerun_during_load", [False, True])
@pytest.mark.parametrize("directory_link_count", [1, 2])
def test_fake_local_import_publishes_candidate_and_requires_review_for_findings(
modules, monkeypatch, tmp_path, finding_present, rerun_during_load
modules, monkeypatch, tmp_path, finding_present, rerun_during_load,
directory_link_count,
):
importer = modules.importer
prepare = modules.prepare
@@ -889,6 +906,7 @@ def test_fake_local_import_publishes_candidate_and_requires_review_for_findings(
monkeypatch.setattr(importer, "_publish_candidate", fake_no_overwrite_publish)
candidate_directory = state_root / "mcp-hub-release-candidates" / revision
_candidate_directory_link_count(monkeypatch, candidate_directory, directory_link_count)
if rerun_during_load:
with pytest.raises(importer.CandidateRejected, match="run changed"):
importer.prepare_candidate(
@@ -970,6 +988,39 @@ def test_fake_local_import_publishes_candidate_and_requires_review_for_findings(
assert (candidate_directory / "import-receipt.json").read_bytes() == receipt_before_review
@pytest.mark.skipif(os.name != "posix", reason="POSIX directory inode metadata")
@pytest.mark.parametrize("directory_issue", ["zero_links", "public_mode", "foreign_owner", "symlink", "file"])
def test_cached_candidate_rejects_unsafe_directory(
modules, monkeypatch, tmp_path, directory_issue,
):
importer, controller = modules.importer, modules.controller
revision = "a" * 40
state_root = tmp_path / "state"
directory = state_root / "mcp-hub-release-candidates" / revision
directory.mkdir(mode=0o700, parents=True)
monkeypatch.setattr(controller, "STATE_ROOT", state_root)
monkeypatch.setattr(controller, "_root_owned", lambda *_args: directory_issue != "foreign_owner")
_candidate_directory_link_count(monkeypatch, directory, 0 if directory_issue == "zero_links" else 1)
if directory_issue == "public_mode":
directory.chmod(0o755)
elif directory_issue == "symlink":
target = directory.with_name("owned-target")
directory.rename(target)
directory.symlink_to(target, target_is_directory=True)
elif directory_issue == "file":
directory.rmdir()
_private_file(directory, b"{}")
def reject_late_read(*_args):
raise AssertionError("Directory rejection must precede candidate evidence reads")
monkeypatch.setattr(controller, "_mcp_hub_candidate_directory", reject_late_read)
with pytest.raises(importer.CandidateRejected, match="not.*private"):
importer._cached_candidate_result(
revision, "b" * 40, {}, "", lambda *_args: {}, lambda *_args: None,
)
def test_candidate_artifact_is_exact_bounded_and_unexpired(modules):
importer = modules.importer
revision = "c" * 40