1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
3 meta.maintainers = with lib.maintainers; [ hmenke ];
6 services.c2fmzq-server = {
9 passphraseFile = builtins.toFile "pwfile" "hunter2"; # don't do this on real deployments
12 # make sure multiple freeform options evaluate
13 allow-new-accounts = true;
14 auto-approve-new-accounts = true;
20 C2FMZQ_PASSPHRASE = "lol";
21 C2FMZQ_API_SERVER = "http://localhost:8080";
25 (pkgs.writeScriptBin "c2FmZQ-client-wrapper" ''
26 #!${pkgs.expect}/bin/expect -f
27 spawn c2FmZQ-client {*}$argv
29 "Enter password:" { send "$env(PASSWORD)\r" }
30 "Type YES to confirm:" { send "YES\r" }
40 testScript = { nodes, ... }: ''
42 machine.wait_for_unit("c2fmzq-server.service")
43 machine.wait_for_open_port(8080)
45 with subtest("Create accounts for alice and bob"):
46 machine.succeed("PASSWORD=foobar c2FmZQ-client-wrapper -- -v 3 create-account alice@example.com")
47 machine.succeed("PASSWORD=fizzbuzz c2FmZQ-client-wrapper -- -v 3 create-account bob@example.com")
49 with subtest("Log in as alice"):
50 machine.succeed("PASSWORD=foobar c2FmZQ-client-wrapper -- -v 3 login alice@example.com")
51 msg = machine.succeed("c2FmZQ-client -v 3 status")
52 assert "Logged in as alice@example.com" in msg, f"ERROR: Not logged in as alice:\n{msg}"
54 with subtest("Create a new album, upload a file, and delete the uploaded file"):
55 machine.succeed("c2FmZQ-client -v 3 create-album 'Rarest Memes'")
56 machine.succeed("echo 'pls do not steal' > meme.txt")
57 machine.succeed("c2FmZQ-client -v 3 import meme.txt 'Rarest Memes'")
58 machine.succeed("c2FmZQ-client -v 3 sync")
59 machine.succeed("rm meme.txt")
61 with subtest("Share the album with bob"):
62 machine.succeed("c2FmZQ-client-wrapper -- -v 3 share 'Rarest Memes' bob@example.com")
64 with subtest("Log in as bob"):
65 machine.succeed("PASSWORD=fizzbuzz c2FmZQ-client-wrapper -- -v 3 login bob@example.com")
66 msg = machine.succeed("c2FmZQ-client -v 3 status")
67 assert "Logged in as bob@example.com" in msg, f"ERROR: Not logged in as bob:\n{msg}"
69 with subtest("Download the shared file"):
70 machine.succeed("c2FmZQ-client -v 3 download 'shared/Rarest Memes/meme.txt'")
71 machine.succeed("c2FmZQ-client -v 3 export 'shared/Rarest Memes/meme.txt' .")
72 msg = machine.succeed("cat meme.txt")
73 assert "pls do not steal\n" == msg, f"File content is not the same:\n{msg}"
75 with subtest("Test that PWA is served"):
76 msg = machine.succeed("curl -sSfL http://localhost:8080")
77 assert "c2FmZQ" in msg, f"Could not find 'c2FmZQ' in the output:\n{msg}"
79 with subtest("A setting with false value is properly passed"):
80 machine.succeed("systemctl show -p ExecStart --value c2fmzq-server.service | grep -F -- '--licenses=false'");