From 3e98a07ca68ec4c0c1a45ccad986e7e738ec998d Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Sat, 17 Feb 2024 21:51:55 +0100 Subject: [PATCH] nixos/tests/filebrowser: init test module Signed-off-by: Christoph Heiss --- nixos/tests/all-tests.nix | 1 + nixos/tests/filebrowser.nix | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 nixos/tests/filebrowser.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 232f10d7c24dde0..457620f63822475 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -307,6 +307,7 @@ in { fenics = handleTest ./fenics.nix {}; ferm = handleTest ./ferm.nix {}; ferretdb = handleTest ./ferretdb.nix {}; + filebrowser = handleTest ./filebrowser.nix { }; filesystems-overlayfs = runTest ./filesystems-overlayfs.nix; firefly-iii = handleTest ./firefly-iii.nix {}; firefox = handleTest ./firefox.nix { firefoxPackage = pkgs.firefox; }; diff --git a/nixos/tests/filebrowser.nix b/nixos/tests/filebrowser.nix new file mode 100644 index 000000000000000..67cc8b3731fbb09 --- /dev/null +++ b/nixos/tests/filebrowser.nix @@ -0,0 +1,46 @@ +import ./make-test-python.nix ({ pkgs, lib, ... }: + let + tls-cert = pkgs.runCommand "selfSignedCerts" { + buildInputs = [ pkgs.openssl ]; + } '' + mkdir -p $out + openssl req -x509 \ + -subj '/CN=localhost/' -days 365 \ + -addext 'subjectAltName = DNS:localhost' \ + -keyout "$out/cert.key" -newkey ed25519 \ + -out "$out/cert.pem" -noenc + ''; + in { + name = "filebrowser"; + meta.maintainers = with lib.maintainers; [ christoph-heiss ]; + + nodes = { + http = { + services.filebrowser = { + enable = true; + }; + }; + https = { + security.pki.certificateFiles = [ "${tls-cert}/cert.pem" ]; + services.filebrowser = { + enable = true; + tlsCertificate = "${tls-cert}/cert.pem"; + tlsCertificateKey = "${tls-cert}/cert.key"; + }; + }; + }; + + testScript = '' + start_all() + + with subtest("check if http works"): + http.wait_for_unit("filebrowser.service") + http.wait_for_open_port(8080) + http.succeed("curl -sSf http://localhost:8080 | grep ''") + + with subtest("check if https works"): + https.wait_for_unit("filebrowser.service") + https.wait_for_open_port(8080) + https.succeed("curl -sSf https://localhost:8080 | grep ''") + ''; + })