Stage pinned Multiverse Core for Lobby world transfers

This commit is contained in:
unimatrixgit 2026-12-05 14:33:18 +01:00
commit 534cfb1959
3 changed files with 113 additions and 0 deletions

View file

@ -0,0 +1,29 @@
name: Reviewed Lobby Multiverse Core
on:
workflow_dispatch:
push:
branches: ['fix/compact-menu-links-*']
jobs:
multiverse-core:
runs-on: dune-ci
steps:
- name: Check out exact revision
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git init .
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git "$GITHUB_SHA"
git checkout --detach FETCH_HEAD
- name: Verify the official Core input and package Lobby configuration
shell: bash
run: |
set -euo pipefail
python3 tools/test_multiverse_core.py -v
python3 tools/stage_multiverse_core.py multiverse-core-lobby "$GITHUB_SHA"
- uses: actions/upload-artifact@v3
with:
name: DuneRealms-Multiverse-Core-Lobby
path: multiverse-core-lobby
if-no-files-found: error

View file

@ -0,0 +1,52 @@
"""Package the immutable official Multiverse-Core input for Lobby only."""
import argparse
import hashlib
import io
import json
from pathlib import Path
import re
from urllib.request import Request, urlopen
import zipfile
ROOT = Path(__file__).resolve().parents[1]
def verify(data, pin):
for kind in ("sha256", "sha512"):
if hashlib.new(kind, data).hexdigest() != pin[kind]:
raise ValueError("Unexpected official Multiverse checksum")
with zipfile.ZipFile(io.BytesIO(data)) as jar:
descriptor = jar.read("plugin.yml").decode()
for key, value in (("name", "Multiverse-Core"), ("version", pin["version"])):
if not re.search(r"^" + key + r":\s*['\"]?" + re.escape(value) + r"['\"]?\s*$", descriptor, re.M):
raise ValueError("Unexpected Multiverse plugin identity")
if pin["scope"] != ["lobby"] or pin["optionalModulesInstalled"]:
raise ValueError("Only Core on Lobby is authorized")
def stage(output, source, supplied=None):
if not re.fullmatch(r"[a-f0-9]{40}", source):
raise ValueError("An exact source commit is required")
pin_path = ROOT / "network/lobby/multiverse-core.json"
pin = json.loads(pin_path.read_text())
if supplied:
data = supplied.read_bytes()
else:
request = Request(pin["url"], headers={"User-Agent": "DuneRealms-reviewed-build/1"})
with urlopen(request, timeout=60) as response:
data = response.read(8 * 1024 * 1024 + 1)
verify(data, pin)
output.mkdir(exist_ok=False)
(output / pin["filename"]).write_bytes(data)
(output / "config.yml").write_bytes((ROOT / "network/lobby/multiverse-config.yml").read_bytes())
(output / "multiverse-core.json").write_bytes(pin_path.read_bytes())
(output / "LICENSE-Multiverse-Core.md").write_bytes((ROOT / "network/lobby/multiverse-LICENSE.md").read_bytes())
(output / "SOURCE_COMMIT").write_text(source + "\n")
sums = [hashlib.sha256(p.read_bytes()).hexdigest() + " " + p.name for p in sorted(output.iterdir())]
(output / "SHA256SUMS").write_text("\n".join(sums) + "\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("output", type=Path)
parser.add_argument("source")
parser.add_argument("--supplied", type=Path)
args = parser.parse_args()
stage(args.output, args.source, args.supplied)

View file

@ -0,0 +1,32 @@
import hashlib
import io
import unittest
import zipfile
from stage_multiverse_core import verify
class VendorIdentity(unittest.TestCase):
def fixture(self, name="Multiverse-Core"):
out=io.BytesIO()
with zipfile.ZipFile(out,"w") as z:
z.writestr("plugin.yml",f"name: {name}\nversion: 5.8.2\n")
data=out.getvalue()
pin={k:hashlib.new(k,data).hexdigest() for k in ["sha256","sha512"]}
return data,dict(pin,version="5.8.2",scope=["lobby"],optionalModulesInstalled=[])
def test_exact_identity(self):
data,pin=self.fixture();verify(data,pin)
def test_changed_binary_rejected(self):
data,pin=self.fixture()
with self.assertRaises(ValueError):verify(data+b"changed",pin)
def test_inventory_module_rejected(self):
data,pin=self.fixture("Multiverse-Inventories")
with self.assertRaises(ValueError):verify(data,pin)
def test_scope_and_optional_modules_rejected(self):
data,pin=self.fixture()
for edit in [dict(scope=["sigma_draconis_iv"]),dict(optionalModulesInstalled=["inventories"])]:
with self.assertRaises(ValueError):verify(data,dict(pin,**edit))
if __name__=="__main__":unittest.main()