Skip to content

Commit cee137b

Browse files
pks-tgitster
authored andcommitted
t/lib-httpd: refactor "one-time-perl" CGI script to not depend on Perl
Our Apache HTTPD setup exposes an "one_time_perl" endpoint to access repositories. If used, we execute the "apply-one-time-perl.sh" CGI script that checks whether we have a "one-time-perl" script. If so, that script gets executed so that it can munge what would be served. Once done, the script gets removed so that it doesn't execute a second time. As the name says, this functionality expects the user to pass a Perl script. This isn't really necessary though: we can just as easily implement the same thing with arbitrary scripts. Refactor the code so that we instead expect an arbitrary script to exist and rename the functionality to "one-time-script". Adapt callers to use shell utilities instead of Perl so that we can drop the PERL_TEST_HELPERS prerequisite. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de9eeab commit cee137b

8 files changed

+86
-77
lines changed

t/lib-httpd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ prepare_httpd() {
165165
install_script broken-smart-http.sh
166166
install_script error-smart-http.sh
167167
install_script error.sh
168-
install_script apply-one-time-perl.sh
168+
install_script apply-one-time-script.sh
169169
install_script nph-custom-auth.sh
170170

171171
ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"

t/lib-httpd/apache.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ SetEnv PERL_PATH ${PERL_PATH}
135135
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
136136
SetEnv GIT_HTTP_EXPORT_ALL
137137
</LocationMatch>
138-
<LocationMatch /one_time_perl/>
138+
<LocationMatch /one_time_script/>
139139
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
140140
SetEnv GIT_HTTP_EXPORT_ALL
141141
</LocationMatch>
@@ -159,7 +159,7 @@ ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
159159
ScriptAlias /broken_smart/ broken-smart-http.sh/
160160
ScriptAlias /error_smart/ error-smart-http.sh/
161161
ScriptAlias /error/ error.sh/
162-
ScriptAliasMatch /one_time_perl/(.*) apply-one-time-perl.sh/$1
162+
ScriptAliasMatch /one_time_script/(.*) apply-one-time-script.sh/$1
163163
ScriptAliasMatch /custom_auth/(.*) nph-custom-auth.sh/$1
164164
<Directory ${GIT_EXEC_PATH}>
165165
Options FollowSymlinks
@@ -182,7 +182,7 @@ ScriptAliasMatch /custom_auth/(.*) nph-custom-auth.sh/$1
182182
<Files error.sh>
183183
Options ExecCGI
184184
</Files>
185-
<Files apply-one-time-perl.sh>
185+
<Files apply-one-time-script.sh>
186186
Options ExecCGI
187187
</Files>
188188
<Files ${GIT_EXEC_PATH}/git-http-backend>

t/lib-httpd/apply-one-time-perl.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

t/lib-httpd/apply-one-time-script.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
# If "one-time-script" exists in $HTTPD_ROOT_PATH, run the script on the HTTP
4+
# response. If the response was modified as a result, delete "one-time-script"
5+
# so that subsequent HTTP responses are no longer modified.
6+
#
7+
# This can be used to simulate the effects of the repository changing in
8+
# between HTTP request-response pairs.
9+
if test -f one-time-script
10+
then
11+
LC_ALL=C
12+
export LC_ALL
13+
14+
"$GIT_EXEC_PATH/git-http-backend" >out
15+
./one-time-script out >out_modified
16+
17+
if cmp -s out out_modified
18+
then
19+
cat out
20+
else
21+
cat out_modified
22+
rm one-time-script
23+
fi
24+
else
25+
"$GIT_EXEC_PATH/git-http-backend"
26+
fi

t/t5537-fetch-shallow.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ start_httpd
256256

257257
REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
258258

259-
test_expect_success PERL_TEST_HELPERS 'shallow fetches check connectivity before writing shallow file' '
259+
test_expect_success 'shallow fetches check connectivity before writing shallow file' '
260260
rm -rf "$REPO" client &&
261261
262262
git init "$REPO" &&
@@ -271,22 +271,21 @@ test_expect_success PERL_TEST_HELPERS 'shallow fetches check connectivity before
271271
git -C "$REPO" config protocol.version 2 &&
272272
git -C client config protocol.version 2 &&
273273
274-
git -C client fetch --depth=2 "$HTTPD_URL/one_time_perl/repo" main:a_branch &&
274+
git -C client fetch --depth=2 "$HTTPD_URL/one_time_script/repo" main:a_branch &&
275275
276276
# Craft a situation in which the server sends back an unshallow request
277277
# with an empty packfile. This is done by refetching with a shorter
278278
# depth (to ensure that the packfile is empty), and overwriting the
279279
# shallow line in the response with the unshallow line we want.
280-
printf "$(test_oid perl)" \
281-
"$(git -C "$REPO" rev-parse HEAD)" \
282-
"$(git -C "$REPO" rev-parse HEAD^)" \
283-
>"$HTTPD_ROOT_PATH/one-time-perl" &&
280+
write_script "$HTTPD_ROOT_PATH/one-time-script" <<-EOF &&
281+
sed "$(printf "$(test_oid perl)" "$(git -C "$REPO" rev-parse HEAD)" "$(git -C "$REPO" rev-parse HEAD^)")" "\$1"
282+
EOF
284283
test_must_fail env GIT_TEST_SIDEBAND_ALL=0 git -C client \
285-
fetch --depth=1 "$HTTPD_URL/one_time_perl/repo" \
284+
fetch --depth=1 "$HTTPD_URL/one_time_script/repo" \
286285
main:a_branch &&
287286
288-
# Ensure that the one-time-perl script was used.
289-
! test -e "$HTTPD_ROOT_PATH/one-time-perl" &&
287+
# Ensure that the one-time-script script was used.
288+
! test -e "$HTTPD_ROOT_PATH/one-time-script" &&
290289
291290
# Ensure that the resulting repo is consistent, despite our failure to
292291
# fetch.

t/t5616-partial-clone.sh

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -737,21 +737,25 @@ intersperse () {
737737
sed 's/\(..\)/'$1'\1/g'
738738
}
739739

740-
# Create a one-time-perl command to replace the existing packfile with $1.
740+
# Create a one-time-script command to replace the existing packfile with $1.
741741
replace_packfile () {
742-
# The protocol requires that the packfile be sent in sideband 1, hence
743-
# the extra \x01 byte at the beginning.
744-
cp $1 "$HTTPD_ROOT_PATH/one-time-pack" &&
745-
echo 'if (/packfile/) {
746-
print;
747-
my $length = -s "one-time-pack";
748-
printf "%04x\x01", $length + 5;
749-
print `cat one-time-pack` . "0000";
750-
last
751-
}' >"$HTTPD_ROOT_PATH/one-time-perl"
742+
cp "$1" one-time-pack &&
743+
write_script "$HTTPD_ROOT_PATH/one-time-script" <<-EOF
744+
if grep packfile "\$1" >/dev/null
745+
then
746+
sed '/packfile/q' "\$1" &&
747+
# The protocol requires that the packfile be sent in sideband
748+
# 1, hence the extra \001 byte at the beginning.
749+
printf "%04x\001" \$((\$(wc -c <"$PWD/one-time-pack") + 5)) &&
750+
cat "$PWD/one-time-pack" &&
751+
printf "0000"
752+
else
753+
cat "\$1"
754+
fi
755+
EOF
752756
}
753757

754-
test_expect_success PERL_TEST_HELPERS 'upon cloning, check that all refs point to objects' '
758+
test_expect_success 'upon cloning, check that all refs point to objects' '
755759
SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
756760
rm -rf "$SERVER" repo &&
757761
test_create_repo "$SERVER" &&
@@ -776,15 +780,15 @@ test_expect_success PERL_TEST_HELPERS 'upon cloning, check that all refs point t
776780
# section header.
777781
test_config -C "$SERVER" protocol.version 2 &&
778782
test_must_fail git -c protocol.version=2 clone \
779-
--filter=blob:none $HTTPD_URL/one_time_perl/server repo 2>err &&
783+
--filter=blob:none $HTTPD_URL/one_time_script/server repo 2>err &&
780784
781785
test_grep "did not send all necessary objects" err &&
782786
783-
# Ensure that the one-time-perl script was used.
784-
! test -e "$HTTPD_ROOT_PATH/one-time-perl"
787+
# Ensure that the one-time-script script was used.
788+
! test -e "$HTTPD_ROOT_PATH/one-time-script"
785789
'
786790

787-
test_expect_success PERL_TEST_HELPERS 'when partial cloning, tolerate server not sending target of tag' '
791+
test_expect_success 'when partial cloning, tolerate server not sending target of tag' '
788792
SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
789793
rm -rf "$SERVER" repo &&
790794
test_create_repo "$SERVER" &&
@@ -818,11 +822,11 @@ test_expect_success PERL_TEST_HELPERS 'when partial cloning, tolerate server not
818822
819823
# Exercise to make sure it works.
820824
git -c protocol.version=2 clone \
821-
--filter=blob:none $HTTPD_URL/one_time_perl/server repo 2> err &&
825+
--filter=blob:none $HTTPD_URL/one_time_script/server repo 2> err &&
822826
! grep "missing object referenced by" err &&
823827
824-
# Ensure that the one-time-perl script was used.
825-
! test -e "$HTTPD_ROOT_PATH/one-time-perl"
828+
# Ensure that the one-time-script script was used.
829+
! test -e "$HTTPD_ROOT_PATH/one-time-script"
826830
'
827831

828832
test_expect_success PERL_TEST_HELPERS 'tolerate server sending REF_DELTA against missing promisor objects' '
@@ -845,7 +849,7 @@ test_expect_success PERL_TEST_HELPERS 'tolerate server sending REF_DELTA against
845849
846850
# Clone. The client has deltabase_have but not deltabase_missing.
847851
git -c protocol.version=2 clone --no-checkout \
848-
--filter=blob:none $HTTPD_URL/one_time_perl/server repo &&
852+
--filter=blob:none $HTTPD_URL/one_time_script/server repo &&
849853
git -C repo hash-object -w -- "$SERVER/have.txt" &&
850854
851855
# Sanity check to ensure that the client does not have
@@ -899,8 +903,8 @@ test_expect_success PERL_TEST_HELPERS 'tolerate server sending REF_DELTA against
899903
grep "want $(cat deltabase_missing)" trace &&
900904
! grep "want $(cat deltabase_have)" trace &&
901905
902-
# Ensure that the one-time-perl script was used.
903-
! test -e "$HTTPD_ROOT_PATH/one-time-perl"
906+
# Ensure that the one-time-script script was used.
907+
! test -e "$HTTPD_ROOT_PATH/one-time-script"
904908
'
905909

906910
# DO NOT add non-httpd-specific tests here, because the last part of this

t/t5702-protocol-v2.sh

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ test_expect_success 'push with http:// and a config of v2 does not request v2' '
11201120
! grep "git< version 2" log
11211121
'
11221122

1123-
test_expect_success PERL_TEST_HELPERS 'when server sends "ready", expect DELIM' '
1123+
test_expect_success 'when server sends "ready", expect DELIM' '
11241124
rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child &&
11251125
11261126
git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
@@ -1132,15 +1132,16 @@ test_expect_success PERL_TEST_HELPERS 'when server sends "ready", expect DELIM'
11321132
11331133
# After "ready" in the acknowledgments section, pretend that a FLUSH
11341134
# (0000) was sent instead of a DELIM (0001).
1135-
printf "\$ready = 1 if /ready/; \$ready && s/0001/0000/" \
1136-
>"$HTTPD_ROOT_PATH/one-time-perl" &&
1135+
write_script "$HTTPD_ROOT_PATH/one-time-script" <<-\EOF &&
1136+
sed "/ready/{n;s/0001/0000/;}" "$1"
1137+
EOF
11371138
11381139
test_must_fail git -C http_child -c protocol.version=2 \
1139-
fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
1140+
fetch "$HTTPD_URL/one_time_script/http_parent" 2> err &&
11401141
test_grep "expected packfile to be sent after .ready." err
11411142
'
11421143

1143-
test_expect_success PERL_TEST_HELPERS 'when server does not send "ready", expect FLUSH' '
1144+
test_expect_success 'when server does not send "ready", expect FLUSH' '
11441145
rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child log &&
11451146
11461147
git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
@@ -1157,12 +1158,13 @@ test_expect_success PERL_TEST_HELPERS 'when server does not send "ready", expect
11571158
11581159
# After the acknowledgments section, pretend that a DELIM
11591160
# (0001) was sent instead of a FLUSH (0000).
1160-
printf "\$ack = 1 if /acknowledgments/; \$ack && s/0000/0001/" \
1161-
>"$HTTPD_ROOT_PATH/one-time-perl" &&
1161+
write_script "$HTTPD_ROOT_PATH/one-time-script" <<-\EOF &&
1162+
sed "/acknowledgments/,//{s/0000/0001/;}" "$1"
1163+
EOF
11621164
11631165
test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" git -C http_child \
11641166
-c protocol.version=2 \
1165-
fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
1167+
fetch "$HTTPD_URL/one_time_script/http_parent" 2> err &&
11661168
grep "fetch< .*acknowledgments" log &&
11671169
! grep "fetch< .*ready" log &&
11681170
test_grep "expected no other sections to be sent after no .ready." err
@@ -1446,14 +1448,15 @@ test_expect_success 'http:// --negotiate-only' '
14461448
grep "$COMMON" out
14471449
'
14481450

1449-
test_expect_success PERL_TEST_HELPERS 'http:// --negotiate-only without wait-for-done support' '
1451+
test_expect_success 'http:// --negotiate-only without wait-for-done support' '
14501452
SERVER="server" &&
1451-
URI="$HTTPD_URL/one_time_perl/server" &&
1453+
URI="$HTTPD_URL/one_time_script/server" &&
14521454
14531455
setup_negotiate_only "$SERVER" "$URI" &&
14541456
1455-
echo "s/ wait-for-done/ xxxx-xxx-xxxx/" \
1456-
>"$HTTPD_ROOT_PATH/one-time-perl" &&
1457+
write_script "$HTTPD_ROOT_PATH/one-time-script" <<-\EOF &&
1458+
sed "s/ wait-for-done/ xxxx-xxx-xxxx/" "$1"
1459+
EOF
14571460
14581461
test_must_fail git -c protocol.version=2 -C client fetch \
14591462
--no-tags \

t/t5703-upload-pack-ref-in-want.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ test_expect_success 'setup repos for change-while-negotiating test' '
468468
test_commit m3 &&
469469
git tag -d m2 m3
470470
) &&
471-
git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_perl/repo" &&
471+
git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_script/repo" &&
472472
git -C "$LOCAL_PRISTINE" config protocol.version 2
473473
'
474474

@@ -481,7 +481,9 @@ inconsistency () {
481481
# RPCs during a single negotiation.
482482
oid1=$(git -C "$REPO" rev-parse $1) &&
483483
oid2=$(git -C "$REPO" rev-parse $2) &&
484-
echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-perl"
484+
write_script "$HTTPD_ROOT_PATH/one-time-script" <<-EOF
485+
sed "s/$oid1/$oid2/" "\$1"
486+
EOF
485487
}
486488

487489
test_expect_success 'server is initially ahead - no ref in want' '
@@ -533,7 +535,9 @@ test_expect_success 'server loses a ref - ref in want' '
533535
git -C "$REPO" config uploadpack.allowRefInWant true &&
534536
rm -rf local &&
535537
cp -r "$LOCAL_PRISTINE" local &&
536-
echo "s/main/rain/" >"$HTTPD_ROOT_PATH/one-time-perl" &&
538+
write_script "$HTTPD_ROOT_PATH/one-time-script" <<-\EOF &&
539+
sed "s/main/rain/" "$1"
540+
EOF
537541
test_must_fail git -C local fetch 2>err &&
538542
539543
test_grep "fatal: remote error: unknown ref refs/heads/rain" err

0 commit comments

Comments
 (0)