From e974027848e4f969aa2b21d79b2276d13cf2bafb Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Tue, 1 Sep 2026 17:22:14 -1000 Subject: Add a test suite for the shipped extensions --- tests/t0504-email-avatar.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 tests/t0504-email-avatar.sh (limited to 'tests/t0504-email-avatar.sh') diff --git a/tests/t0504-email-avatar.sh b/tests/t0504-email-avatar.sh new file mode 100755 index 0000000..0a4b74f --- /dev/null +++ b/tests/t0504-email-avatar.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# Checks email-gravatar.lua and email-libravatar.lua, the shipped email +# filters, which differ only in the service the icon is fetched from. The +# unit checks run each under every suitable standalone Lua with a +# deterministic digest standing in for luaossl, and once more against the +# real module wherever it is installed, which adds the check that a known +# address hashes to its published md5. The run through cgit itself needs +# luaossl inside the binary's own Lua, so it is probed for rather than +# assumed. + +test_description='Check the shipped email avatar extensions' +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 + for script in email-gravatar email-libravatar + do + test_expect_success "$script checks under $lua" " + '$lua' '$EXT_TEST_DIRECTORY/test-email-avatar.lua' \ + '$EXTENSIONS_DIRECTORY/$script.lua' stub + " + + if "$lua" -e "require([[openssl.digest]])" >/dev/null 2>&1 + then + test_expect_success "$script checks with real luaossl under $lua" " + '$lua' '$EXT_TEST_DIRECTORY/test-email-avatar.lua' \ + '$EXTENSIONS_DIRECTORY/$script.lua' real + " + fi + done +done + +test_expect_success 'create a repository with one commit' ' + test_create_repo repos/avatar && + ( + cd repos/avatar && + echo content >file && + git add file && + git commit -m "add file" + ) +' + +if test "$CGIT_HAS_LUA" -eq 1 && + cgit_lua_probe "$PWD/repos/avatar/.git" openssl.digest +then + test_set_prereq CGIT_LUA_OSSL +else + say 'cgit lua has no luaossl, filter checks through cgit skipped' +fi + +test_expect_success CGIT_LUA_OSSL 'point cgit at it through the email filter' ' + cat >cgitrc <<-EOF + virtual-root=/ + cache-size=0 + enable-filter-overrides=1 + repo.url=avatar + repo.path=$PWD/repos/avatar/.git + repo.email-filter=lua:$EXTENSIONS_DIRECTORY/email-gravatar.lua + EOF +' + +# The address behind the hash is author@example.com, the identity the test +# library commits under. +test_expect_success CGIT_LUA_OSSL 'the commit page draws the author icon' ' + cgit_url "avatar/commit/" >tmp && + grep "www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1" tmp && + grep "loading=.lazy." tmp +' + +test_done -- cgit v2.8.0