at 25.11-pre 4.8 kB view raw
1{ 2 system ? builtins.currentSystem, 3 config ? { }, 4 pkgs ? import ../.. { inherit system config; }, 5 lib ? pkgs.lib, 6}: 7let 8 makeTest = import ./make-test-python.nix; 9 textInput = "This works."; 10 inputBoxText = "Enter input"; 11 inputBox = pkgs.writeShellScript "zenity-input" '' 12 ${lib.getExe pkgs.zenity} --entry --text '${inputBoxText}:' > /tmp/output & 13 ''; 14 asUser = '' 15 def as_user(cmd: str): 16 """ 17 Return a shell command for running a shell command as a specific user. 18 """ 19 return f"sudo -u alice -i {cmd}" 20 ''; 21in 22{ 23 headless = makeTest { 24 name = "headless"; 25 26 enableOCR = true; 27 28 nodes.machine = { 29 imports = [ ./common/user-account.nix ]; 30 31 users.users.alice.extraGroups = [ "ydotool" ]; 32 33 programs.ydotool.enable = true; 34 35 services.getty.autologinUser = "alice"; 36 }; 37 38 testScript = 39 asUser 40 + '' 41 start_all() 42 43 machine.wait_for_unit("multi-user.target") 44 machine.wait_for_text("alice") 45 machine.succeed(as_user("ydotool type 'echo ${textInput} > /tmp/output'")) # text input 46 machine.succeed(as_user("ydotool key 28:1 28:0")) # text input 47 machine.screenshot("headless_input") 48 machine.wait_for_file("/tmp/output") 49 machine.wait_until_succeeds("grep '${textInput}' /tmp/output") # text input 50 ''; 51 52 meta.maintainers = with lib.maintainers; [ 53 OPNA2608 54 quantenzitrone 55 ]; 56 }; 57 58 x11 = makeTest { 59 name = "x11"; 60 61 enableOCR = true; 62 63 nodes.machine = { 64 imports = [ 65 ./common/user-account.nix 66 ./common/auto.nix 67 ./common/x11.nix 68 ]; 69 70 users.users.alice.extraGroups = [ "ydotool" ]; 71 72 programs.ydotool.enable = true; 73 74 test-support.displayManager.auto = { 75 enable = true; 76 user = "alice"; 77 }; 78 79 services.xserver.windowManager.dwm.enable = true; 80 services.displayManager.defaultSession = lib.mkForce "none+dwm"; 81 }; 82 83 testScript = 84 asUser 85 + '' 86 start_all() 87 88 machine.wait_for_x() 89 machine.execute(as_user("${inputBox}")) 90 machine.wait_for_text("${inputBoxText}") 91 machine.succeed(as_user("ydotool type '${textInput}'")) # text input 92 machine.screenshot("x11_input") 93 machine.succeed(as_user("ydotool mousemove -a 400 110")) # mouse input 94 machine.succeed(as_user("ydotool click 0xC0")) # mouse input 95 machine.wait_for_file("/tmp/output") 96 machine.wait_until_succeeds("grep '${textInput}' /tmp/output") # text input 97 ''; 98 99 meta.maintainers = with lib.maintainers; [ 100 OPNA2608 101 quantenzitrone 102 ]; 103 }; 104 105 wayland = makeTest { 106 name = "wayland"; 107 108 enableOCR = true; 109 110 nodes.machine = { 111 imports = [ ./common/user-account.nix ]; 112 113 services.cage = { 114 enable = true; 115 user = "alice"; 116 }; 117 118 programs.ydotool.enable = true; 119 120 services.cage.program = inputBox; 121 }; 122 123 testScript = '' 124 start_all() 125 126 machine.wait_for_unit("graphical.target") 127 machine.wait_for_text("${inputBoxText}") 128 machine.succeed("ydotool type '${textInput}'") # text input 129 machine.screenshot("wayland_input") 130 machine.succeed("ydotool mousemove -a 100 100") # mouse input 131 machine.succeed("ydotool click 0xC0") # mouse input 132 machine.wait_for_file("/tmp/output") 133 machine.wait_until_succeeds("grep '${textInput}' /tmp/output") # text input 134 ''; 135 136 meta.maintainers = with lib.maintainers; [ 137 OPNA2608 138 quantenzitrone 139 ]; 140 }; 141 142 customGroup = 143 let 144 name = "customGroup"; 145 nodeName = "${name}Node"; 146 insideGroupUsername = "ydotool-user"; 147 outsideGroupUsername = "other-user"; 148 groupName = "custom-group"; 149 in 150 makeTest { 151 inherit name; 152 153 nodes."${nodeName}" = { 154 programs.ydotool = { 155 enable = true; 156 group = groupName; 157 }; 158 159 users.users = { 160 "${insideGroupUsername}" = { 161 isNormalUser = true; 162 extraGroups = [ groupName ]; 163 }; 164 "${outsideGroupUsername}".isNormalUser = true; 165 }; 166 }; 167 168 testScript = '' 169 start_all() 170 171 # Wait for service to start 172 ${nodeName}.wait_for_unit("multi-user.target") 173 ${nodeName}.wait_for_unit("ydotoold.service") 174 175 # Verify that user with the configured group can use the service 176 ${nodeName}.succeed("sudo --login --user=${insideGroupUsername} ydotool type 'Hello, World!'") 177 178 # Verify that user without the configured group can't use the service 179 ${nodeName}.fail("sudo --login --user=${outsideGroupUsername} ydotool type 'Hello, World!'") 180 ''; 181 182 meta.maintainers = with lib.maintainers; [ l0b0 ]; 183 }; 184}