1{ runTest }:
2
3let
4 galeneTestGroupsDir = "/var/lib/galene/groups";
5 galeneTestGroupFile = "galene-test-config.json";
6 galenePort = 8443;
7 galeneTestGroupAdminName = "admin";
8 galeneTestGroupAdminPassword = "1234";
9in
10{
11 basic = runTest (
12 { pkgs, lib, ... }:
13 {
14 name = "galene-works";
15 meta = {
16 inherit (pkgs.galene.meta) maintainers;
17 platforms = lib.platforms.linux;
18 };
19
20 nodes.machine =
21 { config, pkgs, ... }:
22 {
23 imports = [ ./common/x11.nix ];
24
25 services.xserver.enable = true;
26
27 environment = {
28 # https://galene.org/INSTALL.html
29 etc.${galeneTestGroupFile}.source = (pkgs.formats.json { }).generate galeneTestGroupFile {
30 op = [
31 {
32 username = galeneTestGroupAdminName;
33 password = galeneTestGroupAdminPassword;
34 }
35 ];
36 other = [ { } ];
37 };
38
39 systemPackages = with pkgs; [
40 firefox
41 ];
42 };
43
44 services.galene = {
45 enable = true;
46 insecure = true;
47 httpPort = galenePort;
48 groupsDir = galeneTestGroupsDir;
49 };
50 };
51
52 enableOCR = true;
53
54 testScript = ''
55 machine.wait_for_x()
56
57 with subtest("galene starts"):
58 # Starts?
59 machine.wait_for_unit("galene")
60 machine.wait_for_open_port(${builtins.toString galenePort})
61
62 # Reponds fine?
63 machine.succeed("curl -s -D - -o /dev/null 'http://localhost:${builtins.toString galenePort}' >&2")
64
65 machine.succeed("cp -v /etc/${galeneTestGroupFile} ${galeneTestGroupsDir}/test.json >&2")
66 machine.wait_until_succeeds("curl -s -D - -o /dev/null 'http://localhost:${builtins.toString galenePort}/group/test/' >&2")
67
68 with subtest("galene can join group"):
69 # Open site
70 machine.succeed("firefox --new-window 'http://localhost:${builtins.toString galenePort}/group/test/' >&2 &")
71 # Note: Firefox doesn't use a regular "-" in the window title, but "—" (Hex: 0xe2 0x80 0x94)
72 machine.wait_for_window("Test — Mozilla Firefox")
73 machine.send_key("ctrl-minus")
74 machine.send_key("ctrl-minus")
75 machine.send_key("alt-f10")
76 machine.wait_for_text(r"(Galène|Username|Password|Connect)")
77 machine.screenshot("galene-group-test-join")
78
79 # Log in as admin
80 machine.send_chars("${galeneTestGroupAdminName}")
81 machine.send_key("tab")
82 machine.send_chars("${galeneTestGroupAdminPassword}")
83 machine.send_key("ret")
84 machine.sleep(5)
85 # Close "Remember credentials?" FF prompt
86 machine.send_key("esc")
87 machine.sleep(5)
88 machine.wait_for_text(r"(Enable|Share|Screen)")
89 machine.screenshot("galene-group-test-logged-in")
90 '';
91 }
92 );
93
94 file-transfer = runTest (
95 { pkgs, lib, ... }:
96 {
97 name = "galene-file-transfer-works";
98 meta = {
99 inherit (pkgs.galene-file-transfer.meta) maintainers;
100 platforms = lib.platforms.linux;
101 };
102
103 nodes.machine =
104 { config, pkgs, ... }:
105 {
106 imports = [ ./common/x11.nix ];
107
108 services.xserver.enable = true;
109
110 environment = {
111 # https://galene.org/INSTALL.html
112 etc.${galeneTestGroupFile}.source = (pkgs.formats.json { }).generate galeneTestGroupFile {
113 op = [
114 {
115 username = galeneTestGroupAdminName;
116 password = galeneTestGroupAdminPassword;
117 }
118 ];
119 other = [ { } ];
120 };
121
122 systemPackages = with pkgs; [
123 firefox
124 galene-file-transfer
125 ];
126 };
127
128 services.galene = {
129 enable = true;
130 insecure = true;
131 httpPort = galenePort;
132 groupsDir = galeneTestGroupsDir;
133 };
134 };
135
136 enableOCR = true;
137
138 testScript = ''
139 machine.wait_for_x()
140
141 with subtest("galene starts"):
142 # Starts?
143 machine.wait_for_unit("galene")
144 machine.wait_for_open_port(${builtins.toString galenePort})
145
146 # Reponds fine?
147 machine.succeed("curl -s -D - -o /dev/null 'http://localhost:${builtins.toString galenePort}' >&2")
148
149 machine.succeed("cp -v /etc/${galeneTestGroupFile} ${galeneTestGroupsDir}/test.json >&2")
150 machine.wait_until_succeeds("curl -s -D - -o /dev/null 'http://localhost:${builtins.toString galenePort}/group/test/' >&2")
151
152 with subtest("galene can join group"):
153 # Open site
154 machine.succeed("firefox --new-window 'http://localhost:${builtins.toString galenePort}/group/test/' >&2 &")
155 # Note: Firefox doesn't use a regular "-" in the window title, but "—" (Hex: 0xe2 0x80 0x94)
156 machine.wait_for_window("Test — Mozilla Firefox")
157 machine.send_key("ctrl-minus")
158 machine.send_key("ctrl-minus")
159 machine.send_key("alt-f10")
160 machine.wait_for_text(r"(Galène|Username|Password|Connect)")
161 machine.screenshot("galene-group-test-join")
162
163 # Log in as admin
164 machine.send_chars("${galeneTestGroupAdminName}")
165 machine.send_key("tab")
166 machine.send_chars("${galeneTestGroupAdminPassword}")
167 machine.send_key("ret")
168 machine.sleep(5)
169 # Close "Remember credentials?" FF prompt
170 machine.send_key("esc")
171 machine.sleep(5)
172 machine.wait_for_text(r"(Enable|Share|Screen)")
173 machine.screenshot("galene-group-test-logged-in")
174
175 with subtest("galene-file-transfer works"):
176 machine.succeed(
177 "galene-file-transfer "
178 + "-to '${galeneTestGroupAdminName}' "
179 + "-insecure 'http://localhost:${builtins.toString galenePort}/group/test/' "
180 + "${galeneTestGroupsDir}/test.json " # just try sending the groups file
181 + " >&2 &"
182 )
183 machine.sleep(5) # Give pop-up some time to appear
184 machine.wait_for_text(r"(offered to send us a file|Accept|Reject|disclose your IP)")
185 machine.screenshot("galene-file-transfer-dislogue")
186
187 # Focus on Accept button
188 machine.send_key("shift-tab")
189 machine.send_key("shift-tab")
190 machine.send_key("shift-tab")
191 machine.send_key("shift-tab")
192
193 # Accept download
194 machine.sleep(2)
195 machine.send_key("ret")
196
197 # Wait until complete & matching
198 machine.wait_until_succeeds(
199 "diff "
200 + "${galeneTestGroupsDir}/test.json " # original
201 + "/root/Downloads/test.json" # Received via file-transfer
202 )
203 '';
204 }
205 );
206
207 stream = runTest (
208 { pkgs, lib, ... }:
209 let
210 galeneTestGroupBotName = "bot";
211 galeneTestGroupBotPassword = "1234";
212 galeneStreamSrtPort = 9710;
213 galeneStreamFeedImage = "galene-stream-feed.png";
214 galeneStreamFeedLabel = "Example";
215 in
216 {
217 name = "galene-stream-works";
218 meta = {
219 # inherit (pkgs.galene-stream.meta) teams;
220 inherit (pkgs.galene.meta) maintainers;
221 platforms = lib.platforms.linux;
222 };
223
224 nodes.machine =
225 { config, pkgs, ... }:
226 {
227 imports = [ ./common/x11.nix ];
228
229 services.xserver.enable = true;
230
231 environment = {
232 # https://galene.org/INSTALL.html
233 etc = {
234 ${galeneTestGroupFile}.source = (pkgs.formats.json { }).generate galeneTestGroupFile {
235 presenter = [
236 {
237 username = galeneTestGroupBotName;
238 password = galeneTestGroupBotPassword;
239 }
240 ];
241 other = [ { } ];
242 };
243
244 ${galeneStreamFeedImage}.source =
245 pkgs.runCommand galeneStreamFeedImage
246 {
247 nativeBuildInputs = with pkgs; [
248 (imagemagick.override { ghostscriptSupport = true; }) # Add text to image
249 ];
250 }
251 ''
252 magick -size 400x400 -background white -fill black canvas:white -pointsize 70 -annotate +100+200 '${galeneStreamFeedLabel}' $out
253 '';
254 };
255
256 systemPackages = with pkgs; [
257 ffmpeg
258 firefox
259 galene-stream
260 ];
261 };
262
263 services.galene = {
264 enable = true;
265 insecure = true;
266 httpPort = galenePort;
267 groupsDir = galeneTestGroupsDir;
268 };
269 };
270
271 enableOCR = true;
272
273 testScript = ''
274 machine.wait_for_x()
275
276 with subtest("galene starts"):
277 # Starts?
278 machine.wait_for_unit("galene")
279 machine.wait_for_open_port(${builtins.toString galenePort})
280
281 # Reponds fine?
282 machine.succeed("curl -s -D - -o /dev/null 'http://localhost:${builtins.toString galenePort}' >&2")
283
284 machine.succeed("cp -v /etc/${galeneTestGroupFile} ${galeneTestGroupsDir}/test.json >&2")
285 machine.wait_until_succeeds("curl -s -D - -o /dev/null 'http://localhost:${builtins.toString galenePort}/group/test/' >&2")
286
287 with subtest("galene-stream works"):
288 # Start interface for stream data
289 machine.succeed(
290 "galene-stream "
291 + "--input 'srt://localhost:${builtins.toString galeneStreamSrtPort}?mode=listener' "
292 + "--insecure --output 'http://localhost:${builtins.toString galenePort}/group/test/' "
293 + "--username ${galeneTestGroupBotName} --password ${galeneTestGroupBotPassword} "
294 + ">&2 &"
295 )
296 machine.wait_for_console_text("Waiting for incoming stream...")
297
298 # Start streaming
299 machine.succeed(
300 "ffmpeg "
301 + "-f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000 " # need an audio track
302 + "-re -loop 1 -i /etc/${galeneStreamFeedImage} " # loop of feed image
303 + "-map 0:a -map 1:v " # arrange the output stream to have silent audio & looped video
304 + "-c:a mp2 " # stream audio codec
305 + "-c:v libx264 -pix_fmt yuv420p " # stream video codec
306 + "-f mpegts " # stream format
307 + "'srt://localhost:${builtins.toString galeneStreamSrtPort}' "
308 + ">/dev/null 2>&1 &"
309 )
310 machine.wait_for_console_text("Setting remote session description")
311
312 # Open site
313 machine.succeed("firefox --new-window 'http://localhost:${builtins.toString galenePort}/group/test/' >&2 &")
314 # Note: Firefox doesn't use a regular "-" in the window title, but "—" (Hex: 0xe2 0x80 0x94)
315 machine.wait_for_window("Test — Mozilla Firefox")
316 machine.send_key("ctrl-minus")
317 machine.send_key("ctrl-minus")
318 machine.send_key("alt-f10")
319 machine.wait_for_text(r"(Galène|Username|Password|Connect)")
320 machine.screenshot("galene-group-test-join")
321
322 # Log in as anon
323 machine.send_key("ret")
324 machine.sleep(5)
325 # Close "Remember credentials?" FF prompt
326 machine.send_key("esc")
327 machine.sleep(5)
328
329 # Look for stream
330 machine.wait_for_text("${galeneStreamFeedLabel}")
331 machine.screenshot("galene-stream-group-test-streams")
332 '';
333 }
334 );
335}