Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Give each robustness test a fixture of its own
repos/rob took commits, refs, tags, a repack and a moved HEAD from test
after test, so what a test checked hung on the ones before it. A test
that changes a repository, or needs one in a shape of its own, now
builds it, and rob is only read. The tests that leaned on a config or a
scanned repository an earlier test left build their own too.
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/t0303-robustness.sh | 249 |
1 file changed, 143 insertions, 106 deletions
diff --git a/tests/t0303-robustness.sh b/tests/t0303-robustness.sh index 7fa06da..f7409f1 100755 --- a/tests/t0303-robustness.sh +++ b/tests/t0303-robustness.sh @@ -7,6 +7,9 @@ test_description='Check the audit regressions' . ./setup.sh +# The tests that only read a repository share rob, and each test that changes +# one, or needs one in a shape of its own, builds it, so what a test finds +# does not hang on the tests that ran before it. test_expect_success 'set up a repository and a config to vary' ' mkrepo repos/rob 3 && sha=$(git -C repos/rob rev-parse HEAD~1) && @@ -32,9 +35,14 @@ test_expect_success 'a repository without a path answers 404' ' # The index dates a repository from files under its path, and one without a # path has none, whatever sits in the working directory. test_expect_success 'a repository without a path has no age on the index' ' + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "repo.url=nopath" + } >nopathagerc && mkdir -p "(null)/refs/heads" && >"(null)/refs/heads/master" && - cgit_ok nopathrc "url=" >tmp && + cgit_ok nopathagerc "url=" >tmp && test_grep ">nopath</a>" tmp && test_grep "<td class=.col-idle.></td>" tmp && test_grep ! "<time " tmp @@ -106,7 +114,6 @@ test_expect_success 'a valueless or broken git config in a scanned repository is # the request's environment, a visitor's cookie among it, into a page the # cache then serves to others. test_expect_success 'set up a scanned repository setting every key that waits on trust' ' - git clone -q --bare repos/rob/.git scan/b.git && mkrepo scankeys/k 1 && sub=$(git -C scankeys/k rev-parse HEAD) && git -C scankeys/k update-index --add --cacheinfo 160000,$sub,sub && @@ -171,19 +178,25 @@ test_expect_success 'with trust-scan-config the same keys apply' ' # A path on the server waits on trust, and so does a readme ending in a # colon, which names no ref and is read as a path too. test_expect_success 'a filesystem readme from a scanned repository is refused' ' + git clone -q --bare repos/rob/.git readmescan/b.git && echo "outside the repository" >outside && - echo "outside the repository" >"scan/outside:" && + echo "outside the repository" >"readmescan/outside:" && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "scan-path=$PWD/readmescan" + } >readmescanrc && { echo "trust-scan-config=1" && - cat gitcfgrc - } >gitcfgtrustrc && + cat readmescanrc + } >readmescantrustrc && for readme in "$PWD/outside" ../outside: do - echo "readme=$readme" >scan/b.git/cgitrc && - cgit_rc gitcfgrc "url=b.git/about/" >tmp 2>err && + echo "readme=$readme" >readmescan/b.git/cgitrc && + cgit_rc readmescanrc "url=b.git/about/" >tmp 2>err && test_grep "^Status: 302" tmp && - test_grep "Ignoring readme in $PWD/scan/b.git/: trust-scan-config is not set" err && - cgit_rc gitcfgtrustrc "url=b.git/about/" >tmp && + test_grep "Ignoring readme in $PWD/readmescan/b.git/: trust-scan-config is not set" err && + cgit_rc readmescantrustrc "url=b.git/about/" >tmp && test_grep "^Status: 200" tmp && test_grep "outside the repository" tmp || return 1 done @@ -192,9 +205,13 @@ test_expect_success 'a filesystem readme from a scanned repository is refused' ' # The readme list is read as a page is served rather than copied at the # scan-path line, so a readme set after the scan still applies. test_expect_success 'a readme set after scan-path reaches a scanned repository' ' - rm scan/b.git/cgitrc && - cat gitcfgrc >laterrc && - echo "readme=master:file-1" >>laterrc && + git clone -q --bare repos/rob/.git laterscan/b.git && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "scan-path=$PWD/laterscan" && + echo "readme=master:file-1" + } >laterrc && cgit_rc laterrc "url=b.git/about/" >tmp && grep "<pre class=.plaintext.>1$" tmp ' @@ -203,14 +220,10 @@ test_expect_success 'a readme set after scan-path reaches a scanned repository' # the switch waits on trust like the keys that place markup. The warning has # to name the repository, which it did not for a key read from git config. test_expect_success 'html serving from a scanned repository waits on trust' ' - ( - cd repos/rob && - printf "<p>page</p>\n" >page.html && - git add page.html && - git commit -m html - ) && + mkrepo repos/html 1 && + test_commit -C repos/html --no-tag html page.html "<p>page</p>" && mkdir -p scan2 && - git clone -q --bare repos/rob/.git scan2/c.git && + git clone -q --bare repos/html/.git scan2/c.git && git -C scan2/c.git config cgit.enable-html-serving 1 && { echo "virtual-root=/" && @@ -225,6 +238,7 @@ test_expect_success 'html serving from a scanned repository waits on trust' ' grep "Ignoring enable-html-serving in $PWD/scan2/c.git/: trust-scan-config is not set" err ' +# The repository and config are the ones the test above set up. test_expect_success 'with trust-scan-config the same repository serves html' ' { echo "trust-scan-config=1" && @@ -284,32 +298,31 @@ test_expect_success 'a filter that exits without reading does not end cgit' ' ' test_expect_success 'a commit encoding header is read without its newline' ' + mkrepo repos/latin 1 && ( - cd repos/rob && + cd repos/latin && echo more >file-1 && git add file-1 && git -c i18n.commitEncoding=ISO-8859-1 commit -m "$(printf "caf\351")" ) && - cgit_rc robrc "url=rob/commit/" >tmp && + cgitrc_repo latinrc latin && + cgit_rc latinrc "url=latin/commit/" >tmp && grep "<div class=.commit-subject.>caf$(printf "\303\251")<" tmp ' # The about page shows the readme alone and its links lead into the tree, # so a path below it names nothing, the site about page included. test_expect_success 'a path below the about page answers 404' ' + mkrepo repos/about 3 && ( - cd repos/rob && - git update-index --add --cacheinfo 160000,$sha,sub && + cd repos/about && + git update-index --add --cacheinfo 160000,$(git rev-parse HEAD~1),sub && git commit -m gitlink ) && - { - echo "mimetype.png=image/png" && - cat robrc && - echo "repo.readme=master:file-1" - } >aboutrc && - for path in sub sub/ missing.png file-1 ../robrc + cgitrc_repo aboutrc about mimetype.png=image/png repo.readme=master:file-1 && + for path in sub sub/ missing.png file-1 ../aboutrc do - cgit_rc aboutrc "url=rob/about/$path" >tmp 2>err && + cgit_rc aboutrc "url=about/about/$path" >tmp 2>err && grep "^Status: 404" tmp && grep "^Content-Type: text/html" tmp && ! grep fatal err || return 1 @@ -350,19 +363,27 @@ test_expect_success 'a path opening with a colon is refused on the log and patch ' test_expect_success 'a revision spelled like an option is refused' ' - git -C repos/rob update-ref refs/heads/--stdin HEAD && - cgit_rc robrc "url=rob/log/&h=--stdin" >tmp && + mkrepo repos/optref 1 && + git -C repos/optref update-ref refs/heads/--stdin HEAD && + cgitrc_repo optrefrc optref && + cgit_rc optrefrc "url=optref/log/&h=--stdin" >tmp && grep "^Status: 404" tmp && - cgit_rc robrc "url=rob/blame/file-1&id=--stdin" >tmp && + cgit_rc optrefrc "url=optref/blame/file-1&id=--stdin" >tmp && grep "^Status: 400" tmp && - cgit_rc robrc "url=rob/atom/&h=--stdin" >tmp && + cgit_rc optrefrc "url=optref/atom/&h=--stdin" >tmp && grep "^Status: 404" tmp ' +# Three tests read through the annotated tag set up here. +test_expect_success 'set up a repository with an annotated tag' ' + mkrepo repos/tagged 3 && + git -C repos/tagged tag -a -m note ann HEAD && + cgitrc_repo taggedrc tagged +' + test_expect_success 'the blob page reads a file through an annotated tag' ' - git -C repos/rob tag -a -m note ann HEAD && - git -C repos/rob cat-file blob ann:file-1 >want && - cgit_ok robrc "url=rob/blob/&h=ann&path=file-1" >tmp && + git -C repos/tagged cat-file blob ann:file-1 >want && + cgit_ok taggedrc "url=tagged/blob/&h=ann&path=file-1" >tmp && strip_headers <tmp >body && test_cmp want body ' @@ -370,17 +391,17 @@ test_expect_success 'the blob page reads a file through an annotated tag' ' # The plain page walks a path out of whatever commit the id names, and the # blob page used to answer such a request with the raw commit object. test_expect_success 'the blob page walks a path out of the commit or tag the id names' ' - tip=$(git -C repos/rob rev-parse HEAD) && - git -C repos/rob cat-file blob HEAD:file-1 >want && - cgit_ok robrc "url=rob/blob/file-1&id=$tip" >tmp && + tip=$(git -C repos/tagged rev-parse HEAD) && + git -C repos/tagged cat-file blob HEAD:file-1 >want && + cgit_ok taggedrc "url=tagged/blob/file-1&id=$tip" >tmp && strip_headers <tmp >body && test_cmp want body && - tag=$(git -C repos/rob rev-parse ann) && - git -C repos/rob cat-file blob ann:file-1 >want && - cgit_ok robrc "url=rob/blob/file-1&id=$tag" >tmp && + tag=$(git -C repos/tagged rev-parse ann) && + git -C repos/tagged cat-file blob ann:file-1 >want && + cgit_ok taggedrc "url=tagged/blob/file-1&id=$tag" >tmp && strip_headers <tmp >body && test_cmp want body && - cgit_rc robrc "url=rob/blob/missing&id=$tip" >tmp && + cgit_rc taggedrc "url=tagged/blob/missing&id=$tip" >tmp && grep "^Status: 404" tmp ' @@ -519,11 +540,11 @@ test_expect_success 'a filter pipeline sees the default SIGPIPE disposition' ' # Such a branch is refused as a head, so the fallback passes over it, and the # switcher must not offer a choice that can only lead to an error page. test_expect_success 'the fallback branch skips a name spelled like an option' ' - git -C repos/rob update-ref refs/heads/-first HEAD && - test_when_finished "git -C repos/rob update-ref -d refs/heads/-first" && - git -C repos/rob symbolic-ref HEAD refs/heads/gone && - test_when_finished "git -C repos/rob symbolic-ref HEAD refs/heads/master" && - cgit_ok robrc "url=rob/" >tmp && + mkrepo repos/fallback 1 && + git -C repos/fallback update-ref refs/heads/-first HEAD && + git -C repos/fallback symbolic-ref HEAD refs/heads/gone && + cgitrc_repo fallbackrc fallback && + cgit_ok fallbackrc "url=fallback/" >tmp && test_grep "<option value=.master. selected>" tmp && test_grep ! "<option value=.-first." tmp ' @@ -531,18 +552,19 @@ test_expect_success 'the fallback branch skips a name spelled like an option' ' # A cache that stored nothing would pass the first config whatever its ttl, # so a second keeps the same page for ever and has to show it unchanged. test_expect_success 'a refs page named with an id is not cached for ever' ' - cgitrc_repo ttlrc rob cache-size=10 "cache-root=$PWD/ttlcache" \ + mkrepo repos/ttl 1 && + cgitrc_repo ttlrc ttl cache-size=10 "cache-root=$PWD/ttlcache" \ cache-static-ttl=-1 cache-dynamic-ttl=0 cache-summary-ttl=0 && - cgitrc_repo foreverrc rob cache-size=10 "cache-root=$PWD/forevercache" \ + cgitrc_repo foreverrc ttl cache-size=10 "cache-root=$PWD/forevercache" \ cache-static-ttl=-1 cache-dynamic-ttl=-1 cache-summary-ttl=0 && mkdir ttlcache forevercache && - full=$(git -C repos/rob rev-parse HEAD) && - cgit_ok ttlrc "url=rob/refs/&id=$full" >tmp && - cgit_ok foreverrc "url=rob/refs/&id=$full" >tmp && - git -C repos/rob tag later HEAD && - cgit_ok ttlrc "url=rob/refs/&id=$full" >tmp && + full=$(git -C repos/ttl rev-parse HEAD) && + cgit_ok ttlrc "url=ttl/refs/&id=$full" >tmp && + cgit_ok foreverrc "url=ttl/refs/&id=$full" >tmp && + git -C repos/ttl tag later HEAD && + cgit_ok ttlrc "url=ttl/refs/&id=$full" >tmp && test_grep ">later<" tmp && - cgit_ok foreverrc "url=rob/refs/&id=$full" >tmp && + cgit_ok foreverrc "url=ttl/refs/&id=$full" >tmp && test_grep "<tr class=.branch.>" tmp && test_grep ! ">later<" tmp ' @@ -571,8 +593,10 @@ test_expect_success 'the diff caps hold when the path names a directory' ' test_lazy_prereq GZIP 'command -v gzip' test_expect_success GZIP 'a snapshot of a tag spelled like an option is archived' ' - git -C repos/rob update-ref refs/tags/-l HEAD && - cgit_ok robrc "url=rob/snapshot/-l.tar.gz" >tmp && + mkrepo repos/opttag 1 && + git -C repos/opttag update-ref refs/tags/-l HEAD && + cgitrc_repo opttagrc opttag snapshots=tar.gz && + cgit_ok opttagrc "url=opttag/snapshot/-l.tar.gz" >tmp && strip_headers <tmp >archive.tar.gz && gzip -dc archive.tar.gz >archive.tar && tar -tf archive.tar >list && @@ -595,24 +619,22 @@ test_expect_success NO_VALGRIND 'a snapshot format whose compressor is missing a ' test_expect_success 'a disk readme in the repository directory serves no sibling' ' - echo hello >repos/rob/.git/README && - { - cat robrc && - echo "repo.readme=README" - } >diskrc && - cgit_rc diskrc "url=rob/about/" >tmp && + mkrepo repos/disk 1 && + echo hello >repos/disk/.git/README && + cgitrc_repo diskrc disk repo.readme=README && + cgit_rc diskrc "url=disk/about/" >tmp && grep "hello" tmp && - cgit_rc diskrc "url=rob/about/config" >tmp && + cgit_rc diskrc "url=disk/about/config" >tmp && grep "^Status: 404" tmp && ! grep "repositoryformatversion" tmp ' test_expect_success 'a tag pointing at a tag links the inner tag by id' ' - git -C repos/rob tag -a -m outer outer ann && - inner=$(git -C repos/rob rev-parse ann) && - cgit_ok robrc "url=rob/tag/&h=outer" >tmp && - test_grep "<th scope=.row.>tagged object</th><td class=.oid.><a href=./rob/tag/?h=outer&id=$inner.>tag $inner</a>" tmp && - cgit_ok robrc "url=rob/tag/&h=outer&id=$inner" >tmp && + git -C repos/tagged tag -a -m outer outer ann && + inner=$(git -C repos/tagged rev-parse ann) && + cgit_ok taggedrc "url=tagged/tag/&h=outer" >tmp && + test_grep "<th scope=.row.>tagged object</th><td class=.oid.><a href=./tagged/tag/?h=outer&id=$inner.>tag $inner</a>" tmp && + cgit_ok taggedrc "url=tagged/tag/&h=outer&id=$inner" >tmp && test_grep "<th scope=.row.>tag name</th><td>$inner " tmp && test_grep "<div class=.commit-subject.>note</div>" tmp ' @@ -630,16 +652,18 @@ test_expect_success 'the dumb transport serves an empty repository' ' # A pack is handed over as it sits on the disk, so the client can be told # its size up front and compare what arrived against it. test_expect_success 'the dumb transport sends a file with its size' ' - git -C repos/rob repack -q -d && - cgit_rc robrc "url=rob/objects/info/packs" >tmp && + mkrepo repos/packed 1 && + git -C repos/packed repack -q -d && + cgitrc_repo packedrc packed && + cgit_rc packedrc "url=packed/objects/info/packs" >tmp && pack=$(strip_headers <tmp | sed -n "s/^P //p" | head -n 1) && test -n "$pack" && - cgit_rc robrc "url=rob/objects/pack/$pack" >tmp && + cgit_rc packedrc "url=packed/objects/pack/$pack" >tmp && grep "^Status: 200" tmp && - size=$(wc -c <repos/rob/.git/objects/pack/$pack | tr -d " ") && + size=$(wc -c <repos/packed/.git/objects/pack/$pack | tr -d " ") && grep "^Content-Length: $size$" tmp && strip_headers <tmp >body && - cmp body repos/rob/.git/objects/pack/$pack + cmp body repos/packed/.git/objects/pack/$pack ' # A reftable repository keeps only a placeholder in its HEAD file, so the @@ -657,14 +681,19 @@ test_expect_success 'the dumb transport answers HEAD from the refs' ' strip_headers <tmp >head && echo "ref: refs/heads/trunk" >expect && test_cmp expect head && - cgit_rc emptyrc "url=empty/HEAD" >tmp && + git init -q --bare emptyhead.git && + cgitrc_repo emptyheadrc emptyhead "repo.path=$PWD/emptyhead.git" && + cgit_rc emptyheadrc "url=emptyhead/HEAD" >tmp && strip_headers <tmp >head && echo "ref: refs/heads/master" >expect && test_cmp expect head ' test_expect_success 'a reftable repository shows its age on the index' ' - cgit_rc rtrc "url=" >tmp && + git init -q --bare --ref-format=reftable -b trunk rtage.git && + git -C repos/rob push -q "$PWD/rtage.git" master:trunk && + cgitrc_repo rtagerc rtage "repo.path=$PWD/rtage.git" && + cgit_rc rtagerc "url=" >tmp && grep "<td class=.col-idle.><time " tmp ' @@ -672,13 +701,15 @@ test_expect_success 'a reftable repository shows its age on the index' ' # so the request ends quietly instead of dying twice into the log. The page # has to outgrow the pipe for the write after the reader has gone to fail. test_expect_success 'a client that disconnects ends the request quietly' ' + mkrepo repos/long 1 && ( - cd repos/rob && + cd repos/long && awk "BEGIN{for(i=0;i<20000;i++) print \"line \" i}" >long.txt && git add long.txt && git commit -m long ) && - { cgit_rc robrc "url=rob/tree/long.txt" 2>err; echo $? >status; } | test_copy_bytes 1 >/dev/null && + cgitrc_repo longrc long && + { cgit_rc longrc "url=long/tree/long.txt" 2>err; echo $? >status; } | test_copy_bytes 1 >/dev/null && test "$(cat status)" = 0 && ! grep -i "broken pipe" err && ! grep "die()" err @@ -707,25 +738,26 @@ test_expect_success 'pages behind an auth filter are marked private' ' # A repository without a readme sends its about page to the summary, and # the branch asked for has to survive that hop. test_expect_success 'the about redirect keeps the query string' ' - git -C repos/rob branch other HEAD && - cgit_rc robrc "url=rob/about&h=other&x=1" >tmp && + mkrepo repos/redirect 1 && + git -C repos/redirect branch other HEAD && + cgitrc_repo redirectrc redirect && + cgit_rc redirectrc "url=redirect/about&h=other&x=1" >tmp && grep "^Status: 302" tmp && - grep "^Location: /rob/?h=other&x=1$" tmp && - cgit_rc aboutrc "url=rob/about&h=other" >tmp && + grep "^Location: /redirect/?h=other&x=1$" tmp && + cgitrc_repo redirectreadmerc redirect repo.readme=master:file-1 && + cgit_rc redirectreadmerc "url=redirect/about&h=other" >tmp && grep "^Status: 200" tmp ' # A readme named without a branch is read from the head being browsed, and an # annotated tag reaches its commit only through the tag object. test_expect_success 'the readme follows an annotated tag as the head' ' - git -C repos/rob tag -a -m release v1 HEAD && - { - cat robrc && - echo "repo.readme=:file-1" - } >tagreadmerc && - cgit_rc tagreadmerc "url=rob/about/&h=v1" >tmp && + mkrepo repos/tagreadme 1 && + git -C repos/tagreadme tag -a -m release v1 HEAD && + cgitrc_repo tagreadmerc tagreadme repo.readme=:file-1 && + cgit_rc tagreadmerc "url=tagreadme/about/&h=v1" >tmp && grep "^Status: 200" tmp && - cgit_rc tagreadmerc "url=rob/tree/&h=v1" >tmp && + cgit_rc tagreadmerc "url=tagreadme/tree/&h=v1" >tmp && grep ">about<" tmp ' @@ -736,15 +768,17 @@ test_expect_success 'the about redirect encodes the repository url once' ' ' test_expect_success 'a symlink whose target is a large blob is listed without it' ' + mkrepo repos/biglink 1 && printf "%05000d" 0 | tr 0 a >big-target && - big=$(git -C repos/rob hash-object -w --stdin <big-target) && - test $(git -C repos/rob cat-file -s $big) = 5000 && + big=$(git -C repos/biglink hash-object -w --stdin <big-target) && + test $(git -C repos/biglink cat-file -s $big) = 5000 && ( - cd repos/rob && + cd repos/biglink && git update-index --add --cacheinfo 120000,$big,biglink && git commit -m biglink ) && - cgit_ok robrc "url=rob/tree/" >tmp && + cgitrc_repo biglinkrc biglink && + cgit_ok biglinkrc "url=biglink/tree/" >tmp && test_grep "<tr class=.link.>.*>biglink</a></td><td class=.ls-size.>5000<" tmp && test_grep ! "aaaaaaaaaa" tmp ' @@ -780,15 +814,12 @@ test_expect_success SANITY 'a scan entry that cannot be searched is named in ful # A readme past max-blob-size is never read, so the about page says why it # has nothing to show. test_expect_success 'a readme past max-blob-size is reported on the about page' ' - test_seq 1 1000 >repos/rob/big-readme && - git -C repos/rob add big-readme && - git -C repos/rob commit -q -m "big readme" && - { - echo "max-blob-size=1" && - cat robrc && - echo "repo.readme=:big-readme" - } >bigreadmerc && - cgit_rc bigreadmerc "url=rob/about/" >tmp && + mkrepo repos/bigreadme 1 && + test_seq 1 1000 >repos/bigreadme/big-readme && + git -C repos/bigreadme add big-readme && + git -C repos/bigreadme commit -q -m "big readme" && + cgitrc_repo bigreadmerc bigreadme max-blob-size=1 repo.readme=:big-readme && + cgit_rc bigreadmerc "url=bigreadme/about/" >tmp && grep "The readme is larger than max-blob-size (1 KB)" tmp ' @@ -860,10 +891,16 @@ test_expect_success 'a notes ref that names no tree is passed over' ' # The path runs through refs/heads, which reftable keeps as a file, so only # the files backend shows the escape. test_expect_success REFFILES 'a scanned defbranch cannot name a path outside the repository' ' + git clone -q --bare repos/rob/.git defscan/b.git && mkdir -p secret && touch -t 200001010000 secret/file && - echo "defbranch=../../../../secret/file" >scan/b.git/cgitrc && - cgit_rc gitcfgrc "url=" >tmp && + echo "defbranch=../../../../secret/file" >defscan/b.git/cgitrc && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "scan-path=$PWD/defscan" + } >defscanrc && + cgit_rc defscanrc "url=" >tmp && grep ">b.git</a>" tmp && ! grep "data-ut=.946" tmp ' |
