65 lines
2.7 KiB
Python
65 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Validate the inactive Phase-1.0AD record and byte bindings."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import ast
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def digest(path: Path) -> tuple[int, str]:
|
|
data = path.read_bytes()
|
|
return len(data), hashlib.sha256(data).hexdigest()
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--root", type=Path, required=True)
|
|
root = parser.parse_args().root.resolve()
|
|
manifest = json.loads((root / "manifests/retroarch/phase-1.0ad-inactive-activation.json").read_text(encoding="utf-8"))
|
|
activation = manifest["activation"]
|
|
authorization = manifest["authorizations"]
|
|
assert manifest["phase"] == "PHASE_1_0AD_INACTIVE_NUMERIC_TARGET_CONTRACT"
|
|
assert activation["active"] is False
|
|
assert all(activation[name] is None for name in (
|
|
"target_address", "target_port", "run_id", "not_before",
|
|
"expires_at", "launcher_sha256", "payload_sha256", "approval_sha256"))
|
|
assert activation["one_shot"] is True
|
|
assert activation["automatic_retry"] is False
|
|
assert activation["reconnect"] is False
|
|
assert activation["resume"] is False
|
|
assert not any(authorization.values())
|
|
assert manifest["decision"]["device_action_allowed"] is False
|
|
assert manifest["decision"]["bigapp_launcher_implementation_allowed"] is False
|
|
|
|
bindings = manifest["source_bindings"]
|
|
files = {
|
|
"contract": root / "tools/phase10ad_activation_contract.py",
|
|
"tests": root / "tests/test_phase10ad_activation_contract.py",
|
|
"documentation": root / "docs/retroarch/phase-1.0ad-inactive-activation-contract.md",
|
|
}
|
|
for name, path in files.items():
|
|
size, sha256 = digest(path)
|
|
assert bindings[f"{name}_size"] == size
|
|
assert bindings[f"{name}_sha256"] == sha256
|
|
|
|
tree = ast.parse(files["contract"].read_text(encoding="utf-8"))
|
|
imports = {alias.name.split(".")[0] for node in ast.walk(tree)
|
|
if isinstance(node, ast.Import) for alias in node.names}
|
|
imports.update(node.module.split(".")[0] for node in ast.walk(tree)
|
|
if isinstance(node, ast.ImportFrom) and node.module)
|
|
assert not imports.intersection({"socket", "selectors", "subprocess", "urllib", "http", "requests"})
|
|
calls = {node.func.id for node in ast.walk(tree) if isinstance(node, ast.Call)
|
|
and isinstance(node.func, ast.Name)}
|
|
assert not calls.intersection({"open", "exec", "eval", "compile", "input"})
|
|
print("Phase-1.0AD inactive activation contract validation passed")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|