From e4b09e47ace7d87de083786b404bf232eb6c89d8 Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Fri, 30 May 2025 20:48:08 +0200 Subject: [PATCH] nixosTests.galene.file-transfer: init --- nixos/tests/galene.nix | 122 +++++++++++++++++- .../ga/galene-file-transfer/package.nix | 2 + 2 files changed, 120 insertions(+), 4 deletions(-) diff --git a/nixos/tests/galene.nix b/nixos/tests/galene.nix index a42d178ddc91..8805a088a56c 100644 --- a/nixos/tests/galene.nix +++ b/nixos/tests/galene.nix @@ -3,14 +3,12 @@ let galeneTestGroupsDir = "/var/lib/galene/groups"; galeneTestGroupFile = "galene-test-config.json"; galenePort = 8443; + galeneTestGroupAdminName = "admin"; + galeneTestGroupAdminPassword = "1234"; in { basic = makeTest ( { pkgs, lib, ... }: - let - galeneTestGroupAdminName = "admin"; - galeneTestGroupAdminPassword = "1234"; - in { name = "galene-works"; meta = { @@ -94,4 +92,120 @@ in ''; } ); + + file-transfer = makeTest ( + { 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") + + # Keeps running after startup? + machine.sleep(10) + machine.wait_for_unit("galene") + + # Reponds fine? + machine.succeed("curl -s -D - -o /dev/null 'http://localhost:${builtins.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:${builtins.toString galenePort}/group/test/' >&2") + + with subtest("galene can join group"): + # Open site + machine.succeed("firefox --new-window 'http://localhost:${builtins.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:${builtins.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 + ) + ''; + } + ); } diff --git a/pkgs/by-name/ga/galene-file-transfer/package.nix b/pkgs/by-name/ga/galene-file-transfer/package.nix index 08776012c811..43b4c8619486 100644 --- a/pkgs/by-name/ga/galene-file-transfer/package.nix +++ b/pkgs/by-name/ga/galene-file-transfer/package.nix @@ -3,6 +3,7 @@ buildGoModule, fetchFromGitHub, gitUpdater, + nixosTests, writeShellApplication, _experimental-update-script-combinators, galene, @@ -31,6 +32,7 @@ buildGoModule (finalAttrs: { ]; passthru = { + tests.vm = nixosTests.galene.file-transfer; updateScriptSrc = gitUpdater { rev-prefix = "galene-file-transfer-"; };