From 5ae9c6959e5439e19a960ccd3fd361fa322397ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20van=20Br=C3=BCgge?= Date: Tue, 8 Oct 2024 22:26:49 +0100 Subject: [PATCH] nixos/tests/linkwarden: init tests --- nixos/tests/all-tests.nix | 1 + nixos/tests/web-apps/linkwarden.nix | 60 ++++++++++++++++++++++++++ pkgs/by-name/li/linkwarden/package.nix | 5 +++ 3 files changed, 66 insertions(+) create mode 100644 nixos/tests/web-apps/linkwarden.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index c0d43a9bea5a..12a6ae94221a 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -831,6 +831,7 @@ in lighttpd = runTest ./lighttpd.nix; limesurvey = runTest ./limesurvey.nix; limine = import ./limine { inherit runTest; }; + linkwarden = runTest ./web-apps/linkwarden.nix; listmonk = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./listmonk.nix { }; litellm = runTest ./litellm.nix; litestream = runTest ./litestream.nix; diff --git a/nixos/tests/web-apps/linkwarden.nix b/nixos/tests/web-apps/linkwarden.nix new file mode 100644 index 000000000000..153c7e437599 --- /dev/null +++ b/nixos/tests/web-apps/linkwarden.nix @@ -0,0 +1,60 @@ +{ ... }: +{ + name = "linkwarden-nixos"; + + nodes.machine = + { pkgs, ... }: + let + secretsFile = pkgs.writeText "linkwarden-secret-env" '' + VERY_SENSITIVE_SECRET + ''; + webroot = pkgs.runCommand "webroot" { } '' + mkdir $out + cd $out + echo '

HELLO LINKWARDEN

' > index.html + ''; + in + { + services.linkwarden = { + enable = true; + enableRegistration = true; + secretFiles = { + NEXTAUTH_SECRET = toString secretsFile; + }; + environment = { + NEXTAUTH_URL = "http://localhost:3000/api/v1/auth"; + }; + }; + + services.nginx = { + enable = true; + virtualHosts.localhost.root = webroot; + }; + }; + + testScript = '' + import json + + machine.wait_for_unit("linkwarden.service") + machine.wait_for_unit("linkwarden-worker.service") + + machine.wait_for_open_port(3000) + machine.succeed("curl --fail -s http://localhost:3000/") + + machine.succeed("curl -L --fail -s --data '{\"name\":\"Admin\",\"username\":\"admin\",\"password\":\"adminadmin\"}' -H 'Content-Type: application/json' -X POST http://localhost:3000/api/v1/users") + + response = machine.succeed("curl -L --fail -s -c next_cookies.txt -H 'Content-Type: application/json' -X GET http://localhost:3000/api/v1/auth/csrf") + csrfToken = json.loads(response)['csrfToken'] + + machine.succeed("curl -L --fail -s -b next_cookies.txt -c next_cookies.txt -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'username=admin' --data-urlencode 'password=adminadmin' --data-urlencode 'csrfToken=%s' http://localhost:3000/api/v1/auth/callback/credentials" % csrfToken) + + curlCmd = "curl -L --fail -s -b next_cookies.txt -H 'Content-Type: application/json' " + + machine.succeed(curlCmd + "--data '{\"url\":\"http://localhost/\"}' -X POST http://localhost:3000/api/v1/links") + + machine.succeed(curlCmd + "-X GET http://localhost:3000/api/v1/links") + + machine.wait_for_file("/var/lib/linkwarden/archives/1/1.html") + machine.succeed("grep -q '

HELLO LINKWARDEN

'