diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index be546f2acc3aa6..e8c18d977c8f21 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1194,6 +1194,7 @@ in { zeronet-conservancy = handleTest ./zeronet-conservancy.nix {}; zfs = handleTest ./zfs.nix {}; zigbee2mqtt = handleTest ./zigbee2mqtt.nix {}; + zipline = handleTest ./zipline.nix {}; zoneminder = handleTest ./zoneminder.nix {}; zookeeper = handleTest ./zookeeper.nix {}; zram-generator = handleTest ./zram-generator.nix {}; diff --git a/nixos/tests/zipline.nix b/nixos/tests/zipline.nix new file mode 100644 index 00000000000000..a9c1252bd29b28 --- /dev/null +++ b/nixos/tests/zipline.nix @@ -0,0 +1,48 @@ +import ./make-test-python.nix ( + { lib, ... }: + { + name = "zipline"; + meta.maintainers = with lib.maintainers; [ defelo ]; + + nodes.machine = { + services.zipline = { + enable = true; + settings = { + CORE_HOST = "127.0.0.1"; + CORE_PORT = 8000; + }; + environmentFiles = [ + (builtins.toFile "zipline.env" '' + CORE_SECRET=testsecret + '') + ]; + }; + + networking.hosts."127.0.0.1" = [ "zipline.local" ]; + }; + + testScript = '' + import json + import re + + machine.wait_for_unit("zipline.service") + machine.wait_for_open_port(8000) + + 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") + assert json.loads(resp.splitlines()[-1]) == {"success": True} + + assert (cookie := re.search(r"(?m)^< Set-Cookie: ([^;]*)", resp)) + resp = machine.succeed(f"curl zipline.local:8000/api/user/token -H 'Cookie: {cookie[1]}' -X PATCH") + token = json.loads(resp)["success"] + + 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\"}}'") + url = json.loads(resp)["url"] + assert url == "http://zipline.local:8000/go/nixos" + + resp = machine.succeed(f"curl -I {url}") + assert re.search(r"(?m)^HTTP/1.1 302 Found\r?$", resp) + assert (location := re.search(r"(?mi)^location: (.+?)\r?$", resp)) + assert location[1] == "https://nixos.org/" + ''; + } +) diff --git a/pkgs/by-name/zi/zipline/package.nix b/pkgs/by-name/zi/zipline/package.nix index 43d87c0007c480..153479f1cd76d6 100644 --- a/pkgs/by-name/zi/zipline/package.nix +++ b/pkgs/by-name/zi/zipline/package.nix @@ -12,6 +12,7 @@ ffmpeg, python3, vips, + nixosTests, }: stdenv.mkDerivation (finalAttrs: { @@ -128,6 +129,10 @@ stdenv.mkDerivation (finalAttrs: { done ''; + passthru = { + tests = { inherit (nixosTests) zipline; }; + }; + meta = { description = "ShareX/file upload server that is easy to use, packed with features, and with an easy setup"; changelog = "https://github.com/diced/zipline/releases/tag/v${finalAttrs.version}";