#!/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, 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 SHA-256. # Through cgit itself the icon is checked wherever a probe finds luaossl in # the binary's own Lua, and the fallback with every Lua module kept off the # search path, which gives it on any machine. test_description='Check the shipped email avatar extensions' CGIT_TEST_NO_CREATE_REPOS=YesPlease . ./setup.sh . "$TEST_OUTPUT_DIRECTORY/extensions/lib.sh" for lua in ${interpreters:-lua} do lua_module_prereq "$lua" openssl.digest for script in email-gravatar email-libravatar do test_expect_success STANDALONE_LUA "$script checks under $(lua_version "$lua")" ' "$lua" "$EXT_TEST_DIRECTORY/test-email-avatar.lua" "$EXTENSIONS_DIRECTORY/$script.lua" stub ' test_expect_success STANDALONE_LUA "$script checks without luaossl under $(lua_version "$lua")" ' "$lua" "$EXT_TEST_DIRECTORY/test-email-avatar.lua" "$EXTENSIONS_DIRECTORY/$script.lua" missing ' test_expect_success "STANDALONE_LUA,$lua_prereq" "$script checks with real luaossl under $(lua_version "$lua")" ' "$lua" "$EXT_TEST_DIRECTORY/test-email-avatar.lua" "$EXTENSIONS_DIRECTORY/$script.lua" real ' 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 cgit_lua_probe "$PWD/repos/avatar/.git" openssl.digest then test_set_prereq CGIT_LUA_OSSL fi test_expect_success 'point cgit at it through the email filter' ' cat >cgitrc <<-EOF virtual-root=/ cache-size=0 repo.url=avatar repo.path=$PWD/repos/avatar/.git repo.email-filter=lua:$EXTENSIONS_DIRECTORY/email-gravatar.lua repo.url=libravatar repo.path=$PWD/repos/avatar/.git repo.email-filter=lua:$EXTENSIONS_DIRECTORY/email-libravatar.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_ok_url "avatar/commit/" >tmp && test_grep "gravatar.com/avatar/b0eda69977c26118feff17875d53376006568bcbcde5ca0c916d01f05c281436" tmp && test_grep "loading=.lazy." tmp && test_grep "referrerpolicy=.no-referrer." tmp ' test_expect_success CGIT_LUA_OSSL 'the libravatar filter draws it from its own service' ' cgit_ok_url "libravatar/commit/" >tmp && test_grep "seccdn.libravatar.org/avatar/b0eda69977c26118feff17875d53376006568bcbcde5ca0c916d01f05c281436" tmp && test_grep "referrerpolicy=.no-referrer." tmp ' test_expect_success CGIT_LUA 'without luaossl the page keeps the name alone' ' echo "[cgit] Unable to load openssl.digest, so no avatar icons are drawn" >expect && without_lua_modules cgit_url "avatar/commit/" >tmp 2>err && test_cmp expect err && test_grep "^Status: 200" tmp && test_grep "" tmp && test_grep "A U Thor" tmp && test_grep ! "