Jonathan Nieder | c74c720 | 2013-11-25 13:03:06 -0800 | [diff] [blame] | 1 | # Shell library to run an HTTP server for use in tests. |
| 2 | # Ends the test early if httpd tests should not be run, |
| 3 | # for example because the user has not enabled them. |
| 4 | # |
| 5 | # Usage: |
| 6 | # |
| 7 | # . ./test-lib.sh |
| 8 | # . "$TEST_DIRECTORY"/lib-httpd.sh |
| 9 | # start_httpd |
| 10 | # |
| 11 | # test_expect_success '...' ' |
| 12 | # ... |
| 13 | # ' |
| 14 | # |
| 15 | # test_expect_success ... |
| 16 | # |
Jonathan Nieder | c74c720 | 2013-11-25 13:03:06 -0800 | [diff] [blame] | 17 | # test_done |
| 18 | # |
| 19 | # Can be configured using the following variables. |
| 20 | # |
| 21 | # GIT_TEST_HTTPD enable HTTPD tests |
| 22 | # LIB_HTTPD_PATH web server path |
| 23 | # LIB_HTTPD_MODULE_PATH web server modules path |
| 24 | # LIB_HTTPD_PORT listening port |
| 25 | # LIB_HTTPD_DAV enable DAV |
Eric Wong | a8a5d25 | 2016-07-23 04:26:08 +0000 | [diff] [blame] | 26 | # LIB_HTTPD_SVN enable SVN at given location (e.g. "svn") |
Jonathan Nieder | c74c720 | 2013-11-25 13:03:06 -0800 | [diff] [blame] | 27 | # LIB_HTTPD_SSL enable SSL |
Jeff King | 29ae2c9 | 2023-02-16 15:56:32 -0500 | [diff] [blame] | 28 | # LIB_HTTPD_PROXY enable proxy |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 29 | # |
| 30 | # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> |
| 31 | # |
| 32 | |
Ævar Arnfjörð Bjarmason | 7596fe9 | 2022-06-15 12:36:32 +0200 | [diff] [blame] | 33 | if ! test_have_prereq LIBCURL |
Jeff King | c9d441a | 2015-05-06 13:42:29 -0400 | [diff] [blame] | 34 | then |
| 35 | skip_all='skipping test, git built without http support' |
| 36 | test_done |
| 37 | fi |
| 38 | |
Junio C Hamano | 309a9e3 | 2015-05-07 09:06:14 -0700 | [diff] [blame] | 39 | if test -n "$NO_EXPAT" && test -n "$LIB_HTTPD_DAV" |
| 40 | then |
| 41 | skip_all='skipping test, git built without expat support' |
| 42 | test_done |
| 43 | fi |
| 44 | |
SZEDER Gábor | 43a2afe | 2019-11-22 14:14:36 +0100 | [diff] [blame] | 45 | if ! test_bool_env GIT_TEST_HTTPD true |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 46 | then |
Jeff King | 83d842d | 2014-02-10 16:29:37 -0500 | [diff] [blame] | 47 | skip_all="Network testing disabled (unset GIT_TEST_HTTPD to enable)" |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 48 | test_done |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 49 | fi |
| 50 | |
Jeff King | 1767c51 | 2015-01-16 04:16:49 -0500 | [diff] [blame] | 51 | if ! test_have_prereq NOT_ROOT; then |
Ævar Arnfjörð Bjarmason | 3b072c5 | 2019-06-21 12:18:11 +0200 | [diff] [blame] | 52 | test_skip_or_die GIT_TEST_HTTPD \ |
Jeff King | a1a3011 | 2014-05-10 10:02:59 -0400 | [diff] [blame] | 53 | "Cannot run httpd tests as root" |
| 54 | fi |
| 55 | |
Jay Soffian | 69707d6 | 2009-02-25 03:28:15 -0500 | [diff] [blame] | 56 | HTTPD_PARA="" |
| 57 | |
Patrick Steinhardt | 7d05974 | 2023-11-10 09:17:00 +0100 | [diff] [blame] | 58 | for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' \ |
| 59 | '/usr/sbin/apache2' \ |
| 60 | "$(command -v httpd)" \ |
| 61 | "$(command -v apache2)" |
Tarmigan Casebolt | 0d34473 | 2010-01-02 14:04:25 -0800 | [diff] [blame] | 62 | do |
Patrick Steinhardt | 7d05974 | 2023-11-10 09:17:00 +0100 | [diff] [blame] | 63 | if test -n "$DEFAULT_HTTPD_PATH" && test -x "$DEFAULT_HTTPD_PATH" |
Tarmigan Casebolt | 0d34473 | 2010-01-02 14:04:25 -0800 | [diff] [blame] | 64 | then |
| 65 | break |
| 66 | fi |
| 67 | done |
| 68 | |
Patrick Steinhardt | 7d05974 | 2023-11-10 09:17:00 +0100 | [diff] [blame] | 69 | if test -x "$DEFAULT_HTTPD_PATH" |
| 70 | then |
| 71 | DETECTED_HTTPD_ROOT="$("$DEFAULT_HTTPD_PATH" -V 2>/dev/null | sed -n 's/^ -D HTTPD_ROOT="\(.*\)"$/\1/p')" |
| 72 | fi |
| 73 | |
Tarmigan Casebolt | 0d34473 | 2010-01-02 14:04:25 -0800 | [diff] [blame] | 74 | for DEFAULT_HTTPD_MODULE_PATH in '/usr/libexec/apache2' \ |
| 75 | '/usr/lib/apache2/modules' \ |
| 76 | '/usr/lib64/httpd/modules' \ |
Eric Sunshine | 1c7dc23 | 2022-11-21 03:01:35 +0000 | [diff] [blame] | 77 | '/usr/lib/httpd/modules' \ |
Patrick Steinhardt | 7d05974 | 2023-11-10 09:17:00 +0100 | [diff] [blame] | 78 | '/usr/libexec/httpd' \ |
Junio C Hamano | 14a4445 | 2023-12-09 16:37:48 -0800 | [diff] [blame] | 79 | '/usr/lib/apache2' \ |
Patrick Steinhardt | 7d05974 | 2023-11-10 09:17:00 +0100 | [diff] [blame] | 80 | "${DETECTED_HTTPD_ROOT:+${DETECTED_HTTPD_ROOT}/modules}" |
Tarmigan Casebolt | 0d34473 | 2010-01-02 14:04:25 -0800 | [diff] [blame] | 81 | do |
Patrick Steinhardt | 7d05974 | 2023-11-10 09:17:00 +0100 | [diff] [blame] | 82 | if test -n "$DEFAULT_HTTPD_MODULE_PATH" && test -d "$DEFAULT_HTTPD_MODULE_PATH" |
Tarmigan Casebolt | 0d34473 | 2010-01-02 14:04:25 -0800 | [diff] [blame] | 83 | then |
| 84 | break |
| 85 | fi |
| 86 | done |
| 87 | |
Jay Soffian | 69707d6 | 2009-02-25 03:28:15 -0500 | [diff] [blame] | 88 | case $(uname) in |
| 89 | Darwin) |
Jay Soffian | 69707d6 | 2009-02-25 03:28:15 -0500 | [diff] [blame] | 90 | HTTPD_PARA="$HTTPD_PARA -DDarwin" |
| 91 | ;; |
Jay Soffian | 69707d6 | 2009-02-25 03:28:15 -0500 | [diff] [blame] | 92 | esac |
| 93 | |
| 94 | LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"} |
SZEDER Gábor | fa84058 | 2019-01-05 02:08:58 +0100 | [diff] [blame] | 95 | test_set_port LIB_HTTPD_PORT |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 96 | |
Junio C Hamano | bfdbee9 | 2008-08-08 02:26:28 -0700 | [diff] [blame] | 97 | TEST_PATH="$TEST_DIRECTORY"/lib-httpd |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 98 | HTTPD_ROOT_PATH="$PWD"/httpd |
| 99 | HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www |
| 100 | |
Jeff King | f628825 | 2012-07-24 09:43:59 -0400 | [diff] [blame] | 101 | # hack to suppress apache PassEnv warnings |
| 102 | GIT_VALGRIND=$GIT_VALGRIND; export GIT_VALGRIND |
| 103 | GIT_VALGRIND_OPTIONS=$GIT_VALGRIND_OPTIONS; export GIT_VALGRIND_OPTIONS |
Todd Zullinger | e18edc7 | 2019-02-14 01:35:13 -0500 | [diff] [blame] | 104 | GIT_TEST_SIDEBAND_ALL=$GIT_TEST_SIDEBAND_ALL; export GIT_TEST_SIDEBAND_ALL |
Jeff King | 89c57ab | 2015-03-13 00:51:15 -0400 | [diff] [blame] | 105 | GIT_TRACE=$GIT_TRACE; export GIT_TRACE |
Jeff King | f628825 | 2012-07-24 09:43:59 -0400 | [diff] [blame] | 106 | |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 107 | if ! test -x "$LIB_HTTPD_PATH" |
| 108 | then |
Ævar Arnfjörð Bjarmason | 3b072c5 | 2019-06-21 12:18:11 +0200 | [diff] [blame] | 109 | test_skip_or_die GIT_TEST_HTTPD "no web server found at '$LIB_HTTPD_PATH'" |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 110 | fi |
| 111 | |
Elia Pinto | e429dfd | 2015-12-22 15:10:30 +0100 | [diff] [blame] | 112 | HTTPD_VERSION=$($LIB_HTTPD_PATH -v | \ |
Jeff King | d762617 | 2023-02-01 06:37:21 -0500 | [diff] [blame] | 113 | sed -n 's/^Server version: Apache\/\([0-9.]*\).*$/\1/p; q') |
| 114 | HTTPD_VERSION_MAJOR=$(echo $HTTPD_VERSION | cut -d. -f1) |
| 115 | HTTPD_VERSION_MINOR=$(echo $HTTPD_VERSION | cut -d. -f2) |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 116 | |
Jeff King | d762617 | 2023-02-01 06:37:21 -0500 | [diff] [blame] | 117 | if test -n "$HTTPD_VERSION_MAJOR" |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 118 | then |
| 119 | if test -z "$LIB_HTTPD_MODULE_PATH" |
| 120 | then |
Jeff King | d762617 | 2023-02-01 06:37:21 -0500 | [diff] [blame] | 121 | if ! test "$HTTPD_VERSION_MAJOR" -eq 2 || |
Jeff King | edd060d | 2023-02-01 06:38:24 -0500 | [diff] [blame] | 122 | ! test "$HTTPD_VERSION_MINOR" -ge 4 |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 123 | then |
Ævar Arnfjörð Bjarmason | 3b072c5 | 2019-06-21 12:18:11 +0200 | [diff] [blame] | 124 | test_skip_or_die GIT_TEST_HTTPD \ |
Jeff King | edd060d | 2023-02-01 06:38:24 -0500 | [diff] [blame] | 125 | "at least Apache version 2.4 is required" |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 126 | fi |
Tarmigan Casebolt | 0d34473 | 2010-01-02 14:04:25 -0800 | [diff] [blame] | 127 | if ! test -d "$DEFAULT_HTTPD_MODULE_PATH" |
| 128 | then |
Ævar Arnfjörð Bjarmason | 3b072c5 | 2019-06-21 12:18:11 +0200 | [diff] [blame] | 129 | test_skip_or_die GIT_TEST_HTTPD \ |
Jeff King | 83d842d | 2014-02-10 16:29:37 -0500 | [diff] [blame] | 130 | "Apache module directory not found" |
Tarmigan Casebolt | 0d34473 | 2010-01-02 14:04:25 -0800 | [diff] [blame] | 131 | fi |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 132 | |
Jay Soffian | 69707d6 | 2009-02-25 03:28:15 -0500 | [diff] [blame] | 133 | LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH" |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 134 | fi |
| 135 | else |
Ævar Arnfjörð Bjarmason | 3b072c5 | 2019-06-21 12:18:11 +0200 | [diff] [blame] | 136 | test_skip_or_die GIT_TEST_HTTPD \ |
Jeff King | 83d842d | 2014-02-10 16:29:37 -0500 | [diff] [blame] | 137 | "Could not identify web server at '$LIB_HTTPD_PATH'" |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 138 | fi |
| 139 | |
Patrick Steinhardt | 0d3911a | 2023-11-09 09:05:50 +0100 | [diff] [blame] | 140 | if test -n "$LIB_HTTPD_DAV" && test -f /etc/os-release |
| 141 | then |
| 142 | case "$(grep "^ID=" /etc/os-release | cut -d= -f2-)" in |
| 143 | alpine) |
| 144 | # The WebDAV module in Alpine Linux is broken at least up to |
| 145 | # Alpine v3.16 as the default DBM driver is missing. |
| 146 | # |
| 147 | # https://gitlab.alpinelinux.org/alpine/aports/-/issues/13112 |
| 148 | test_skip_or_die GIT_TEST_HTTPD \ |
| 149 | "Apache WebDAV module does not have default DBM backend driver" |
| 150 | ;; |
| 151 | esac |
| 152 | fi |
| 153 | |
Jeff King | c7db2d1 | 2014-05-22 05:28:56 -0400 | [diff] [blame] | 154 | install_script () { |
| 155 | write_script "$HTTPD_ROOT_PATH/$1" <"$TEST_PATH/$1" |
| 156 | } |
| 157 | |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 158 | prepare_httpd() { |
Mike Hommey | 13b5481 | 2008-07-07 21:02:37 +0200 | [diff] [blame] | 159 | mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH" |
Gabriel Corona | 3cf8fe1 | 2010-11-14 02:51:14 +0100 | [diff] [blame] | 160 | cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH" |
Jeff King | 29ae2c9 | 2023-02-16 15:56:32 -0500 | [diff] [blame] | 161 | cp "$TEST_PATH"/proxy-passwd "$HTTPD_ROOT_PATH" |
Denton Liu | 74b082a | 2020-05-19 06:53:58 -0400 | [diff] [blame] | 162 | install_script incomplete-length-upload-pack-v2-http.sh |
| 163 | install_script incomplete-body-upload-pack-v2-http.sh |
Jeff King | e4c9538 | 2021-10-18 15:43:47 -0400 | [diff] [blame] | 164 | install_script error-no-report.sh |
Jeff King | c7db2d1 | 2014-05-22 05:28:56 -0400 | [diff] [blame] | 165 | install_script broken-smart-http.sh |
Josh Steadmon | 30dea56 | 2019-02-06 14:19:10 -0500 | [diff] [blame] | 166 | install_script error-smart-http.sh |
Jeff King | dbcf2bd | 2014-05-22 05:29:03 -0400 | [diff] [blame] | 167 | install_script error.sh |
Johannes Schindelin | eafff6e | 2020-02-27 13:23:11 +0000 | [diff] [blame] | 168 | install_script apply-one-time-perl.sh |
Matthew John Cheetham | 988aad9 | 2023-02-27 17:20:18 +0000 | [diff] [blame] | 169 | install_script nph-custom-auth.sh |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 170 | |
Mike Hommey | 13b5481 | 2008-07-07 21:02:37 +0200 | [diff] [blame] | 171 | ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules" |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 172 | |
| 173 | if test -n "$LIB_HTTPD_SSL" |
| 174 | then |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 175 | HTTPD_PROTO=https |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 176 | |
| 177 | RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \ |
Mike Hommey | 13b5481 | 2008-07-07 21:02:37 +0200 | [diff] [blame] | 178 | -config "$TEST_PATH/ssl.cnf" \ |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 179 | -new -x509 -nodes \ |
Mike Hommey | 13b5481 | 2008-07-07 21:02:37 +0200 | [diff] [blame] | 180 | -out "$HTTPD_ROOT_PATH/httpd.pem" \ |
| 181 | -keyout "$HTTPD_ROOT_PATH/httpd.pem" |
Bryan Donlan | 0e46e70 | 2008-05-04 01:37:58 -0400 | [diff] [blame] | 182 | GIT_SSL_NO_VERIFY=t |
| 183 | export GIT_SSL_NO_VERIFY |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 184 | HTTPD_PARA="$HTTPD_PARA -DSSL" |
| 185 | else |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 186 | HTTPD_PROTO=http |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 187 | fi |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 188 | HTTPD_DEST=127.0.0.1:$LIB_HTTPD_PORT |
| 189 | HTTPD_URL=$HTTPD_PROTO://$HTTPD_DEST |
| 190 | HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 191 | HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:pass%40host@$HTTPD_DEST |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 192 | |
Elia Pinto | ce5dadb | 2014-06-06 07:55:54 -0700 | [diff] [blame] | 193 | if test -n "$LIB_HTTPD_DAV" || test -n "$LIB_HTTPD_SVN" |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 194 | then |
| 195 | HTTPD_PARA="$HTTPD_PARA -DDAV" |
| 196 | |
| 197 | if test -n "$LIB_HTTPD_SVN" |
| 198 | then |
| 199 | HTTPD_PARA="$HTTPD_PARA -DSVN" |
Eric Wong | a8a5d25 | 2016-07-23 04:26:08 +0000 | [diff] [blame] | 200 | LIB_HTTPD_SVNPATH="$rawsvnrepo" |
| 201 | svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/" |
| 202 | svnrepo="$svnrepo$LIB_HTTPD_SVN" |
| 203 | export LIB_HTTPD_SVN LIB_HTTPD_SVNPATH |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 204 | fi |
| 205 | fi |
Jeff King | 29ae2c9 | 2023-02-16 15:56:32 -0500 | [diff] [blame] | 206 | |
| 207 | if test -n "$LIB_HTTPD_PROXY" |
| 208 | then |
| 209 | HTTPD_PARA="$HTTPD_PARA -DPROXY" |
| 210 | fi |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 211 | } |
| 212 | |
Jeff King | 73c49a4 | 2022-11-11 22:35:05 +0000 | [diff] [blame] | 213 | enable_http2 () { |
| 214 | HTTPD_PARA="$HTTPD_PARA -DHTTP2" |
| 215 | test_set_prereq HTTP2 |
| 216 | } |
| 217 | |
Jeff King | eb1c42d | 2023-05-18 15:21:02 -0400 | [diff] [blame] | 218 | enable_cgipassauth () { |
| 219 | # We are looking for 2.4.13 or more recent. Since we only support |
| 220 | # 2.4 and up, no need to check for older major/minor. |
| 221 | if test "$HTTPD_VERSION_MAJOR" = 2 && |
| 222 | test "$HTTPD_VERSION_MINOR" = 4 && |
| 223 | test "$(echo $HTTPD_VERSION | cut -d. -f3)" -lt 13 |
| 224 | then |
| 225 | echo >&4 "apache $HTTPD_VERSION too old for CGIPassAuth" |
| 226 | return |
| 227 | fi |
| 228 | HTTPD_PARA="$HTTPD_PARA -DUSE_CGIPASSAUTH" |
| 229 | test_set_prereq CGIPASSAUTH |
| 230 | } |
| 231 | |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 232 | start_httpd() { |
Jeff King | 75318a3 | 2009-02-25 03:32:08 -0500 | [diff] [blame] | 233 | prepare_httpd >&3 2>&4 |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 234 | |
SZEDER Gábor | 8c3b9f7 | 2019-03-13 13:24:13 +0100 | [diff] [blame] | 235 | test_atexit stop_httpd |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 236 | |
Mike Hommey | 13b5481 | 2008-07-07 21:02:37 +0200 | [diff] [blame] | 237 | "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \ |
| 238 | -f "$TEST_PATH/apache.conf" $HTTPD_PARA \ |
Jeff King | 75318a3 | 2009-02-25 03:32:08 -0500 | [diff] [blame] | 239 | -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \ |
| 240 | >&3 2>&4 |
Clemens Buchacher | a5adcbe | 2009-06-01 14:28:25 +0200 | [diff] [blame] | 241 | if test $? -ne 0 |
| 242 | then |
Nguyễn Thái Ngọc Duy | 44f243d | 2016-06-13 19:35:09 +0700 | [diff] [blame] | 243 | cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null |
Ævar Arnfjörð Bjarmason | 3b072c5 | 2019-06-21 12:18:11 +0200 | [diff] [blame] | 244 | test_skip_or_die GIT_TEST_HTTPD "web server setup failed" |
Jeff King | 75318a3 | 2009-02-25 03:32:08 -0500 | [diff] [blame] | 245 | fi |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | stop_httpd() { |
Mike Hommey | 13b5481 | 2008-07-07 21:02:37 +0200 | [diff] [blame] | 249 | "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \ |
Jay Soffian | 69707d6 | 2009-02-25 03:28:15 -0500 | [diff] [blame] | 250 | -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 251 | } |
Tay Ray Chuan | 6cbd6e9 | 2010-03-02 18:49:26 +0800 | [diff] [blame] | 252 | |
Junio C Hamano | 05c1eb1 | 2013-08-02 15:14:50 -0700 | [diff] [blame] | 253 | test_http_push_nonff () { |
Tay Ray Chuan | 6cbd6e9 | 2010-03-02 18:49:26 +0800 | [diff] [blame] | 254 | REMOTE_REPO=$1 |
| 255 | LOCAL_REPO=$2 |
| 256 | BRANCH=$3 |
Junio C Hamano | 05c1eb1 | 2013-08-02 15:14:50 -0700 | [diff] [blame] | 257 | EXPECT_CAS_RESULT=${4-failure} |
Tay Ray Chuan | 6cbd6e9 | 2010-03-02 18:49:26 +0800 | [diff] [blame] | 258 | |
| 259 | test_expect_success 'non-fast-forward push fails' ' |
| 260 | cd "$REMOTE_REPO" && |
| 261 | HEAD=$(git rev-parse --verify HEAD) && |
| 262 | |
| 263 | cd "$LOCAL_REPO" && |
| 264 | git checkout $BRANCH && |
| 265 | echo "changed" > path2 && |
| 266 | git commit -a -m path2 --amend && |
| 267 | |
Brandon Casey | 77b5be2 | 2010-07-20 13:27:55 -0500 | [diff] [blame] | 268 | test_must_fail git push -v origin >output 2>&1 && |
Ævar Arnfjörð Bjarmason | 0cd1a88 | 2023-02-06 23:44:30 +0100 | [diff] [blame] | 269 | ( |
| 270 | cd "$REMOTE_REPO" && |
| 271 | echo "$HEAD" >expect && |
| 272 | git rev-parse --verify HEAD >actual && |
| 273 | test_cmp expect actual |
| 274 | ) |
Tay Ray Chuan | 6cbd6e9 | 2010-03-02 18:49:26 +0800 | [diff] [blame] | 275 | ' |
| 276 | |
| 277 | test_expect_success 'non-fast-forward push show ref status' ' |
| 278 | grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output |
| 279 | ' |
| 280 | |
Junio C Hamano | d3bd042 | 2011-04-12 16:12:47 -0700 | [diff] [blame] | 281 | test_expect_success 'non-fast-forward push shows help message' ' |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 282 | test_grep "Updates were rejected because" output |
Tay Ray Chuan | 6cbd6e9 | 2010-03-02 18:49:26 +0800 | [diff] [blame] | 283 | ' |
Junio C Hamano | e69fa70 | 2013-08-01 11:05:02 -0700 | [diff] [blame] | 284 | |
Jeff King | 42aa29e | 2013-09-20 06:25:00 -0400 | [diff] [blame] | 285 | test_expect_${EXPECT_CAS_RESULT} 'force with lease aka cas' ' |
Junio C Hamano | e69fa70 | 2013-08-01 11:05:02 -0700 | [diff] [blame] | 286 | HEAD=$( cd "$REMOTE_REPO" && git rev-parse --verify HEAD ) && |
| 287 | test_when_finished '\'' |
| 288 | (cd "$REMOTE_REPO" && git update-ref HEAD "$HEAD") |
| 289 | '\'' && |
| 290 | ( |
| 291 | cd "$LOCAL_REPO" && |
| 292 | git push -v --force-with-lease=$BRANCH:$HEAD origin |
| 293 | ) && |
| 294 | git rev-parse --verify "$BRANCH" >expect && |
| 295 | ( |
| 296 | cd "$REMOTE_REPO" && git rev-parse --verify HEAD |
| 297 | ) >actual && |
| 298 | test_cmp expect actual |
| 299 | ' |
Tay Ray Chuan | 6cbd6e9 | 2010-03-02 18:49:26 +0800 | [diff] [blame] | 300 | } |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 301 | |
| 302 | setup_askpass_helper() { |
| 303 | test_expect_success 'setup askpass helper' ' |
| 304 | write_script "$TRASH_DIRECTORY/askpass" <<-\EOF && |
| 305 | echo >>"$TRASH_DIRECTORY/askpass-query" "askpass: $*" && |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 306 | case "$*" in |
| 307 | *Username*) |
| 308 | what=user |
| 309 | ;; |
| 310 | *Password*) |
| 311 | what=pass |
| 312 | ;; |
| 313 | esac && |
| 314 | cat "$TRASH_DIRECTORY/askpass-$what" |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 315 | EOF |
| 316 | GIT_ASKPASS="$TRASH_DIRECTORY/askpass" && |
| 317 | export GIT_ASKPASS && |
| 318 | export TRASH_DIRECTORY |
| 319 | ' |
| 320 | } |
| 321 | |
| 322 | set_askpass() { |
| 323 | >"$TRASH_DIRECTORY/askpass-query" && |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 324 | echo "$1" >"$TRASH_DIRECTORY/askpass-user" && |
| 325 | echo "$2" >"$TRASH_DIRECTORY/askpass-pass" |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | expect_askpass() { |
Jeff King | 050ef36 | 2013-09-28 04:35:35 -0400 | [diff] [blame] | 329 | dest=$HTTPD_DEST${3+/$3} |
| 330 | |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 331 | { |
| 332 | case "$1" in |
| 333 | none) |
| 334 | ;; |
| 335 | pass) |
Jeff King | 9d15b1e | 2023-02-23 06:05:55 -0500 | [diff] [blame] | 336 | echo "askpass: Password for '$HTTPD_PROTO://$2@$dest': " |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 337 | ;; |
| 338 | both) |
Jeff King | 9d15b1e | 2023-02-23 06:05:55 -0500 | [diff] [blame] | 339 | echo "askpass: Username for '$HTTPD_PROTO://$dest': " |
| 340 | echo "askpass: Password for '$HTTPD_PROTO://$2@$dest': " |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 341 | ;; |
| 342 | *) |
| 343 | false |
| 344 | ;; |
| 345 | esac |
| 346 | } >"$TRASH_DIRECTORY/askpass-expect" && |
| 347 | test_cmp "$TRASH_DIRECTORY/askpass-expect" \ |
| 348 | "$TRASH_DIRECTORY/askpass-query" |
| 349 | } |
SZEDER Gábor | 6940a06 | 2018-07-12 14:22:15 +0200 | [diff] [blame] | 350 | |
| 351 | strip_access_log() { |
| 352 | sed -e " |
| 353 | s/^.* \"// |
| 354 | s/\"// |
| 355 | s/ [1-9][0-9]*\$// |
| 356 | s/^GET /GET / |
| 357 | " "$HTTPD_ROOT_PATH"/access.log |
| 358 | } |
SZEDER Gábor | e8b3b2e | 2018-07-12 14:22:16 +0200 | [diff] [blame] | 359 | |
| 360 | # Requires one argument: the name of a file containing the expected stripped |
| 361 | # access log entries. |
| 362 | check_access_log() { |
| 363 | sort "$1" >"$1".sorted && |
| 364 | strip_access_log >access.log.stripped && |
| 365 | sort access.log.stripped >access.log.sorted && |
| 366 | if ! test_cmp "$1".sorted access.log.sorted |
| 367 | then |
| 368 | test_cmp "$1" access.log.stripped |
| 369 | fi |
| 370 | } |