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 };
13 };
14 environment = {
15 sessionVariables = {
16 C2FMZQ_PASSPHRASE = "lol";
17 C2FMZQ_API_SERVER = "http://localhost:8080";
18 };
19 systemPackages = [
20 pkgs.c2fmzq
21 (pkgs.writeScriptBin "c2FmZQ-client-wrapper" ''
22 #!${pkgs.expect}/bin/expect -f
23 spawn c2FmZQ-client {*}$argv
24 expect {
25 "Enter password:" { send "$env(PASSWORD)\r" }
26 "Type YES to confirm:" { send "YES\r" }
27 timeout { exit 1 }
28 eof { exit 0 }
29 }
30 interact
31 '')
32 ];
33 };
34 };
35
36 testScript = { nodes, ... }: ''
37 machine.start()
38 machine.wait_for_unit("c2fmzq-server.service")
39 machine.wait_for_open_port(8080)
40
41 with subtest("Create accounts for alice and bob"):
42 machine.succeed("PASSWORD=foobar c2FmZQ-client-wrapper -- -v 3 create-account alice@example.com")
43 machine.succeed("PASSWORD=fizzbuzz c2FmZQ-client-wrapper -- -v 3 create-account bob@example.com")
44
45 with subtest("Log in as alice"):
46 machine.succeed("PASSWORD=foobar c2FmZQ-client-wrapper -- -v 3 login alice@example.com")
47 msg = machine.succeed("c2FmZQ-client -v 3 status")
48 assert "Logged in as alice@example.com" in msg, f"ERROR: Not logged in as alice:\n{msg}"
49
50 with subtest("Create a new album, upload a file, and delete the uploaded file"):
51 machine.succeed("c2FmZQ-client -v 3 create-album 'Rarest Memes'")
52 machine.succeed("echo 'pls do not steal' > meme.txt")
53 machine.succeed("c2FmZQ-client -v 3 import meme.txt 'Rarest Memes'")
54 machine.succeed("c2FmZQ-client -v 3 sync")
55 machine.succeed("rm meme.txt")
56
57 with subtest("Share the album with bob"):
58 machine.succeed("c2FmZQ-client-wrapper -- -v 3 share 'Rarest Memes' bob@example.com")
59
60 with subtest("Log in as bob"):
61 machine.succeed("PASSWORD=fizzbuzz c2FmZQ-client-wrapper -- -v 3 login bob@example.com")
62 msg = machine.succeed("c2FmZQ-client -v 3 status")
63 assert "Logged in as bob@example.com" in msg, f"ERROR: Not logged in as bob:\n{msg}"
64
65 with subtest("Download the shared file"):
66 machine.succeed("c2FmZQ-client -v 3 download 'shared/Rarest Memes/meme.txt'")
67 machine.succeed("c2FmZQ-client -v 3 export 'shared/Rarest Memes/meme.txt' .")
68 msg = machine.succeed("cat meme.txt")
69 assert "pls do not steal\n" == msg, f"File content is not the same:\n{msg}"
70
71 with subtest("Test that PWA is served"):
72 msg = machine.succeed("curl -sSfL http://localhost:8080")
73 assert "c2FmZQ" in msg, f"Could not find 'c2FmZQ' in the output:\n{msg}"
74 '';
75})