Skip to content

Commit

Permalink
Add CI test for proper Lua backtrace generation
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Sep 23, 2024
1 parent ddbce63 commit 31d0684
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

}
4 changes: 4 additions & 0 deletions test/broken_lua.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?
mg.write("Hello, world!\n")
mg.include("does_not_exist.lp", "r")
?>
5 changes: 4 additions & 1 deletion test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
20 changes: 17 additions & 3 deletions test/test_suite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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[@]}"
Expand Down

0 comments on commit 31d0684

Please sign in to comment.