test: verify the source of upstream issue inputs
This commit was merged in pull request #10.
This commit is contained in:
1 parent
8c8360c942
commit
3cc477de60
2 files changed
+70
No files matched your search
@@ -19,6 +19,7 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- python3 tools/ci/test_release_metadata.py
|
- python3 tools/ci/test_release_metadata.py
|
||||||
- python3 tools/ci/test_publish_gitea.py
|
- python3 tools/ci/test_publish_gitea.py
|
||||||
|
- python3 tools/ci/test_verify_upstream.py
|
||||||
- cargo fmt --all -- --check
|
- cargo fmt --all -- --check
|
||||||
- cargo clippy --workspace --all-targets --locked -- -D warnings
|
- cargo clippy --workspace --all-targets --locked -- -D warnings
|
||||||
- cargo test --workspace --locked
|
- cargo test --workspace --locked
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
"""Regression tests for the root task and Knowledge verification boundary."""
|
||||||
|
import hashlib
|
||||||
|
import importlib.util
|
||||||
|
import json
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
spec = importlib.util.spec_from_file_location("upstream", Path(__file__).with_name("verify-upstream.py"))
|
||||||
|
upstream = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(upstream)
|
||||||
|
|
||||||
|
|
||||||
|
def digest(value):
|
||||||
|
return hashlib.sha256(value.encode()).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
class UpstreamTaskTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.source, self.consumer, self.root, self.index, self.asset = (c * n for c, n in
|
||||||
|
(("a", 40), ("b", 40), ("c", 40), ("d", 64), ("e", 64)))
|
||||||
|
self.tag = "v3.0.0-rc.6"
|
||||||
|
key = digest(f"{upstream.REPO}\n{self.tag}\n{self.source}")
|
||||||
|
inputs = {"consumer": {"id": "knowledge", "source_sha": self.consumer},
|
||||||
|
"accepted_dependencies": [],
|
||||||
|
"release": {"repository": upstream.REPO, "tag": self.tag, "source_sha": self.source,
|
||||||
|
"index_sha256": self.index, "dependencies": [],
|
||||||
|
"assets": [{"name": f"marqdo-{self.tag[1:]}-{upstream.TARGET}.tar.gz",
|
||||||
|
"sha256": self.asset, "target": upstream.TARGET, "size": 9}]}}
|
||||||
|
value = digest(json.dumps(inputs, sort_keys=True, separators=(",", ":")))
|
||||||
|
task = digest(f"{key}\nknowledge\n{value}")
|
||||||
|
user = {"login": upstream.COORDINATOR}
|
||||||
|
fence = chr(96) * 3
|
||||||
|
self.issue = {"state": "open", "user": user, "body":
|
||||||
|
f"<!-- marqdo:upstream release={key} consumer=knowledge -->\n"
|
||||||
|
f"<!-- marqdo:candidate-inputs {task} -->\n"
|
||||||
|
f"- Root tracking issue: {upstream.FORGE}/{upstream.ROOT_REPO}/issues/11\n"
|
||||||
|
f"- Root candidate: {self.root}\n- Input digest: {value}\n- State: pending\n"
|
||||||
|
f"\n{fence}json\n{json.dumps(inputs)}\n{fence}"}
|
||||||
|
self.tracker = {"state": "open", "user": user, "body":
|
||||||
|
f"<!-- marqdo:release-reconcile repository={upstream.REPO} tag={self.tag} -->\n"
|
||||||
|
f"<!-- marqdo:verified-release {self.source} {self.index} -->"}
|
||||||
|
self.branch = {"protected": True, "commit": {"id": self.root}}
|
||||||
|
|
||||||
|
def forge(self, opener, path):
|
||||||
|
if "comments?" in path:
|
||||||
|
return []
|
||||||
|
return {f"/repos/{upstream.CONSUMER}/issues/12": self.issue,
|
||||||
|
f"/repos/{upstream.ROOT_REPO}/branches/main": self.branch,
|
||||||
|
f"/repos/{upstream.ROOT_REPO}/issues/11": self.tracker}[path]
|
||||||
|
|
||||||
|
def run_verify(self):
|
||||||
|
with patch.object(upstream, "forge_json", self.forge):
|
||||||
|
return upstream.issue_input(None, 12, self.consumer)
|
||||||
|
|
||||||
|
def test_current_authorized_task_resolves_to_exact_cli(self):
|
||||||
|
self.assertEqual(self.run_verify(), (self.tag, self.source, self.asset))
|
||||||
|
|
||||||
|
def test_stale_root_and_wrong_task_author_are_rejected(self):
|
||||||
|
self.branch["commit"]["id"] = "f" * 40
|
||||||
|
with self.assertRaisesRegex(upstream.VerificationError, "stale"):
|
||||||
|
self.run_verify()
|
||||||
|
self.issue["user"] = {"login": "untrusted"}
|
||||||
|
with self.assertRaisesRegex(upstream.VerificationError, "reconcile account"):
|
||||||
|
self.run_verify()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user