about summary refs log tree commit diff
path: root/pkgs/servers
diff options
context:
space:
mode:
authorRaphael Robatsch <raphael-git@tapesoftware.net>2024-01-16 12:47:21 +0100
committerRaphael Robatsch <raphael-git@tapesoftware.net>2024-06-12 19:51:16 +0200
commitc2928b54bcc2806be15c0700b44c8e915258ba24 (patch)
tree9cd6c7642ad6e455f29f2dee0cb062c431f442bb /pkgs/servers
parentd7cfd8c02928954141567bbb8849379df1bb2af7 (diff)
hiawatha: Add package test
Tests whether curl can communicate with hiawatha via http and https.
Diffstat (limited to 'pkgs/servers')
-rw-r--r--pkgs/servers/http/hiawatha/default.nix13
-rw-r--r--pkgs/servers/http/hiawatha/test.nix84
2 files changed, 94 insertions, 3 deletions
diff --git a/pkgs/servers/http/hiawatha/default.nix b/pkgs/servers/http/hiawatha/default.nix
index 09ef5bab41463..26fdb96080426 100644
--- a/pkgs/servers/http/hiawatha/default.nix
+++ b/pkgs/servers/http/hiawatha/default.nix
@@ -1,5 +1,6 @@
 { lib, stdenv
 , fetchFromGitLab
+, callPackage
 
 , cmake
 , ninja
@@ -16,14 +17,14 @@
 , enableToolkit   ? true     # The URL Toolkit.
 }:
 
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
   pname = "hiawatha";
   version = "10.11";
 
   src = fetchFromGitLab {
     owner = "hsleisink";
     repo = "hiawatha";
-    rev = "v${version}";
+    rev = "v${finalAttrs.version}";
     sha256 = "10a7dqj37zrbmgnhwsw0mqm5x25kasl8p95g01rzakviwxkdrkid";
   };
 
@@ -46,12 +47,18 @@ stdenv.mkDerivation rec {
     ( if enableToolkit   then "-DENABLE_TOOLKIT=on"     else "-DENABLE_TOOLKIT=off"     )
   ];
 
+  passthru.tests.serve-static-files = callPackage ./test.nix {
+    hiawatha = finalAttrs.finalPackage;
+    inherit enableTls;
+  };
+
   meta = with lib; {
     homepage = "https://www.hiawatha-webserver.org";
     description = "Advanced and secure webserver";
     license = licenses.gpl2Only;
     platforms = platforms.unix;    # "Hiawatha runs perfectly on Linux, BSD and MacOS X"
+    mainProgram = "hiawatha";
     maintainers = [];
   };
 
-}
+})
diff --git a/pkgs/servers/http/hiawatha/test.nix b/pkgs/servers/http/hiawatha/test.nix
new file mode 100644
index 0000000000000..157d0ee79644d
--- /dev/null
+++ b/pkgs/servers/http/hiawatha/test.nix
@@ -0,0 +1,84 @@
+{ lib
+, stdenvNoCC
+, hiawatha
+, curl
+, mbedtls
+, enableTls
+}:
+
+stdenvNoCC.mkDerivation {
+  name = "hiawatha-test";
+
+  nativeBuildInputs = [
+    hiawatha
+    curl
+  ] ++ lib.optional enableTls mbedtls;
+
+  env = {
+    inherit enableTls;
+  };
+
+  buildCommand = ''
+    cp -r --no-preserve=mode ${hiawatha}/etc/hiawatha config
+    sed "1i set TEST_DIR = $(pwd)" $serverConfigPath > config/hiawatha.conf
+
+    mkdir www
+    echo "it works" > www/index.html
+
+    if [ -n "$enableTls" ]; then
+      echo "Generating self-signed certificate"
+      gen_key type=ec filename=server.key
+      cert_write selfsign=1 issuer_key=server.key output_file=server.crt
+      cat server.crt server.key > config/server.crt
+    fi
+
+    echo "Checking server configuration"
+    hiawatha -c ./config -k
+
+    echo "Starting server"
+    hiawatha -c ./config
+
+    testUrl() {
+      echo "Testing $1"
+      curl --verbose --insecure --fail "$1" | tee response
+      grep -q "it works" response
+    }
+
+    testUrl http://127.0.0.1:8000
+    if [ -n "$enableTls" ]; then
+      testUrl https://127.0.0.1:8443
+    fi
+
+    touch $out
+  '';
+
+  serverConfig = ''
+    # By default the server uses read-only directories like /var/lib and /etc
+    WorkDirectory = TEST_DIR
+    PIDfile = TEST_DIR/hiawatha.pid
+    SystemLogfile = TEST_DIR/system.log
+    GarbageLogfile = TEST_DIR/garbage.log
+    ExploitLogfile = TEST_DIR/exploit.log
+    AccessLogfile = TEST_DIR/access.log
+    ErrorLogfile = TEST_DIR/error.log
+
+    Binding {
+      Interface = 127.0.0.1
+      Port = 8000
+    }
+
+    ${lib.optionalString enableTls ''
+      Binding {
+        Interface = 127.0.0.1
+        Port = 8443
+        TLScertFile = TEST_DIR/config/server.crt
+      }
+    ''}
+
+    Hostname = 127.0.0.1
+    WebsiteRoot = TEST_DIR/www
+    StartFile = index.html
+  '';
+
+  passAsFile = [ "serverConfig" ];
+}