diff options
context:
space:
mode:
Diffstat (limited to 'tests/t0501-about-render.sh')
-rwxr-xr-xtests/t0501-about-render.sh90
1 file changed, 90 insertions, 0 deletions
diff --git a/tests/t0501-about-render.sh b/tests/t0501-about-render.sh
new file mode 100755
index 0000000..eff2a61
--- /dev/null
+++ b/tests/t0501-about-render.sh
@@ -0,0 +1,90 @@
+#!/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 as installed 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, where the outcome depends on
+# whether the Lua inside the binary has lpeg, so a probe decides which of
+# the two right answers to expect.
+
+test_description='Check the shipped about-render extension'
+CGIT_TEST_NO_CREATE_REPOS=YesPlease
+. ./setup.sh
+. "$TEST_OUTPUT_DIRECTORY/extensions/lib.sh"
+
+interpreters=$(ext_lua_interpreters 4)
+test -z "$interpreters" &&
+ say 'no standalone lua on the path, unit checks skipped'
+
+for lua in $interpreters
+do
+ test_expect_success "unit checks under $lua" "
+ '$lua' '$EXT_TEST_DIRECTORY/test-about-render.lua' \
+ '$EXTENSIONS_DIRECTORY/about-render.lua'
+ "
+
+ test_expect_success "fallback checks without lpeg under $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 <script>alert(1)</script> attempt.
+ EOF
+ git add README.md &&
+ git commit -m "add readme"
+ )
+'
+
+test_expect_success 'point cgit at it through the about filter' '
+ cat >cgitrc <<-EOF
+ virtual-root=/
+ cache-size=0
+ enable-filter-overrides=1
+ repo.url=md
+ repo.path=$PWD/repos/md/.git
+ repo.readme=master:README.md
+ repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua
+ EOF
+'
+
+if test "$CGIT_HAS_LUA" -eq 1
+then
+ if cgit_lua_probe "$PWD/repos/md/.git" lpeg
+ then
+ test_set_prereq CGIT_LUA_LPEG
+ else
+ test_set_prereq CGIT_LUA_NOLPEG
+ say 'cgit lua has no lpeg, expecting the plain text fallback'
+ fi
+else
+ say 'cgit built without lua, filter checks through cgit skipped'
+fi
+
+test_expect_success CGIT_LUA_LPEG 'the about page renders the markdown' '
+ cgit_url "md/about/" >tmp &&
+ grep "<h1>The Title</h1>" tmp &&
+ grep "<strong>bold</strong>" tmp
+'
+
+test_expect_success CGIT_LUA_LPEG 'readme markup reaches the page escaped' '
+ cgit_url "md/about/" >tmp &&
+ grep "&lt;script&gt;alert(1)&lt;/script&gt;" tmp &&
+ ! grep "<script>alert(1)" tmp
+'
+
+test_expect_success CGIT_LUA_NOLPEG 'without lpeg the readme is served escaped' '
+ cgit_url "md/about/" >tmp &&
+ grep "<pre class=.plaintext.>" tmp &&
+ grep "# The Title" tmp
+'
+
+test_done