mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 22:05:59 +00:00
Move the Linux runtime to Ubuntu 26.04 LTS with a separate Kubuntu desktop (#1733)
This commit is contained in:
1 parent
5de690ef39
commit
29c83976d0
305 files changed
+9383
-462
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import hashlib
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
REMEMBER = Path(__file__).resolve().parents[1] / "ubuntu/overlay-runtime/usr/share/droiddeck/apt/remember"
|
||||
|
||||
|
||||
class AptRememberTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temp.cleanup)
|
||||
self.top = Path(temp.name)
|
||||
self.dir = self.top / "share/apt"
|
||||
self.state = self.top / "state"
|
||||
self.etc = self.top / "etc/apt"
|
||||
self.keys = self.top / "keyrings"
|
||||
self.autostart = self.top / "autostart"
|
||||
for d in (self.dir, self.etc / "sources.list.d", self.keys, self.autostart, self.top / "bin"):
|
||||
d.mkdir(parents=True)
|
||||
(self.dir / "system-manual.txt").write_text("base\n")
|
||||
(self.dir / "runtime-id").write_text("new\n")
|
||||
system = self.keys / "ubuntu-archive.gpg"
|
||||
system.write_text("system key")
|
||||
(self.dir / "system-sources.txt").write_text("%s %s\n" % (system, hashlib.sha256(b"system key").hexdigest()))
|
||||
apt_mark = self.top / "bin/apt-mark"
|
||||
apt_mark.write_text("#!/bin/sh\nprintf 'base\\nvlc\\n'\n")
|
||||
apt_mark.chmod(0o755)
|
||||
script = REMEMBER.read_text()
|
||||
script = script.replace("/usr/share/droiddeck/apt", str(self.dir))
|
||||
script = script.replace("/root/.local/share/droiddeck/apt", str(self.state))
|
||||
script = script.replace("/etc/xdg/autostart", str(self.autostart))
|
||||
script = script.replace("/usr/share/keyrings", str(self.keys))
|
||||
script = script.replace("/etc/apt", str(self.etc))
|
||||
self.script = self.top / "remember"
|
||||
self.script.write_text(script)
|
||||
|
||||
def run_remember(self):
|
||||
env = dict(os.environ, PATH="%s:%s" % (self.top / "bin", os.environ["PATH"]))
|
||||
env.pop("DROIDDECK_APT_RESTORING", None)
|
||||
subprocess.run(["bash", str(self.script)], env=env, check=True, timeout=30)
|
||||
|
||||
def test_user_sources_and_keys_outside_etc_apt_are_kept(self):
|
||||
(self.etc / "sources.list").write_text("deb http://example.invalid stable main\n")
|
||||
(self.keys / "example.gpg").write_text("user key")
|
||||
self.run_remember()
|
||||
self.assertEqual("vlc\n", (self.state / "packages.txt").read_text())
|
||||
self.assertTrue((self.state / "sources/sources.list").is_file())
|
||||
self.assertEqual("user key", (self.state / "keyrings" / ("%s_example.gpg" % str(self.keys).lstrip("/").replace("/", "_"))).read_text())
|
||||
self.assertFalse(any("ubuntu-archive" in p.name for p in (self.state / "keyrings").iterdir()))
|
||||
|
||||
def test_the_previous_runtime_snapshot_waits_for_the_desktop_restore(self):
|
||||
(self.autostart / "droiddeck-apt-restore.desktop").write_text("")
|
||||
self.state.mkdir()
|
||||
(self.state / "packages.txt").write_text("old-app\n")
|
||||
(self.state / "restored").write_text("old\n")
|
||||
self.run_remember()
|
||||
self.assertEqual("old-app\n", (self.state / "packages.txt").read_text())
|
||||
(self.state / "attempted").write_text("new\n")
|
||||
self.run_remember()
|
||||
self.assertEqual("vlc\n", (self.state / "packages.txt").read_text())
|
||||
|
||||
def test_without_the_desktop_the_snapshot_follows_the_runtime(self):
|
||||
self.state.mkdir()
|
||||
(self.state / "packages.txt").write_text("old-app\n")
|
||||
(self.state / "restored").write_text("old\n")
|
||||
self.run_remember()
|
||||
self.assertEqual("vlc\n", (self.state / "packages.txt").read_text())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,107 @@
|
||||
import json
|
||||
import os
|
||||
import runpy
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
BWRAP = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-bwrap"
|
||||
|
||||
PROBE = """
|
||||
import fcntl, os, sys
|
||||
fd = os.open(sys.argv[1], os.O_RDWR)
|
||||
try:
|
||||
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except OSError:
|
||||
print("held")
|
||||
else:
|
||||
print("free")
|
||||
"""
|
||||
|
||||
|
||||
class BwrapLockFileTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.shim = runpy.run_path(str(BWRAP))
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.instance = Path(self.temp.name) / "instance"
|
||||
self.instance.mkdir()
|
||||
(self.instance / ".ref").write_text("")
|
||||
|
||||
def spec(self, *extra):
|
||||
argv = ["--ro-bind", str(self.instance), "/run/user/1000/.flatpak/7", *extra, "--", "true"]
|
||||
return self.shim["parse"](argv)
|
||||
|
||||
def probe(self):
|
||||
return subprocess.run([sys.executable, "-c", PROBE, str(self.instance / ".ref")],
|
||||
capture_output=True, text=True, timeout=30, check=True).stdout.strip()
|
||||
|
||||
def test_sandbox_paths_resolve_through_the_binds(self):
|
||||
spec = self.spec()
|
||||
self.assertEqual(str(self.instance / ".ref"), self.shim["host_path"](spec, "/run/user/1000/.flatpak/7/.ref"))
|
||||
self.assertEqual("/etc/hosts", self.shim["host_path"](spec, "/etc/hosts"))
|
||||
|
||||
def test_the_instance_lock_is_held_while_the_sandbox_runs(self):
|
||||
spec = self.spec("--lock-file", "/run/user/1000/.flatpak/7/.ref")
|
||||
self.assertEqual("free", self.probe())
|
||||
self.shim["hold_locks"](spec)
|
||||
self.assertEqual("held", self.probe())
|
||||
|
||||
def test_without_a_lock_file_nothing_is_locked(self):
|
||||
self.shim["hold_locks"](self.spec())
|
||||
self.assertEqual("free", self.probe())
|
||||
|
||||
def test_the_lock_survives_exec(self):
|
||||
script = (
|
||||
"import runpy, sys; shim = runpy.run_path(sys.argv[1]); "
|
||||
"spec = shim['parse'](['--ro-bind', sys.argv[2], '/run/user/1000/.flatpak/7', "
|
||||
"'--lock-file', '/run/user/1000/.flatpak/7/.ref', '--', 'true']); "
|
||||
"shim['hold_locks'](spec); "
|
||||
"import os; os.execv(sys.executable, [sys.executable, '-c', "
|
||||
"'import subprocess, sys; print(subprocess.run([sys.executable, \"-c\", sys.argv[1], sys.argv[2]], "
|
||||
"capture_output=True, text=True).stdout.strip())', sys.argv[3], sys.argv[4]])"
|
||||
)
|
||||
out = subprocess.run([sys.executable, "-c", script, str(BWRAP), str(self.instance), PROBE,
|
||||
str(self.instance / ".ref")], capture_output=True, text=True, timeout=30, check=True)
|
||||
self.assertEqual("held", out.stdout.strip())
|
||||
|
||||
|
||||
class BwrapReportedPidTest(unittest.TestCase):
|
||||
def test_flatpak_is_given_the_wrapper_so_killing_it_ends_the_whole_sandbox(self):
|
||||
name = "droiddeck-bwrap-test-%d" % os.getpid()
|
||||
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
server.bind("\0" + name)
|
||||
server.listen(1)
|
||||
self.addCleanup(server.close)
|
||||
|
||||
def answer():
|
||||
conn, _ = server.accept()
|
||||
with conn:
|
||||
head = conn.recv(5)
|
||||
size = struct.unpack(">I", head[1:])[0]
|
||||
while size > 0:
|
||||
size -= len(conn.recv(size))
|
||||
for kind, payload in ((b"P", b"424242"), (b"X", b"0")):
|
||||
conn.sendall(kind + struct.pack(">I", len(payload)) + payload)
|
||||
|
||||
thread = threading.Thread(target=answer, daemon=True)
|
||||
thread.start()
|
||||
read_end, write_end = os.pipe()
|
||||
env = dict(os.environ, DROIDDECK_BWRAP_SOCKET=name)
|
||||
proc = subprocess.Popen([sys.executable, str(BWRAP), "--ro-bind", "/", "/elsewhere", "--info-fd",
|
||||
str(write_end), "--", "true"], env=env, pass_fds=[write_end])
|
||||
os.close(write_end)
|
||||
info = os.read(read_end, 4096)
|
||||
os.close(read_end)
|
||||
self.assertEqual(0, proc.wait(30))
|
||||
thread.join(5)
|
||||
self.assertEqual({"child-pid": proc.pid}, json.loads(info))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,104 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
||||
IME = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-ime'
|
||||
|
||||
|
||||
def message(obj, opcode, payload=b''):
|
||||
return struct.pack('<II', obj, ((8 + len(payload)) << 16) | opcode) + payload
|
||||
|
||||
|
||||
def wl_string(value):
|
||||
data = value.encode() + b'\0'
|
||||
return struct.pack('<I', len(data)) + data + b'\0' * (-len(data) % 4)
|
||||
|
||||
|
||||
class DesktopImeTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.session = Path(self.temp.name)
|
||||
self.server, client = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.addCleanup(self.server.close)
|
||||
env = dict(os.environ, BL_LAUNCH_DIR=str(self.session), WAYLAND_SOCKET=str(client.fileno()))
|
||||
self.proc = subprocess.Popen(['python3', str(IME)], env=env, pass_fds=[client.fileno()],
|
||||
stderr=subprocess.PIPE, text=True)
|
||||
client.close()
|
||||
self.addCleanup(self.stop)
|
||||
self.server.settimeout(5)
|
||||
self.assertEqual(self.read(12), message(1, 1, struct.pack('<I', 2)))
|
||||
self.server.sendall(message(2, 0, struct.pack('<I', 7) + wl_string('zwp_input_method_v1') + struct.pack('<I', 1)))
|
||||
bind = self.read(8 + 4 + len(wl_string('zwp_input_method_v1')) + 8)
|
||||
self.assertEqual(bind, message(2, 0, struct.pack('<I', 7) + wl_string('zwp_input_method_v1') + struct.pack('<II', 1, 3)))
|
||||
|
||||
def stop(self):
|
||||
if self.proc.poll() is None:
|
||||
self.proc.kill()
|
||||
self.proc.wait(5)
|
||||
self.proc.stderr.close()
|
||||
|
||||
def read(self, size):
|
||||
data = b''
|
||||
while len(data) < size:
|
||||
chunk = self.server.recv(size - len(data))
|
||||
if not chunk:
|
||||
break
|
||||
data += chunk
|
||||
return data
|
||||
|
||||
def state(self, seq, timeout=5):
|
||||
path = self.session / 'agent/ime.json'
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
try:
|
||||
snapshot = json.loads(path.read_text())
|
||||
except (OSError, ValueError):
|
||||
snapshot = None
|
||||
if snapshot and snapshot['seq'] >= seq:
|
||||
return snapshot
|
||||
time.sleep(0.02)
|
||||
self.fail('ime.json never reached seq %d' % seq)
|
||||
|
||||
def test_focus_and_blur_are_reported(self):
|
||||
self.server.sendall(message(3, 0, struct.pack('<I', 100)))
|
||||
self.assertTrue(self.state(1)['textField'])
|
||||
self.server.sendall(message(100, 2, struct.pack('<II', 0, 9)))
|
||||
snapshot = self.state(2)
|
||||
self.assertEqual((snapshot['textField'], snapshot['purpose']), (True, 9))
|
||||
self.server.sendall(message(3, 1, struct.pack('<I', 100)))
|
||||
self.assertEqual(self.read(8), message(100, 0))
|
||||
self.assertFalse(self.state(3)['textField'])
|
||||
self.assertEqual(oct((self.session / 'agent/ime.json').stat().st_mode & 0o777), '0o600')
|
||||
|
||||
def test_switching_fields_does_not_flicker(self):
|
||||
self.server.sendall(message(3, 0, struct.pack('<I', 100)))
|
||||
self.assertTrue(self.state(1)['textField'])
|
||||
self.server.sendall(message(3, 1, struct.pack('<I', 100)) + message(3, 0, struct.pack('<I', 101)))
|
||||
self.assertEqual(self.read(8), message(100, 0))
|
||||
time.sleep(0.4)
|
||||
self.assertEqual(self.state(1), {'textField': True, 'hint': 0, 'purpose': 0, 'seq': 1})
|
||||
|
||||
def test_compositor_exit_clears_the_field(self):
|
||||
self.server.sendall(message(3, 0, struct.pack('<I', 100)))
|
||||
self.assertTrue(self.state(1)['textField'])
|
||||
self.server.close()
|
||||
self.assertEqual(self.proc.wait(5), 0)
|
||||
self.assertFalse(self.state(2)['textField'])
|
||||
|
||||
|
||||
def test_a_protocol_error_clears_the_field(self):
|
||||
self.server.sendall(message(3, 0, struct.pack('<I', 100)))
|
||||
self.assertTrue(self.state(1)['textField'])
|
||||
self.server.sendall(message(1, 0, struct.pack('<II', 3, 1) + wl_string('bad request')))
|
||||
self.assertEqual(self.proc.wait(5), 1)
|
||||
self.assertFalse(self.state(2)['textField'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -146,6 +146,49 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
"""
|
||||
|
||||
WRAPPER = r"""
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/filter.h>
|
||||
#include <linux/seccomp.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef SYS_openat2
|
||||
#define SYS_openat2 437
|
||||
#endif
|
||||
|
||||
struct how { uint64_t flags, mode, resolve; };
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct sock_filter filter[] = {
|
||||
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
|
||||
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_openat2, 0, 1),
|
||||
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | ENOSYS),
|
||||
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
|
||||
};
|
||||
struct sock_fprog prog = {sizeof(filter) / sizeof(filter[0]), filter};
|
||||
if (argc < 3 || prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) || prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) return 3;
|
||||
int (*call)(int, const char *, struct how *, size_t) = (int (*)(int, const char *, struct how *, size_t))dlsym(RTLD_DEFAULT, "openat2");
|
||||
if (!call) return 4;
|
||||
int dir = open(argv[1], O_PATH | O_DIRECTORY | O_CLOEXEC);
|
||||
struct how h = {O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644, 0x08};
|
||||
int fd = call(dir, argv[2], &h, sizeof(h));
|
||||
if (fd < 0) {
|
||||
printf("ERR %d\n", errno);
|
||||
return 1;
|
||||
}
|
||||
printf("OK\n");
|
||||
return close(fd);
|
||||
}
|
||||
"""
|
||||
|
||||
RAW_LOOKUP = r"""
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
@@ -326,6 +369,12 @@ class Openat2PreloadTest(unittest.TestCase):
|
||||
LD_PRELOAD="%s:%s" % (cls.lib, cls.tmp / "real/libblfastpath.so")))
|
||||
except subprocess.TimeoutExpired:
|
||||
cls.fex = None
|
||||
wrapper = cls.tmp / "wrapper.c"
|
||||
wrapper.write_text(WRAPPER)
|
||||
subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-o", str(cls.tmp / "wrapper"), str(wrapper), "-ldl"], check=True)
|
||||
(cls.tmp / "extract").mkdir()
|
||||
cls.wrapper = subprocess.run([str(cls.tmp / "wrapper"), str(cls.tmp / "extract"), "file"], capture_output=True,
|
||||
text=True, timeout=20, env=dict(os.environ, LD_PRELOAD=str(cls.lib)))
|
||||
(cls.tmp / "fex-lookup").mkdir()
|
||||
shutil.copy(cls.tmp / "raw_lookup", cls.tmp / "fex-lookup/FEX")
|
||||
try:
|
||||
@@ -373,6 +422,10 @@ class Openat2PreloadTest(unittest.TestCase):
|
||||
self.assertEqual(self.fex.returncode, 0, self.fex.stderr)
|
||||
self.assertEqual(self.fex.stdout, "inside\n")
|
||||
|
||||
def test_the_libc_openat2_wrapper_creates_files_without_openat2(self):
|
||||
self.assertEqual(self.wrapper.returncode, 0, self.wrapper.stdout + self.wrapper.stderr)
|
||||
self.assertTrue((self.tmp / "extract/file").exists())
|
||||
|
||||
def test_the_kernel_agrees(self):
|
||||
if self.kernel is None:
|
||||
self.skipTest("this kernel or sandbox has no openat2")
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import io
|
||||
import os
|
||||
import runpy
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
PACMAN = Path(__file__).resolve().parents[1] / "desktop-kde/overlay/usr/share/droiddeck/pacman"
|
||||
|
||||
|
||||
class PacmanSharedFilesTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temp.cleanup)
|
||||
self.top = Path(temp.name)
|
||||
|
||||
def keep(self, action):
|
||||
lib = self.top / "lib"
|
||||
lib.mkdir(exist_ok=True)
|
||||
script = (PACMAN / "keep").read_text().replace("/var/lib/pacman", str(lib))
|
||||
subprocess.run(["bash", "-c", script, "keep", action], check=True, timeout=30)
|
||||
return lib
|
||||
|
||||
def test_an_upgrade_that_drops_a_shared_file_gets_it_back(self):
|
||||
shared = self.top / "usr/lib/libshared.so"
|
||||
shared.parent.mkdir(parents=True)
|
||||
shared.write_text("shared")
|
||||
lib = self.top / "lib"
|
||||
lib.mkdir()
|
||||
(lib / "droiddeck-shared-files").write_text("%s\n%s\n" % (shared, self.top / "usr/lib/never-there"))
|
||||
self.keep("save")
|
||||
shared.unlink()
|
||||
self.keep("restore")
|
||||
self.assertEqual("shared", shared.read_text())
|
||||
self.assertFalse((self.top / "usr/lib/never-there").exists())
|
||||
self.assertFalse((lib / "droiddeck-shared-keep").exists())
|
||||
|
||||
def test_a_backup_for_a_file_still_missing_survives_the_next_save(self):
|
||||
shared = self.top / "usr/lib/libshared.so"
|
||||
shared.parent.mkdir(parents=True)
|
||||
shared.write_text("shared")
|
||||
lib = self.top / "lib"
|
||||
lib.mkdir()
|
||||
(lib / "droiddeck-shared-files").write_text("%s\n" % shared)
|
||||
self.keep("save")
|
||||
shared.unlink()
|
||||
self.keep("save")
|
||||
self.keep("restore")
|
||||
self.assertEqual("shared", shared.read_text())
|
||||
|
||||
def test_only_identical_files_are_taken_over(self):
|
||||
adopt = runpy.run_path(str(PACMAN / "adopt"), run_name="adopt")
|
||||
package = io.BytesIO()
|
||||
with tarfile.open(fileobj=package, mode="w") as archive:
|
||||
for name, data in (("same", b"one"), ("different", b"two")):
|
||||
info = tarfile.TarInfo(name)
|
||||
info.size = len(data)
|
||||
archive.addfile(info, io.BytesIO(data))
|
||||
(self.top / "same").write_bytes(b"one")
|
||||
(self.top / "different").write_bytes(b"other")
|
||||
package.seek(0)
|
||||
with tarfile.open(fileobj=package) as archive:
|
||||
members = {m.name: m for m in archive}
|
||||
self.assertTrue(adopt["same"](archive, members["same"], str(self.top / "same")))
|
||||
self.assertFalse(adopt["same"](archive, members["different"], str(self.top / "different")))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -43,3 +43,10 @@ class SessionAssetsTest(unittest.TestCase):
|
||||
assets.check_extraction(self.overlay, ''))
|
||||
mapping = '"usr/local/bin/droiddeck-login1" to "usr/local/bin/droiddeck-login1"'
|
||||
self.assertEqual([], assets.check_extraction(self.overlay, mapping))
|
||||
|
||||
def test_helper_extracted_under_another_name_counts(self):
|
||||
mapping = '"usr/local/bin/droiddeck-login1" to "usr/local/bin/login1"'
|
||||
self.assertEqual([], assets.check_extraction(self.overlay, mapping))
|
||||
mapping = '"usr/local/bin/droiddeck-login1" to "usr/local/bin/sub/login1"'
|
||||
self.assertEqual(['not extracted at session start: usr/local/bin/droiddeck-login1'],
|
||||
assets.check_extraction(self.overlay, mapping))
|
||||
@@ -9,8 +9,8 @@ SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/d
|
||||
|
||||
|
||||
def log_redirect():
|
||||
match = re.search(r"^\s*(exec > >\(.*\) 2>&1)$", SESSION.read_text(), re.M)
|
||||
return match.group(1)
|
||||
match = re.search(r"^\s*(dd=.*)\n\s*(exec > >\(.*\) 2>&1)$", SESSION.read_text(), re.M)
|
||||
return "%s\n%s" % match.groups()
|
||||
|
||||
|
||||
class SessionLogTest(unittest.TestCase):
|
||||
|
||||
@@ -57,6 +57,23 @@ class DesktopSteamLaunchTest(unittest.TestCase):
|
||||
self.assertEqual(result.stdout.splitlines()[-1], 'steam://rungameid/501590')
|
||||
self.assertFalse((self.session / 'steam-launch').exists())
|
||||
|
||||
def test_exit_without_a_running_client_starts_nothing(self):
|
||||
result = self.launch('desktop', 'steam://exit')
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout, '')
|
||||
self.assertFalse((self.session / 'steam-launch').exists())
|
||||
|
||||
def test_shim_turns_shutdown_into_exit_url(self):
|
||||
launch = self.root / 'record-launch'
|
||||
launch.write_text('#!/bin/bash\nprintf "%s\\n" "$@"\n')
|
||||
launch.chmod(0o755)
|
||||
shim = self.root / 'shim'
|
||||
shim.write_text((BIN / 'droiddeck-steam-shim').read_text().replace(
|
||||
'/usr/local/bin/droiddeck-steam-launch', str(launch)))
|
||||
result = subprocess.run(['bash', str(shim), '-shutdown'], env=self.env, text=True, capture_output=True)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout.splitlines(), ['desktop', 'steam://exit'])
|
||||
|
||||
def test_second_click_forwards_without_another_supervisor(self):
|
||||
lock = self.root / 'cache/droiddeck/steam-desktop.lock'
|
||||
lock.parent.mkdir(parents=True)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
@@ -20,6 +22,30 @@ class SteamRestartCapTest(unittest.TestCase):
|
||||
return subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
|
||||
check=True).stdout.split()
|
||||
|
||||
def installs(self, *steps):
|
||||
function = stuck_function()
|
||||
self.assertIsNotNone(function, "droiddeck-session has no steam_update_stuck()")
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
script = function + "steam_root=%s\nmkdir -p \"$steam_root/package\"\n" % shlex.quote(root)
|
||||
script += "installed=\"$steam_root/package/steam_client_linuxarm64.installed\"\n"
|
||||
script += "echo 0 > \"$installed\"\nsteam_updates=0\nsteam_installs=0\n"
|
||||
script += "steam_update_stamp=$(stat -c '%n %Y %s' \"$steam_root\"/package/*.installed)\n"
|
||||
for n, installed in enumerate(steps, 1):
|
||||
if installed:
|
||||
script += "printf '%%0%dd' 0 > \"$installed\"\n" % (n + 1)
|
||||
script += "if steam_update_stuck 10; then echo stop; else echo restart; fi\n"
|
||||
return subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
|
||||
check=True).stdout.split()
|
||||
|
||||
def test_restarts_that_each_install_an_update_go_on(self):
|
||||
self.assertEqual(["restart"] * 4, self.installs(True, False, True, False))
|
||||
|
||||
def test_an_update_that_never_installs_is_stopped_on_the_third(self):
|
||||
self.assertEqual(["restart", "restart", "stop"], self.installs(False, False, False))
|
||||
|
||||
def test_installs_that_never_settle_are_stopped(self):
|
||||
self.assertIn("stop", self.installs(*[True] * 12))
|
||||
|
||||
def test_an_update_that_keeps_asking_at_once_is_stopped_on_the_third(self):
|
||||
self.assertEqual(["restart", "restart", "stop"], self.restarts(11, 13, 9))
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import getpass
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
SU = Path(__file__).resolve().parents[1] / "ubuntu/overlay-runtime/usr/local/bin/su"
|
||||
|
||||
|
||||
class SuWrapperTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temp.cleanup)
|
||||
self.dir = Path(temp.name)
|
||||
sudo = self.dir / "sudo"
|
||||
sudo.write_text("#!/bin/bash\nprintf 'sudo'; printf ' <%s>' \"$@\"; echo\n")
|
||||
sudo.chmod(0o755)
|
||||
self.su = self.dir / "su"
|
||||
self.su.write_text(SU.read_text().replace("/usr/local/bin/sudo", str(sudo)))
|
||||
self.su.chmod(0o755)
|
||||
|
||||
def run_su(self, *args):
|
||||
env = dict(os.environ, SHELL="/bin/bash")
|
||||
return subprocess.run([str(self.su), *args], capture_output=True, text=True, timeout=30, env=env)
|
||||
|
||||
def test_a_command_after_the_user_reaches_the_root_shell(self):
|
||||
out = self.run_su("root", "-c", "echo hi")
|
||||
self.assertEqual("sudo <-s> <echo hi>\n", out.stdout)
|
||||
|
||||
def test_the_current_user_is_not_elevated(self):
|
||||
out = self.run_su(getpass.getuser(), "-c", "echo as-me")
|
||||
if getpass.getuser() == "root":
|
||||
self.assertEqual("sudo <-s> <echo as-me>\n", out.stdout)
|
||||
else:
|
||||
self.assertEqual("as-me\n", out.stdout)
|
||||
|
||||
def test_arguments_after_the_user_go_to_the_shell(self):
|
||||
out = self.run_su("-", "root", "-c", "echo $0 $1", "zero", "one")
|
||||
self.assertEqual("sudo <-i> </bin/bash> <-c> <echo $0 $1> <zero> <one>\n", out.stdout)
|
||||
|
||||
def test_other_users_are_refused(self):
|
||||
out = self.run_su("droiddeck-nobody-here")
|
||||
self.assertEqual(1, out.returncode)
|
||||
self.assertEqual("", out.stdout)
|
||||
|
||||
def test_plain_su_opens_a_root_shell(self):
|
||||
self.assertEqual("sudo <-s>\n", self.run_su().stdout)
|
||||
self.assertEqual("sudo <-i>\n", self.run_su("-").stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user