From ce831333a24011d0692f6871047fe74eab9fab8c Mon Sep 17 00:00:00 2001 From: "quentin@aristote.fr" Date: Sun, 29 Nov 2026 17:24:18 +0100 Subject: initial commit --- tests/configuration.nix | 75 ++++++++++++++++++++++++++++++++ tests/run-tests.sh | 112 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 tests/configuration.nix create mode 100755 tests/run-tests.sh (limited to 'tests') diff --git a/tests/configuration.nix b/tests/configuration.nix new file mode 100644 index 0000000..3d81f07 --- /dev/null +++ b/tests/configuration.nix @@ -0,0 +1,75 @@ +{ + config, + lib, + ... +}: +let + nginxPorts = lib.concatLists ( + lib.mapAttrsToList ( + _: cfg: (builtins.map (x: x.port) cfg.listen) + ) config.services.nginx.virtualHosts + ); + nginxMakeLocal = port: { + listen = lib.mkForce [ + { + inherit port; + addr = "0.0.0.0"; + } + ]; + forceSSL = lib.mkForce false; + enableACME = lib.mkForce false; + }; +in +{ + imports = [ ../config ]; + + boot = { + isContainer = true; + isNspawnContainer = true; + }; + + networking = lib.mkForce { + domain = "aristote.vm"; + + interfaces = { }; + defaultGateway = null; + nameservers = [ ]; + + firewall = { + allowedTCPPorts = nginxPorts; + }; + + dhcpcd.enable = false; + }; + + personal.system.autoUpgrade.enable = lib.mkForce false; + + services.tailscale.enable = lib.mkForce false; + + services.resolved.enable = lib.mkForce false; + + services.rss-bridge.debug = true; + + services.headscale.settings.server_url = lib.mkForce "http://10.233.1.2:8085/"; + + services.nginx.virtualHosts = { + quentin = nginxMakeLocal 8080; + rss = nginxMakeLocal 8082; + webkeydirectory = nginxMakeLocal 8083; + mesh = nginxMakeLocal 8084; + git = nginxMakeLocal 8086; + dav = nginxMakeLocal 8087; + }; + + environment.etc = { + "searx/secrets".text = '' + SECRET_KEY=secret_key + ''; + "msmtp/secrets".text = '' + password + ''; + "radicale/.htpasswd".text = '' + user:$apr1$e1OqTkNV$c.2giw6XR9Atjm32B/hkn. + ''; + }; +} diff --git a/tests/run-tests.sh b/tests/run-tests.sh new file mode 100755 index 0000000..ef833c7 --- /dev/null +++ b/tests/run-tests.sh @@ -0,0 +1,112 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p jq curl + +function cleanup { + echo + popd >/dev/null + echo Shutting down container ... + sudo nixos-container stop hermes +} + +pushd $(dirname $0) >/dev/null +echo Stopping container for update ... +sudo nixos-container stop hermes || exit 2 +echo Updating container ... +sudo nixos-container update hermes --flake .#hermes-test || exit 2 +echo Starting container ... +sudo nixos-container start hermes || exit 2 + +trap cleanup EXIT +sleep 0.1 +IP=$(nixos-container show-ip hermes) +CURL_FLAGS='--location --silent' + +echo +echo Checking that all the services are running: +declare -A PORTS +PORTS[quentin]=8080 +PORTS[rss]=8082 +PORTS[mesh]=8084 +PORTS[git]=8086 +declare -A SUFFIX +SUFFIX[quentin]="" +SUFFIX[rss]="" +SUFFIX[git]="?p=about" +SUFFIX[mesh]="health" + +for SERVICE in "${!PORTS[@]}" +do + URL="http://$IP:${PORTS[$SERVICE]}/${SUFFIX[$SERVICE]}" + echo Checking connection to container version of $SERVICE.aristote.fr ... + RESULT=$(curl "$URL" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n') + case "$RESULT" in + 200) echo "Up and running at $URL !";; + 301) echo "Redirected.";; + *) echo "Connection failed.";; + esac +done + + +echo +echo Checking web keys directory: +URL_PREFIX="http://$IP:8083/.well-known/openpgpkey/aristote.vm" +KEYS="$(ls ../config/services/web/webkeydirectory/hu)" +for KEY in $KEYS +do + echo Checking key $KEY ... + RESULT=$(curl "$URL_PREFIX/hu/$KEY" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n') + if [[ ! "$RESULT" = 200 ]] + then + echo "Connection failed." + fi +done +echo Checking policy file ... +RESULT=$(curl "$URL_PREFIX/policy" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n') +if [[ ! "$RESULT" = 200 ]] +then + echo "Connection failed." +fi +echo Done. + + +echo +echo Checking custom RSS bridges: +BRIDGES="$(ls ../config/services/web/rss/*Bridge.php | xargs basename -s Bridge.php)" +for BRIDGE in $BRIDGES +do + echo Checking bridge $BRIDGE ... + RESULT=$(curl "http://$IP:${PORTS[rss]}/?action=display&bridge=$BRIDGE&format=Plaintext" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n') + if [[ ! "$RESULT" = 200 ]] + then + echo "Connection failed." + fi +done +echo Done. + + +# echo +# echo Checking custom Searx engines: +# declare -A QUERIES +# QUERIES[alternativeto]=Searx +# QUERIES[nlab]='Kan%20extension' +# QUERIES[wfr]=Paris +# QUERIES[wen]=Paris +# for ENGINE in "${!QUERIES[@]}" +# do +# echo Checking engine $ENGINE ... +# REQUEST_URL="http://$IP:${PORTS[searx]}/search?q=${QUERIES[$ENGINE]}+!$ENGINE&format=json" +# JSON_RESULT=$(curl "$REQUEST_URL" $CURL_FLAGS) +# RESULTS=$(echo $JSON_RESULT | jq '.results') +# UNRESPONSIVE_ENGINES=$(echo $JSON_RESULT | jq '.unresponsive_engines') +# if [[ ! "$UNRESPONSIVE_ENGINES" = '[]' ]] +# then +# echo "Engine not responsive." +# elif [[ "$RESULTS" = [] ]] +# then +# echo "No results found." +# fi +# done +# echo Done. + +echo +read -n1 -srp "Press any key to stop the server." -- cgit v1.3.1