Fix read-only Web runtime publication
This commit is contained in:
@@ -9,6 +9,8 @@ import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from urllib.error import HTTPError
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -32,6 +34,10 @@ DEPLOYER_BUILD = _load(
|
||||
"build_deployer_zipapp",
|
||||
ROOT / "tools/deployment/build-deployer-zipapp.py",
|
||||
)
|
||||
PUBLISH = _load(
|
||||
"publish_runtime_release",
|
||||
ROOT / "tools/release/publish-runtime-release.py",
|
||||
)
|
||||
|
||||
|
||||
class RuntimeDistributionBuildTests(unittest.TestCase):
|
||||
@@ -99,6 +105,20 @@ class RuntimeDistributionBuildTests(unittest.TestCase):
|
||||
dockerfile,
|
||||
)
|
||||
|
||||
def test_web_runtime_uses_only_writable_tmpfs_for_nginx_temp_files(self) -> None:
|
||||
nginx = (ROOT / "tools/release/runtime/nginx.conf").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
for temporary_path in (
|
||||
"client_body_temp_path /tmp/client_temp;",
|
||||
"fastcgi_temp_path /tmp/fastcgi_temp;",
|
||||
"proxy_temp_path /tmp/proxy_temp;",
|
||||
"scgi_temp_path /tmp/scgi_temp;",
|
||||
"uwsgi_temp_path /tmp/uwsgi_temp;",
|
||||
):
|
||||
self.assertIn(temporary_path, nginx)
|
||||
|
||||
def test_workflow_verifies_portable_bootstrap_artifacts_before_execution(
|
||||
self,
|
||||
) -> None:
|
||||
@@ -128,6 +148,79 @@ class RuntimeDistributionBuildTests(unittest.TestCase):
|
||||
self.assertIn("runtime-smoke-amd64.json", workflow)
|
||||
self.assertIn("runtime-smoke-arm64.json", workflow)
|
||||
|
||||
def test_workflow_binds_the_release_tag_to_the_workflow_commit(self) -> None:
|
||||
workflow = (ROOT / ".gitea/workflows/runtime-distribution.yml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
publisher = (ROOT / "tools/release/publish-runtime-release.py").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
self.assertIn("SOURCE_COMMIT: ${{ gitea.sha }}", workflow)
|
||||
self.assertIn('--target-commit "$SOURCE_COMMIT"', workflow)
|
||||
self.assertIn('"target_commitish": target_commit', publisher)
|
||||
self.assertIn("self._resolve_commit(tag) != target_commit", publisher)
|
||||
|
||||
def test_runtime_publisher_rejects_a_tag_on_another_commit(self) -> None:
|
||||
publisher = PUBLISH.GiteaReleasePublisher(
|
||||
base_url="https://git.example.test",
|
||||
owner="GovOPlaN",
|
||||
repo="govoplan",
|
||||
token="secret",
|
||||
)
|
||||
target = "1" * 40
|
||||
with (
|
||||
patch.object(
|
||||
publisher,
|
||||
"_resolve_commit",
|
||||
side_effect=(target, "2" * 40),
|
||||
),
|
||||
self.assertRaisesRegex(PUBLISH.PublishError, "another commit"),
|
||||
):
|
||||
publisher.release(
|
||||
tag="v1.2.3",
|
||||
target_commit=target,
|
||||
title="Release",
|
||||
body="Body",
|
||||
)
|
||||
|
||||
def test_runtime_publisher_creates_the_tag_at_the_exact_commit(self) -> None:
|
||||
publisher = PUBLISH.GiteaReleasePublisher(
|
||||
base_url="https://git.example.test",
|
||||
owner="GovOPlaN",
|
||||
repo="govoplan",
|
||||
token="secret",
|
||||
)
|
||||
target = "1" * 40
|
||||
requests: list[tuple[str, dict[str, object] | None]] = []
|
||||
|
||||
def request(method: str, _url: str, **kwargs):
|
||||
payload = kwargs.get("payload")
|
||||
requests.append((method, payload))
|
||||
if method == "GET":
|
||||
raise HTTPError(_url, 404, "not found", {}, None)
|
||||
return {"id": 1}
|
||||
|
||||
with (
|
||||
patch.object(
|
||||
publisher,
|
||||
"_resolve_commit",
|
||||
side_effect=(target, None, target),
|
||||
),
|
||||
patch.object(publisher, "_json", side_effect=request),
|
||||
):
|
||||
release = publisher.release(
|
||||
tag="v1.2.3",
|
||||
target_commit=target,
|
||||
title="Release",
|
||||
body="Body",
|
||||
)
|
||||
|
||||
self.assertEqual({"id": 1}, release)
|
||||
self.assertEqual("POST", requests[-1][0])
|
||||
assert requests[-1][1] is not None
|
||||
self.assertEqual(target, requests[-1][1]["target_commitish"])
|
||||
|
||||
def test_resolves_platforms_and_builds_evidence_descriptor(self) -> None:
|
||||
index = {
|
||||
"schemaVersion": 2,
|
||||
|
||||
Reference in New Issue
Block a user