#!/bin/sh # Checks about-render.lua, the shipped about-filter. The unit checks drive # the script under every suitable standalone Lua through the harness in # extensions/, once with lpeg wherever that interpreter has it and once with # lpeg forced away so the plain text fallback is proven everywhere. A # repository with a markdown readme is then rendered through cgit itself, # with lpeg wherever a probe finds it in the Lua inside the binary, and with # every Lua module kept off the search path, which gives the fallback on any # machine. test_description='Check the shipped about-render extension' CGIT_TEST_NO_CREATE_REPOS=YesPlease . ./setup.sh . "$TEST_OUTPUT_DIRECTORY/extensions/lib.sh" for lua in ${interpreters:-lua} do lua_module_prereq "$lua" lpeg test_expect_success "STANDALONE_LUA,$lua_prereq" "unit checks under $(lua_version "$lua")" ' "$lua" "$EXT_TEST_DIRECTORY/test-about-render.lua" "$EXTENSIONS_DIRECTORY/about-render.lua" lpeg ' test_expect_success STANDALONE_LUA "fallback checks without lpeg under $(lua_version "$lua")" ' "$lua" "$EXT_TEST_DIRECTORY/test-about-render.lua" "$EXTENSIONS_DIRECTORY/about-render.lua" nolpeg ' done test_expect_success 'create a repository with a markdown readme' ' test_create_repo repos/md && ( cd repos/md && cat >README.md <<-\EOF && # The Title A **bold** claim and a attempt. See the [roadmap](ROADMAP.md#plan). EOF cat >tool.1 <<-\EOF && .TH TOOL 1 .SH NAME tool \- does one thing \(em well .SH OPTIONS .TP .B \-v Be \fIverbose\fR. .nf tool \-v .fi EOF echo "Plain notes & more" >NOTES && git add README.md tool.1 NOTES && git commit -m "add readme" && git branch next ) ' test_expect_success 'point cgit at it through the about filter' ' cat >cgitrc <<-EOF virtual-root=/ cache-size=0 repo.url=md repo.path=$PWD/repos/md/.git repo.readme=:README.md repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua repo.url=man repo.path=$PWD/repos/md/.git repo.readme=:tool.1 repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua repo.url=txt repo.path=$PWD/repos/md/.git repo.readme=:NOTES repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua repo.url=noreadme repo.path=$PWD/repos/md/.git repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua EOF ' if cgit_lua_probe "$PWD/repos/md/.git" lpeg then test_set_prereq CGIT_LUA_LPEG fi test_expect_success CGIT_LUA_LPEG 'the about page renders the markdown' ' cgit_ok_url "md/about/" >tmp && test_grep "

The Title

" tmp && test_grep "bold" tmp ' test_expect_success CGIT_LUA_LPEG 'readme markup reaches the page escaped' ' cgit_ok_url "md/about/" >tmp && test_grep "<script>alert(1)</script>" tmp && test_grep ! "