vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / xrdp-with-audio-pulseaudio.nix
blob27da7c457c493d97030b6f84d8e9657e09852e8e
1 import ./make-test-python.nix ({ pkgs, ...} : {
2   # How to interactively test this module if the audio actually works
4   # - nix run .#pulseaudio-module-xrdp.tests.xrdp-with-audio-pulseaudio.driverInteractive
5   # - test_script() # launches the terminal and the tests itself
6   # - server.send_monitor_command("hostfwd_add tcp::3389-:3389") # forward the RDP port to the host
7   # - Connect with the RDP client you like (ex: Remmina)
8   # - Don't forget to enable audio support. In remmina: Advanced -> Audio output mode to Local (default is Off)
9   # - Open a browser or something that plays sound. Ex: chromium
11   name = "xrdp-with-audio-pulseaudio";
12   meta = with pkgs.lib.maintainers; {
13     maintainers = [ lucasew ];
14   };
16   nodes = {
17     server = { pkgs, ... }: {
18       imports = [ ./common/user-account.nix ];
20       environment.etc."xrdp/test.txt".text = "Shouldn't conflict";
22       services.xrdp.enable = true;
23       services.xrdp.audio.enable = true;
24       services.xrdp.defaultWindowManager = "${pkgs.xterm}/bin/xterm";
26       hardware.pulseaudio = {
27         enable = true;
28       };
30       systemd.user.services.pactl-list = {
31         script = ''
32           while [ ! -S /tmp/.xrdp/xrdp_chansrv_audio_in_socket_* ]; do
33             sleep 1
34           done
35           sleep 1
36           ${pkgs.pulseaudio}/bin/pactl list
37           echo Source:
38           ${pkgs.pulseaudio}/bin/pactl get-default-source | tee /tmp/pulseaudio-source
39           echo Sink:
40           ${pkgs.pulseaudio}/bin/pactl get-default-sink | tee /tmp/pulseaudio-sink
42         '';
43         wantedBy = [ "default.target" ];
44       };
46       networking.firewall.allowedTCPPorts = [ 3389 ];
47     };
49     client = { pkgs, ... }: {
50       imports = [ ./common/x11.nix ./common/user-account.nix ];
51       test-support.displayManager.auto.user = "alice";
53       environment.systemPackages = [ pkgs.freerdp ];
55       services.xrdp.enable = true;
56       services.xrdp.audio.enable = true;
57       services.xrdp.defaultWindowManager = "${pkgs.icewm}/bin/icewm";
59       hardware.pulseaudio = {
60         enable = true;
61       };
62     };
63   };
65   testScript = { nodes, ... }: let
66     user = nodes.client.config.users.users.alice;
67   in ''
68     start_all()
70     client.wait_for_x()
71     client.wait_for_file("${user.home}/.Xauthority")
72     client.succeed("xauth merge ${user.home}/.Xauthority")
74     client.sleep(5)
76     client.execute("xterm >&2 &")
77     client.sleep(1)
79     client.send_chars("xfreerdp /cert-tofu /w:640 /h:480 /v:127.0.0.1 /u:${user.name} /p:${user.password} /sound\n")
81     client.sleep(10)
83     client.succeed("[ -S /tmp/.xrdp/xrdp_chansrv_audio_in_socket_* ]") # checks if it's a socket
84     client.sleep(5)
85     client.screenshot("localrdp")
87     client.execute("xterm >&2 &")
88     client.sleep(1)
89     client.send_chars("xfreerdp /cert-tofu /w:640 /h:480 /v:server /u:${user.name} /p:${user.password} /sound\n")
90     client.sleep(10)
92     server.succeed("[ -S /tmp/.xrdp/xrdp_chansrv_audio_in_socket_* ]") # checks if it's a socket
93     server.succeed('[ "$(cat /tmp/pulseaudio-source)" == "xrdp-source" ]')
94     server.succeed('[ "$(cat /tmp/pulseaudio-sink)" == "xrdp-sink" ]')
95     client.screenshot("remoterdp")
96   '';