Two install-path bugs surfaced by SSHing into the hot-fixed test VM:
1. mktemp creates the staging dir with mode 700 by default; the rename
to /opt/furtka/versions/<ver>/ preserved it, and Caddy (running as
the unprivileged `caddy` user) got 403 Forbidden because it couldn't
traverse the version dir. Now the install + self-update both
`chmod 755` after the rename.
2. _furtka_json_cmd was a silent no-op on the 43a39a4 VM — the
base64-encoded body + sed substitution approach layered two sets of
quotes through archinstall's custom_commands eval, and the sed
step either never ran or didn't match. Replaced with a plain
heredoc that interpolates $(date -Iseconds) and $(cat VERSION) at
chroot runtime. Result lands /var/lib/furtka/furtka.json reliably,
which is what the landing page's hostname chip and the settings
page's install-date field depend on.
Both issues confirmed fixed by applying them manually on the VM
(chmod 755 /opt/furtka/versions/26.0-alpha + writing furtka.json by
hand): landing page, /apps, /settings, /furtka.json all now 200 with
correct content.
Tests updated (the chmod 755 gets asserted; the old base64+sed test
gets replaced with a heredoc-shape check; the updater test asserts
0o755 mode on the finished version dir).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
138 lines
5.6 KiB
Python
138 lines
5.6 KiB
Python
"""Asset sourcing + install-flow tests for webinstaller.
|
|
|
|
Phase-2 slice 1a moved every HTML/CSS/script/unit payload out of inline
|
|
Python string constants and into real files under furtka/assets/. Slice 1b
|
|
then flipped Caddy to serve from /opt/furtka/current/assets/www/, retired
|
|
/srv/furtka/www/, and switched systemd units from hand-written files in
|
|
/etc/systemd/system/ to `systemctl link` against the shipped asset tree.
|
|
|
|
These tests lock the new contract:
|
|
- the Caddyfile and the status.json placeholder still land via
|
|
_write_file_cmd and match the on-disk asset bit-for-bit,
|
|
- the resource-manager bootstrap extracts to /opt/furtka/versions/<ver>/,
|
|
creates /opt/furtka/current, and systemctl-links every unit,
|
|
- furtka.json is written with the installer's hostname,
|
|
- no write ever targets /srv/furtka/www/ (that path is retired).
|
|
"""
|
|
|
|
import base64
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "webinstaller"))
|
|
import app # noqa: E402
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
ASSETS = REPO_ROOT / "assets"
|
|
|
|
|
|
# (install target path, asset path under furtka/assets/) — only the files we
|
|
# still copy bit-for-bit at install time. Scripts + unit files are no longer
|
|
# copied; they're reached via /opt/furtka/current and `systemctl link`.
|
|
ASSET_TARGETS = [
|
|
("/etc/caddy/Caddyfile", "Caddyfile"),
|
|
("/var/lib/furtka/status.json", "www/status.json"),
|
|
]
|
|
|
|
|
|
def _extract_written_content(cmd, target):
|
|
"""Pull the base64 payload back out of a _write_file_cmd() shell string."""
|
|
match = re.search(r"printf %s (\S+) \| base64 -d > " + re.escape(target), cmd)
|
|
assert match, f"cmd didn't look like a write of {target}: {cmd[:100]}"
|
|
return base64.b64decode(match.group(1)).decode("utf-8")
|
|
|
|
|
|
@pytest.fixture
|
|
def install_cmds(tmp_path, monkeypatch):
|
|
# Make _resource_manager_commands return a non-empty list so the full
|
|
# command tree is exercised. A fake payload file is enough since the
|
|
# test only inspects the generated shell strings.
|
|
fake = tmp_path / "payload.tar.gz"
|
|
fake.write_bytes(b"not a real tarball")
|
|
monkeypatch.setattr(app, "RESOURCE_MANAGER_PAYLOAD", fake)
|
|
return app._post_install_commands("testhost")
|
|
|
|
|
|
@pytest.mark.parametrize("target,asset_relpath", ASSET_TARGETS)
|
|
def test_post_install_writes_asset_from_disk(install_cmds, target, asset_relpath):
|
|
expected = (ASSETS / asset_relpath).read_text(encoding="utf-8")
|
|
matching = [c for c in install_cmds if f" > {target}" in c]
|
|
assert matching, f"no command writes {target}"
|
|
assert _extract_written_content(matching[0], target) == expected
|
|
|
|
|
|
def test_no_command_writes_to_retired_srv_path(install_cmds):
|
|
for c in install_cmds:
|
|
assert "/srv/furtka/www" not in c, f"retired /srv/furtka/www write: {c[:120]}"
|
|
|
|
|
|
def test_resource_manager_extracts_to_versioned_slot(install_cmds):
|
|
extract_cmd = next((c for c in install_cmds if "tar -xzf" in c), None)
|
|
assert extract_cmd is not None, "no tar extract command"
|
|
assert "/opt/furtka/versions" in extract_cmd
|
|
assert "staging-" in extract_cmd # mktemp -d pattern
|
|
assert 'cat "$staging/VERSION"' in extract_cmd
|
|
# An empty VERSION file must abort the install instead of silently
|
|
# moving the staging dir into versions/ as a subdir.
|
|
assert '[ -n "$ver" ]' in extract_cmd
|
|
# Version dir must be 755 so Caddy (non-root) can traverse it.
|
|
assert 'chmod 755 "/opt/furtka/versions/$ver"' in extract_cmd
|
|
assert 'ln -sfn "/opt/furtka/versions/$ver" /opt/furtka/current' in extract_cmd
|
|
|
|
|
|
def test_furtka_json_cmd_uses_heredoc_and_interpolates_hostname(install_cmds):
|
|
# Regression: the previous base64+sed version of this command was a
|
|
# silent no-op on some installs due to archinstall-side quoting; the
|
|
# heredoc version is the one that reliably writes furtka.json.
|
|
cmd = next((c for c in install_cmds if "/var/lib/furtka/furtka.json" in c), None)
|
|
assert cmd is not None
|
|
assert "cat > /var/lib/furtka/furtka.json <<EOF" in cmd
|
|
assert '"hostname": "testhost"' in cmd
|
|
assert "date -Iseconds" in cmd
|
|
assert "/opt/furtka/current/VERSION" in cmd
|
|
|
|
|
|
def test_resource_manager_systemctl_links_every_unit(install_cmds):
|
|
link_cmd = next((c for c in install_cmds if c.startswith("systemctl link ")), None)
|
|
assert link_cmd is not None, "no systemctl link command"
|
|
for unit in app._FURTKA_UNITS:
|
|
assert f"/opt/furtka/current/assets/systemd/{unit}" in link_cmd
|
|
|
|
|
|
def test_resource_manager_enables_all_units(install_cmds):
|
|
enable_cmd = next((c for c in install_cmds if c.startswith("systemctl enable ")), None)
|
|
assert enable_cmd is not None
|
|
for unit in app._FURTKA_UNITS:
|
|
assert unit in enable_cmd
|
|
|
|
|
|
def test_wrapper_script_points_at_current_symlink():
|
|
assert "PYTHONPATH=/opt/furtka/current" in app._FURTKA_WRAPPER_SH
|
|
|
|
|
|
def test_caddyfile_asset_serves_from_current():
|
|
caddy = (ASSETS / "Caddyfile").read_text()
|
|
assert "root * /opt/furtka/current/assets/www" in caddy
|
|
assert "/srv/furtka/www" not in caddy
|
|
# Runtime JSON paths served from /var/lib/furtka/ so updates don't clobber.
|
|
assert "root * /var/lib/furtka" in caddy
|
|
|
|
|
|
def test_systemd_units_reference_current_paths():
|
|
for unit in ("furtka-status.service", "furtka-welcome.service"):
|
|
body = (ASSETS / "systemd" / unit).read_text()
|
|
assert "/opt/furtka/current/assets/bin/" in body, (
|
|
f"{unit} still references a /usr/local/bin path"
|
|
)
|
|
|
|
|
|
def test_read_asset_raises_for_missing_file():
|
|
with pytest.raises(FileNotFoundError):
|
|
app._read_asset("does/not/exist.html")
|
|
|
|
|
|
def test_assets_dir_resolves_to_repo_tree():
|
|
assert app._ASSETS_DIR == ASSETS
|