at master 1.9 kB view raw
1{ lib, pkgs, ... }: 2 3{ 4 name = "zipline"; 5 meta.maintainers = with lib.maintainers; [ defelo ]; 6 7 nodes.machine = { 8 # On x86, testing with a CPU without SSE 4.2 support 9 # to ensure native libvips is used 10 virtualisation.qemu.options = lib.mkIf pkgs.stdenv.hostPlatform.isx86 [ "-cpu core2duo" ]; 11 services.zipline = { 12 enable = true; 13 settings = { 14 CORE_HOSTNAME = "127.0.0.1"; 15 CORE_PORT = 8000; 16 }; 17 environmentFiles = [ 18 (builtins.toFile "zipline.env" '' 19 CORE_SECRET=DMlouex3W0QLRbVwkUafNnNws5jpgRDX 20 '') 21 ]; 22 }; 23 24 networking.hosts."127.0.0.1" = [ "zipline.local" ]; 25 }; 26 27 interactive.nodes.machine = { 28 services.zipline.settings.CORE_HOSTNAME = lib.mkForce "0.0.0.0"; 29 networking.firewall.allowedTCPPorts = [ 8000 ]; 30 virtualisation.forwardPorts = [ 31 { 32 from = "host"; 33 host.port = 8000; 34 guest.port = 8000; 35 } 36 ]; 37 }; 38 39 testScript = '' 40 import json 41 import re 42 43 machine.wait_for_unit("zipline.service") 44 machine.wait_for_open_port(8000, timeout=300) 45 46 resp = machine.succeed("curl zipline.local:8000/api/setup -v -X POST -H 'Content-Type: application/json' -d '{\"username\": \"administrator\", \"password\": \"password\"}' 2>&1") 47 data = json.loads(resp.splitlines()[-1]) 48 assert data["firstSetup"] is True 49 assert data["user"]["username"] == "administrator" 50 assert data["user"]["role"] == "SUPERADMIN" 51 52 resp = machine.succeed("curl zipline.local:8000/api/auth/login -v -X POST -H 'Content-Type: application/json' -d '{\"username\": \"administrator\", \"password\": \"password\"}' 2>&1") 53 54 assert (cookie := re.search(r"(?m)^< set-cookie: ([^;]*)", resp)) 55 resp = machine.succeed(f"curl zipline.local:8000/api/user -H 'Cookie: {cookie[1]}'") 56 assert json.loads(resp)["user"]["id"] == data["user"]["id"] 57 ''; 58}