blob: 0a4b74f9a4f793d2c52850c2ede5fc88629932e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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