1 import ./make-test-python.nix (
5 meta.maintainers = with lib.maintainers; [ defelo ];
11 CORE_HOST = "127.0.0.1";
15 (builtins.toFile "zipline.env" ''
16 CORE_SECRET=testsecret
21 networking.hosts."127.0.0.1" = [ "zipline.local" ];
28 machine.wait_for_unit("zipline.service")
29 machine.wait_for_open_port(8000)
31 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")
32 assert json.loads(resp.splitlines()[-1]) == {"success": True}
34 assert (cookie := re.search(r"(?m)^< Set-Cookie: ([^;]*)", resp))
35 resp = machine.succeed(f"curl zipline.local:8000/api/user/token -H 'Cookie: {cookie[1]}' -X PATCH")
36 token = json.loads(resp)["success"]
38 resp = machine.succeed(f"curl zipline.local:8000/api/shorten -H 'Authorization: {token}' -X POST -H 'Content-Type: application/json' -d '{{\"url\": \"https://nixos.org/\", \"vanity\": \"nixos\"}}'")
39 url = json.loads(resp)["url"]
40 assert url == "http://zipline.local:8000/go/nixos"
42 resp = machine.succeed(f"curl -I {url}")
43 assert re.search(r"(?m)^HTTP/1.1 302 Found\r?$", resp)
44 assert (location := re.search(r"(?mi)^location: (.+?)\r?$", resp))
45 assert location[1] == "https://nixos.org/"