#!/bin/sh # Regression tests from the audits of September and October 2026. Each case # is a config, repository or request that used to crash cgit, end it inside # git, or hand a visitor something other than what was asked for. test_description='Check the audit regressions' . ./setup.sh # Writes a config to the file named first, rooted at / with the cache off, # holding the settings named after it in order, for a site cgitrc_repo cannot # describe, a scan or more than one repository say. cgitrc_site() { cgitrc_site_file=$1 shift printf '%s\n' virtual-root=/ cache-size=0 "$@" >"$cgitrc_site_file" } # Fails unless the response in the file named second opens with the status # named first and carries no other, as a page that fails once its headers are # out answers a second time below them. expect_status() { sed -n 1p "$2" >status-line && test_grep "^Status: $1 " status-line && grep "^Status:" "$2" >status-lines && test_line_count = 1 status-lines } # 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) && cgitrc_repo robrc rob snapshots=tar.gz ' test_expect_success 'a repository without a path answers 404' ' cgitrc_site nopathrc repo.url=nopath repo.url=emptypath repo.path= && for r in nopath emptypath do cgit_rc nopathrc "url=$r/log/" >tmp && expect_status 404 tmp && grep "Failed to open $r: Not a valid git repository" tmp || return 1 done ' # 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' ' cgitrc_site nopathagerc repo.url=nopath && mkdir -p "(null)/refs/heads" && >"(null)/refs/heads/master" && cgit_ok nopathagerc "url=" >tmp && test_grep ">nopath" tmp && test_grep "