Files
komorebi/nix/tests/vm/lib/tests/test_rdp.py
T
LGUG2Z 0e8e25957c 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.
2026-10-28 14:20:08 -07:00

81 lines
2.4 KiB
Python

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)