diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Draw no avatar when luaossl is missing
The require at the top raised as cgit loaded the filter, so every page
that lists an author stopped at its first author cell with an error.
Diffstat (limited to '')
| -rw-r--r-- | custom/extensions/email-gravatar.lua | 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | custom/extensions/email-libravatar.lua | 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | tests/extensions/test-email-avatar.lua | 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rwxr-xr-x | tests/t0504-email-avatar.sh | 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 files changed, 41 insertions, 15 deletions
diff --git a/custom/extensions/email-gravatar.lua b/custom/extensions/email-gravatar.lua index 01db3f9..836841f 100644 --- a/custom/extensions/email-gravatar.lua +++ b/custom/extensions/email-gravatar.lua @@ -12,7 +12,8 @@ -- The one dependency is luaossl, the OpenSSL binding that provides -- openssl.digest, from <https://github.com/wahern/luaossl>. The reliable -- cross-platform install is LuaRocks, matched to the Lua version cgit is built --- against, and it needs the OpenSSL development headers present. +-- against, and it needs the OpenSSL development headers present. Without it +-- the filter draws no icons and leaves the names as they are. -- -- # Debian and Ubuntu -- sudo apt install luarocks libssl-dev @@ -31,7 +32,7 @@ -- that is not acceptable for your instance. Addresses are hashed with MD5, -- which Gravatar still accepts. -local digest = require("openssl.digest") +local has_digest, digest = pcall(require, "openssl.digest") -- The size is in pixels and serves both as the image asked of the service @@ -94,7 +95,7 @@ end function filter_open(email, page) buffer = "" local address = normalize_email(email) - if address == nil then + if address == nil or not has_digest then avatar_hash = nil else avatar_hash = hash_hex(address) diff --git a/custom/extensions/email-libravatar.lua b/custom/extensions/email-libravatar.lua index 1fb979d..2b1fecd 100644 --- a/custom/extensions/email-libravatar.lua +++ b/custom/extensions/email-libravatar.lua @@ -11,7 +11,8 @@ -- The one dependency is luaossl, the OpenSSL binding that provides -- openssl.digest, from <https://github.com/wahern/luaossl>. The reliable -- cross-platform install is LuaRocks, matched to the Lua version cgit is built --- against, and it needs the OpenSSL development headers present. +-- against, and it needs the OpenSSL development headers present. Without it +-- the filter draws no icons and leaves the names as they are. -- -- # Debian and Ubuntu -- sudo apt install luarocks libssl-dev @@ -29,7 +30,7 @@ -- committer's email to a third-party service, so leave this filter off if -- that is not acceptable for your instance. Addresses are hashed with MD5. -local digest = require("openssl.digest") +local has_digest, digest = pcall(require, "openssl.digest") -- The size is in pixels and serves both as the image asked of the service @@ -92,7 +93,7 @@ end function filter_open(email, page) buffer = "" local address = normalize_email(email) - if address == nil then + if address == nil or not has_digest then avatar_hash = nil else avatar_hash = hash_hex(address) diff --git a/tests/extensions/test-email-avatar.lua b/tests/extensions/test-email-avatar.lua index 4960ec3..bedcfe8 100644 --- a/tests/extensions/test-email-avatar.lua +++ b/tests/extensions/test-email-avatar.lua @@ -3,8 +3,8 @@ -- two scripts differ only in the service they point at, so the expected host -- is picked from the script's name. The second argument chooses how the -- openssl.digest dependency is met, stub swaps in the deterministic fake --- from the harness, and real uses an installed luaossl and adds the one --- check only a genuine MD5 can pass. +-- from the harness, real uses an installed luaossl and adds the one check +-- only a genuine MD5 can pass, and missing makes the module fail to load. local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") @@ -21,6 +21,8 @@ end if mode == "stub" then h.stub_digest() +elseif mode == "missing" then + h.preload_failure("openssl.digest") end h.load(script) @@ -29,6 +31,13 @@ local function render(email, name) return h.run({ email, "commit" }, { name }) end +if mode == "missing" then + local out, ret = render("<author@example.com>", "A U Thor") + h.equals("without luaossl the name stands alone", out, "A U Thor") + h.equals("and close still answers zero", ret, 0) + h.finish() +end + local function hash_of(output) local prefix = base_url:gsub("([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1") return output:match("src='" .. prefix .. "(%x+)%?") diff --git a/tests/t0504-email-avatar.sh b/tests/t0504-email-avatar.sh index 91ddc20..0150c54 100755 --- a/tests/t0504-email-avatar.sh +++ b/tests/t0504-email-avatar.sh @@ -3,11 +3,11 @@ # 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. +# deterministic digest standing in for luaossl, with the module made to +# fail to load, and once more against the real module wherever it is +# installed, which adds the check that a known address hashes to its +# published md5. Through cgit itself the answer depends on whether the +# binary's own Lua has luaossl, so it is probed for rather than assumed. test_description='Check the shipped email avatar extensions' CGIT_TEST_NO_CREATE_REPOS=YesPlease @@ -25,6 +25,9 @@ do test_expect_success "$script checks under $lua" " '$lua' '$EXT_TEST_DIRECTORY/test-email-avatar.lua' '$EXTENSIONS_DIRECTORY/$script.lua' stub " + test_expect_success "$script checks without luaossl under $lua" " + '$lua' '$EXT_TEST_DIRECTORY/test-email-avatar.lua' '$EXTENSIONS_DIRECTORY/$script.lua' missing + " if "$lua" -e "require([[openssl.digest]])" >/dev/null 2>&1 then @@ -49,11 +52,16 @@ if test "$CGIT_HAS_LUA" -eq 1 && cgit_lua_probe "$PWD/repos/avatar/.git" openssl.digest then test_set_prereq CGIT_LUA_OSSL +elif test "$CGIT_HAS_LUA" -eq 1 +then + test_set_prereq CGIT_LUA_NOOSSL + say 'cgit lua has no luaossl, expecting names without icons' else - say 'cgit lua has no luaossl, filter checks through cgit skipped' + say 'cgit built without lua, filter checks through cgit skipped' fi +test "$CGIT_HAS_LUA" -eq 1 && test_set_prereq CGIT_LUA -test_expect_success CGIT_LUA_OSSL 'point cgit at it through the email filter' ' +test_expect_success CGIT_LUA 'point cgit at it through the email filter' ' cat >cgitrc <<-EOF virtual-root=/ cache-size=0 @@ -71,4 +79,11 @@ test_expect_success CGIT_LUA_OSSL 'the commit page draws the author icon' ' grep "loading=.lazy." tmp ' +test_expect_success CGIT_LUA_NOOSSL 'without luaossl the page keeps the name alone' ' + cgit_url "avatar/commit/" >tmp && + grep "A U Thor" tmp && + ! grep "<img src=.https:" tmp && + ! grep "Unable to complete the request" tmp +' + test_done |
