1import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "c2FmZQ";
3 meta.maintainers = with lib.maintainers; [ hmenke ];
4
5 nodes.machine = {
6 services.c2fmzq-server = {
7 enable = true;
8 port = 8080;
9 passphraseFile = builtins.toFile "pwfile" "hunter2"; # don't do this on real deployments
10 settings = {
11 verbose = 3; # debug
12 # make sure multiple freeform options evaluate
13 allow-new-accounts = true;
14 auto-approve-new-accounts = true;
15 licenses = false;
16 };
17 };
18 environment = {
19 sessionVariables = {
20 C2FMZQ_PASSPHRASE = "lol";
21 C2FMZQ_API_SERVER = "http://localhost:8080";
22 };
23 systemPackages = [
24 pkgs.c2fmzq
25 (pkgs.writeScriptBin "c2FmZQ-client-wrapper" ''
26 #!${pkgs.expect}/bin/expect -f
27 spawn c2FmZQ-client {*}$argv
28 expect {
29 "Enter password:" { send "$env(PASSWORD)\r" }
30 "Type YES to confirm:" { send "YES\r" }
31 timeout { exit 1 }
32 eof { exit 0 }
33 }
34 interact
35 '')
36 ];
37 };
38 };
39
40 testScript = { nodes, ... }: ''
41 machine.start()
42 machine.wait_for_unit("c2fmzq-server.service")
43 machine.wait_for_open_port(8080)
44
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")
48
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}"
53
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")
60
61 with subtest("Share the album with bob"):
62 machine.succeed("c2FmZQ-client-wrapper -- -v 3 share 'Rarest Memes' bob@example.com")
63
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}"
68
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}"
74
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}"
78
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'");
81 '';
82})