]>
Commit | Line | Data |
---|---|---|
3ce9450a JN |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2009 Mark Rada | |
4 | # | |
5 | ||
6 | test_description='gitweb as standalone script (parsing script output). | |
7 | ||
8 | This test runs gitweb (git web interface) as a CGI script from the | |
9 | commandline, and checks that it produces the correct output, either | |
10 | in the HTTP header or the actual script output.' | |
11 | ||
12 | ||
765577b5 | 13 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
14 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
15 | ||
3fca1fc6 | 16 | . ./lib-gitweb.sh |
3ce9450a JN |
17 | |
18 | # ---------------------------------------------------------------------- | |
19 | # snapshot file name and prefix | |
20 | ||
21 | cat >>gitweb_config.perl <<\EOF | |
22 | ||
23 | $known_snapshot_formats{'tar'} = { | |
24 | 'display' => 'tar', | |
25 | 'type' => 'application/x-tar', | |
26 | 'suffix' => '.tar', | |
27 | 'format' => 'tar', | |
28 | }; | |
29 | ||
30 | $feature{'snapshot'}{'default'} = ['tar']; | |
31 | EOF | |
32 | ||
33 | # Call check_snapshot with the arguments "<basename> [<prefix>]" | |
34 | # | |
35 | # This will check that gitweb HTTP header contains proposed filename | |
36 | # as <basename> with '.tar' suffix added, and that generated tarfile | |
943fd027 | 37 | # (gitweb message body) has <prefix> as prefix for all files in tarfile |
3ce9450a JN |
38 | # |
39 | # <prefix> default to <basename> | |
40 | check_snapshot () { | |
41 | basename=$1 | |
42 | prefix=${2:-"$1"} | |
43 | echo "basename=$basename" | |
44 | grep "filename=.*$basename.tar" gitweb.headers >/dev/null 2>&1 && | |
45 | "$TAR" tf gitweb.body >file_list && | |
2060ed50 | 46 | ! grep -v -e "^$prefix$" -e "^$prefix/" -e "^pax_global_header$" file_list |
3ce9450a JN |
47 | } |
48 | ||
49 | test_expect_success setup ' | |
50 | test_commit first foo && | |
51 | git branch xx/test && | |
52 | FULL_ID=$(git rev-parse --verify HEAD) && | |
53 | SHORT_ID=$(git rev-parse --verify --short=7 HEAD) | |
54 | ' | |
55 | test_debug ' | |
56 | echo "FULL_ID = $FULL_ID" | |
57 | echo "SHORT_ID = $SHORT_ID" | |
58 | ' | |
59 | ||
60 | test_expect_success 'snapshot: full sha1' ' | |
61 | gitweb_run "p=.git;a=snapshot;h=$FULL_ID;sf=tar" && | |
b629275f | 62 | check_snapshot ".git-$SHORT_ID" |
3ce9450a JN |
63 | ' |
64 | test_debug 'cat gitweb.headers && cat file_list' | |
65 | ||
66 | test_expect_success 'snapshot: shortened sha1' ' | |
67 | gitweb_run "p=.git;a=snapshot;h=$SHORT_ID;sf=tar" && | |
b629275f MR |
68 | check_snapshot ".git-$SHORT_ID" |
69 | ' | |
70 | test_debug 'cat gitweb.headers && cat file_list' | |
71 | ||
72 | test_expect_success 'snapshot: almost full sha1' ' | |
73 | ID=$(git rev-parse --short=30 HEAD) && | |
74 | gitweb_run "p=.git;a=snapshot;h=$ID;sf=tar" && | |
75 | check_snapshot ".git-$SHORT_ID" | |
3ce9450a JN |
76 | ' |
77 | test_debug 'cat gitweb.headers && cat file_list' | |
78 | ||
79 | test_expect_success 'snapshot: HEAD' ' | |
80 | gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tar" && | |
b629275f | 81 | check_snapshot ".git-HEAD-$SHORT_ID" |
3ce9450a JN |
82 | ' |
83 | test_debug 'cat gitweb.headers && cat file_list' | |
84 | ||
765577b5 JS |
85 | test_expect_success 'snapshot: short branch name (main)' ' |
86 | gitweb_run "p=.git;a=snapshot;h=main;sf=tar" && | |
87 | ID=$(git rev-parse --verify --short=7 main) && | |
88 | check_snapshot ".git-main-$ID" | |
b629275f MR |
89 | ' |
90 | test_debug 'cat gitweb.headers && cat file_list' | |
91 | ||
92 | test_expect_success 'snapshot: short tag name (first)' ' | |
93 | gitweb_run "p=.git;a=snapshot;h=first;sf=tar" && | |
94 | ID=$(git rev-parse --verify --short=7 first) && | |
95 | check_snapshot ".git-first-$ID" | |
96 | ' | |
97 | test_debug 'cat gitweb.headers && cat file_list' | |
98 | ||
765577b5 JS |
99 | test_expect_success 'snapshot: full branch name (refs/heads/main)' ' |
100 | gitweb_run "p=.git;a=snapshot;h=refs/heads/main;sf=tar" && | |
101 | ID=$(git rev-parse --verify --short=7 main) && | |
102 | check_snapshot ".git-main-$ID" | |
b629275f MR |
103 | ' |
104 | test_debug 'cat gitweb.headers && cat file_list' | |
105 | ||
106 | test_expect_success 'snapshot: full tag name (refs/tags/first)' ' | |
107 | gitweb_run "p=.git;a=snapshot;h=refs/tags/first;sf=tar" && | |
108 | check_snapshot ".git-first" | |
3ce9450a JN |
109 | ' |
110 | test_debug 'cat gitweb.headers && cat file_list' | |
111 | ||
b629275f | 112 | test_expect_success 'snapshot: hierarchical branch name (xx/test)' ' |
3ce9450a JN |
113 | gitweb_run "p=.git;a=snapshot;h=xx/test;sf=tar" && |
114 | ! grep "filename=.*/" gitweb.headers | |
115 | ' | |
116 | test_debug 'cat gitweb.headers' | |
117 | ||
12b1443c JN |
118 | # ---------------------------------------------------------------------- |
119 | # forks of projects | |
120 | ||
121 | test_expect_success 'forks: setup' ' | |
122 | git init --bare foo.git && | |
123 | echo file > file && | |
124 | git --git-dir=foo.git --work-tree=. add file && | |
125 | git --git-dir=foo.git --work-tree=. commit -m "Initial commit" && | |
126 | echo "foo" > foo.git/description && | |
127 | git clone --bare foo.git foo.bar.git && | |
128 | echo "foo.bar" > foo.bar.git/description && | |
129 | git clone --bare foo.git foo_baz.git && | |
130 | echo "foo_baz" > foo_baz.git/description && | |
131 | rm -fr foo && | |
132 | mkdir -p foo && | |
133 | ( | |
134 | cd foo && | |
135 | git clone --shared --bare ../foo.git foo-forked.git && | |
136 | echo "fork of foo" > foo-forked.git/description | |
137 | ) | |
138 | ' | |
139 | ||
140 | test_expect_success 'forks: not skipped unless "forks" feature enabled' ' | |
141 | gitweb_run "a=project_list" && | |
142 | grep -q ">\\.git<" gitweb.body && | |
143 | grep -q ">foo\\.git<" gitweb.body && | |
144 | grep -q ">foo_baz\\.git<" gitweb.body && | |
145 | grep -q ">foo\\.bar\\.git<" gitweb.body && | |
146 | grep -q ">foo_baz\\.git<" gitweb.body && | |
147 | grep -q ">foo/foo-forked\\.git<" gitweb.body && | |
148 | grep -q ">fork of .*<" gitweb.body | |
149 | ' | |
150 | ||
d8cd3279 JK |
151 | test_expect_success 'enable forks feature' ' |
152 | cat >>gitweb_config.perl <<-\EOF | |
153 | $feature{"forks"}{"default"} = [1]; | |
154 | EOF | |
155 | ' | |
12b1443c JN |
156 | |
157 | test_expect_success 'forks: forks skipped if "forks" feature enabled' ' | |
158 | gitweb_run "a=project_list" && | |
159 | grep -q ">\\.git<" gitweb.body && | |
160 | grep -q ">foo\\.git<" gitweb.body && | |
161 | grep -q ">foo_baz\\.git<" gitweb.body && | |
162 | grep -q ">foo\\.bar\\.git<" gitweb.body && | |
163 | grep -q ">foo_baz\\.git<" gitweb.body && | |
164 | grep -v ">foo/foo-forked\\.git<" gitweb.body && | |
165 | grep -v ">fork of .*<" gitweb.body | |
166 | ' | |
167 | ||
168 | test_expect_success 'forks: "forks" action for forked repository' ' | |
169 | gitweb_run "p=foo.git;a=forks" && | |
170 | grep -q ">foo/foo-forked\\.git<" gitweb.body && | |
171 | grep -q ">fork of foo<" gitweb.body | |
172 | ' | |
173 | ||
174 | test_expect_success 'forks: can access forked repository' ' | |
175 | gitweb_run "p=foo/foo-forked.git;a=summary" && | |
176 | grep -q "200 OK" gitweb.headers && | |
177 | grep -q ">fork of foo<" gitweb.body | |
178 | ' | |
179 | ||
180 | test_expect_success 'forks: project_index lists all projects (incl. forks)' ' | |
d8cd3279 | 181 | cat >expected <<-\EOF && |
12b1443c JN |
182 | .git |
183 | foo.bar.git | |
184 | foo.git | |
185 | foo/foo-forked.git | |
186 | foo_baz.git | |
187 | EOF | |
188 | gitweb_run "a=project_index" && | |
189 | sed -e "s/ .*//" <gitweb.body | sort >actual && | |
190 | test_cmp expected actual | |
191 | ' | |
192 | ||
0f0ecf68 | 193 | xss() { |
0eba60c9 JK |
194 | echo >&2 "Checking $*..." && |
195 | gitweb_run "$@" && | |
0f0ecf68 JK |
196 | if grep "$TAG" gitweb.body; then |
197 | echo >&2 "xss: $TAG should have been quoted in output" | |
198 | return 1 | |
199 | fi | |
200 | return 0 | |
201 | } | |
202 | ||
203 | test_expect_success 'xss checks' ' | |
204 | TAG="<magic-xss-tag>" && | |
205 | xss "a=rss&p=$TAG" && | |
a376e37b JK |
206 | xss "a=rss&p=foo.git&f=$TAG" && |
207 | xss "" "$TAG+" | |
0f0ecf68 | 208 | ' |
12b1443c | 209 | |
a262585d JY |
210 | no_http_equiv_content_type() { |
211 | gitweb_run "$@" && | |
212 | ! grep -E "http-equiv=['\"]?content-type" gitweb.body | |
213 | } | |
214 | ||
215 | # See: <https://html.spec.whatwg.org/dev/semantics.html#attr-meta-http-equiv-content-type> | |
216 | test_expect_success 'no http-equiv="content-type" in XHTML' ' | |
217 | no_http_equiv_content_type && | |
218 | no_http_equiv_content_type "p=.git" && | |
219 | no_http_equiv_content_type "p=.git;a=log" && | |
220 | no_http_equiv_content_type "p=.git;a=tree" | |
221 | ' | |
222 | ||
0e1a85ca JY |
223 | proper_doctype() { |
224 | gitweb_run "$@" && | |
225 | grep -F "<!DOCTYPE html [" gitweb.body && | |
226 | grep "<!ENTITY nbsp" gitweb.body && | |
227 | grep "<!ENTITY sdot" gitweb.body | |
228 | } | |
229 | ||
230 | test_expect_success 'Proper DOCTYPE with entity declarations' ' | |
231 | proper_doctype && | |
232 | proper_doctype "p=.git" && | |
233 | proper_doctype "p=.git;a=log" && | |
234 | proper_doctype "p=.git;a=tree" | |
235 | ' | |
236 | ||
3ce9450a | 237 | test_done |