diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 68b920a4dd41..ac9a23e0408e 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -574,6 +574,7 @@ in _module.args.firefoxPackage = pkgs.firefox-esr-140; }; firefox-syncserver = runTest ./firefox-syncserver.nix; + firefox_decrypt = runTest ./firefox_decrypt.nix; firefoxpwa = runTest ./firefoxpwa.nix; firejail = runTest ./firejail.nix; firewall = runTest { diff --git a/nixos/tests/firefox_decrypt.nix b/nixos/tests/firefox_decrypt.nix new file mode 100644 index 000000000000..4612f122214e --- /dev/null +++ b/nixos/tests/firefox_decrypt.nix @@ -0,0 +1,73 @@ +{ lib, ... }: +{ + name = "firefox_decrypt"; + + meta = { + maintainers = with lib.maintainers; [ schnusch ]; + }; + + nodes.machine = + { pkgs, ... }: + { + imports = [ ./common/x11.nix ]; + programs.firefox.enable = true; + environment.systemPackages = [ pkgs.firefox_decrypt ]; + }; + + enableOCR = true; + + testScript = '' + import csv + import io + import random + import string + + machine.wait_for_x() + + expected: dict[str, str] = { + "url": "http://localhost", + "user": "user", + "password": "".join(random.choices(string.ascii_letters + string.digits, k=32)), + } + + machine.execute("firefox about:logins >&2 &") + + # press "Add password" button + # "Search Passwords" is not found by OCR, probably due to too low contrast. + machine.wait_for_text("No passwords saved") + for c in ("tab", "\n"): + machine.send_key(c) + + # add a new password entry + machine.wait_for_text("Add password") + for text, control in [ + (expected["url"], "tab"), + (expected["user"], "tab"), + (expected["password"], "\n"), + ]: + with machine.nested(f"typing {repr(text)}"): + for c in text: + machine.send_key(c, log=False) + machine.send_key(control) + + # "Remove" button for our new entry appeared + machine.wait_for_text("Remove") + + # close Firefox + machine.send_key("ctrl-q") + machine.wait_for_text(r"Quit Firefox or close current tab\?") + machine.send_key("\n") + + # extract Firefox logins + credentials = list( + csv.DictReader( + io.StringIO( + machine.succeed("firefox_decrypt -f csv ~/.config/mozilla/firefox"), + newline="", + ), + delimiter=";", + ) + ) + assert expected in credentials, f"expected {expected!r} in {credentials!r}" + ''; +} diff --git a/pkgs/by-name/fi/firefox_decrypt/package.nix b/pkgs/by-name/fi/firefox_decrypt/package.nix index 0dba1e092146..7b1412d14352 100644 --- a/pkgs/by-name/fi/firefox_decrypt/package.nix +++ b/pkgs/by-name/fi/firefox_decrypt/package.nix @@ -2,6 +2,7 @@ lib, fetchFromGitHub, nss, + nixosTests, nix-update-script, stdenv, python3Packages, @@ -32,7 +33,12 @@ python3Packages.buildPythonApplication (finalAttrs: { (lib.makeLibraryPath [ nss ]) ]; - passthru.updateScript = nix-update-script { }; + passthru = { + tests = { + inherit (nixosTests) firefox_decrypt; + }; + updateScript = nix-update-script { }; + }; meta = { homepage = "https://github.com/unode/firefox_decrypt";