]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add basic TEST-74-AUX-UTILS.socket-proxyd.sh
authorMichael Vogt <michael@amutable.com>
Wed, 18 Mar 2026 12:23:20 +0000 (13:23 +0100)
committerMichael Vogt <michael@amutable.com>
Fri, 20 Mar 2026 08:37:24 +0000 (09:37 +0100)
With the planned extraction of the socket-forward code its useful
to have a basic way to validate the functionality. So add a basic
test that ensures at least base functionality is intact.

mkosi/mkosi.sanitizers/mkosi.postinst
test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/proxy-echo.py [new file with mode: 0755]
test/meson.build
test/units/TEST-74-AUX-UTILS.socket-proxyd.sh [new file with mode: 0755]

index d4d00907ed07f0190a4fa524232e43d6bf3e7d54..229a5368b92f4ec9eb4c60a6fa97e66486f8dcb2 100755 (executable)
@@ -43,6 +43,7 @@ fi
 wrap=(
     /usr/lib/polkit-1/polkitd
     /usr/libexec/polkit-1/polkitd
+    /usr/lib/systemd/tests/testdata/TEST-74-AUX-UTILS.units/proxy-echo.py
     agetty
     btrfs
     capsh
diff --git a/test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/proxy-echo.py b/test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/proxy-echo.py
new file mode 100755 (executable)
index 0000000..827ce6a
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/python3
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+import socket
+import sys
+
+data = sys.stdin.buffer.read()
+s = socket.create_connection(("localhost", 12345), timeout=15)
+s.settimeout(15)
+s.sendall(data)
+received = b""
+while len(received) < len(data):
+    chunk = s.recv(65536)
+    if not chunk:
+        break
+    received += chunk
+sys.stdout.buffer.write(received)
+s.close()
index 7bf557cc193357d4d52dc0fcd66973eaf85a087a..b64f971126df6827accba40c7e78a043b0662cd4 100644 (file)
@@ -357,6 +357,7 @@ if install_tests
                 'integration-tests/TEST-63-PATH/TEST-63-PATH.units',
                 'integration-tests/TEST-65-ANALYZE/TEST-65-ANALYZE.units',
                 'integration-tests/TEST-66-DEVICE-ISOLATION/TEST-66-DEVICE-ISOLATION.units',
+                'integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units',
                 'integration-tests/TEST-80-NOTIFYACCESS/TEST-80-NOTIFYACCESS.units',
                 'units',
         ]
diff --git a/test/units/TEST-74-AUX-UTILS.socket-proxyd.sh b/test/units/TEST-74-AUX-UTILS.socket-proxyd.sh
new file mode 100755 (executable)
index 0000000..c028747
--- /dev/null
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+# shellcheck source=test/units/util.sh
+. "$(dirname "$0")"/util.sh
+
+# Test systemd-socket-proxyd by setting up a backend server, a proxy in front of it,
+# and verifying that data passes through correctly.
+
+BACKEND_SOCK="/tmp/test-proxyd-backend.sock"
+
+at_exit() {
+    set +e
+    systemctl stop test-proxyd-backend.service 2>/dev/null
+    systemctl stop test-proxyd.socket 2>/dev/null
+    systemctl stop test-proxyd.service 2>/dev/null
+    rm -f "$BACKEND_SOCK"
+    rm -f /run/systemd/system/test-proxyd.socket /run/systemd/system/test-proxyd.service
+    systemctl daemon-reload 2>/dev/null
+}
+trap at_exit EXIT
+
+# Start a backend echo server via systemd-run
+systemd-run --unit=test-proxyd-backend --service-type=simple \
+    socat UNIX-LISTEN:"$BACKEND_SOCK",fork EXEC:cat
+
+# Ensure socket is ready
+timeout 5 bash -c "until [[ -S $BACKEND_SOCK ]]; do sleep 0.1; done"
+
+# Create a socket unit for the proxy
+cat >/run/systemd/system/test-proxyd.socket <<EOF
+[Socket]
+ListenStream=12345
+EOF
+
+cat >/run/systemd/system/test-proxyd.service <<EOF
+[Service]
+ExecStart=/usr/lib/systemd/systemd-socket-proxyd $BACKEND_SOCK
+EOF
+
+systemctl daemon-reload
+systemctl start test-proxyd.socket
+
+proxy_echo() {
+    /usr/lib/systemd/tests/testdata/TEST-74-AUX-UTILS.units/proxy-echo.py
+}
+
+# Test basic forwarding
+assert_eq "$(echo -n hello | proxy_echo)" "hello"
+
+# Test a second connection (socket re-activates the proxy)
+assert_eq "$(echo -n world | proxy_echo)" "world"
+
+# Test with larger data (64KB random, base64-encoded)
+LARGE_DATA="$(dd if=/dev/urandom bs=1024 count=64 status=none | base64)"
+assert_eq "$(echo -n "$LARGE_DATA" | proxy_echo)" "$LARGE_DATA"