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
16 C2FMZQ_PASSPHRASE = "lol";
17 C2FMZQ_API_SERVER = "http://localhost:8080";
21 (pkgs.writeScriptBin "c2FmZQ-client-wrapper" ''
22 #!${pkgs.expect}/bin/expect -f
23 spawn c2FmZQ-client {*}$argv
25 "Enter password:" { send "$env(PASSWORD)\r" }
26 "Type YES to confirm:" { send "YES\r" }
36 testScript = { nodes, ... }: ''
38 machine.wait_for_unit("c2fmzq-server.service")
39 machine.wait_for_open_port(8080)
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")
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}"
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")
57 with subtest("Share the album with bob"):
58 machine.succeed("c2FmZQ-client-wrapper -- -v 3 share 'Rarest Memes' bob@example.com")
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}"
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}"
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}"