Merge branch 'jc/ci-upload-artifact-and-linux32'
[git/gitster.git] / t / t9502-gitweb-standalone-parse-output.sh
blobb41ea1933143814d895be93053382052637c34b4
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 TEST_PASSES_SANITIZE_LEAK=true
17 . ./lib-gitweb.sh
19 # ----------------------------------------------------------------------
20 # snapshot file name and prefix
22 cat >>gitweb_config.perl <<\EOF
24 $known_snapshot_formats{'tar'} = {
25 'display' => 'tar',
26 'type' => 'application/x-tar',
27 'suffix' => '.tar',
28 'format' => 'tar',
31 $feature{'snapshot'}{'default'} = ['tar'];
32 EOF
34 # Call check_snapshot with the arguments "<basename> [<prefix>]"
36 # This will check that gitweb HTTP header contains proposed filename
37 # as <basename> with '.tar' suffix added, and that generated tarfile
38 # (gitweb message body) has <prefix> as prefix for all files in tarfile
40 # <prefix> default to <basename>
41 check_snapshot () {
42 basename=$1
43 prefix=${2:-"$1"}
44 echo "basename=$basename"
45 grep "filename=.*$basename.tar" gitweb.headers >/dev/null 2>&1 &&
46 "$TAR" tf gitweb.body >file_list &&
47 ! grep -v -e "^$prefix$" -e "^$prefix/" -e "^pax_global_header$" file_list
50 test_expect_success setup '
51 test_commit first foo &&
52 git branch xx/test &&
53 FULL_ID=$(git rev-parse --verify HEAD) &&
54 SHORT_ID=$(git rev-parse --verify --short=7 HEAD)
56 test_debug '
57 echo "FULL_ID = $FULL_ID"
58 echo "SHORT_ID = $SHORT_ID"
61 test_expect_success 'snapshot: full sha1' '
62 gitweb_run "p=.git;a=snapshot;h=$FULL_ID;sf=tar" &&
63 check_snapshot ".git-$SHORT_ID"
65 test_debug 'cat gitweb.headers && cat file_list'
67 test_expect_success 'snapshot: shortened sha1' '
68 gitweb_run "p=.git;a=snapshot;h=$SHORT_ID;sf=tar" &&
69 check_snapshot ".git-$SHORT_ID"
71 test_debug 'cat gitweb.headers && cat file_list'
73 test_expect_success 'snapshot: almost full sha1' '
74 ID=$(git rev-parse --short=30 HEAD) &&
75 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tar" &&
76 check_snapshot ".git-$SHORT_ID"
78 test_debug 'cat gitweb.headers && cat file_list'
80 test_expect_success 'snapshot: HEAD' '
81 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tar" &&
82 check_snapshot ".git-HEAD-$SHORT_ID"
84 test_debug 'cat gitweb.headers && cat file_list'
86 test_expect_success 'snapshot: short branch name (main)' '
87 gitweb_run "p=.git;a=snapshot;h=main;sf=tar" &&
88 ID=$(git rev-parse --verify --short=7 main) &&
89 check_snapshot ".git-main-$ID"
91 test_debug 'cat gitweb.headers && cat file_list'
93 test_expect_success 'snapshot: short tag name (first)' '
94 gitweb_run "p=.git;a=snapshot;h=first;sf=tar" &&
95 ID=$(git rev-parse --verify --short=7 first) &&
96 check_snapshot ".git-first-$ID"
98 test_debug 'cat gitweb.headers && cat file_list'
100 test_expect_success 'snapshot: full branch name (refs/heads/main)' '
101 gitweb_run "p=.git;a=snapshot;h=refs/heads/main;sf=tar" &&
102 ID=$(git rev-parse --verify --short=7 main) &&
103 check_snapshot ".git-main-$ID"
105 test_debug 'cat gitweb.headers && cat file_list'
107 test_expect_success 'snapshot: full tag name (refs/tags/first)' '
108 gitweb_run "p=.git;a=snapshot;h=refs/tags/first;sf=tar" &&
109 check_snapshot ".git-first"
111 test_debug 'cat gitweb.headers && cat file_list'
113 test_expect_success 'snapshot: hierarchical branch name (xx/test)' '
114 gitweb_run "p=.git;a=snapshot;h=xx/test;sf=tar" &&
115 ! grep "filename=.*/" gitweb.headers
117 test_debug 'cat gitweb.headers'
119 # ----------------------------------------------------------------------
120 # forks of projects
122 test_expect_success 'forks: setup' '
123 git init --bare foo.git &&
124 echo file > file &&
125 git --git-dir=foo.git --work-tree=. add file &&
126 git --git-dir=foo.git --work-tree=. commit -m "Initial commit" &&
127 echo "foo" > foo.git/description &&
128 git clone --bare foo.git foo.bar.git &&
129 echo "foo.bar" > foo.bar.git/description &&
130 git clone --bare foo.git foo_baz.git &&
131 echo "foo_baz" > foo_baz.git/description &&
132 rm -fr foo &&
133 mkdir -p foo &&
135 cd foo &&
136 git clone --shared --bare ../foo.git foo-forked.git &&
137 echo "fork of foo" > foo-forked.git/description
141 test_expect_success 'forks: not skipped unless "forks" feature enabled' '
142 gitweb_run "a=project_list" &&
143 grep -q ">\\.git<" gitweb.body &&
144 grep -q ">foo\\.git<" gitweb.body &&
145 grep -q ">foo_baz\\.git<" gitweb.body &&
146 grep -q ">foo\\.bar\\.git<" gitweb.body &&
147 grep -q ">foo_baz\\.git<" gitweb.body &&
148 grep -q ">foo/foo-forked\\.git<" gitweb.body &&
149 grep -q ">fork of .*<" gitweb.body
152 test_expect_success 'enable forks feature' '
153 cat >>gitweb_config.perl <<-\EOF
154 $feature{"forks"}{"default"} = [1];
158 test_expect_success 'forks: forks skipped if "forks" feature enabled' '
159 gitweb_run "a=project_list" &&
160 grep -q ">\\.git<" gitweb.body &&
161 grep -q ">foo\\.git<" gitweb.body &&
162 grep -q ">foo_baz\\.git<" gitweb.body &&
163 grep -q ">foo\\.bar\\.git<" gitweb.body &&
164 grep -q ">foo_baz\\.git<" gitweb.body &&
165 grep -v ">foo/foo-forked\\.git<" gitweb.body &&
166 grep -v ">fork of .*<" gitweb.body
169 test_expect_success 'forks: "forks" action for forked repository' '
170 gitweb_run "p=foo.git;a=forks" &&
171 grep -q ">foo/foo-forked\\.git<" gitweb.body &&
172 grep -q ">fork of foo<" gitweb.body
175 test_expect_success 'forks: can access forked repository' '
176 gitweb_run "p=foo/foo-forked.git;a=summary" &&
177 grep -q "200 OK" gitweb.headers &&
178 grep -q ">fork of foo<" gitweb.body
181 test_expect_success 'forks: project_index lists all projects (incl. forks)' '
182 cat >expected <<-\EOF &&
183 .git
184 foo.bar.git
185 foo.git
186 foo/foo-forked.git
187 foo_baz.git
189 gitweb_run "a=project_index" &&
190 sed -e "s/ .*//" <gitweb.body | sort >actual &&
191 test_cmp expected actual
194 xss() {
195 echo >&2 "Checking $*..." &&
196 gitweb_run "$@" &&
197 if grep "$TAG" gitweb.body; then
198 echo >&2 "xss: $TAG should have been quoted in output"
199 return 1
201 return 0
204 test_expect_success 'xss checks' '
205 TAG="<magic-xss-tag>" &&
206 xss "a=rss&p=$TAG" &&
207 xss "a=rss&p=foo.git&f=$TAG" &&
208 xss "" "$TAG+"
211 no_http_equiv_content_type() {
212 gitweb_run "$@" &&
213 ! grep -E "http-equiv=['\"]?content-type" gitweb.body
216 # See: <https://html.spec.whatwg.org/dev/semantics.html#attr-meta-http-equiv-content-type>
217 test_expect_success 'no http-equiv="content-type" in XHTML' '
218 no_http_equiv_content_type &&
219 no_http_equiv_content_type "p=.git" &&
220 no_http_equiv_content_type "p=.git;a=log" &&
221 no_http_equiv_content_type "p=.git;a=tree"
224 proper_doctype() {
225 gitweb_run "$@" &&
226 grep -F "<!DOCTYPE html [" gitweb.body &&
227 grep "<!ENTITY nbsp" gitweb.body &&
228 grep "<!ENTITY sdot" gitweb.body
231 test_expect_success 'Proper DOCTYPE with entity declarations' '
232 proper_doctype &&
233 proper_doctype "p=.git" &&
234 proper_doctype "p=.git;a=log" &&
235 proper_doctype "p=.git;a=tree"
238 test_done