1import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "plausible";
3 meta = with lib.maintainers; {
4 maintainers = [ ];
5 };
6
7 nodes.machine = { pkgs, ... }: {
8 virtualisation.memorySize = 4096;
9 services.plausible = {
10 enable = true;
11 adminUser = {
12 email = "admin@example.org";
13 passwordFile = "${pkgs.writeText "pwd" "foobar"}";
14 activate = true;
15 };
16 server = {
17 baseUrl = "http://localhost:8000";
18 secretKeybaseFile = "${pkgs.writeText "dont-try-this-at-home" "nannannannannannannannannannannannannannannannannannannan_batman!"}";
19 };
20 };
21 };
22
23 testScript = ''
24 start_all()
25 machine.wait_for_unit("plausible.service")
26 machine.wait_for_open_port(8000)
27
28 # Ensure that the software does not make not make the machine
29 # listen on any public interfaces by default.
30 machine.fail("ss -tlpn 'src = 0.0.0.0 or src = [::]' | grep LISTEN")
31
32 machine.succeed("curl -f localhost:8000 >&2")
33
34 machine.succeed("curl -f localhost:8000/js/script.js >&2")
35
36 csrf_token = machine.succeed(
37 "curl -c /tmp/cookies localhost:8000/login | grep '_csrf_token' | sed -E 's,.*value=\"(.*)\".*,\\1,g'"
38 )
39
40 machine.succeed(
41 f"curl -b /tmp/cookies -f -X POST localhost:8000/login -F email=admin@example.org -F password=foobar -F _csrf_token={csrf_token.strip()} -D headers"
42 )
43
44 # By ensuring that the user is redirected to the dashboard after login, we
45 # also make sure that the automatic verification of the module works.
46 machine.succeed(
47 "[[ $(grep 'location: ' headers | cut -d: -f2- | xargs echo) == /sites* ]]"
48 )
49
50 machine.shutdown()
51 '';
52})