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 | |
| 13 | . ./gitweb-lib.sh |
| 14 | |
| 15 | # ---------------------------------------------------------------------- |
| 16 | # snapshot file name and prefix |
| 17 | |
| 18 | cat >>gitweb_config.perl <<\EOF |
| 19 | |
| 20 | $known_snapshot_formats{'tar'} = { |
| 21 | 'display' => 'tar', |
| 22 | 'type' => 'application/x-tar', |
| 23 | 'suffix' => '.tar', |
| 24 | 'format' => 'tar', |
| 25 | }; |
| 26 | |
| 27 | $feature{'snapshot'}{'default'} = ['tar']; |
| 28 | EOF |
| 29 | |
| 30 | # Call check_snapshot with the arguments "<basename> [<prefix>]" |
| 31 | # |
| 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 |
| 35 | # |
| 36 | # <prefix> default to <basename> |
| 37 | check_snapshot () { |
| 38 | basename=$1 |
| 39 | prefix=${2:-"$1"} |
| 40 | echo "basename=$basename" |
| 41 | grep "filename=.*$basename.tar" gitweb.headers >/dev/null 2>&1 && |
| 42 | "$TAR" tf gitweb.body >file_list && |
Junio C Hamano | 2060ed5 | 2012-12-18 20:57:13 -0800 | [diff] [blame] | 43 | ! grep -v -e "^$prefix$" -e "^$prefix/" -e "^pax_global_header$" file_list |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | test_expect_success setup ' |
| 47 | test_commit first foo && |
| 48 | git branch xx/test && |
| 49 | FULL_ID=$(git rev-parse --verify HEAD) && |
| 50 | SHORT_ID=$(git rev-parse --verify --short=7 HEAD) |
| 51 | ' |
| 52 | test_debug ' |
| 53 | echo "FULL_ID = $FULL_ID" |
| 54 | echo "SHORT_ID = $SHORT_ID" |
| 55 | ' |
| 56 | |
| 57 | test_expect_success 'snapshot: full sha1' ' |
| 58 | gitweb_run "p=.git;a=snapshot;h=$FULL_ID;sf=tar" && |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 59 | check_snapshot ".git-$SHORT_ID" |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 60 | ' |
| 61 | test_debug 'cat gitweb.headers && cat file_list' |
| 62 | |
| 63 | test_expect_success 'snapshot: shortened sha1' ' |
| 64 | gitweb_run "p=.git;a=snapshot;h=$SHORT_ID;sf=tar" && |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 65 | check_snapshot ".git-$SHORT_ID" |
| 66 | ' |
| 67 | test_debug 'cat gitweb.headers && cat file_list' |
| 68 | |
| 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" |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 73 | ' |
| 74 | test_debug 'cat gitweb.headers && cat file_list' |
| 75 | |
| 76 | test_expect_success 'snapshot: HEAD' ' |
| 77 | gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tar" && |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 78 | check_snapshot ".git-HEAD-$SHORT_ID" |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 79 | ' |
| 80 | test_debug 'cat gitweb.headers && cat file_list' |
| 81 | |
| 82 | test_expect_success 'snapshot: short branch name (master)' ' |
| 83 | gitweb_run "p=.git;a=snapshot;h=master;sf=tar" && |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 84 | ID=$(git rev-parse --verify --short=7 master) && |
| 85 | check_snapshot ".git-master-$ID" |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 86 | ' |
| 87 | test_debug 'cat gitweb.headers && cat file_list' |
| 88 | |
Mark Rada | b629275 | 2009-11-07 16:13:29 +0100 | [diff] [blame] | 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" |
| 93 | ' |
| 94 | test_debug 'cat gitweb.headers && cat file_list' |
| 95 | |
| 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" |
| 100 | ' |
| 101 | test_debug 'cat gitweb.headers && cat file_list' |
| 102 | |
| 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" |
| 106 | ' |
| 107 | test_debug 'cat gitweb.headers && cat file_list' |
| 108 | |
| 109 | test_expect_success 'snapshot: hierarchical branch name (xx/test)' ' |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 110 | gitweb_run "p=.git;a=snapshot;h=xx/test;sf=tar" && |
| 111 | ! grep "filename=.*/" gitweb.headers |
| 112 | ' |
| 113 | test_debug 'cat gitweb.headers' |
| 114 | |
Jakub Narebski | 12b1443 | 2011-04-29 19:51:56 +0200 | [diff] [blame] | 115 | # ---------------------------------------------------------------------- |
| 116 | # forks of projects |
| 117 | |
| 118 | test_expect_success 'forks: setup' ' |
| 119 | git init --bare foo.git && |
| 120 | echo file > file && |
| 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 && |
| 128 | rm -fr foo && |
| 129 | mkdir -p foo && |
| 130 | ( |
| 131 | cd foo && |
| 132 | git clone --shared --bare ../foo.git foo-forked.git && |
| 133 | echo "fork of foo" > foo-forked.git/description |
| 134 | ) |
| 135 | ' |
| 136 | |
| 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 |
| 146 | ' |
| 147 | |
Jeff King | d8cd327 | 2015-03-20 06:13:01 -0400 | [diff] [blame] | 148 | test_expect_success 'enable forks feature' ' |
| 149 | cat >>gitweb_config.perl <<-\EOF |
| 150 | $feature{"forks"}{"default"} = [1]; |
| 151 | EOF |
| 152 | ' |
Jakub Narebski | 12b1443 | 2011-04-29 19:51:56 +0200 | [diff] [blame] | 153 | |
| 154 | test_expect_success 'forks: forks skipped if "forks" feature enabled' ' |
| 155 | gitweb_run "a=project_list" && |
| 156 | grep -q ">\\.git<" gitweb.body && |
| 157 | grep -q ">foo\\.git<" gitweb.body && |
| 158 | grep -q ">foo_baz\\.git<" gitweb.body && |
| 159 | grep -q ">foo\\.bar\\.git<" gitweb.body && |
| 160 | grep -q ">foo_baz\\.git<" gitweb.body && |
| 161 | grep -v ">foo/foo-forked\\.git<" gitweb.body && |
| 162 | grep -v ">fork of .*<" gitweb.body |
| 163 | ' |
| 164 | |
| 165 | test_expect_success 'forks: "forks" action for forked repository' ' |
| 166 | gitweb_run "p=foo.git;a=forks" && |
| 167 | grep -q ">foo/foo-forked\\.git<" gitweb.body && |
| 168 | grep -q ">fork of foo<" gitweb.body |
| 169 | ' |
| 170 | |
| 171 | test_expect_success 'forks: can access forked repository' ' |
| 172 | gitweb_run "p=foo/foo-forked.git;a=summary" && |
| 173 | grep -q "200 OK" gitweb.headers && |
| 174 | grep -q ">fork of foo<" gitweb.body |
| 175 | ' |
| 176 | |
| 177 | test_expect_success 'forks: project_index lists all projects (incl. forks)' ' |
Jeff King | d8cd327 | 2015-03-20 06:13:01 -0400 | [diff] [blame] | 178 | cat >expected <<-\EOF && |
Jakub Narebski | 12b1443 | 2011-04-29 19:51:56 +0200 | [diff] [blame] | 179 | .git |
| 180 | foo.bar.git |
| 181 | foo.git |
| 182 | foo/foo-forked.git |
| 183 | foo_baz.git |
| 184 | EOF |
| 185 | gitweb_run "a=project_index" && |
| 186 | sed -e "s/ .*//" <gitweb.body | sort >actual && |
| 187 | test_cmp expected actual |
| 188 | ' |
| 189 | |
Jeff King | 0f0ecf6 | 2012-11-12 16:34:28 -0500 | [diff] [blame] | 190 | xss() { |
| 191 | echo >&2 "Checking $1..." && |
| 192 | gitweb_run "$1" && |
| 193 | if grep "$TAG" gitweb.body; then |
| 194 | echo >&2 "xss: $TAG should have been quoted in output" |
| 195 | return 1 |
| 196 | fi |
| 197 | return 0 |
| 198 | } |
| 199 | |
| 200 | test_expect_success 'xss checks' ' |
| 201 | TAG="<magic-xss-tag>" && |
| 202 | xss "a=rss&p=$TAG" && |
| 203 | xss "a=rss&p=foo.git&f=$TAG" |
| 204 | ' |
Jakub Narebski | 12b1443 | 2011-04-29 19:51:56 +0200 | [diff] [blame] | 205 | |
Jakub Narebski | 3ce9450 | 2009-11-07 16:13:28 +0100 | [diff] [blame] | 206 | test_done |