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.'
15 # ----------------------------------------------------------------------
16 # snapshot file name and prefix
18 cat >>gitweb_config.perl
<<\EOF
20 $known_snapshot_formats{'tar'} = {
22 'type' => 'application/x-tar',
27 $feature{'snapshot'}{'default'} = ['tar'];
30 # Call check_snapshot with the arguments "<basename> [<prefix>]"
32 # This will check that gitweb HTTP header contains proposed filename
33 # as <basename> with '.tar' suffix added, and that generated tarfile
34 # (gitweb message body) has <prefix> as prefix for al files in tarfile
36 # <prefix> default to <basename>
40 echo "basename=$basename"
41 grep "filename=.*$basename.tar" gitweb.headers
>/dev
/null
2>&1 &&
42 "$TAR" tf gitweb.body
>file_list
&&
43 ! grep -v -e "^$prefix$" -e "^$prefix/" -e "^pax_global_header$" file_list
46 test_expect_success setup
'
47 test_commit first foo &&
49 FULL_ID=$(git rev-parse --verify HEAD) &&
50 SHORT_ID=$(git rev-parse --verify --short=7 HEAD)
53 echo "FULL_ID = $FULL_ID"
54 echo "SHORT_ID = $SHORT_ID"
57 test_expect_success
'snapshot: full sha1' '
58 gitweb_run "p=.git;a=snapshot;h=$FULL_ID;sf=tar" &&
59 check_snapshot ".git-$SHORT_ID"
61 test_debug
'cat gitweb.headers && cat file_list'
63 test_expect_success
'snapshot: shortened sha1' '
64 gitweb_run "p=.git;a=snapshot;h=$SHORT_ID;sf=tar" &&
65 check_snapshot ".git-$SHORT_ID"
67 test_debug
'cat gitweb.headers && cat file_list'
69 test_expect_success
'snapshot: almost full sha1' '
70 ID=$(git rev-parse --short=30 HEAD) &&
71 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tar" &&
72 check_snapshot ".git-$SHORT_ID"
74 test_debug
'cat gitweb.headers && cat file_list'
76 test_expect_success
'snapshot: HEAD' '
77 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tar" &&
78 check_snapshot ".git-HEAD-$SHORT_ID"
80 test_debug
'cat gitweb.headers && cat file_list'
82 test_expect_success
'snapshot: short branch name (master)' '
83 gitweb_run "p=.git;a=snapshot;h=master;sf=tar" &&
84 ID=$(git rev-parse --verify --short=7 master) &&
85 check_snapshot ".git-master-$ID"
87 test_debug
'cat gitweb.headers && cat file_list'
89 test_expect_success
'snapshot: short tag name (first)' '
90 gitweb_run "p=.git;a=snapshot;h=first;sf=tar" &&
91 ID=$(git rev-parse --verify --short=7 first) &&
92 check_snapshot ".git-first-$ID"
94 test_debug
'cat gitweb.headers && cat file_list'
96 test_expect_success
'snapshot: full branch name (refs/heads/master)' '
97 gitweb_run "p=.git;a=snapshot;h=refs/heads/master;sf=tar" &&
98 ID=$(git rev-parse --verify --short=7 master) &&
99 check_snapshot ".git-master-$ID"
101 test_debug
'cat gitweb.headers && cat file_list'
103 test_expect_success
'snapshot: full tag name (refs/tags/first)' '
104 gitweb_run "p=.git;a=snapshot;h=refs/tags/first;sf=tar" &&
105 check_snapshot ".git-first"
107 test_debug
'cat gitweb.headers && cat file_list'
109 test_expect_success
'snapshot: hierarchical branch name (xx/test)' '
110 gitweb_run "p=.git;a=snapshot;h=xx/test;sf=tar" &&
111 ! grep "filename=.*/" gitweb.headers
113 test_debug
'cat gitweb.headers'
115 # ----------------------------------------------------------------------
118 test_expect_success
'forks: setup' '
119 git init --bare foo.git &&
121 git --git-dir=foo.git --work-tree=. add file &&
122 git --git-dir=foo.git --work-tree=. commit -m "Initial commit" &&
123 echo "foo" > foo.git/description &&
124 git clone --bare foo.git foo.bar.git &&
125 echo "foo.bar" > foo.bar.git/description &&
126 git clone --bare foo.git foo_baz.git &&
127 echo "foo_baz" > foo_baz.git/description &&
132 git clone --shared --bare ../foo.git foo-forked.git &&
133 echo "fork of foo" > foo-forked.git/description
137 test_expect_success
'forks: not skipped unless "forks" feature enabled' '
138 gitweb_run "a=project_list" &&
139 grep -q ">\\.git<" gitweb.body &&
140 grep -q ">foo\\.git<" gitweb.body &&
141 grep -q ">foo_baz\\.git<" gitweb.body &&
142 grep -q ">foo\\.bar\\.git<" gitweb.body &&
143 grep -q ">foo_baz\\.git<" gitweb.body &&
144 grep -q ">foo/foo-forked\\.git<" gitweb.body &&
145 grep -q ">fork of .*<" gitweb.body
148 cat >>gitweb_config.perl
<<\EOF
&&
149 $feature{'forks'}{'default'} = [1];
152 test_expect_success
'forks: forks skipped if "forks" feature enabled' '
153 gitweb_run "a=project_list" &&
154 grep -q ">\\.git<" gitweb.body &&
155 grep -q ">foo\\.git<" gitweb.body &&
156 grep -q ">foo_baz\\.git<" gitweb.body &&
157 grep -q ">foo\\.bar\\.git<" gitweb.body &&
158 grep -q ">foo_baz\\.git<" gitweb.body &&
159 grep -v ">foo/foo-forked\\.git<" gitweb.body &&
160 grep -v ">fork of .*<" gitweb.body
163 test_expect_success
'forks: "forks" action for forked repository' '
164 gitweb_run "p=foo.git;a=forks" &&
165 grep -q ">foo/foo-forked\\.git<" gitweb.body &&
166 grep -q ">fork of foo<" gitweb.body
169 test_expect_success
'forks: can access forked repository' '
170 gitweb_run "p=foo/foo-forked.git;a=summary" &&
171 grep -q "200 OK" gitweb.headers &&
172 grep -q ">fork of foo<" gitweb.body
175 test_expect_success
'forks: project_index lists all projects (incl. forks)' '
176 cat >expected <<-\EOF
183 gitweb_run "a=project_index" &&
184 sed -e "s/ .*//" <gitweb.body | sort >actual &&
185 test_cmp expected actual
189 echo >&2 "Checking $1..." &&
191 if grep "$TAG" gitweb.body
; then
192 echo >&2 "xss: $TAG should have been quoted in output"
198 test_expect_success
'xss checks' '
199 TAG="<magic-xss-tag>" &&
200 xss "a=rss&p=$TAG" &&
201 xss "a=rss&p=foo.git&f=$TAG"