1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "pass-secret-service";
3 meta.maintainers = [ lib.maintainers.aidalgol ];
5 nodes.machine = { nodes, pkgs, ... }:
7 imports = [ ./common/user-account.nix ];
9 services.passSecretService.enable = true;
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"
15 libraries = [ pkgs.python3Packages.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.")
29 dirmngr.enable = true;
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, ... }:
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";
43 # Initialise the pass(1) storage.
45 sudo -u alice gpg --pinentry-mode loopback --batch --passphrase ${gpg-pw} \
46 --quick-gen-key ${gpg-uid} \
48 machine.succeed("sudo -u alice pass init ${gpg-uid}")
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")
59 _, output = machine.systemctl("status dbus-org.freedesktop.secrets --no-pager", "alice")
60 assert "Active: inactive (dead)" in output
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