From 75fde36d64ab7b9972c3c94a87f1fd5ace436cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Old=C5=99ich=20Jedli=C4=8Dka?= Date: Sun, 6 Oct 2024 15:06:58 +0200 Subject: [PATCH] tang: allow reading full request by socat fake http server (#488) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `socat` forwards HTTP request to a script and forwards whatever the script produces to the HTTP client. The `socat` in this configuration fails occasionally. When the script is finished and there is still something to be forwarded to it, the `socat` reports a broken pipe. Fix this by explicitly configuring the read and write ends, reading from the file and writing to /dev/null. This fixes the following build test error: ``` + clevis encrypt tang '{"url":"localhost:44157"}' -y > 2024/10/05 14:46:51.000039424 length=82 from=0 to=81 GET /adv/ HTTP/1.1\r Host: localhost:44157\r User-Agent: curl/8.6.0\r Accept: */*\r \r 2024/10/05 14:46:51 socat[16880] E write(5, 0x55efa9173000, 82): Broken pipe + echo 'Error (do_test) response: /tmp/tmp.skxEYJGb28/cases/good-01' Error (do_test) response: /tmp/tmp.skxEYJGb28/cases/good-01 + '[' -r /tmp/tmp.skxEYJGb28/cases/good-01.stderr ']' + cat /tmp/tmp.skxEYJGb28/cases/good-01.stderr Unable to fetch advertisement: 'localhost:44157/adv/'! + return 1 ``` Signed-off-by: Oldřich Jedlička --- src/pins/tang/tests/tang-common-test-functions.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pins/tang/tests/tang-common-test-functions.in b/src/pins/tang/tests/tang-common-test-functions.in index f314d61a..38cbab37 100644 --- a/src/pins/tang/tests/tang-common-test-functions.in +++ b/src/pins/tang/tests/tang-common-test-functions.in @@ -218,7 +218,7 @@ run_test_server() { pidfile="${basedir}/tang.pid" portfile="${basedir}/tang.port" - "${SOCAT}" -v -v TCP4-LISTEN:0,reuseaddr,bind=localhost SYSTEM:"cat ${response}" & + "${SOCAT}" -v -v TCP4-LISTEN:0,bind=localhost "SYSTEM:cat ${response}!!OPEN:/dev/null" & pid=$! echo "${pid}" > "${pidfile}"