build(nix): the demo guest as a VM suite

The demo guest is what the command `run-kde` starts, so it should not stop
working between the times somebody runs it by hand. The suite `run-kde` puts the
guest module, nix/dev/run-kde.nix, on the session node, as the rdp suite does
with krdp.nix, and checks what only a booted session can say: the demo opens two
Konsole windows, Kate and Dolphin and komorebi tiles them clear of the panel,
the cheat sheet is a window that is not a tile, what it shows of `komorebic
check` has no error, and KWin says what it draws with.

The node makes the directory the host shares as the guest finds it once it has
mounted it: owned by a user the guest does not have, with a password and a
public key in it. The suite checks that the guest takes them as root before the
login, that ssh lets in that key and no other, that KRDP starts by itself and
listens, and that a client with the password is let in and shows the display.

The client of those RDP checks moves from the rdp suite into the library as
RdpClient, with unit tests against the fake machine, so that both suites run the
same checks; the machine protocol gains copy_from_machine for it.
This commit is contained in:
LGUG2Z committed 2026-10-28 14:20:08 -07:00
1 parent e37f275b9b
commit 0e8e25957c
11 files changed
+466 -77

No files matched your search

+3 -2
View File
@@ -149,8 +149,9 @@ Linux machine with KVM (the same two QEMU guests, for `x86_64` and for
and what a builder has to be for a Mac. They install komorebi with the NixOS
module, and carry nothing of the person who uses them: a key, a password or a
configuration of yours goes into the guest when it runs, never into these files.
The `plasma-guests-eval` check evaluates them, and the VM suite `rdp` runs their
RDP server, [`nix/dev/krdp.nix`](nix/dev/krdp.nix). The demo guest has no
The `plasma-guests-eval` check evaluates them, the VM suite `rdp` runs their
RDP server, [`nix/dev/krdp.nix`](nix/dev/krdp.nix), and the VM suite `run-kde`
boots the demo guest. The demo guest has no
password and no key in its closure: the host shares a directory with them, and
`run-kde` ([`scripts/run-kde`](scripts/run-kde)) starts it. The script is
shellchecked when the package is built, and `run-kde-dry-run` and
+3 -1
View File
@@ -840,7 +840,9 @@ and KRDP 6.8.1 and FreeRDP 3.32.2:
that FreeRDP's client is let in with the password and not with another (`/auth-only`); and that
the picture the client gets, on an X server of its own, is the display: thousands of colors,
within 16 of 255 on average of a screenshot taken right after it (6.7 and 6.6 in two runs, 2.9
seconds after the client started).
seconds after the client started). The VM suite `run-kde` runs the same checks against the
demo guest, whose password comes from a directory of the host that the guest's user cannot
read: the guest copies it before the login, and KRDP starts by itself.
- Keys over RDP are not verified end to end. KRDP injects them into KWin through
`org_kde_kwin_fake_input`, which, read from the sources, puts them through the input pipeline
of KWin that KDE's global shortcuts are part of. No test sends one: aardwolf, a client that can
+15 -2
View File
@@ -120,8 +120,14 @@ Wayland socket after 11 to 19 seconds and a painted desktop after 35 seconds.
A suite's `node` can import a module of the repository: `rdp` imports
[`nix/dev/krdp.nix`](../../nix/dev/krdp.nix), the RDP server of the Plasma
guests to develop in, so that the suite checks the unit those guests run. The
guests themselves, which stay up for a person to use, are in [utm.md](utm.md).
guests to develop in, so that the suite checks the unit those guests run, and
`run-kde` imports [`nix/dev/run-kde.nix`](../../nix/dev/run-kde.nix), the demo
guest that the command `run-kde` starts, so that what CI boots is what the
command starts. The node of `run-kde` also makes the directory that the host
shares with that guest (`/run/run-kde`), owned by a user the guest does not
have, with a password and a public key in it, as the guest finds it once it has
mounted it. The guests themselves, which stay up for a person to use, are in
[utm.md](utm.md).
## The library
@@ -214,6 +220,13 @@ the run.
pointer lands within a pixel of where it is asked. The program itself is
[`komorebi_vm/uinput.py`](../../nix/tests/vm/lib/komorebi_vm/uinput.py),
whose arithmetic the `vm-lib` check tests.
- `RdpClient(machine, kde)` is FreeRDP's client on an X server of its own, for a
node that runs KRDP: `listening()` asks the guest whether the server has its
port, `logs_in(password)` whether a client with that password is let in,
`connect(password)` starts a client that stays, `picture()` reads what it
shows from its X server, and `shows_display()` waits for that to be the
display (more than a thousand colors, within 16 of 255 on average of a
screenshot). The suites `rdp` and `run-kde` both use it.
- `Keys(machine).send("alt-shift-k")` presses a combo on the machine's
keyboard, written as KDE writes it in lower case with `-` between the keys
(`meta` and `super` are the left Super key).
+4
View File
@@ -15,6 +15,8 @@ A suite imports what it needs from here:
the ring around a window.
* [`latency`](komorebi_vm.latency) times the daemon's commands from a recording
of the session bus.
* [`RdpClient`](komorebi_vm.rdp.RdpClient) logs in to KRDP from FreeRDP on an X server of its own,
and reads its picture back.
* [`Pointer`](komorebi_vm.pointer.Pointer) moves and clicks the pointer of a
session node, through [`uinput`](komorebi_vm.uinput), a program the node runs.
@@ -29,6 +31,7 @@ from komorebi_vm.kde import Kde, Outputs, Rect
from komorebi_vm.keys import Keys
from komorebi_vm.machine import Machine
from komorebi_vm.pointer import Pointer
from komorebi_vm.rdp import RdpClient
__all__ = [
"Checks",
@@ -37,6 +40,7 @@ __all__ = [
"Machine",
"Outputs",
"Pointer",
"RdpClient",
"Rect",
"daemon",
"latency",
+4
View File
@@ -31,6 +31,10 @@ class Machine(Protocol):
"""Runs each command and fails the test if it exits with status 0."""
...
def copy_from_machine(self, source: str, /) -> None:
"""Copies the file `source` of the machine into `out_dir`, under its own name."""
...
def screenshot(self, filename: str, /) -> None:
"""Saves a PNG of the machine's display as `filename` in `out_dir`."""
...
+122
View File
@@ -0,0 +1,122 @@
"""A FreeRDP client on a session node, for the suites that check KRDP.
KRDP, Plasma's RDP server, runs in the session as a user unit (`nix/dev/krdp.nix`). What a suite
can tell is whether a client with the password is let in and one without it is not, and whether
the picture the client gets is what the display shows. The client is FreeRDP's, on an X server of
its own (Xvfb), so that its picture can be read back and compared with a screenshot of the
display: a client on the display would be in its own picture. No keys are sent, since no client
could script them against KRDP (docs/dev/PLATFORM.md).
"""
import shlex
from PIL import Image, ImageChops, ImageStat
from komorebi_vm.kde import Kde
from komorebi_vm.machine import Machine
def difference(remote: Image.Image, local: Image.Image) -> float:
"""The mean difference of two pictures, from 0 (the same) to 255, over every channel.
The first is resized to the size of the second when they differ.
"""
if remote.size != local.size:
remote = remote.resize(local.size)
return sum(ImageStat.Stat(ImageChops.difference(remote, local)).mean) / 3
def colors(image: Image.Image) -> int:
"""The number of different colors a picture has."""
found = image.getcolors(maxcolors=image.width * image.height)
return len(found) if found is not None else 0
class RdpClient:
"""FreeRDP's client, logging in to the KRDP of a session node as its user.
`size` is the size of the client's X server and of the display it gets a picture of.
"""
def __init__(
self,
machine: Machine,
kde: Kde,
*,
x_display: str = ":99",
size: tuple[int, int] = (1280, 800),
user: str = "komorebi",
) -> None:
self.machine = machine
self.kde = kde
self.x_display = x_display
self.size = size
self.user = user
def listening(self) -> bool:
"""Returns true if and only if KRDP's server has port 3389 in the guest.
QEMU's port forwarding accepts a connection whether or not anything listens behind it,
so this asks the guest, which `ss` sees.
"""
return self.machine.execute("ss -ltnpH 'sport = :3389' | grep -q krdpserver")[0] == 0
def start_x_server(self) -> None:
"""Starts the client's X server and waits for its socket, for up to 30 seconds."""
width, height = self.size
self.machine.succeed(
f"setsid nohup Xvfb {self.x_display} -screen 0 {width}x{height}x24"
" > /tmp/xvfb.log 2>&1 < /dev/null &"
)
socket = f"/tmp/.X11-unix/X{self.x_display[1:]}"
self.machine.succeed(f"timeout 30 sh -c 'until test -S {socket}; do sleep 1; done'")
def command(self, secret: str, *args: str) -> str:
"""The command line of the client on its X server, logging in with `secret` as the user."""
words = [
"xfreerdp",
"/v:127.0.0.1",
f"/u:{self.user}",
f"/p:{secret}",
"/cert:ignore",
*args,
]
return f"env DISPLAY={self.x_display} " + " ".join(shlex.quote(word) for word in words)
def logs_in(self, secret: str) -> bool:
"""Returns true if and only if the server lets a client with `secret` in (`/auth-only`)."""
return self.machine.execute(self.command(secret, "/auth-only"))[0] == 0
def connect(self, secret: str) -> None:
"""Starts a client that stays connected, in the background, with a window of `size`."""
width, height = self.size
command = self.command(secret, f"/size:{width}x{height}")
self.machine.succeed(f"setsid nohup {command} > /tmp/xfreerdp.log 2>&1 < /dev/null &")
def picture(self) -> Image.Image:
"""What the client shows, read from its X server."""
self.machine.succeed(
f"xwd -display {self.x_display} -root -silent | xwdtopnm > /tmp/rdp.ppm 2>/dev/null"
)
self.machine.copy_from_machine("/tmp/rdp.ppm")
return Image.open(self.machine.out_dir / "rdp.ppm").convert("RGB")
def shows_display(self, timeout: float = 90) -> bool:
"""Waits for the client's picture to be the display, and says whether it was.
A client that has no picture yet shows black, a desktop has thousands of colors, and the
video KRDP sends is lossy, so the picture is the display when it has more than a thousand
colors and is within 16 of 255, on average, of a screenshot taken right after it.
"""
def same() -> bool:
remote = self.picture()
local = self.kde.shot("display")
diff = difference(remote, local)
print(
f"the client's picture: {remote.size}, {colors(remote)} colors,"
f" {diff:.1f} from the display"
)
return colors(remote) > 1000 and diff < 16
return self.kde.wait_for(same, timeout=timeout, interval=2)
+5
View File
@@ -15,6 +15,7 @@ class FakeMachine:
self.commands: list[str] = []
self.keys: list[str] = []
self.copied: list[str] = []
self.replies: list[tuple[Callable[[str], bool], tuple[int, str]]] = []
def reply(self, contains: str, status: int = 0, output: str = "") -> None:
@@ -31,6 +32,10 @@ class FakeMachine:
def send_key(self, key: str, /) -> None:
self.keys.append(key)
def copy_from_machine(self, source: str, /) -> None:
self.copied.append(source)
Image.new("RGB", (4, 4), (10, 20, 30)).save(self.out_dir / Path(source).name, format="PPM")
def screenshot(self, filename: str, /) -> None:
Image.new("RGB", (4, 4), (10, 20, 30)).save(self.out_dir / f"{filename}.png")
+80
View File
@@ -0,0 +1,80 @@
import shlex
from PIL import Image
from komorebi_vm import Kde, RdpClient
from komorebi_vm.rdp import colors, difference
from .conftest import FakeMachine
def client(machine: FakeMachine) -> RdpClient:
return RdpClient(machine, Kde(machine, "session"))
def test_a_picture_does_not_differ_from_itself() -> None:
picture = Image.new("RGB", (8, 8), (30, 60, 90))
assert difference(picture, picture) == 0
def test_the_difference_is_the_mean_over_every_channel() -> None:
black = Image.new("RGB", (8, 8), (0, 0, 0))
grey = Image.new("RGB", (8, 8), (30, 60, 90))
assert difference(grey, black) == 60
def test_a_picture_of_another_size_is_resized_to_the_second() -> None:
small = Image.new("RGB", (4, 4), (30, 60, 90))
large = Image.new("RGB", (16, 16), (30, 60, 90))
assert difference(small, large) == 0
def test_colors_counts_the_colors_a_picture_has() -> None:
picture = Image.new("RGB", (4, 1), (0, 0, 0))
picture.putpixel((1, 0), (255, 0, 0))
picture.putpixel((2, 0), (0, 255, 0))
assert colors(picture) == 3
def test_the_client_logs_in_as_the_user_on_its_own_x_server(machine: FakeMachine) -> None:
command = client(machine).command("s3cret", "/size:1280x800")
words = shlex.split(command)
assert words[:3] == ["env", "DISPLAY=:99", "xfreerdp"]
assert {"/u:komorebi", "/p:s3cret", "/v:127.0.0.1", "/size:1280x800"} <= set(words)
def test_a_secret_with_a_space_is_one_word(machine: FakeMachine) -> None:
words = shlex.split(client(machine).command("two words"))
assert "/p:two words" in words
def test_logging_in_is_what_the_client_says_with_auth_only(machine: FakeMachine) -> None:
rdp = client(machine)
assert rdp.logs_in("right")
machine.reply("/p:wrong", status=1)
assert not rdp.logs_in("wrong")
assert all("/auth-only" in command for command in machine.commands)
def test_listening_asks_the_guest_for_krdp_on_its_port(machine: FakeMachine) -> None:
rdp = client(machine)
assert rdp.listening()
machine.reply("krdpserver", status=1)
assert not rdp.listening()
assert "sport = :3389" in machine.commands[0]
def test_the_picture_is_copied_out_of_the_x_server(machine: FakeMachine) -> None:
picture = client(machine).picture()
assert machine.copied == ["/tmp/rdp.ppm"]
assert "xwd -display :99 -root" in machine.commands[0]
assert picture.size == (4, 4)
+14 -72
View File
@@ -4,26 +4,23 @@
# KRDP have the screen without asking, that a client with the password is let in and one without
# it is not, and that the picture the client gets is what the display shows.
#
# The client is FreeRDP's, on an X server of its own (Xvfb), so its picture can be read back and
# compared with a screenshot of the display. A client on the display would be in its own picture.
# No keys are sent: no client could script them against KRDP (docs/dev/PLATFORM.md).
# The client is FreeRDP's, on an X server of its own (`komorebi_vm.RdpClient`), so its picture can be
# read back and compared with a screenshot of the display. The suite `run-kde` runs the same checks
# with a password that the demo guest takes from the host's directory.
import secrets
import time
from PIL import Image, ImageChops, ImageStat
from komorebi_vm import Checks, Kde
from komorebi_vm import Checks, Kde, RdpClient
from komorebi_vm.rdp import colors
PASSWORD_FILE = "/home/komorebi/.config/komorebi-vm/rdp-password"
# the client's X server, and the size of the display it gets a picture of
X = ":99"
WIDTH, HEIGHT = 1280, 800
start_all()
machine.wait_for_unit("multi-user.target")
checks = Checks()
kde = Kde.session(machine, scale=SCALE)
rdp = RdpClient(machine, kde)
def active(unit: str) -> bool:
@@ -39,75 +36,20 @@ kde.as_user(
)
kde.systemctl("start", "krdp.service")
checks.check("with a password, KRDP listens on port 3389", kde.wait_for(rdp.listening, timeout=60))
def listening() -> bool:
return machine.execute("ss -ltnpH 'sport = :3389' | grep -q krdpserver")[0] == 0
rdp.start_x_server()
checks.check("with a password, KRDP listens on port 3389", kde.wait_for(listening, timeout=60))
machine.succeed(
f"setsid nohup Xvfb {X} -screen 0 {WIDTH}x{HEIGHT}x24 > /tmp/xvfb.log 2>&1 < /dev/null &"
)
machine.wait_until_succeeds(f"test -S /tmp/.X11-unix/X{X[1:]}", timeout=30)
def client(secret: str, *args: str) -> str:
"""The command line of FreeRDP's client, on the client's X server, logging in as komorebi."""
words = ["xfreerdp", "/v:127.0.0.1", "/u:komorebi", f"/p:{secret}", "/cert:ignore", *args]
return f"env DISPLAY={X} " + " ".join(words)
checks.check(
"a client with the password is let in",
machine.execute(client(password, "/auth-only"))[0] == 0,
)
checks.check(
"a client with another password is not",
machine.execute(client("not-" + password, "/auth-only"))[0] != 0,
)
checks.check("a client with the password is let in", rdp.logs_in(password))
checks.check("a client with another password is not", not rdp.logs_in("not-" + password))
started = time.monotonic()
machine.succeed(
"setsid nohup "
+ client(password, f"/size:{WIDTH}x{HEIGHT}")
+ " > /tmp/xfreerdp.log 2>&1 < /dev/null &"
)
def client_picture() -> Image.Image:
"""What the client shows, read from its X server."""
machine.succeed(f"xwd -display {X} -root -silent | xwdtopnm > /tmp/rdp.ppm 2>/dev/null")
machine.copy_from_machine("/tmp/rdp.ppm")
return Image.open(machine.out_dir / "rdp.ppm").convert("RGB")
def difference(remote: Image.Image, local: Image.Image) -> float:
"""The mean difference of the two pictures, from 0 (the same) to 255, over every channel."""
if remote.size != local.size:
remote = remote.resize(local.size)
return sum(ImageStat.Stat(ImageChops.difference(remote, local)).mean) / 3
def colors(image: Image.Image) -> int:
found = image.getcolors(maxcolors=image.width * image.height)
return len(found) if found is not None else 0
def same_picture() -> bool:
remote = client_picture()
local = kde.shot("display")
diff = difference(remote, local)
print(f"the client's picture: {remote.size}, {colors(remote)} colors, {diff:.1f} from the display")
# a client that has no picture yet shows black, a desktop has thousands of colors, and the video
# KRDP sends is lossy
return colors(remote) > 1000 and diff < 16
checks.check("the client's picture is the display", kde.wait_for(same_picture, timeout=90, interval=2))
rdp.connect(password)
checks.check("the client's picture is the display", rdp.shows_display())
print(f"after {time.monotonic() - started:.1f}s")
remote = client_picture()
remote = rdp.picture()
print(f"the client's picture: {remote.size}, {colors(remote)} colors")
remote.save(machine.out_dir / "client.png")
print(machine.execute("journalctl --no-pager _SYSTEMD_USER_UNIT=krdp.service | tail -n 20")[1])
print(machine.execute("tail -n 20 /tmp/xfreerdp.log")[1])
+53
View File
@@ -0,0 +1,53 @@
{
tier = "fast";
kind = "session";
timeoutMinutes = 12;
node =
{ pkgs, ... }:
let
# a key pair for the ssh check: the suite makes one, and the host's directory has its public half
key = pkgs.runCommand "run-kde-test-key" { nativeBuildInputs = [ pkgs.openssh ]; } ''
mkdir $out
ssh-keygen -q -t ed25519 -N "" -f $out/key
'';
# the directory the host shares, as the guest finds it once it has mounted it: a user of the
# host owns it, and the guest's user cannot read it
host = {
user = "4242";
group = "4242";
};
in
{
# the guest of `run-kde`, as the command starts it, on the session node
imports = [ ../../../../dev/run-kde.nix ];
systemd.tmpfiles.settings."run-kde-share" = {
"/run/run-kde".d = host // {
mode = "0700";
};
"/run/run-kde/rdp-password".f = host // {
mode = "0600";
argument = "a-password-of-the-host";
};
"/run/run-kde/ssh_key.pub".C = host // {
mode = "0600";
argument = "${key}/key.pub";
};
};
environment.etc."run-kde-test/ssh_key".source = "${key}/key";
# the session guests have sshd, and the key is for it
services.openssh = {
enable = true;
settings.PasswordAuthentication = false;
};
# the client of the RDP checks: an X server of its own, and what reads its picture back
environment.systemPackages = [
pkgs.iproute2
pkgs.netpbm
pkgs.xvfb
pkgs.xwd
];
};
}
+163
View File
@@ -0,0 +1,163 @@
# The demo guest of `run-kde` (nix/dev/run-kde.nix), as the command starts it: the module is the
# session node's. What only a real session can tell: that the demo opens its windows and komorebi
# tiles them clear of the panel, that the cheat sheet is a window komorebi leaves alone, that what
# the cheat sheet shows of `komorebic check` has no error in it, and that the password and the key
# the host shares reach the units that use them. The host's directory is made as the guest finds it
# when it has mounted it (the node says how): another user owns it, so that the guest's own user
# cannot read what is in it, and the guest has to take it as root.
#
# The RDP checks are those of the suite `rdp`, with the password from that directory. Nothing starts
# KRDP by hand here: that it listens shows that the guest took the password before the login, as the
# command's guest has to. The command itself, `scripts/run-kde`, is checked by `run-kde-dry-run` and
# `run-kde-doctor`, which a VM cannot: it is a program of the host.
import re
from komorebi_vm import Checks, Kde, RdpClient
from komorebi_vm.rdp import colors
SHARED = "/run/run-kde"
TAKEN = "/run/run-kde-guest"
PASSWORD = "a-password-of-the-host"
CHEAT_SHEET_TITLE = "komorebi cheat sheet"
start_all()
machine.wait_for_unit("multi-user.target")
checks = Checks()
kde = Kde.session(machine, scale=SCALE)
rdp = RdpClient(machine, kde)
def active(unit: str) -> bool:
return kde.run(f"systemctl --user is-active --quiet {unit}")[0] == 0
def tiles() -> list[str]:
"""The titles of the tiled windows of the first workspace, or none while the daemon is busy."""
try:
return [title for container in kde.containers(0) for title in container]
except AssertionError:
return []
def demo_is_open() -> bool:
titles = tiles()
return (
sum("Konsole" in title for title in titles) == 2
and any("Kate" in title for title in titles)
and any("Dolphin" in title for title in titles)
)
checks.check("komorebi runs in the session", kde.wait_for(lambda: active("komorebi"), timeout=60))
print("== the windows of the demo")
checks.check(
"the demo opens two Konsole windows, Kate and Dolphin, and komorebi tiles them",
kde.wait_for(demo_is_open, timeout=240),
)
checks.check(
"the cheat sheet is a window",
kde.wait_for(lambda: kde.wid(CHEAT_SHEET_TITLE) != "", timeout=120),
)
titles = tiles()
print(f"the tiles: {titles}")
checks.check("the cheat sheet is not one of the tiles", len(titles) == 4)
# a window tiled before komorebi knew the panel's room is tiled under the panel
monitor = kde.state()["monitors"]["elements"][0]
work = monitor["work_area_size"]
work_bottom = work["top"] + work["bottom"]
bottoms = {title: (lambda r: r.y + r.h)(kde.rect(kde.wid(title))) for title in titles}
print(f"the bottom of the work area: {work_bottom}; of the tiles: {bottoms}")
checks.check(
"every tile ends above the panel",
all(bottom <= work_bottom for bottom in bottoms.values()),
)
checks.check("the screen shows a desktop", colors(kde.shot("demo")) > 1000)
print("== the cheat sheet")
checks.check(
"the cheat sheet has the bindings of the sample file",
machine.execute("grep -q 'alt + shift - 0x21' /etc/run-kde/cheat-sheet.txt")[0] == 0
and machine.execute("grep -q 'komorebic change-layout' /etc/run-kde/cheat-sheet.txt")[0] == 0,
)
checks.check(
"KWin's renderer is found, and said as the cheat sheet says it",
kde.wait_for(
lambda: machine.execute(f"test -s /run/user/{kde.uid}/run-kde-renderer")[0] == 0,
timeout=60,
),
)
renderer = machine.succeed(f"cat /run/user/{kde.uid}/run-kde-renderer").strip()
print(f"the renderer: {renderer}")
checks.check(
"a node with no GPU draws in software",
re.match(r"software \(llvmpipe\): ", renderer) is not None,
)
checks.check(
"the console is told too",
machine.execute(
"journalctl -b -u run-kde-report --no-pager | grep -q 'run-kde: KWin draws with'"
)[0]
== 0,
)
status, out = kde.run("KOMOREBI_CONFIG_HOME=/etc/run-kde/config-home komorebic check")
print(out)
checks.check(
"komorebic check, as the cheat sheet runs it, has no error",
status == 0 and "\n0 error(s)" in out,
)
checks.check(
"it reads the key bindings the daemon runs",
re.search(r"ok +\S*skhdrc has \d+ key bindings?", out) is not None,
)
checks.check(
"it sees komorebi, and its script in KWin",
"komorebi is running, and its script is in KWin" in out,
)
print("== what the host shares")
checks.check(
"the guest's user cannot read the host's directory",
machine.execute(f"runuser -u komorebi -- cat {SHARED}/rdp-password")[0] != 0,
)
checks.check(
"the password is taken for the user, and for no one else",
machine.succeed(f"stat -c '%U %a' {TAKEN}/rdp-password").strip() == "komorebi 400",
)
checks.check(
"the key is taken as the user's authorized key",
machine.succeed(f"cat {TAKEN}/authorized_keys.d/komorebi").split()[:2]
== machine.succeed(f"cut -d' ' -f1,2 {SHARED}/ssh_key.pub").split(),
)
machine.succeed("install -m 600 /etc/run-kde-test/ssh_key /tmp/ssh_key")
ssh = (
"ssh -i /tmp/ssh_key -o IdentitiesOnly=yes -o StrictHostKeyChecking=no"
" -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=ERROR komorebi@127.0.0.1"
)
machine.wait_for_unit("sshd.service")
checks.check("ssh lets in the host's key", machine.execute(f"{ssh} true")[0] == 0)
checks.check(
"and no other",
machine.execute(
"ssh-keygen -q -t ed25519 -N '' -f /tmp/other_key"
f" && {ssh.replace('/tmp/ssh_key', '/tmp/other_key')} true"
)[0]
!= 0,
)
print("== RDP, with the host's password")
checks.check(
"KRDP started by itself and listens on port 3389",
kde.wait_for(lambda: active("krdp") and rdp.listening(), timeout=60),
)
rdp.start_x_server()
checks.check("a client with the host's password is let in", rdp.logs_in(PASSWORD))
checks.check("a client with another password is not", not rdp.logs_in("not-" + PASSWORD))
rdp.connect(PASSWORD)
checks.check("the client's picture is the display", rdp.shows_display())
rdp.picture().save(machine.out_dir / "client.png")
checks.finish()