1import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "plausible";
3 meta = with lib.maintainers; {
4 maintainers = [ ma27 ];
5 };
6
7 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 machine.succeed("curl -f localhost:8000 >&2")
29
30 csrf_token = machine.succeed(
31 "curl -c /tmp/cookies localhost:8000/login | grep '_csrf_token' | sed -E 's,.*value=\"(.*)\".*,\\1,g'"
32 )
33
34 machine.succeed(
35 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"
36 )
37
38 # By ensuring that the user is redirected to the dashboard after login, we
39 # also make sure that the automatic verification of the module works.
40 machine.succeed(
41 "[[ $(grep 'location: ' headers | cut -d: -f2- | xargs echo) == /sites* ]]"
42 )
43
44 machine.shutdown()
45 '';
46})