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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
test_description='Check the atom feed'
. ./setup.sh
test_lazy_prereq XMLLINT 'command -v xmllint'
test_expect_success 'the response is an atom feed' '
cgit_ok_url "foo/atom" >tmp &&
sed "/^$/q" tmp | grep "^Content-Type: application/atom+xml" &&
strip_headers <tmp >feed &&
grep "<feed xmlns=.http://www.w3.org/2005/Atom.>" feed &&
grep "<title>foo, branch master</title>" feed &&
sed -n "1,/^<entry>$/p" feed >top &&
grep "^<updated>2005-04-01T11:14:15Z</updated>$" top
'
test_expect_success XMLLINT 'the feed is well-formed xml' '
cgit_ok_url "foo/atom" >tmp &&
strip_headers <tmp >feed &&
xmllint --noout feed
'
test_expect_success 'every commit of a small repository is an entry' '
cgit_ok_url "foo/atom" >tmp &&
test $(grep -c "<entry>" tmp) -eq 5 &&
grep "<title>commit 1</title>" tmp &&
grep "<title>commit 5</title>" tmp
'
test_expect_success 'set up a repo with a commit dated twice' '
test_create_repo repos/stamped &&
(
cd repos/stamped &&
GIT_AUTHOR_DATE="@1112354055 +0200" \
GIT_COMMITTER_DATE="@1112911993 +0000" \
git commit --allow-empty -m stamped -m "the body" &&
git checkout -b side &&
git commit --allow-empty -m aside &&
git checkout -
) &&
cgitrc_repo stampedrc stamped
'
test_expect_success 'an entry carries the commit it stands for' '
hex=$(git -C repos/stamped rev-parse master) &&
algo=$(git -C repos/stamped rev-parse --show-object-format) &&
cgit_ok stampedrc "url=stamped/atom" >tmp &&
strip_headers <tmp >feed &&
sed -n "1,/^<entry>$/p" feed >top &&
grep "^<updated>2005-04-07T22:13:13Z</updated>$" top &&
sed -n "/^<entry>$/,/^<\/entry>$/p" feed | tr -d "\047" >actual &&
cat >expect <<-EOF &&
<entry>
<title>stamped</title>
<updated>2005-04-07T22:13:13Z</updated>
<author>
<name>A U Thor</name>
<email>author@example.com</email>
</author>
<published>2005-04-01T11:14:15Z</published>
<link rel=alternate type=text/html href=http://localhost/stamped/commit/?id=$hex/>
<id>urn:$algo:$hex</id>
<content type=text>the body
</content>
</entry>
EOF
test_cmp expect actual
'
test_expect_success 'all=1 follows every branch and names none' '
cgit_ok stampedrc "url=stamped/atom&all=1" >tmp &&
grep "<title>stamped</title>" tmp &&
grep "<title>aside</title>" tmp &&
! grep ", branch" tmp &&
cgit_ok stampedrc "url=stamped/atom" >tmp &&
grep "<title>stamped, branch master</title>" tmp &&
! grep "<title>aside</title>" tmp
'
test_expect_success 'ten entries is the default ceiling' '
cgit_ok_url "bar/atom" >tmp &&
test $(grep -c "<entry>" tmp) -eq 10 &&
grep "<title>commit 50</title>" tmp &&
! grep "<title>commit 40</title>" tmp
'
test_expect_success 'max-atom-items overrides the ceiling' '
cgitrc_repo atomrc bar max-atom-items=3 &&
cgit_ok atomrc "url=bar/atom" >tmp &&
test $(grep -c "<entry>" tmp) -eq 3 &&
grep "<title>commit 48</title>" tmp
'
test_expect_success 'max-atom-items 0 empties the feed and below 0 lets all in' '
cgitrc_repo atomrc bar max-atom-items=0 &&
cgit_ok atomrc "url=bar/atom" >tmp &&
grep "<title>bar, branch master</title>" tmp &&
grep "^<updated>1970-01-01T00:00:00Z</updated>$" tmp &&
! grep "<entry>" tmp &&
cgitrc_repo atomrc bar max-atom-items=-1 &&
cgit_ok atomrc "url=bar/atom" >tmp &&
test $(grep -c "<entry>" tmp) -eq 50
'
test_expect_success 'a path with pathspec magic is refused' '
cgit_url "foo/atom/%3A%28icase%29FILE-1" >tmp &&
grep "^Status: 400" tmp &&
cgit_ok_url "foo/atom/file-1" >tmp &&
test $(grep -c "<entry>" tmp) -eq 1 &&
grep "<title>commit 1</title>" tmp &&
grep "<title>foo/file-1, branch master</title>" tmp
'
test_expect_success 'enable-plain-email=0 leaves the address out of the feed' '
cgitrc_copy plainrc enable-plain-email=0 &&
cgit_ok plainrc "url=foo/atom" >tmp &&
grep "<name>A U Thor</name>" tmp &&
! grep "<email>" tmp &&
! grep "author@example.com" tmp
'
test_expect_success 'the feed link encodes the repository and the branch' '
cgitrc_copy feedrc &&
CGIT_CONFIG="$PWD/feedrc" HTTP_HOST=example.org QUERY_STRING="url=foo%2Bbar/log/&h=1%2B2" cgit >tmp 2>err &&
test_must_be_empty err &&
grep "^Status: 200" tmp &&
grep "title=.Atom feed. href=.http://example.org/foo%2Bbar/atom/?h=1%2B2." tmp
'
test_expect_success 'an empty repository answers with a feed of no entries' '
git init -q --bare repos/empty.git &&
cgitrc_repo emptyrc empty "repo.path=$PWD/repos/empty.git" &&
cgit_ok emptyrc "url=empty/atom" >tmp &&
sed "/^$/q" tmp | grep "Content-Type: application/atom+xml" &&
strip_headers <tmp >feed &&
grep "<title>empty</title>" feed &&
grep "^<updated>1970-01-01T00:00:00Z</updated>$" feed &&
! grep "<entry>" feed &&
grep "</feed>" feed
'
test_expect_success XMLLINT 'the empty feed is well-formed xml' '
cgit_ok emptyrc "url=empty/atom" >tmp &&
strip_headers <tmp >feed &&
xmllint --noout feed
'
test_expect_success 'set up a commit holding what XML cannot carry' '
test_create_repo repos/odd &&
(
cd repos/odd &&
tree=$(git mktree </dev/null) &&
printf "tree %s\n" "$tree" >commit &&
printf "author Odd & Name \003 \375 \357\277\276 X <odd@example.com> 1112354055 +0200\n" >>commit &&
printf "committer C O Mitter <committer@example.com> 1112354055 +0200\n\n" >>commit &&
printf "a < b & c \001 \377 \357\277\276 \303\251\n\nbody > x & \002 \376 \357\277\277\n" >>commit &&
oid=$(git hash-object -t commit -w commit) &&
git update-ref HEAD "$oid" &&
git cat-file commit HEAD >actual &&
test_cmp commit actual
) &&
cgitrc_repo oddrc odd "repo.desc=$(printf "d < e & \004 \374 \357\277\277 \303\251")"
'
test_expect_success 'the feed escapes markup and replaces what XML forbids' '
cgit_ok oddrc "url=odd/atom" >tmp &&
strip_headers <tmp >oddfeed &&
printf "<subtitle>d < e & ? ? ? \303\251</subtitle>\n" >expect &&
grep "^<subtitle>" oddfeed >actual &&
test_cmp expect actual &&
printf "<title>a < b & c ? ? ? \303\251</title>\n" >expect &&
grep "^<title>a " oddfeed >actual &&
test_cmp expect actual &&
printf "<content type=\047text\047>body > x & ? ? ?\n" >expect &&
grep "^<content " oddfeed >actual &&
test_cmp expect actual &&
printf "<name>Odd & Name ? ? ? X</name>\n" >expect &&
grep "^<name>" oddfeed >actual &&
test_cmp expect actual
'
test_expect_success XMLLINT 'that feed is well-formed xml' '
cgit_ok oddrc "url=odd/atom" >tmp &&
strip_headers <tmp >oddfeed &&
xmllint --noout oddfeed
'
test_done
|