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