Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 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 | |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 13 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 14 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 15 | |
Ævar Arnfjörð Bjarmason | 3fca1fc | 2021-02-09 22:41:53 +0100 | [diff] [blame] | 16 | . ./lib-gitweb.sh |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 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 |
Jason Yundt | 943fd02 | 2022-03-08 10:56:11 -0500 | [diff] [blame] | 37 | # (gitweb message body) has <prefix> as prefix for all files in tarfile |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 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 && |
Junio C Hamano | 2060ed5 | 2012-12-18 20:57:13 -0800 | [diff] [blame] | 46 | ! grep -v -e "^$prefix$" -e "^$prefix/" -e "^pax_global_header$" file_list |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 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" && |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 62 | check_snapshot ".git-$SHORT_ID" |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 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" && |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 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" |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 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" && |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 81 | check_snapshot ".git-HEAD-$SHORT_ID" |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 82 | ' |
| 83 | test_debug 'cat gitweb.headers && cat file_list' |
| 84 | |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 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" |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 89 | ' |
| 90 | test_debug 'cat gitweb.headers && cat file_list' |
| 91 | |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 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 | |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 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" |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 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)' ' |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 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 | |
Jakub Narebski | 12b1443 | 2011-04-29 19:51:56 +0200 | [diff] [blame] | 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 | |
Jeff King | d8cd327 | 2015-03-20 06:13:01 -0400 | [diff] [blame] | 151 | test_expect_success 'enable forks feature' ' |
| 152 | cat >>gitweb_config.perl <<-\EOF |
| 153 | $feature{"forks"}{"default"} = [1]; |
| 154 | EOF |
| 155 | ' |
Jakub Narebski | 12b1443 | 2011-04-29 19:51:56 +0200 | [diff] [blame] | 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)' ' |
Jeff King | d8cd327 | 2015-03-20 06:13:01 -0400 | [diff] [blame] | 181 | cat >expected <<-\EOF && |
Jakub Narebski | 12b1443 | 2011-04-29 19:51:56 +0200 | [diff] [blame] | 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 | |
Jeff King | 0f0ecf6 | 2012-11-12 16:34:28 -0500 | [diff] [blame] | 193 | xss() { |
Jeff King | 0eba60c | 2019-11-15 04:05:56 -0500 | [diff] [blame] | 194 | echo >&2 "Checking $*..." && |
| 195 | gitweb_run "$@" && |
Jeff King | 0f0ecf6 | 2012-11-12 16:34:28 -0500 | [diff] [blame] | 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" && |
Jeff King | a376e37 | 2019-11-15 04:06:07 -0500 | [diff] [blame] | 206 | xss "a=rss&p=foo.git&f=$TAG" && |
| 207 | xss "" "$TAG+" |
Jeff King | 0f0ecf6 | 2012-11-12 16:34:28 -0500 | [diff] [blame] | 208 | ' |
Jakub Narebski | 12b1443 | 2011-04-29 19:51:56 +0200 | [diff] [blame] | 209 | |
Jason Yundt | a262585 | 2022-03-08 10:56:12 -0500 | [diff] [blame] | 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 | |
Jason Yundt | 0e1a85c | 2022-06-02 07:43:05 -0400 | [diff] [blame] | 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 | |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 237 | test_done |