1import ./make-test-python.nix (
2 { pkgs, lib, ... }:
3 {
4 name = "c2FmZQ";
5 meta.maintainers = with lib.maintainers; [ hmenke ];
6
7 nodes.machine = {
8 services.c2fmzq-server = {
9 enable = true;
10 port = 8080;
11 passphraseFile = builtins.toFile "pwfile" "hunter2"; # don't do this on real deployments
12 settings = {
13 verbose = 3; # debug
14 # make sure multiple freeform options evaluate
15 allow-new-accounts = true;
16 auto-approve-new-accounts = true;
17 licenses = false;
18 };
19 };
20 environment = {
21 sessionVariables = {
22 C2FMZQ_PASSPHRASE = "lol";
23 C2FMZQ_API_SERVER = "http://localhost:8080";
24 };
25 systemPackages = [
26 pkgs.c2fmzq
27 (pkgs.writeScriptBin "c2FmZQ-client-wrapper" ''
28 #!${pkgs.expect}/bin/expect -f
29 spawn c2FmZQ-client {*}$argv
30 expect {
31 "Enter password:" { send "$env(PASSWORD)\r" }
32 "Type YES to confirm:" { send "YES\r" }
33 timeout { exit 1 }
34 eof { exit 0 }
35 }
36 interact
37 '')
38 ];
39 };
40 };
41
42 testScript =
43 { nodes, ... }:
44 ''
45 machine.start()
46 machine.wait_for_unit("c2fmzq-server.service")
47 machine.wait_for_open_port(8080)
48
49 with subtest("Create accounts for alice and bob"):
50 machine.succeed("PASSWORD=foobar c2FmZQ-client-wrapper -- -v 3 create-account alice@example.com")
51 machine.succeed("PASSWORD=fizzbuzz c2FmZQ-client-wrapper -- -v 3 create-account bob@example.com")
52
53 with subtest("Log in as alice"):
54 machine.succeed("PASSWORD=foobar c2FmZQ-client-wrapper -- -v 3 login alice@example.com")
55 msg = machine.succeed("c2FmZQ-client -v 3 status")
56 assert "Logged in as alice@example.com" in msg, f"ERROR: Not logged in as alice:\n{msg}"
57
58 with subtest("Create a new album, upload a file, and delete the uploaded file"):
59 machine.succeed("c2FmZQ-client -v 3 create-album 'Rarest Memes'")
60 machine.succeed("echo 'pls do not steal' > meme.txt")
61 machine.succeed("c2FmZQ-client -v 3 import meme.txt 'Rarest Memes'")
62 machine.succeed("c2FmZQ-client -v 3 sync")
63 machine.succeed("rm meme.txt")
64
65 with subtest("Share the album with bob"):
66 machine.succeed("c2FmZQ-client-wrapper -- -v 3 share 'Rarest Memes' bob@example.com")
67
68 with subtest("Log in as bob"):
69 machine.succeed("PASSWORD=fizzbuzz c2FmZQ-client-wrapper -- -v 3 login bob@example.com")
70 msg = machine.succeed("c2FmZQ-client -v 3 status")
71 assert "Logged in as bob@example.com" in msg, f"ERROR: Not logged in as bob:\n{msg}"
72
73 with subtest("Download the shared file"):
74 machine.succeed("c2FmZQ-client -v 3 download 'shared/Rarest Memes/meme.txt'")
75 machine.succeed("c2FmZQ-client -v 3 export 'shared/Rarest Memes/meme.txt' .")
76 msg = machine.succeed("cat meme.txt")
77 assert "pls do not steal\n" == msg, f"File content is not the same:\n{msg}"
78
79 with subtest("Test that PWA is served"):
80 msg = machine.succeed("curl -sSfL http://localhost:8080")
81 assert "c2FmZQ" in msg, f"Could not find 'c2FmZQ' in the output:\n{msg}"
82
83 with subtest("A setting with false value is properly passed"):
84 machine.succeed("systemctl show -p ExecStart --value c2fmzq-server.service | grep -F -- '--licenses=false'");
85 '';
86 }
87)