at 23.05-pre 1.6 kB view raw
1import ./make-test-python.nix ({ pkgs, lib, ... }: { 2 name = "plausible"; 3 meta = with lib.maintainers; { 4 maintainers = [ ma27 ]; 5 }; 6 7 nodes.machine = { pkgs, ... }: { 8 virtualisation.memorySize = 4096; 9 services.plausible = { 10 enable = true; 11 releaseCookiePath = "${pkgs.runCommand "cookie" { } '' 12 ${pkgs.openssl}/bin/openssl rand -base64 64 >"$out" 13 ''}"; 14 adminUser = { 15 email = "admin@example.org"; 16 passwordFile = "${pkgs.writeText "pwd" "foobar"}"; 17 activate = true; 18 }; 19 server = { 20 baseUrl = "http://localhost:8000"; 21 secretKeybaseFile = "${pkgs.writeText "dont-try-this-at-home" "nannannannannannannannannannannannannannannannannannannan_batman!"}"; 22 }; 23 }; 24 }; 25 26 testScript = '' 27 start_all() 28 machine.wait_for_unit("plausible.service") 29 machine.wait_for_open_port(8000) 30 31 machine.succeed("curl -f localhost:8000 >&2") 32 33 csrf_token = machine.succeed( 34 "curl -c /tmp/cookies localhost:8000/login | grep '_csrf_token' | sed -E 's,.*value=\"(.*)\".*,\\1,g'" 35 ) 36 37 machine.succeed( 38 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" 39 ) 40 41 # By ensuring that the user is redirected to the dashboard after login, we 42 # also make sure that the automatic verification of the module works. 43 machine.succeed( 44 "[[ $(grep 'location: ' headers | cut -d: -f2- | xargs echo) == /sites* ]]" 45 ) 46 47 machine.shutdown() 48 ''; 49})