blob: 26231af58167b56f7c91d2aeea131a0400ee74f8 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh

# Checks what the configuration parser reports on stderr. A key it does not
# know, a repo key before any repository and a filter set by a scanned
# repository without trust-scan-filters are each ignored with a warning naming
# the key, a repo filter in the main cgitrc passes without one, a repository
# whose path is missing answers 404 on every page, and a config cgit fully
# understands stays silent.

test_description='Check configuration diagnostics'
. ./setup.sh

test_expect_success 'set up configs' '
	{
		echo "virtual-root=/" &&
		echo "cache-size=0" &&
		echo "no-such-key=1" &&
		echo "repo.url=diag" &&
		echo "repo.path=$PWD/repos/foo/.git" &&
		echo "repo.no-such-repo-key=1"
	} >diagrc &&
	{
		echo "virtual-root=/" &&
		echo "cache-size=0" &&
		echo "repo.desc=early" &&
		echo "repo.url=diag" &&
		echo "repo.path=$PWD/repos/foo/.git" &&
		echo "repo.about-filter=exec:/bin/true"
	} >earlyrc
'

test_expect_success 'unknown keys are reported and the page still renders' '
	CGIT_CONFIG="$PWD/diagrc" QUERY_STRING="url=diag/" cgit >tmp 2>err &&
	grep "Status: 200" tmp &&
	grep "Unknown config key: no-such-key" err &&
	grep "Unknown repo config key: no-such-repo-key" err
'

test_expect_success 'a repo key before any repo.url is reported' '
	CGIT_CONFIG="$PWD/earlyrc" QUERY_STRING="url=diag/" cgit >tmp 2>err &&
	grep "Status: 200" tmp &&
	grep "Ignoring repo.desc before any repo.url" err
'

test_expect_success 'a filter in a scanned repository is reported without its flag' '
	git clone -q --bare repos/foo/.git scan/foo.git &&
	echo "commit-filter=exec:$FILTER_DIRECTORY/dump.sh" >scan/foo.git/cgitrc &&
	{
		echo "virtual-root=/" &&
		echo "cache-size=0" &&
		echo "scan-path=$PWD/scan"
	} >scanrc &&
	CGIT_CONFIG="$PWD/scanrc" QUERY_STRING="url=foo.git/commit/" cgit >tmp 2>err &&
	grep "<div class=.commit-subject.>commit 5" tmp &&
	grep "Ignoring commit-filter in $PWD/scan/foo.git/: trust-scan-filters is not set" err
'

test_expect_success 'the flag lets a scanned repository set its filters' '
	{
		echo "trust-scan-filters=1" &&
		cat scanrc
	} >scanrc-on &&
	CGIT_CONFIG="$PWD/scanrc-on" QUERY_STRING="url=foo.git/commit/" cgit >tmp 2>err &&
	grep "<div class=.commit-subject.>COMMIT 5" tmp &&
	! grep "Ignoring" err
'

test_expect_success 'a repo filter in the main cgitrc needs no flag' '
	! grep "about-filter" err &&
	CGIT_CONFIG="$PWD/earlyrc" QUERY_STRING="url=diag/" cgit >tmp 2>err &&
	! grep "about-filter" err
'

test_expect_success 'a repository whose path is missing answers 404' '
	{
		echo "virtual-root=/" &&
		echo "cache-size=1021" &&
		echo "cache-root=$PWD/gone-cache" &&
		echo "repo.url=gone" &&
		echo "repo.path=$PWD/no/such/repo/.git"
	} >gonerc &&
	mkdir -p gone-cache &&
	for page in "" log/ commit/ "tag/&h=x" atom/ plain/f
	do
		CGIT_CONFIG="$PWD/gonerc" QUERY_STRING="url=gone/$page" cgit >tmp 2>err &&
		grep "^Status: 404 Not Found" tmp &&
		grep "Failed to open gone: No such file or directory" tmp || return 1
	done &&
	test -z "$(ls gone-cache)"
'

test_expect_success 'a fully understood config stays silent' '
	cgit_url "foo/" >tmp 2>err &&
	grep "Status: 200" tmp &&
	! grep "\[cgit\]" err
'

test_done