Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t9502-gitweb-standalone-parse-output.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t9502-gitweb-standalone-parse-output.sh` 250 lines ยท 7549 bytes Raw Blame History 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=main 14 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 15 16 . ./lib-gitweb.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 " []" 34 # 35 # This will check that gitweb HTTP header contains proposed filename 36 # as with '.tar' suffix added, and that generated tarfile 37 # (gitweb message body) has as prefix for all files in tarfile 38 # 39 # default to 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 (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" 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/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" 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 test_grep ! "filename=.*/" gitweb.headers 115 ' 116 test_debug 'cat gitweb.headers' 117 118 test_expect_success 'commitdiff: index line shortens hashes with mode' ' 119 old_blob=$(git rev-parse HEAD:foo) && 120 old_short=$(git rev-parse --short=7 HEAD:foo) && 121 echo changed >foo && 122 git commit -am "change foo" && 123 new_blob=$(git rev-parse HEAD:foo) && 124 new_short=$(git rev-parse --short=7 HEAD:foo) && 125 gitweb_run "p=.git;a=commitdiff;h=HEAD" && 126 test_grep ">${old_short}\\.\\.]*>${new_short} 100644 (file)" \ 127 gitweb.body && 128 test_grep ! "index ${old_blob}\\.\\.${new_blob} 100644" gitweb.body 129 ' 130 131 # ---------------------------------------------------------------------- 132 # forks of projects 133 134 test_expect_success 'forks: setup' ' 135 git init --bare foo.git && 136 echo file > file && 137 git --git-dir=foo.git --work-tree=. add file && 138 git --git-dir=foo.git --work-tree=. commit -m "Initial commit" && 139 echo "foo" > foo.git/description && 140 git clone --bare foo.git foo.bar.git && 141 echo "foo.bar" > foo.bar.git/description && 142 git clone --bare foo.git foo_baz.git && 143 echo "foo_baz" > foo_baz.git/description && 144 rm -fr foo && 145 mkdir -p foo && 146 ( 147 cd foo && 148 git clone --shared --bare ../foo.git foo-forked.git && 149 echo "fork of foo" > foo-forked.git/description 150 ) 151 ' 152 153 test_expect_success 'forks: not skipped unless "forks" feature enabled' ' 154 gitweb_run "a=project_list" && 155 test_grep -q ">\\.git<" gitweb.body && 156 test_grep -q ">foo\\.git<" gitweb.body && 157 test_grep -q ">foo_baz\\.git<" gitweb.body && 158 test_grep -q ">foo\\.bar\\.git<" gitweb.body && 159 test_grep -q ">foo_baz\\.git<" gitweb.body && 160 test_grep -q ">foo/foo-forked\\.git<" gitweb.body && 161 test_grep -q ">fork of .*<" gitweb.body 162 ' 163 164 test_expect_success 'enable forks feature' ' 165 cat >>gitweb_config.perl <<-\EOF 166 $feature{"forks"}{"default"} = [1]; 167 EOF 168 ' 169 170 test_expect_success 'forks: forks skipped if "forks" feature enabled' ' 171 gitweb_run "a=project_list" && 172 test_grep -q ">\\.git<" gitweb.body && 173 test_grep -q ">foo\\.git<" gitweb.body && 174 test_grep -q ">foo_baz\\.git<" gitweb.body && 175 test_grep -q ">foo\\.bar\\.git<" gitweb.body && 176 test_grep -q ">foo_baz\\.git<" gitweb.body && 177 test_grep -v ">foo/foo-forked\\.git<" gitweb.body && 178 test_grep -v ">fork of .*<" gitweb.body 179 ' 180 181 test_expect_success 'forks: "forks" action for forked repository' ' 182 gitweb_run "p=foo.git;a=forks" && 183 test_grep -q ">foo/foo-forked\\.git<" gitweb.body && 184 test_grep -q ">fork of foo<" gitweb.body 185 ' 186 187 test_expect_success 'forks: can access forked repository' ' 188 gitweb_run "p=foo/foo-forked.git;a=summary" && 189 test_grep -q "200 OK" gitweb.headers && 190 test_grep -q ">fork of foo<" gitweb.body 191 ' 192 193 test_expect_success 'forks: project_index lists all projects (incl. forks)' ' 194 cat >expected <<-\EOF && 195 .git 196 foo.bar.git 197 foo.git 198 foo/foo-forked.git 199 foo_baz.git 200 EOF 201 gitweb_run "a=project_index" && 202 sed -e "s/ .*//" actual && 203 test_cmp expected actual 204 ' 205 206 xss() { 207 echo >&2 "Checking $*..." && 208 gitweb_run "$@" && 209 if grep "$TAG" gitweb.body; then 210 echo >&2 "xss: $TAG should have been quoted in output" 211 return 1 212 fi 213 return 0 214 } 215 216 test_expect_success 'xss checks' ' 217 TAG="" && 218 xss "a=rss&p=$TAG" && 219 xss "a=rss&p=foo.git&f=$TAG" && 220 xss "" "$TAG+" 221 ' 222 223 no_http_equiv_content_type() { 224 gitweb_run "$@" && 225 ! grep -E "http-equiv=['\"]?content-type" gitweb.body 226 } 227 228 # See: 229 test_expect_success 'no http-equiv="content-type" in XHTML' ' 230 no_http_equiv_content_type && 231 no_http_equiv_content_type "p=.git" && 232 no_http_equiv_content_type "p=.git;a=log" && 233 no_http_equiv_content_type "p=.git;a=tree" 234 ' 235 236 proper_doctype() { 237 gitweb_run "$@" && 238 grep -F "