interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t5567-one-time-script.sh

96 lines · 2822 bytes Raw Blame History
1#!/bin/sh
2
3test_description='apply-one-time-script CGI helper is safe under concurrent requests'
4
5. ./test-lib.sh
6
7HELPER="$TEST_DIRECTORY/lib-httpd/apply-one-time-script.sh"
8
9test_expect_success PIPE 'helper only serves one rewritten response for concurrent requests' '
10 mkdir workdir fakebin &&
11 ENTERED="$PWD/entered" &&
12 GATE="$PWD/gate" &&
13 export ENTERED GATE &&
14 mkfifo "$ENTERED" "$GATE" &&
15
16 # A stub git-http-backend that returns a response based on
17 # $ROLE. For $ROLE = modify, return the response string
18 # "packfile", which ends up being modified by the example
19 # one-time-script below.
20 #
21 # Otherwise, run the branch returning a response that
22 # should be passed through, and block until released
23 # by "read -r $GATE".
24 write_script fakebin/git-http-backend <<-\EOF &&
25 printf "Status: 200 OK\r\n"
26 printf "Content-Type: application/x-git-result\r\n"
27 printf "\r\n"
28 if test "$ROLE" = modify
29 then
30 printf "packfile\n"
31 else
32 echo entered >"$ENTERED"
33 read -r released <"$GATE"
34 printf "refs\n"
35 fi
36 EOF
37
38 # An example one-time-script for apply-one-time-script
39 # to execute. Checks for "packfile" in the response
40 # that will be returned, and replaces it with a
41 # modified response. Passes through responses without
42 # "packfile" in them.
43 write_script workdir/one-time-script <<-\EOF &&
44 if grep packfile "$1" >/dev/null
45 then
46 sed "/packfile/q" "$1" &&
47 printf "REPLACED\n"
48 else
49 cat "$1"
50 fi
51 EOF
52
53 GIT_EXEC_PATH="$PWD/fakebin" &&
54 export GIT_EXEC_PATH &&
55
56 # Ensure $GATE has a reader so the test does not block indefinitely if
57 # the helper is buggy and "echo released >&9" below does not unblock
58 # the unmodified response gate.
59 exec 9<>"$GATE" &&
60
61 # Launch the passthrough request in the background. Record its pid
62 # so it can be killed when the test finishes if, for some reason, the
63 # request stays blocked and would stall a test runner.
64 { (
65 cd workdir &&
66 ROLE=passthrough sh "$HELPER" >../passthrough.out 2>../passthrough.err
67 ) & } &&
68 passthrough_pid=$! &&
69 test_when_finished "kill $passthrough_pid 2>/dev/null || :" &&
70
71 # Wait until the passthrough request is "in-flight" and paused
72 # mid-response.
73 read -r entered <"$ENTERED" &&
74
75 # Launch the request for a modified response while the passthrough
76 # request is concurrently "in-flight" and paused.
77 (
78 cd workdir &&
79 ROLE=modify sh "$HELPER" >../modify.out 2>../modify.err
80 ) &&
81
82 # Unblock the passthrough request, allowing git-http-backend to
83 # complete its response.
84 echo released >&9 &&
85 { wait "$passthrough_pid" || :; } &&
86
87 test_must_be_empty passthrough.err &&
88 test_must_be_empty modify.err &&
89 test_grep "Status: 200 OK" passthrough.out &&
90 test_grep "Status: 200 OK" modify.out &&
91 test_grep REPLACED modify.out &&
92 test_grep ! REPLACED passthrough.out &&
93 test_grep refs passthrough.out
94'
95
96test_done