at 24.11-pre 2.6 kB view raw
1import ./make-test-python.nix ({ pkgs, lib, ... }: { 2 name = "pass-secret-service"; 3 meta.maintainers = [ lib.maintainers.aidalgol ]; 4 5 nodes.machine = { nodes, pkgs, ... }: 6 { 7 imports = [ ./common/user-account.nix ]; 8 9 services.passSecretService.enable = true; 10 11 environment.systemPackages = [ 12 # Create a script that tries to make a request to the D-Bus secrets API. 13 (pkgs.writers.writePython3Bin "secrets-dbus-init" 14 { 15 libraries = [ pkgs.python3Packages.secretstorage ]; 16 } '' 17 import secretstorage 18 print("Initializing dbus connection...") 19 connection = secretstorage.dbus_init() 20 print("Requesting default collection...") 21 collection = secretstorage.get_default_collection(connection) 22 print("Done! dbus-org.freedesktop.secrets should now be active.") 23 '') 24 pkgs.pass 25 ]; 26 27 programs.gnupg = { 28 agent.enable = true; 29 dirmngr.enable = true; 30 }; 31 }; 32 33 # Some of the commands are run via a virtual console because they need to be 34 # run under a real login session, with D-Bus running in the environment. 35 testScript = { nodes, ... }: 36 let 37 user = nodes.machine.config.users.users.alice; 38 gpg-uid = "alice@example.net"; 39 gpg-pw = "foobar9000"; 40 ready-file = "/tmp/secrets-dbus-init.done"; 41 in 42 '' 43 # Initialise the pass(1) storage. 44 machine.succeed(""" 45 sudo -u alice gpg --pinentry-mode loopback --batch --passphrase ${gpg-pw} \ 46 --quick-gen-key ${gpg-uid} \ 47 """) 48 machine.succeed("sudo -u alice pass init ${gpg-uid}") 49 50 with subtest("Service is not running on login"): 51 machine.wait_until_tty_matches("1", "login: ") 52 machine.send_chars("alice\n") 53 machine.wait_until_tty_matches("1", "login: alice") 54 machine.wait_until_succeeds("pgrep login") 55 machine.wait_until_tty_matches("1", "Password: ") 56 machine.send_chars("${user.password}\n") 57 machine.wait_until_succeeds("pgrep -u alice bash") 58 59 _, output = machine.systemctl("status dbus-org.freedesktop.secrets --no-pager", "alice") 60 assert "Active: inactive (dead)" in output 61 62 with subtest("Service starts after a client tries to talk to the D-Bus API"): 63 machine.send_chars("secrets-dbus-init; touch ${ready-file}\n") 64 machine.wait_for_file("${ready-file}") 65 _, output = machine.systemctl("status dbus-org.freedesktop.secrets --no-pager", "alice") 66 assert "Active: active (running)" in output 67 ''; 68})