t8*: adjust the references to the default branch name "main"
[git] / t / t9502-gitweb-standalone-parse-output.sh
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
13 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
14 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15
16 . ./gitweb-lib.sh
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
37 # (gitweb message body) has <prefix> as prefix for al files in tarfile
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 &&
46         ! grep -v -e "^$prefix$" -e "^$prefix/" -e "^pax_global_header$" file_list
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" &&
62         check_snapshot ".git-$SHORT_ID"
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" &&
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"
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" &&
81         check_snapshot ".git-HEAD-$SHORT_ID"
82 '
83 test_debug 'cat gitweb.headers && cat file_list'
84
85 test_expect_success 'snapshot: short branch name (master)' '
86         gitweb_run "p=.git;a=snapshot;h=master;sf=tar" &&
87         ID=$(git rev-parse --verify --short=7 master) &&
88         check_snapshot ".git-master-$ID"
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
99 test_expect_success 'snapshot: full branch name (refs/heads/master)' '
100         gitweb_run "p=.git;a=snapshot;h=refs/heads/master;sf=tar" &&
101         ID=$(git rev-parse --verify --short=7 master) &&
102         check_snapshot ".git-master-$ID"
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"
109 '
110 test_debug 'cat gitweb.headers && cat file_list'
111
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
115 '
116 test_debug 'cat gitweb.headers'
117
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
151 test_expect_success 'enable forks feature' '
152         cat >>gitweb_config.perl <<-\EOF
153         $feature{"forks"}{"default"} = [1];
154         EOF
155 '
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)' '
181         cat >expected <<-\EOF &&
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
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
199         fi
200         return 0
201 }
202
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+"
208 '
209
210 test_done