kubo/test/sharness/t0235-cli-request.sh
Steven Allen c0f979dfe1 really fix netcat race
We hit this once every few Jenkins runs. This:

1. Ensures netcat has started before we try to use it.
2. Waits for it to actually write the request before trying to read it.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2018-11-29 18:28:03 -08:00

65 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Copyright (c) 2015 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="test http requests made by cli"
. lib/test-lib.sh
test_init_ipfs
test_expect_success "start nc" '
rm -f nc_out nc_outp nc_inp && mkfifo nc_inp nc_outp
nc -k -l 127.0.0.1 5005 <nc_inp >nc_outp &
NCPID=$!
exec 6>nc_inp 7<nc_outp
while ! nc -z 127.0.0.1 5005; do
go-sleep 100ms
done
'
test_expect_success "can make http request against nc server" '
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 &
IPFSPID=$!
# handle request
while read line; do
if [[ "$line" == "$(echo -e "\r")" ]]; then
break
fi
echo "$line"
done <&7 >nc_out &&
echo -e "HTTP/1.1 200 OK\r" >&6 &&
echo -e "Content-Type: text/plain\r" >&6 &&
echo -e "Content-Length: 0\r" >&6 &&
echo -e "\r" >&6 &&
exec 6<&- &&
# Wait for IPFS
wait $IPFSPID
'
test_expect_success "stop nc" '
kill "$NCPID" && wait "$NCPID" || true
'
test_expect_success "output does not contain multipart info" '
test_expect_code 1 grep multipart nc_out
'
test_expect_success "request looks good" '
grep "POST /api/v0/cat" nc_out
'
test_expect_success "api flag does not appear in request" '
test_expect_code 1 grep "api=/ip4" nc_out
'
test_done