Harden release artifact publication

This commit is contained in:
2026-07-22 20:41:42 +02:00
parent 35c346a1fa
commit 4dc0c8d013
5 changed files with 1057 additions and 20 deletions

View File

@@ -0,0 +1,59 @@
from __future__ import annotations
from pathlib import Path
import sys
import unittest
from unittest import mock
META_ROOT = Path(__file__).resolve().parents[1]
RELEASE_TOOLS_ROOT = META_ROOT / "tools" / "release"
if str(RELEASE_TOOLS_ROOT) not in sys.path:
sys.path.insert(0, str(RELEASE_TOOLS_ROOT))
from govoplan_release.module_directory import ( # noqa: E402
module_directory_payloads,
safe_path_part,
)
class ReleaseModuleDirectoryTests(unittest.TestCase):
def test_dot_segments_and_noncanonical_ids_never_become_paths(self) -> None:
for value in (".", "..", "../escape", "/absolute", "module/child"):
with self.subTest(value=value), self.assertRaises(ValueError):
safe_path_part(value)
for module_id in ("..", "../escape", "UPPER", "bad.id"):
with self.subTest(module_id=module_id), mock.patch(
"govoplan_release.module_directory.module_rows",
return_value=[
{
"module_id": module_id,
"version": "1.2.3",
}
],
):
with self.assertRaises(ValueError):
module_directory_payloads(
catalog_payload={},
keyring_payload={},
channel="stable",
)
def test_noncanonical_version_and_channel_fail_before_paths(self) -> None:
with mock.patch(
"govoplan_release.module_directory.module_rows",
return_value=[{"module_id": "demo", "version": "../1.2.3"}],
):
with self.assertRaises(ValueError):
module_directory_payloads(
catalog_payload={}, keyring_payload={}, channel="stable"
)
with self.assertRaises(ValueError):
module_directory_payloads(
catalog_payload={}, keyring_payload={}, channel="../stable"
)
if __name__ == "__main__":
unittest.main()