From 31d06849124e60d847e277b1571f3acc9721ec5d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 23 Sep 2024 22:37:01 +0200 Subject: [PATCH] Add CI test for proper Lua backtrace generation Signed-off-by: DL6ER --- .devcontainer/devcontainer.json | 2 +- test/broken_lua.lp | 4 ++++ test/run.sh | 5 ++++- test/test_suite.bats | 20 +++++++++++++++++--- 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 test/broken_lua.lp diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 646a1a08b..dbb9de7a6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -16,7 +16,7 @@ }, "mounts": [ "type=bind,source=/home/${localEnv:USER}/.ssh,target=/root/.ssh,readonly", - "type=bind,source=/var/www/html,target=/var/www/html,readonly" + "type=bind,source=/var/www/html/admin,target=/var/www/html/admin,readonly" ] } diff --git a/test/broken_lua.lp b/test/broken_lua.lp new file mode 100644 index 000000000..32f57affa --- /dev/null +++ b/test/broken_lua.lp @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/test/run.sh b/test/run.sh index 5d490a822..3a2ee4cf4 100755 --- a/test/run.sh +++ b/test/run.sh @@ -23,7 +23,7 @@ done rm -rf /etc/pihole /var/log/pihole /dev/shm/FTL-* # Create necessary directories and files -mkdir -p /home/pihole /etc/pihole /run/pihole /var/log/pihole /etc/pihole/config_backups +mkdir -p /home/pihole /etc/pihole /run/pihole /var/log/pihole /etc/pihole/config_backups /var/www/html echo "" > /var/log/pihole/FTL.log echo "" > /var/log/pihole/pihole.log echo "" > /var/log/pihole/webserver.log @@ -62,6 +62,9 @@ cp test/01-pihole-tests.conf /etc/dnsmasq.d/01-pihole-tests.conf # Prepare versions file (read by /api/version) cp test/versions /etc/pihole/versions +# Prepare Lua test script +cp test/broken_lua.lp /var/www/html/broken_lua.lp + # Prepare local powerDNS resolver bash test/pdns/setup.sh diff --git a/test/test_suite.bats b/test/test_suite.bats index 2860776f2..59b98902e 100644 --- a/test/test_suite.bats +++ b/test/test_suite.bats @@ -1235,10 +1235,10 @@ [[ ${lines[0]} == '{"error":{"key":"not_found","message":"Not found","hint":"/api/undefined"},"took":'*'}' ]] } -@test "HTTP server responds with normal error 404 to path outside /admin" { - run bash -c 'curl -s 127.0.0.1/undefined' +@test "HTTP server responds with error 404 to path outside /admin" { + run bash -c 'curl -sI 127.0.0.1/undefined' printf "%s\n" "${lines[@]}" - [[ ${lines[0]} == "Error 404: Not Found" ]] + [[ ${lines[@]} == *"HTTP/1.1 404 Not Found"* ]] } @test "LUA: Interpreter returns FTL version" { @@ -1684,6 +1684,20 @@ [[ ${lines[0]} == "0" ]] } +# This test should run before a password it set +@test "Lua server page is generating proper backtrace" { + # Run a page with a syntax error + run bash -c 'curl -s 127.0.0.1/broken_lua' + printf "%s\n" "${lines[@]}" + [[ ${lines[0]} == 'Hello, world!' ]] + [[ ${lines[1]} == '[string "/var/www/html/broken_lua.lp"]:4: Cannot include [/var/www/html/does_not_exist.lp]: not found' ]] + [[ ${lines[2]} == '' ]] + + # Check if the error is logged (-F = fixed string (no regex), -q = quiet) + run grep -qF 'LSP Kepler: call failed: runtime error: [string "/var/www/html/broken_lua.lp"]:4: Cannot include [/var/www/html/does_not_exist.lp]: not found' /var/log/pihole/webserver.log + [[ $status == 0 ]] +} + @test "API authorization (without password): No login required" { run bash -c 'curl -s 127.0.0.1/api/auth' printf "%s\n" "${lines[@]}"