nixosTests.ydotool.{customGroup,headless,wayland,x11}: handleTest -> runTest
This commit is contained in:
parent
7b09056b8f
commit
1889fc8f2f
@ -1555,7 +1555,10 @@ in
|
||||
xterm = runTest ./xterm.nix;
|
||||
xxh = runTest ./xxh.nix;
|
||||
yarr = runTest ./yarr.nix;
|
||||
ydotool = handleTest ./ydotool.nix { };
|
||||
ydotool = import ./ydotool.nix {
|
||||
inherit (pkgs) lib;
|
||||
inherit runTest;
|
||||
};
|
||||
yggdrasil = runTest ./yggdrasil.nix;
|
||||
your_spotify = runTest ./your_spotify.nix;
|
||||
zammad = runTest ./zammad.nix;
|
||||
|
@ -1,16 +1,12 @@
|
||||
{
|
||||
system ? builtins.currentSystem,
|
||||
config ? { },
|
||||
pkgs ? import ../.. { inherit system config; },
|
||||
lib ? pkgs.lib,
|
||||
}:
|
||||
{ runTest, lib }:
|
||||
let
|
||||
makeTest = import ./make-test-python.nix;
|
||||
textInput = "This works.";
|
||||
inputBoxText = "Enter input";
|
||||
inputBox = pkgs.writeShellScript "zenity-input" ''
|
||||
${lib.getExe pkgs.zenity} --entry --text '${inputBoxText}:' > /tmp/output &
|
||||
'';
|
||||
inputBox =
|
||||
pkgs:
|
||||
pkgs.writeShellScript "zenity-input" ''
|
||||
${lib.getExe pkgs.zenity} --entry --text '${inputBoxText}:' > /tmp/output &
|
||||
'';
|
||||
asUser = ''
|
||||
def as_user(cmd: str):
|
||||
"""
|
||||
@ -20,124 +16,137 @@ let
|
||||
'';
|
||||
in
|
||||
{
|
||||
headless = makeTest {
|
||||
name = "headless";
|
||||
headless = runTest (
|
||||
{ lib, ... }:
|
||||
{
|
||||
name = "headless";
|
||||
|
||||
enableOCR = true;
|
||||
enableOCR = true;
|
||||
|
||||
nodes.machine = {
|
||||
imports = [ ./common/user-account.nix ];
|
||||
nodes.machine = {
|
||||
imports = [ ./common/user-account.nix ];
|
||||
|
||||
users.users.alice.extraGroups = [ "ydotool" ];
|
||||
users.users.alice.extraGroups = [ "ydotool" ];
|
||||
|
||||
programs.ydotool.enable = true;
|
||||
programs.ydotool.enable = true;
|
||||
|
||||
services.getty.autologinUser = "alice";
|
||||
};
|
||||
services.getty.autologinUser = "alice";
|
||||
};
|
||||
|
||||
testScript =
|
||||
asUser
|
||||
+ ''
|
||||
start_all()
|
||||
testScript =
|
||||
asUser
|
||||
+ ''
|
||||
start_all()
|
||||
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
machine.wait_for_text("alice")
|
||||
machine.succeed(as_user("ydotool type 'echo ${textInput} > /tmp/output'")) # text input
|
||||
machine.succeed(as_user("ydotool key 28:1 28:0")) # text input
|
||||
machine.screenshot("headless_input")
|
||||
machine.wait_for_file("/tmp/output")
|
||||
machine.wait_until_succeeds("grep '${textInput}' /tmp/output") # text input
|
||||
'';
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
machine.wait_for_text("alice")
|
||||
machine.succeed(as_user("ydotool type 'echo ${textInput} > /tmp/output'")) # text input
|
||||
machine.succeed(as_user("ydotool key 28:1 28:0")) # text input
|
||||
machine.screenshot("headless_input")
|
||||
machine.wait_for_file("/tmp/output")
|
||||
machine.wait_until_succeeds("grep '${textInput}' /tmp/output") # text input
|
||||
'';
|
||||
|
||||
meta.maintainers = with lib.maintainers; [
|
||||
OPNA2608
|
||||
quantenzitrone
|
||||
];
|
||||
};
|
||||
|
||||
x11 = makeTest {
|
||||
name = "x11";
|
||||
|
||||
enableOCR = true;
|
||||
|
||||
nodes.machine = {
|
||||
imports = [
|
||||
./common/user-account.nix
|
||||
./common/auto.nix
|
||||
./common/x11.nix
|
||||
meta.maintainers = with lib.maintainers; [
|
||||
OPNA2608
|
||||
quantenzitrone
|
||||
];
|
||||
}
|
||||
);
|
||||
|
||||
users.users.alice.extraGroups = [ "ydotool" ];
|
||||
x11 = runTest (
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
name = "x11";
|
||||
|
||||
programs.ydotool.enable = true;
|
||||
enableOCR = true;
|
||||
|
||||
test-support.displayManager.auto = {
|
||||
enable = true;
|
||||
user = "alice";
|
||||
};
|
||||
nodes.machine =
|
||||
{ lib, ... }:
|
||||
{
|
||||
imports = [
|
||||
./common/user-account.nix
|
||||
./common/auto.nix
|
||||
./common/x11.nix
|
||||
];
|
||||
|
||||
services.xserver.windowManager.dwm.enable = true;
|
||||
services.displayManager.defaultSession = lib.mkForce "none+dwm";
|
||||
};
|
||||
users.users.alice.extraGroups = [ "ydotool" ];
|
||||
|
||||
testScript =
|
||||
asUser
|
||||
+ ''
|
||||
programs.ydotool.enable = true;
|
||||
|
||||
test-support.displayManager.auto = {
|
||||
enable = true;
|
||||
user = "alice";
|
||||
};
|
||||
|
||||
services.xserver.windowManager.dwm.enable = true;
|
||||
services.displayManager.defaultSession = lib.mkForce "none+dwm";
|
||||
};
|
||||
|
||||
testScript =
|
||||
asUser
|
||||
+ ''
|
||||
start_all()
|
||||
|
||||
machine.wait_for_x()
|
||||
machine.execute(as_user("${inputBox config.node.pkgs}"))
|
||||
machine.wait_for_text("${inputBoxText}")
|
||||
machine.succeed(as_user("ydotool type '${textInput}'")) # text input
|
||||
machine.screenshot("x11_input")
|
||||
machine.succeed(as_user("ydotool mousemove -a 400 110")) # mouse input
|
||||
machine.succeed(as_user("ydotool click 0xC0")) # mouse input
|
||||
machine.wait_for_file("/tmp/output")
|
||||
machine.wait_until_succeeds("grep '${textInput}' /tmp/output") # text input
|
||||
'';
|
||||
|
||||
meta.maintainers = with lib.maintainers; [
|
||||
OPNA2608
|
||||
quantenzitrone
|
||||
];
|
||||
}
|
||||
);
|
||||
|
||||
wayland = runTest (
|
||||
{ lib, ... }:
|
||||
{
|
||||
name = "wayland";
|
||||
|
||||
enableOCR = true;
|
||||
|
||||
nodes.machine =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
imports = [ ./common/user-account.nix ];
|
||||
|
||||
services.cage = {
|
||||
enable = true;
|
||||
user = "alice";
|
||||
};
|
||||
|
||||
programs.ydotool.enable = true;
|
||||
|
||||
services.cage.program = inputBox pkgs;
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all()
|
||||
|
||||
machine.wait_for_x()
|
||||
machine.execute(as_user("${inputBox}"))
|
||||
machine.wait_for_unit("graphical.target")
|
||||
machine.wait_for_text("${inputBoxText}")
|
||||
machine.succeed(as_user("ydotool type '${textInput}'")) # text input
|
||||
machine.screenshot("x11_input")
|
||||
machine.succeed(as_user("ydotool mousemove -a 400 110")) # mouse input
|
||||
machine.succeed(as_user("ydotool click 0xC0")) # mouse input
|
||||
machine.succeed("ydotool type '${textInput}'") # text input
|
||||
machine.screenshot("wayland_input")
|
||||
machine.succeed("ydotool mousemove -a 100 100") # mouse input
|
||||
machine.succeed("ydotool click 0xC0") # mouse input
|
||||
machine.wait_for_file("/tmp/output")
|
||||
machine.wait_until_succeeds("grep '${textInput}' /tmp/output") # text input
|
||||
'';
|
||||
|
||||
meta.maintainers = with lib.maintainers; [
|
||||
OPNA2608
|
||||
quantenzitrone
|
||||
];
|
||||
};
|
||||
|
||||
wayland = makeTest {
|
||||
name = "wayland";
|
||||
|
||||
enableOCR = true;
|
||||
|
||||
nodes.machine = {
|
||||
imports = [ ./common/user-account.nix ];
|
||||
|
||||
services.cage = {
|
||||
enable = true;
|
||||
user = "alice";
|
||||
};
|
||||
|
||||
programs.ydotool.enable = true;
|
||||
|
||||
services.cage.program = inputBox;
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all()
|
||||
|
||||
machine.wait_for_unit("graphical.target")
|
||||
machine.wait_for_text("${inputBoxText}")
|
||||
machine.succeed("ydotool type '${textInput}'") # text input
|
||||
machine.screenshot("wayland_input")
|
||||
machine.succeed("ydotool mousemove -a 100 100") # mouse input
|
||||
machine.succeed("ydotool click 0xC0") # mouse input
|
||||
machine.wait_for_file("/tmp/output")
|
||||
machine.wait_until_succeeds("grep '${textInput}' /tmp/output") # text input
|
||||
'';
|
||||
|
||||
meta.maintainers = with lib.maintainers; [
|
||||
OPNA2608
|
||||
quantenzitrone
|
||||
];
|
||||
};
|
||||
meta.maintainers = with lib.maintainers; [
|
||||
OPNA2608
|
||||
quantenzitrone
|
||||
];
|
||||
}
|
||||
);
|
||||
|
||||
customGroup =
|
||||
let
|
||||
@ -147,38 +156,41 @@ in
|
||||
outsideGroupUsername = "other-user";
|
||||
groupName = "custom-group";
|
||||
in
|
||||
makeTest {
|
||||
inherit name;
|
||||
runTest (
|
||||
{ lib, ... }:
|
||||
{
|
||||
inherit name;
|
||||
|
||||
nodes."${nodeName}" = {
|
||||
programs.ydotool = {
|
||||
enable = true;
|
||||
group = groupName;
|
||||
};
|
||||
|
||||
users.users = {
|
||||
"${insideGroupUsername}" = {
|
||||
isNormalUser = true;
|
||||
extraGroups = [ groupName ];
|
||||
nodes."${nodeName}" = {
|
||||
programs.ydotool = {
|
||||
enable = true;
|
||||
group = groupName;
|
||||
};
|
||||
|
||||
users.users = {
|
||||
"${insideGroupUsername}" = {
|
||||
isNormalUser = true;
|
||||
extraGroups = [ groupName ];
|
||||
};
|
||||
"${outsideGroupUsername}".isNormalUser = true;
|
||||
};
|
||||
"${outsideGroupUsername}".isNormalUser = true;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all()
|
||||
testScript = ''
|
||||
start_all()
|
||||
|
||||
# Wait for service to start
|
||||
${nodeName}.wait_for_unit("multi-user.target")
|
||||
${nodeName}.wait_for_unit("ydotoold.service")
|
||||
# Wait for service to start
|
||||
${nodeName}.wait_for_unit("multi-user.target")
|
||||
${nodeName}.wait_for_unit("ydotoold.service")
|
||||
|
||||
# Verify that user with the configured group can use the service
|
||||
${nodeName}.succeed("sudo --login --user=${insideGroupUsername} ydotool type 'Hello, World!'")
|
||||
# Verify that user with the configured group can use the service
|
||||
${nodeName}.succeed("sudo --login --user=${insideGroupUsername} ydotool type 'Hello, World!'")
|
||||
|
||||
# Verify that user without the configured group can't use the service
|
||||
${nodeName}.fail("sudo --login --user=${outsideGroupUsername} ydotool type 'Hello, World!'")
|
||||
'';
|
||||
# Verify that user without the configured group can't use the service
|
||||
${nodeName}.fail("sudo --login --user=${outsideGroupUsername} ydotool type 'Hello, World!'")
|
||||
'';
|
||||
|
||||
meta.maintainers = with lib.maintainers; [ l0b0 ];
|
||||
};
|
||||
meta.maintainers = with lib.maintainers; [ l0b0 ];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user