add DUP_ARRAY
[git.git] / t / t9502-gitweb-standalone-parse-output.sh
blob81d562555799bebe80b5cf36b1063e28d377ea8c
1 #!/bin/sh
3 # Copyright (c) 2009 Mark Rada
6 test_description='gitweb as standalone script (parsing script output).
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.'
13 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
14 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
16 . ./lib-gitweb.sh
18 # ----------------------------------------------------------------------
19 # snapshot file name and prefix
21 cat >>gitweb_config.perl <<\EOF
23 $known_snapshot_formats{'tar'} = {
24 'display' => 'tar',
25 'type' => 'application/x-tar',
26 'suffix' => '.tar',
27 'format' => 'tar',
30 $feature{'snapshot'}{'default'} = ['tar'];
31 EOF
33 # Call check_snapshot with the arguments "<basename> [<prefix>]"
35 # This will check that gitweb HTTP header contains proposed filename
36 # as <basename> with '.tar' suffix added, and that generated tarfile
37 # (gitweb message body) has <prefix> as prefix for all files in tarfile
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 &&
46 ! grep -v -e "^$prefix$" -e "^$prefix/" -e "^pax_global_header$" file_list
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)
55 test_debug '
56 echo "FULL_ID = $FULL_ID"
57 echo "SHORT_ID = $SHORT_ID"
60 test_expect_success 'snapshot: full sha1' '
61 gitweb_run "p=.git;a=snapshot;h=$FULL_ID;sf=tar" &&
62 check_snapshot ".git-$SHORT_ID"
64 test_debug 'cat gitweb.headers && cat file_list'
66 test_expect_success 'snapshot: shortened sha1' '
67 gitweb_run "p=.git;a=snapshot;h=$SHORT_ID;sf=tar" &&
68 check_snapshot ".git-$SHORT_ID"
70 test_debug 'cat gitweb.headers && cat file_list'
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"
77 test_debug 'cat gitweb.headers && cat file_list'
79 test_expect_success 'snapshot: HEAD' '
80 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tar" &&
81 check_snapshot ".git-HEAD-$SHORT_ID"
83 test_debug 'cat gitweb.headers && cat file_list'
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"
90 test_debug 'cat gitweb.headers && cat file_list'
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"
97 test_debug 'cat gitweb.headers && cat file_list'
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"
104 test_debug 'cat gitweb.headers && cat file_list'
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"
110 test_debug 'cat gitweb.headers && cat file_list'
112 test_expect_success 'snapshot: hierarchical branch name (xx/test)' '
113 gitweb_run "p=.git;a=snapshot;h=xx/test;sf=tar" &&
114 ! grep "filename=.*/" gitweb.headers
116 test_debug 'cat gitweb.headers'
118 # ----------------------------------------------------------------------
119 # forks of projects
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 &&
134 cd foo &&
135 git clone --shared --bare ../foo.git foo-forked.git &&
136 echo "fork of foo" > foo-forked.git/description
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
151 test_expect_success 'enable forks feature' '
152 cat >>gitweb_config.perl <<-\EOF
153 $feature{"forks"}{"default"} = [1];
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
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
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
180 test_expect_success 'forks: project_index lists all projects (incl. forks)' '
181 cat >expected <<-\EOF &&
182 .git
183 foo.bar.git
184 foo.git
185 foo/foo-forked.git
186 foo_baz.git
188 gitweb_run "a=project_index" &&
189 sed -e "s/ .*//" <gitweb.body | sort >actual &&
190 test_cmp expected actual
193 xss() {
194 echo >&2 "Checking $*..." &&
195 gitweb_run "$@" &&
196 if grep "$TAG" gitweb.body; then
197 echo >&2 "xss: $TAG should have been quoted in output"
198 return 1
200 return 0
203 test_expect_success 'xss checks' '
204 TAG="<magic-xss-tag>" &&
205 xss "a=rss&p=$TAG" &&
206 xss "a=rss&p=foo.git&f=$TAG" &&
207 xss "" "$TAG+"
210 no_http_equiv_content_type() {
211 gitweb_run "$@" &&
212 ! grep -E "http-equiv=['\"]?content-type" gitweb.body
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"
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
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"
237 test_done