Ship Archipelago BGRT Plymouth theme; test the Cockpit page in Rust
This commit is contained in:
parent
4100d76100
commit
a818935ed3
9 changed files with 165 additions and 102 deletions
|
|
@ -6,3 +6,4 @@ publish = false
|
|||
|
||||
[dependencies]
|
||||
archipelago-contracts = { path = "../contracts" }
|
||||
serde_json = "1"
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ cat > "$updates/index.html" <<'EOF'
|
|||
<h2>Изменения</h2>
|
||||
<pre id="details" class="muted">Проверьте обновления, чтобы увидеть состав.</pre>
|
||||
</section>
|
||||
<script src="../base1/cockpit.js"></script>
|
||||
<script src="updates.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -118,11 +119,29 @@ function uuid() {
|
|||
hex.slice(16, 20) + "-" + hex.slice(20);
|
||||
}
|
||||
function options(extra) {
|
||||
return Object.assign({ interactive: true, request_id: uuid() }, extra || {});
|
||||
const result = { interactive: cockpit.variant("b", true), request_id: cockpit.variant("s", uuid()) };
|
||||
for (const [key, value] of Object.entries(extra || {})) {
|
||||
if (typeof value === "boolean") { result[key] = cockpit.variant("b", value); }
|
||||
else if (typeof value === "string") { result[key] = cockpit.variant("s", value); }
|
||||
else { throw new Error("Unsupported D-Bus option type: " + key); }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function unbox(value) {
|
||||
if (value && typeof value === "object" && typeof value.t === "string" && Object.prototype.hasOwnProperty.call(value, "v")) {
|
||||
return unbox(value.v);
|
||||
}
|
||||
if (Array.isArray(value)) { return value.map(unbox); }
|
||||
if (value && typeof value === "object") {
|
||||
const result = {};
|
||||
for (const [key, child] of Object.entries(value)) { result[key] = unbox(child); }
|
||||
return result;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
async function call(method, args) {
|
||||
const reply = await bus.call(MANAGER, MANAGER_IFACE, method, args || []);
|
||||
return reply[0];
|
||||
return unbox(reply[0]);
|
||||
}
|
||||
function showError(text) {
|
||||
$("error").hidden = !text;
|
||||
|
|
@ -153,7 +172,8 @@ async function refreshStatus() {
|
|||
}
|
||||
async function waitTransaction(path, caption) {
|
||||
for (;;) {
|
||||
const [snapshot] = await bus.call(path, TRANSACTION_IFACE, "GetSnapshot", []);
|
||||
const [rawSnapshot] = await bus.call(path, TRANSACTION_IFACE, "GetSnapshot", []);
|
||||
const snapshot = unbox(rawSnapshot);
|
||||
const progress = snapshot.Progress || {};
|
||||
const percent = typeof progress.percent === "number" ? progress.percent + "% · " : "";
|
||||
$("progress").textContent = caption + ": " + percent + (progress.message || snapshot.Phase || "");
|
||||
|
|
@ -177,16 +197,21 @@ async function check() {
|
|||
try {
|
||||
const refreshed = await run("Refresh", [options({ force: true })], "Проверка обновлений");
|
||||
target = refreshed.target || null;
|
||||
$("update").textContent = label(refreshed.state);
|
||||
const availability = refreshed.outcome;
|
||||
$("update").textContent = label(availability);
|
||||
planId = null;
|
||||
$("prepare").dataset.ready = target && refreshed.state !== "current" ? "yes" : "no";
|
||||
$("prepare").dataset.ready = target && availability === "available" ? "yes" : "no";
|
||||
$("download").dataset.ready = "no";
|
||||
$("stage").dataset.ready = "no";
|
||||
if (target && refreshed.state !== "current") {
|
||||
const details = await call("GetUpdateDetails", [target, options()]);
|
||||
if (target && availability === "available") {
|
||||
// GetUpdateDetails returns a transaction object path, not the details
|
||||
// payload. Observe the durable operation before rendering its result.
|
||||
const details = await run("GetUpdateDetails", [target, options()], "Состав обновления");
|
||||
$("details").textContent = JSON.stringify(details.plan || details, null, 2);
|
||||
} else {
|
||||
} else if (availability === "current") {
|
||||
$("details").textContent = "Система актуальна: новых образов нет.";
|
||||
} else {
|
||||
throw new Error("Неожиданный ответ Refresh: " + String(availability));
|
||||
}
|
||||
} catch (error) {
|
||||
showError(String(error.message || error));
|
||||
|
|
|
|||
|
|
@ -24,8 +24,10 @@ printf '%%wheel ALL=(ALL:ALL) ALL\n' > /job/core/etc/sudoers.d/10-archipelago-wh
|
|||
chmod 0440 /job/core/etc/sudoers.d/10-archipelago-wheel
|
||||
arch-chroot /job/core visudo -c
|
||||
mkdir -p /job/core/etc/plymouth
|
||||
printf '[Daemon]\nTheme=spinner\n' > /job/core/etc/plymouth/plymouthd.conf
|
||||
test -f /job/core/usr/share/plymouth/themes/spinner/spinner.plymouth
|
||||
printf '[Daemon]\nTheme=archipelago-bgrt\n' > /job/core/etc/plymouth/plymouthd.conf
|
||||
test -f /job/core/usr/share/plymouth/themes/archipelago-bgrt/archipelago-bgrt.plymouth
|
||||
test -f /job/core/usr/share/plymouth/themes/archipelago-bgrt/watermark.png
|
||||
! grep -q 'UseFirmwareBackground=true' /job/core/usr/share/plymouth/themes/archipelago-bgrt/archipelago-bgrt.plymouth
|
||||
cp /job/core/usr/share/archipelago/desktop/toolbox.conf /job/core/etc/containers/toolbox.conf
|
||||
install -Dm644 /job/core/usr/share/archipelago/desktop/toolbox-registries.conf /job/core/etc/containers/registries.conf.d/60-archipelago-toolbox.conf
|
||||
arch-chroot /job/core glib-compile-schemas /usr/share/glib-2.0/schemas
|
||||
|
|
|
|||
|
|
@ -177,7 +177,8 @@ mv /job/finalize-pacman.conf /job/core/etc/pacman.conf
|
|||
arch-chroot /job/core /bin/bash -euxc 'k=$(basename /usr/lib/modules/*); depmod "$k"; mkinitcpio -c /usr/lib/archipelago/mkinitcpio-gnome.conf -k "$k" -g "/usr/lib/modules/$k/initramfs.img"; ldconfig; systemd-hwdb update --usr'
|
||||
arch-chroot /job/core /bin/bash -euc 'k=$(basename /usr/lib/modules/*); lsinitcpio "/usr/lib/modules/$k/initramfs.img"' > /job/evidence/gnome-initramfs-files.txt
|
||||
grep -q 'usr/bin/plymouthd$' /job/evidence/gnome-initramfs-files.txt
|
||||
grep -q 'usr/share/plymouth/themes/spinner/spinner.plymouth$' /job/evidence/gnome-initramfs-files.txt
|
||||
grep -q 'usr/share/plymouth/themes/archipelago-bgrt/archipelago-bgrt.plymouth$' /job/evidence/gnome-initramfs-files.txt
|
||||
grep -q 'usr/share/plymouth/themes/archipelago-bgrt/watermark.png$' /job/evidence/gnome-initramfs-files.txt
|
||||
# Inventory is a read-only local DB query: do not initialize repository trust or
|
||||
# the download sandbox in a finalized root containing factory accounts.
|
||||
arch-chroot /job/core pacman --config /dev/null --dbpath /usr/lib/archipelago/package-db -Q > /job/evidence/core-packages.txt
|
||||
|
|
|
|||
|
|
@ -3,6 +3,20 @@ sed -e 's/HOOKS=(base systemd /HOOKS=(base systemd plymouth /' \
|
|||
-e 's/modconf block/modconf kms keyboard sd-vconsole resume block/' "$pkg/runtime/usr/lib/archipelago/mkinitcpio-core.conf" > "$pkg/runtime/usr/lib/archipelago/mkinitcpio-gnome.conf"
|
||||
printf 'resume hook present: sleep-to-disk provisioning is supported\n' > "$pkg/runtime/usr/lib/archipelago/hibernate"
|
||||
printf 'plymouth\n' > "$pkg/runtime/usr/lib/archipelago/desktop-boot"
|
||||
plymouth_source="$stage/usr/share/plymouth/themes/spinner"
|
||||
plymouth_theme="$pkg/runtime/usr/share/plymouth/themes/archipelago-bgrt"
|
||||
test -f "$plymouth_source/spinner.plymouth"
|
||||
mkdir -p "$plymouth_theme"
|
||||
cp -a "$plymouth_source/." "$plymouth_theme/"
|
||||
rm -f "$plymouth_theme/spinner.plymouth"
|
||||
cat > "$plymouth_theme/archipelago-bgrt.plymouth" <<'BGRT'
|
||||
@@PLYMOUTH_THEME@@
|
||||
BGRT
|
||||
printf '%s' '@@PLYMOUTH_WATERMARK_BASE64@@' | base64 -d > "$plymouth_theme/watermark.png"
|
||||
cmp -s "$plymouth_source/watermark.png" "$plymouth_theme/watermark.png" && {
|
||||
echo 'Plymouth Arch Linux watermark was not replaced' >&2
|
||||
exit 1
|
||||
}
|
||||
mkdir -p "$pkg/runtime/usr/lib/systemd/zram-generator.conf.d"
|
||||
printf '[zram0]\n' > "$pkg/runtime/usr/lib/systemd/zram-generator.conf.d/20-archipelago-desktop.conf"
|
||||
sed 's/Archipelago Core/Archipelago GNOME/g' "$pkg/runtime/usr/lib/archipelago/defaults/os-release" > "$pkg/runtime/usr/lib/archipelago/defaults/os-release-gnome"
|
||||
|
|
|
|||
|
|
@ -53,8 +53,10 @@ chmod 0440 /job/core/etc/sudoers.d/10-archipelago-wheel
|
|||
test "$(stat -c '%a' /job/core/etc/sudoers.d/10-archipelago-wheel)" = "440"
|
||||
test "$(cat /job/core/etc/sudoers.d/10-archipelago-wheel)" = '%wheel ALL=(ALL:ALL) ALL'
|
||||
mkdir -p /job/core/etc/plymouth
|
||||
printf '[Daemon]\nTheme=spinner\n' > /job/core/etc/plymouth/plymouthd.conf
|
||||
test -f /job/core/usr/share/plymouth/themes/spinner/spinner.plymouth
|
||||
printf '[Daemon]\nTheme=archipelago-bgrt\n' > /job/core/etc/plymouth/plymouthd.conf
|
||||
test -f /job/core/usr/share/plymouth/themes/archipelago-bgrt/archipelago-bgrt.plymouth
|
||||
test -f /job/core/usr/share/plymouth/themes/archipelago-bgrt/watermark.png
|
||||
! grep -q 'UseFirmwareBackground=true' /job/core/usr/share/plymouth/themes/archipelago-bgrt/archipelago-bgrt.plymouth
|
||||
test ! -e /job/core/etc/plasma-setup-done
|
||||
cp /job/core/usr/share/archipelago/desktop/toolbox.conf /job/core/etc/containers/toolbox.conf
|
||||
install -Dm644 /job/core/usr/share/archipelago/desktop/toolbox-registries.conf /job/core/etc/containers/registries.conf.d/60-archipelago-toolbox.conf
|
||||
|
|
|
|||
|
|
@ -7,6 +7,20 @@ sed -e 's/HOOKS=(base systemd /HOOKS=(base systemd plymouth /' \
|
|||
-e 's/modconf block/modconf kms keyboard sd-vconsole resume block/' "$pkg/runtime/usr/lib/archipelago/mkinitcpio-core.conf" > "$pkg/runtime/usr/lib/archipelago/mkinitcpio-kde.conf"
|
||||
printf 'resume hook present: sleep-to-disk provisioning is supported\n' > "$pkg/runtime/usr/lib/archipelago/hibernate"
|
||||
printf 'plymouth\n' > "$pkg/runtime/usr/lib/archipelago/desktop-boot"
|
||||
plymouth_source="$stage/usr/share/plymouth/themes/spinner"
|
||||
plymouth_theme="$pkg/runtime/usr/share/plymouth/themes/archipelago-bgrt"
|
||||
test -f "$plymouth_source/spinner.plymouth"
|
||||
mkdir -p "$plymouth_theme"
|
||||
cp -a "$plymouth_source/." "$plymouth_theme/"
|
||||
rm -f "$plymouth_theme/spinner.plymouth"
|
||||
cat > "$plymouth_theme/archipelago-bgrt.plymouth" <<'BGRT'
|
||||
@@PLYMOUTH_THEME@@
|
||||
BGRT
|
||||
printf '%s' '@@PLYMOUTH_WATERMARK_BASE64@@' | base64 -d > "$plymouth_theme/watermark.png"
|
||||
cmp -s "$plymouth_source/watermark.png" "$plymouth_theme/watermark.png" && {
|
||||
echo 'Plymouth Arch Linux watermark was not replaced' >&2
|
||||
exit 1
|
||||
}
|
||||
mkdir -p "$pkg/runtime/usr/lib/systemd/zram-generator.conf.d"
|
||||
printf '[zram0]\n' > "$pkg/runtime/usr/lib/systemd/zram-generator.conf.d/20-archipelago-desktop.conf"
|
||||
sed 's/Archipelago Core/Archipelago KDE/g' "$pkg/runtime/usr/lib/archipelago/defaults/os-release" > "$pkg/runtime/usr/lib/archipelago/defaults/os-release-kde"
|
||||
|
|
|
|||
94
src/lib.rs
94
src/lib.rs
|
|
@ -28,6 +28,7 @@ fn render_iso(kde: bool, replacements: &str) -> String {
|
|||
// Render private profile path tokens before inserting assets: application IDs,
|
||||
// common helpers and policy contents must never undergo variant substitution.
|
||||
let profile = |text: &str| if kde { text.replace("gnome", "kde").replace("GNOME", "KDE") } else { text.to_owned() };
|
||||
let plymouth_watermark = base64(include_bytes!("../../system/integrations/plymouth/watermark.png"));
|
||||
let gnome = assets
|
||||
.replace("@@FLATPAK_POLICY@@", policy)
|
||||
.replace("@@SOFTWARE_HELPER@@", include_str!("../../system/integrations/gnome-software/software-helper"))
|
||||
|
|
@ -35,7 +36,9 @@ fn render_iso(kde: bool, replacements: &str) -> String {
|
|||
.replace("@@SOFTWARE_SERVICE@@", include_str!("../../system/integrations/gnome-software/archipelago-software-refresh.service"))
|
||||
.replace("@@SOFTWARE_TIMER@@", include_str!("../../system/integrations/gnome-software/archipelago-software-refresh.timer"))
|
||||
.replace("@@TOOLBOX_CONFIG@@", include_str!("../../purposes/common/desktop/toolbox.conf"))
|
||||
.replace("@@TOOLBOX_REGISTRIES@@", include_str!("../../purposes/common/desktop/toolbox-registries.conf"));
|
||||
.replace("@@TOOLBOX_REGISTRIES@@", include_str!("../../purposes/common/desktop/toolbox-registries.conf"))
|
||||
.replace("@@PLYMOUTH_THEME@@", include_str!("../../system/integrations/plymouth/archipelago-bgrt.plymouth"))
|
||||
.replace("@@PLYMOUTH_WATERMARK_BASE64@@", &plymouth_watermark);
|
||||
let package = include_str!("../adapters/package.sh")
|
||||
.replace("@@PKGBUILD@@", include_str!("../../cli/packaging/PKGBUILD"))
|
||||
.replace("@@SYSTEM_SERVICE@@", include_str!("../../system/integrations/dbus/archipelagod.service"))
|
||||
|
|
@ -61,6 +64,27 @@ fn render_iso(kde: bool, replacements: &str) -> String {
|
|||
.replace(if kde { "@@KDE_FINALIZE@@" } else { "@@GNOME_FINALIZE@@" }, finalizer)
|
||||
}
|
||||
|
||||
/// Encode a small, checked-in image asset into the generated build script. The
|
||||
/// script writes it into the package payload; no host-side converter or Python
|
||||
/// helper is required in the release build environment.
|
||||
fn base64(bytes: &[u8]) -> String {
|
||||
const TABLE: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
let mut output = String::with_capacity(bytes.len().div_ceil(3) * 4);
|
||||
for chunk in bytes.chunks(3) {
|
||||
let first = chunk[0];
|
||||
let second = *chunk.get(1).unwrap_or(&0);
|
||||
let third = *chunk.get(2).unwrap_or(&0);
|
||||
output.push(TABLE[(first >> 2) as usize] as char);
|
||||
output.push(TABLE[(((first & 0x03) << 4) | (second >> 4)) as usize] as char);
|
||||
if chunk.len() > 1 {
|
||||
output.push(TABLE[(((second & 0x0f) << 2) | (third >> 6)) as usize] as char);
|
||||
} else { output.push('='); }
|
||||
if chunk.len() > 2 { output.push(TABLE[(third & 0x3f) as usize] as char); }
|
||||
else { output.push('='); }
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
/// KDE uses the same private composition path and the cycle's immutable Core.
|
||||
/// Container Runner: server Purpose composed from the cycle's immutable Core.
|
||||
pub fn build_container_runner_script() -> Result<String, String> {
|
||||
|
|
@ -120,6 +144,13 @@ pub fn build_gnome_probe_script() -> Result<String, String> {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use std::{io::Write, process::{Command, Stdio}};
|
||||
|
||||
fn cockpit_file<'a>(script: &'a str, name: &str) -> &'a str {
|
||||
let marker = format!("cat > \"$updates/{name}\" <<'EOF'\n");
|
||||
let rest = script.split_once(&marker).unwrap_or_else(|| panic!("missing packaged Cockpit file {name}")).1;
|
||||
rest.split_once("\nEOF\n").unwrap_or_else(|| panic!("unterminated Cockpit file {name}")).0
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generated_profiles_are_valid_shell() {
|
||||
for script in [build_iso_script(), build_gnome_probe_script().unwrap(),
|
||||
|
|
@ -131,6 +162,67 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn container_runner_update_page_uses_only_the_typed_system_bus() {
|
||||
let script = include_str!("../adapters/container-runner-package.sh");
|
||||
let manifest: serde_json::Value = serde_json::from_str(cockpit_file(script, "manifest.json")).unwrap();
|
||||
assert_eq!(manifest["version"], 0);
|
||||
assert_eq!(manifest["tools"]["archipelago-updates"]["path"], "index.html");
|
||||
let html = cockpit_file(script, "index.html");
|
||||
for id in ["refresh", "prepare", "download", "stage"] {
|
||||
assert!(html.contains(&format!("id=\"{id}\"")), "missing {id} action");
|
||||
}
|
||||
assert!(html.contains("../base1/cockpit.js"), "Cockpit client API must be loaded by the page");
|
||||
let js = cockpit_file(script, "updates.js");
|
||||
for method in ["GetStatus", "Refresh", "GetUpdateDetails", "PrepareUpdate", "Download", "Stage", "GetSnapshot"] {
|
||||
assert!(js.contains(method), "missing D-Bus method {method}");
|
||||
}
|
||||
assert!(js.contains("cockpit.dbus(\"org.archipelago.System1\", { bus: \"system\", superuser: \"try\" })"));
|
||||
assert!(js.contains("cockpit.variant(\"b\", true)"), "a{{sv}} booleans must be explicit D-Bus variants");
|
||||
assert!(js.contains("cockpit.variant(\"s\", uuid())"), "a{{sv}} request IDs must be explicit D-Bus variants");
|
||||
assert!(js.contains("function unbox(value)"), "unpack D-Bus a{{sv}} values before reading fields");
|
||||
assert!(js.contains("await run(\"GetUpdateDetails\""));
|
||||
assert!(js.contains("await run(\"Stage\""));
|
||||
assert!(js.contains("после перезагрузки"));
|
||||
for forbidden in ["PackageKit", "packagekit", "pacman", "cockpit.spawn", "cockpit.job"] {
|
||||
assert!(!js.contains(forbidden), "updater must not use {forbidden}");
|
||||
}
|
||||
let config = include_str!("../../system/integrations/plymouth/archipelago-bgrt.plymouth");
|
||||
assert!(config.contains("Name=Archipelago BGRT"));
|
||||
for action in ["boot-up", "shutdown", "reboot"] {
|
||||
let start = config.find(&format!("[{action}]\n")).unwrap();
|
||||
let tail = &config[start..];
|
||||
let body = tail.split_once('\n').unwrap().1;
|
||||
let body = body.split("\n[").next().unwrap_or(body);
|
||||
assert!(body.contains("UseFirmwareBackground=false"), "firmware logo enabled for {action}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn desktop_profiles_use_bgrt_without_arch_firmware_branding() {
|
||||
let theme = include_str!("../../system/integrations/plymouth/archipelago-bgrt.plymouth");
|
||||
assert!(theme.contains("Name=Archipelago BGRT"));
|
||||
for section in ["[boot-up]", "[shutdown]", "[reboot]"] {
|
||||
let start = theme.find(section).expect("Plymouth action section");
|
||||
let body = &theme[start..];
|
||||
let end = body.find('\n').map(|n| n + 1).unwrap_or(body.len());
|
||||
let next = body[end..].find("\n[").map(|n| end + n).unwrap_or(body.len());
|
||||
assert!(body[end..next].contains("UseFirmwareBackground=false"), "{section}");
|
||||
}
|
||||
for script in [build_gnome_probe_script().unwrap(), build_kde_probe_script().unwrap()] {
|
||||
assert!(script.contains("Theme=archipelago-bgrt"));
|
||||
assert!(script.contains("themes/archipelago-bgrt/archipelago-bgrt.plymouth"));
|
||||
assert!(script.contains("themes/archipelago-bgrt/watermark.png"));
|
||||
assert!(script.contains("Plymouth Arch Linux watermark was not replaced"));
|
||||
assert!(!script.contains("Theme=spinner"));
|
||||
assert!(!script.contains("themes/spinner/spinner.plymouth"));
|
||||
}
|
||||
let arch_watermark = include_bytes!("../../system/integrations/plymouth/watermark.png");
|
||||
assert!(arch_watermark.len() > 256);
|
||||
let encoded = base64(b"Archipelago");
|
||||
assert_eq!(encoded, "QXJjaGlwZWxhZ28=");
|
||||
}
|
||||
|
||||
/// D-038: only a Purpose that declares a replacement may remove a Core
|
||||
/// package. Core and Container Runner keep `linux`; the desktop Purposes
|
||||
/// declare `linux` -> `linux-zen` and record the owner in the layer.
|
||||
|
|
|
|||
|
|
@ -1,88 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Contract checks for the Container Runner Cockpit update page.
|
||||
|
||||
The page is packaged as plain files inside the Purpose layer, so its only
|
||||
executable contract is the typed D-Bus surface it uses. This test reads the
|
||||
adapter that writes those files and rejects a page that would bypass the daemon.
|
||||
"""
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ADAPTER = Path(__file__).parents[1] / 'adapters/container-runner-package.sh'
|
||||
PREFIX = 'usr/share/cockpit/archipelago-updates/'
|
||||
REQUIRED = ['GetStatus', 'Refresh', 'GetUpdateDetails', 'PrepareUpdate', 'Download',
|
||||
'Stage', 'GetSnapshot', 'org.archipelago.System1']
|
||||
FORBIDDEN = ['packagekit', 'PackageKit', 'pacman', 'systemctl', 'cockpit.spawn', 'cockpit.job',
|
||||
'pkcon', 'rpm-ostree']
|
||||
|
||||
|
||||
def heredocs(text):
|
||||
files = {}
|
||||
current = None
|
||||
body = []
|
||||
for line in text.splitlines():
|
||||
if current is None:
|
||||
match = re.match(r"cat > \"\$pkg/runtime/(\S+)\" <<'EOF'$", line)
|
||||
if match:
|
||||
current = match.group(1)
|
||||
body = []
|
||||
continue
|
||||
if line == 'EOF':
|
||||
files[current] = '\n'.join(body) + '\n'
|
||||
current = None
|
||||
continue
|
||||
body.append(line)
|
||||
return files
|
||||
|
||||
|
||||
class CockpitUpdater(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# The adapter writes the page through a $updates shorthand; expand it so the
|
||||
# packaged paths can be asserted exactly.
|
||||
self.text = ADAPTER.read_text().replace(
|
||||
'"$updates/', '"$pkg/runtime/usr/share/cockpit/archipelago-updates/')
|
||||
self.files = heredocs(self.text)
|
||||
self.updates = {name[len(PREFIX):]: body for name, body in self.files.items()
|
||||
if name.startswith(PREFIX)}
|
||||
|
||||
def test_page_is_packaged_with_a_valid_manifest(self):
|
||||
self.assertEqual(sorted(self.updates), ['index.html', 'manifest.json', 'style.css', 'updates.js'])
|
||||
manifest = json.loads(self.updates['manifest.json'])
|
||||
self.assertEqual(manifest['version'], 0)
|
||||
tools = manifest['tools']
|
||||
self.assertEqual(len(tools), 1)
|
||||
entry = next(iter(tools.values()))
|
||||
self.assertEqual(entry['path'], 'index.html')
|
||||
self.assertIn('style.css', self.updates['index.html'])
|
||||
for control in ('refresh', 'prepare', 'download', 'stage'):
|
||||
self.assertIn(f'id="{control}"', self.updates['index.html'], control)
|
||||
self.assertIn('updates.js', self.updates['index.html'])
|
||||
|
||||
def test_page_is_a_typed_dbus_client(self):
|
||||
script = self.updates['updates.js']
|
||||
for name in REQUIRED:
|
||||
self.assertIn(name, script, name)
|
||||
self.assertIn('superuser', script)
|
||||
self.assertIn('request_id', script)
|
||||
self.assertIn('interactive', script)
|
||||
# The staged result is reported as pending, never as installed.
|
||||
self.assertIn('после перезагрузки', script)
|
||||
self.assertNotIn('location.reload', script)
|
||||
for token in FORBIDDEN:
|
||||
self.assertNotIn(token, script.lower() if token.islower() else script, token)
|
||||
|
||||
def test_page_does_not_shell_out_and_adapter_stays_valid(self):
|
||||
for name, body in self.updates.items():
|
||||
for token in FORBIDDEN:
|
||||
self.assertNotIn(token, body, f'{name}: {token}')
|
||||
result = subprocess.run(['bash', '-n', str(ADAPTER)], capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
# The page is written only by the Container Runner Purpose adapter.
|
||||
self.assertEqual(self.text.count(PREFIX), len(self.updates))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Reference in a new issue