summaryrefslogtreecommitdiffstats
path: root/nixos/tests/galene.nix
blob: 7d3a3eabd422f89358d8486c8cfb964d2393b8e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
{ runTest }:

let
  galeneTestGroupsDir = "/var/lib/galene/groups";
  galeneTestGroupFile = "galene-test-config.json";
  galenePort = 8443;
  galeneTestGroupAdminName = "admin";
  galeneTestGroupAdminPassword = "1234";
in
{
  basic = runTest (
    { pkgs, lib, ... }:
    {
      name = "galene-works";
      meta = {
        inherit (pkgs.galene.meta) maintainers;
        platforms = lib.platforms.linux;
      };

      nodes.machine =
        { config, pkgs, ... }:
        {
          imports = [ ./common/x11.nix ];

          services.xserver.enable = true;

          environment = {
            # https://galene.org/INSTALL.html
            etc.${galeneTestGroupFile}.source = (pkgs.formats.json { }).generate galeneTestGroupFile {
              op = [
                {
                  username = galeneTestGroupAdminName;
                  password = galeneTestGroupAdminPassword;
                }
              ];
              other = [ { } ];
            };

            systemPackages = with pkgs; [
              firefox
            ];
          };

          services.galene = {
            enable = true;
            insecure = true;
            httpPort = galenePort;
            groupsDir = galeneTestGroupsDir;
          };
        };

      enableOCR = true;

      testScript = ''
        machine.wait_for_x()

        with subtest("galene starts"):
            # Starts?
            machine.wait_for_unit("galene")
            machine.wait_for_open_port(${toString galenePort})

            # Reponds fine?
            machine.succeed("curl -s -D - -o /dev/null 'http://localhost:${toString galenePort}' >&2")

        machine.succeed("cp -v /etc/${galeneTestGroupFile} ${galeneTestGroupsDir}/test.json >&2")
        machine.wait_until_succeeds("curl -s -D - -o /dev/null 'http://localhost:${toString galenePort}/group/test/' >&2")

        with subtest("galene can join group"):
            # Open site
            machine.succeed("firefox --new-window 'http://localhost:${toString galenePort}/group/test/' >&2 &")
            # Note: Firefox doesn't use a regular "-" in the window title, but "—" (Hex: 0xe2 0x80 0x94)
            machine.wait_for_window("Test — Mozilla Firefox")
            machine.send_key("ctrl-minus")
            machine.send_key("ctrl-minus")
            machine.send_key("alt-f10")
            machine.wait_for_text(r"(Galène|Username|Password|Connect)")
            machine.screenshot("galene-group-test-join")

            # Log in as admin
            machine.send_chars("${galeneTestGroupAdminName}")
            machine.send_key("tab")
            machine.send_chars("${galeneTestGroupAdminPassword}")
            machine.send_key("ret")
            machine.sleep(5)
            # Close "Remember credentials?" FF prompt
            machine.send_key("esc")
            machine.sleep(5)
            machine.wait_for_text(r"(Enable|Share|Screen)")
            machine.screenshot("galene-group-test-logged-in")
      '';
    }
  );

  file-transfer = runTest (
    { pkgs, lib, ... }:
    {
      name = "galene-file-transfer-works";
      meta = {
        inherit (pkgs.galene-file-transfer.meta) maintainers;
        platforms = lib.platforms.linux;
      };

      nodes.machine =
        { config, pkgs, ... }:
        {
          imports = [ ./common/x11.nix ];

          services.xserver.enable = true;

          environment = {
            # https://galene.org/INSTALL.html
            etc.${galeneTestGroupFile}.source = (pkgs.formats.json { }).generate galeneTestGroupFile {
              op = [
                {
                  username = galeneTestGroupAdminName;
                  password = galeneTestGroupAdminPassword;
                }
              ];
              other = [ { } ];
            };

            systemPackages = with pkgs; [
              firefox
              galene-file-transfer
            ];
          };

          services.galene = {
            enable = true;
            insecure = true;
            httpPort = galenePort;
            groupsDir = galeneTestGroupsDir;
          };
        };

      enableOCR = true;

      testScript = ''
        machine.wait_for_x()

        with subtest("galene starts"):
            # Starts?
            machine.wait_for_unit("galene")
            machine.wait_for_open_port(${toString galenePort})

            # Reponds fine?
            machine.succeed("curl -s -D - -o /dev/null 'http://localhost:${toString galenePort}' >&2")

        machine.succeed("cp -v /etc/${galeneTestGroupFile} ${galeneTestGroupsDir}/test.json >&2")
        machine.wait_until_succeeds("curl -s -D - -o /dev/null 'http://localhost:${toString galenePort}/group/test/' >&2")

        with subtest("galene can join group"):
            # Open site
            machine.succeed("firefox --new-window 'http://localhost:${toString galenePort}/group/test/' >&2 &")
            # Note: Firefox doesn't use a regular "-" in the window title, but "—" (Hex: 0xe2 0x80 0x94)
            machine.wait_for_window("Test — Mozilla Firefox")
            machine.send_key("ctrl-minus")
            machine.send_key("ctrl-minus")
            machine.send_key("alt-f10")
            machine.wait_for_text(r"(Galène|Username|Password|Connect)")
            machine.screenshot("galene-group-test-join")

            # Log in as admin
            machine.send_chars("${galeneTestGroupAdminName}")
            machine.send_key("tab")
            machine.send_chars("${galeneTestGroupAdminPassword}")
            machine.send_key("ret")
            machine.sleep(5)
            # Close "Remember credentials?" FF prompt
            machine.send_key("esc")
            machine.sleep(5)
            machine.wait_for_text(r"(Enable|Share|Screen)")
            machine.screenshot("galene-group-test-logged-in")

        with subtest("galene-file-transfer works"):
            machine.succeed(
                "galene-file-transfer "
                + "-to '${galeneTestGroupAdminName}' "
                + "-insecure 'http://localhost:${toString galenePort}/group/test/' "
                + "${galeneTestGroupsDir}/test.json " # just try sending the groups file
                + " >&2 &"
            )
            machine.sleep(5) # Give pop-up some time to appear
            machine.wait_for_text(r"(offered to send us a file|Accept|Reject|disclose your IP)")
            machine.screenshot("galene-file-transfer-dislogue")

            # Focus on Accept button
            machine.send_key("shift-tab")
            machine.send_key("shift-tab")
            machine.send_key("shift-tab")
            machine.send_key("shift-tab")

            # Accept download
            machine.sleep(2)
            machine.send_key("ret")

            # Wait until complete & matching
            machine.wait_until_succeeds(
                "diff "
                + "${galeneTestGroupsDir}/test.json " # original
                + "/root/Downloads/test.json" # Received via file-transfer
            )
      '';
    }
  );

  stream = runTest (
    { pkgs, lib, ... }:
    let
      galeneTestGroupBotName = "bot";
      galeneTestGroupBotPassword = "1234";
      galeneStreamSrtPort = 9710;
      galeneStreamFeedImage = "galene-stream-feed.png";
      galeneStreamFeedLabel = "Example";
    in
    {
      name = "galene-stream-works";
      meta = {
        # inherit (pkgs.galene-stream.meta) teams;
        inherit (pkgs.galene.meta) maintainers;
        platforms = lib.platforms.linux;
      };

      nodes.machine =
        { config, pkgs, ... }:
        {
          imports = [ ./common/x11.nix ];

          services.xserver.enable = true;

          environment = {
            # https://galene.org/INSTALL.html
            etc = {
              ${galeneTestGroupFile}.source = (pkgs.formats.json { }).generate galeneTestGroupFile {
                presenter = [
                  {
                    username = galeneTestGroupBotName;
                    password = galeneTestGroupBotPassword;
                  }
                ];
                other = [ { } ];
              };

              ${galeneStreamFeedImage}.source =
                pkgs.runCommand galeneStreamFeedImage
                  {
                    nativeBuildInputs = with pkgs; [
                      (imagemagick.override { ghostscriptSupport = true; }) # Add text to image
                    ];
                  }
                  ''
                    magick -size 400x400 -background white -fill black canvas:white -pointsize 70 -annotate +100+200 '${galeneStreamFeedLabel}' $out
                  '';
            };

            systemPackages = with pkgs; [
              ffmpeg
              firefox
              galene-stream
            ];
          };

          services.galene = {
            enable = true;
            insecure = true;
            httpPort = galenePort;
            groupsDir = galeneTestGroupsDir;
          };
        };

      enableOCR = true;

      testScript = ''
        machine.wait_for_x()

        with subtest("galene starts"):
            # Starts?
            machine.wait_for_unit("galene")
            machine.wait_for_open_port(${toString galenePort})

            # Reponds fine?
            machine.succeed("curl -s -D - -o /dev/null 'http://localhost:${toString galenePort}' >&2")

        machine.succeed("cp -v /etc/${galeneTestGroupFile} ${galeneTestGroupsDir}/test.json >&2")
        machine.wait_until_succeeds("curl -s -D - -o /dev/null 'http://localhost:${toString galenePort}/group/test/' >&2")

        with subtest("galene-stream works"):
            # Start interface for stream data
            machine.succeed(
                "galene-stream "
                + "--input 'srt://localhost:${toString galeneStreamSrtPort}?mode=listener' "
                + "--insecure --output 'http://localhost:${toString galenePort}/group/test/' "
                + "--username ${galeneTestGroupBotName} --password ${galeneTestGroupBotPassword} "
                + ">&2 &"
            )
            machine.wait_for_console_text("Waiting for incoming stream...")

            # Start streaming
            machine.succeed(
                "ffmpeg "
                + "-f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000 " # need an audio track
                + "-re -loop 1 -i /etc/${galeneStreamFeedImage} " # loop of feed image
                + "-map 0:a -map 1:v " # arrange the output stream to have silent audio & looped video
                + "-c:a mp2 " # stream audio codec
                + "-c:v libx264 -pix_fmt yuv420p " # stream video codec
                + "-f mpegts " # stream format
                + "'srt://localhost:${toString galeneStreamSrtPort}' "
                + ">/dev/null 2>&1 &"
            )
            machine.wait_for_console_text("Setting remote session description")

            # Open site
            machine.succeed("firefox --new-window 'http://localhost:${toString galenePort}/group/test/' >&2 &")
            # Note: Firefox doesn't use a regular "-" in the window title, but "—" (Hex: 0xe2 0x80 0x94)
            machine.wait_for_window("Test — Mozilla Firefox")
            machine.send_key("ctrl-minus")
            machine.send_key("ctrl-minus")
            machine.send_key("alt-f10")
            machine.wait_for_text(r"(Galène|Username|Password|Connect)")
            machine.screenshot("galene-group-test-join")

            # Log in as anon
            machine.send_key("ret")
            machine.sleep(5)
            # Close "Remember credentials?" FF prompt
            machine.send_key("esc")
            machine.sleep(5)

            # Look for stream
            machine.wait_for_text("${galeneStreamFeedLabel}")
            machine.screenshot("galene-stream-group-test-streams")
      '';
    }
  );
}