Diff options
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/t0201-filters.sh | 74 |
1 file changed, 71 insertions, 3 deletions
diff --git a/tests/t0201-filters.sh b/tests/t0201-filters.sh index 2c68921..021dfb2 100755 --- a/tests/t0201-filters.sh +++ b/tests/t0201-filters.sh @@ -126,7 +126,14 @@ test_expect_success 'a filter command with an unknown prefix ends the request' ' # A die inside a lua filter has to reach the visitor as an error page rather # than being fed back into the filter that just failed, and the reason goes to -# the log. +# the log with the script it came from. Each script runs as the auth filter, +# so it fails before any of the page is out. +check_lua_error() { + test $(grep -c "^Status:" tmp) = 1 && + test_grep "^Status: 500" tmp && + test_grep -F "Lua error in $1: " err +} + test_expect_success CGIT_LUA 'a failing lua filter still renders an error page' ' cat >broken.lua <<-\EOF && function filter_open(...) error("boom") end @@ -135,8 +142,7 @@ test_expect_success CGIT_LUA 'a failing lua filter still renders an error page' EOF cgitrc_repo brokenrc foo "auth-filter=lua:$PWD/broken.lua" && cgit_rc brokenrc "url=foo/commit" >tmp 2>err && - grep "Status: 500" tmp && - grep "Lua error in" err + check_lua_error "$PWD/broken.lua" ' # A script may raise a value that is no string, which the log still names. @@ -152,6 +158,68 @@ test_expect_success CGIT_LUA 'a lua filter raising a table is named by type' ' grep "Lua error in .*tabled.lua: (error object is a table value)" err ' +# Lua shortens a long path at the front where it names a chunk, so the line +# a syntax error is reported on is found by the file's own name. +test_expect_success CGIT_LUA 'a lua filter with a syntax error ends the request' ' + cat >syntax.lua <<-\EOF && + function filter_open(...) end + function filter_write(str) html(str end + function filter_close() return 0 end + EOF + cgitrc_repo syntaxrc foo "auth-filter=lua:$PWD/syntax.lua" && + cgit_rc syntaxrc "url=foo/" >tmp 2>err && + check_lua_error "$PWD/syntax.lua" && + test_grep "syntax\.lua:2: " err +' + +test_expect_success CGIT_LUA 'a lua filter whose script is missing ends the request' ' + cgitrc_repo missingrc foo "auth-filter=lua:$PWD/no-such.lua" && + cgit_rc missingrc "url=foo/" >tmp 2>err && + check_lua_error "$PWD/no-such.lua" && + test_grep -F "cannot open $PWD/no-such.lua" err +' + +test_expect_success CGIT_LUA 'a lua filter that fails in filter_close ends the request' ' + cat >close-error.lua <<-\EOF && + function filter_open(...) end + function filter_write(str) end + function filter_close() error("boom") end + EOF + cgitrc_repo closeerrorrc foo "auth-filter=lua:$PWD/close-error.lua" && + cgit_rc closeerrorrc "url=foo/" >tmp 2>err && + check_lua_error "$PWD/close-error.lua" +' + +# Only a login post writes to the auth filter. +test_expect_success CGIT_LUA 'a lua filter that fails in filter_write ends the request' ' + cat >write-error.lua <<-\EOF && + function filter_open(...) end + function filter_write(str) error("boom") end + function filter_close() return 0 end + EOF + cgitrc_repo writeerrorrc foo "auth-filter=lua:$PWD/write-error.lua" && + printf "user=a" >post && + ( + export REQUEST_METHOD=POST CONTENT_LENGTH=6 && + cgit_rc writeerrorrc "p=login" <post + ) >tmp 2>err && + check_lua_error "$PWD/write-error.lua" +' + +test_expect_success CGIT_LUA 'a lua filter without filter_write ends the request' ' + cat >no-write.lua <<-\EOF && + function filter_open(...) end + function filter_close() return 0 end + EOF + cgitrc_repo nowriterc foo "auth-filter=lua:$PWD/no-write.lua" && + printf "user=a" >post && + ( + export REQUEST_METHOD=POST CONTENT_LENGTH=6 && + cgit_rc nowriterc "p=login" <post + ) >tmp 2>err && + check_lua_error "$PWD/no-write.lua" +' + # A script runs its top level before cgit hooks stdout for it, so what it # writes there goes straight onto the page instead of tripping the hook. It # loads as the filter first opens, which puts the text where the filter runs. |
