diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-17 19:06:22 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-17 19:06:22 +0100 |
| commit | 827e90e0daabe32e058e08dd2a253425898a7e7a (patch) | |
| tree | ecd3f31da63890ac029b7929eade88f38e078b3d /tests/run_test.sh | |
| parent | e4ba24b3d24fdce36bc9dbd3c2c8f00b0ec23335 (diff) | |
| download | BobinkCOpcUa-827e90e0daabe32e058e08dd2a253425898a7e7a.tar.gz BobinkCOpcUa-827e90e0daabe32e058e08dd2a253425898a7e7a.zip | |
Replace ClientFindServers with unified Client, use trust store directories
Replace the single-purpose ClientFindServers program with a unified Client
that supports three operations via CLI: find-servers, get-endpoints, and
read-time. This simplifies the architecture by using one client binary with
a single config file instead of a monolithic program that did everything in
one run.
Split the ServerRegister config into separate server and client config files
so the LDS-registration credentials are isolated from the server's own
settings. The discovery URL moves from config to a CLI argument.
Replace repeated trustList config entries with a single trustStore directory
path. Each program now points to a directory under certs/trust/ containing
.der files, so adding or removing trust is a file-copy operation rather than
editing every config file. Add loadTrustStore()/freeTrustStore() to
common.c and remove the now-unused configGetAll() from the config parser.
Simplify the test matrix from 6 to 4 cases (security and auth are
orthogonal, so the full 3x2 matrix is unnecessary). Update run_test.sh to
invoke the new Client three times and use port-polling instead of sleep.
Diffstat (limited to 'tests/run_test.sh')
| -rwxr-xr-x | tests/run_test.sh | 94 |
1 files changed, 60 insertions, 34 deletions
diff --git a/tests/run_test.sh b/tests/run_test.sh index 8a87824..ef359ef 100755 --- a/tests/run_test.sh +++ b/tests/run_test.sh @@ -5,7 +5,8 @@ # Usage: tests/run_test.sh <config_dir> <expected_policy> # # config_dir — directory containing server_lds.conf, -# server_register.conf, client_find_servers.conf +# server_register.conf, server_register_client.conf, +# client.conf # expected_policy — security-policy string that must appear in # the client's endpoint listing (e.g. # "Basic256Sha256", "Aes128_Sha256_RsaOaep", @@ -35,6 +36,24 @@ cleanup() { } trap cleanup EXIT +# ── helpers ──────────────────────────────────────────────────── +wait_for_port() { + local port="$1" pid="$2" label="$3" i=0 + while [ $i -lt 50 ]; do + if ! kill -0 "$pid" 2>/dev/null; then + echo "FAIL: $label exited prematurely" + exit 1 + fi + if ss -tlnp 2>/dev/null | grep -q ":${port} "; then + return 0 + fi + sleep 0.1 + i=$((i + 1)) + done + echo "FAIL: $label did not listen on port $port within 5 s" + exit 1 +} + # ── port check ───────────────────────────────────────────────── for port in $LDS_PORT $SR_PORT; do if ss -tlnp 2>/dev/null | grep -q ":${port} "; then @@ -46,29 +65,14 @@ done # ── start LDS ────────────────────────────────────────────────── build/ServerLDS "$CONFIG_DIR/server_lds.conf" >/dev/null 2>&1 & LDS_PID=$! -sleep 2 -if ! kill -0 "$LDS_PID" 2>/dev/null; then - echo "FAIL: ServerLDS exited prematurely" - exit 1 -fi +wait_for_port "$LDS_PORT" "$LDS_PID" "ServerLDS" # ── start ServerRegister ─────────────────────────────────────── -build/ServerRegister "$CONFIG_DIR/server_register.conf" >/dev/null 2>&1 & +build/ServerRegister "$CONFIG_DIR/server_register.conf" "$CONFIG_DIR/server_register_client.conf" "opc.tcp://localhost:$LDS_PORT" >/dev/null 2>&1 & SR_PID=$! -sleep 3 -if ! kill -0 "$SR_PID" 2>/dev/null; then - echo "FAIL: ServerRegister exited prematurely" - exit 1 -fi +wait_for_port "$SR_PORT" "$SR_PID" "ServerRegister" -# ── run client ───────────────────────────────────────────────── -TMPFILE=$(mktemp) -# UA_Log_Stdout writes to stdout; capture both stdout and stderr. -build/ClientFindServers "$CONFIG_DIR/client_find_servers.conf" >"$TMPFILE" 2>&1 -CLIENT_RC=$? -CLIENT_OUTPUT=$(<"$TMPFILE") - -# ── validation checks ───────────────────────────────────────── +# ── validation helper ───────────────────────────────────────── check() { local label="$1" result="$2" if [ "$result" -eq 0 ]; then @@ -79,27 +83,49 @@ check() { fi } -# 1. Exit code -[ "$CLIENT_RC" -eq 0 ] -check "client exit code is 0 (got $CLIENT_RC)" $? +# ── FindServers ─────────────────────────────────────────────── +TMPFILE=$(mktemp) +build/Client "$CONFIG_DIR/client.conf" find-servers "opc.tcp://localhost:$LDS_PORT" >"$TMPFILE" 2>&1 +FS_RC=$? +FS_OUTPUT=$(<"$TMPFILE") + +[ "$FS_RC" -eq 0 ] +check "find-servers exit code is 0 (got $FS_RC)" $? + +echo "$FS_OUTPUT" | grep -q "urn:bobink.ServerRegister" +check "find-servers contains urn:bobink.ServerRegister" $? + +# ── GetEndpoints ────────────────────────────────────────────── +build/Client "$CONFIG_DIR/client.conf" get-endpoints "opc.tcp://localhost:$SR_PORT" >"$TMPFILE" 2>&1 +GE_RC=$? +GE_OUTPUT=$(<"$TMPFILE") + +[ "$GE_RC" -eq 0 ] +check "get-endpoints exit code is 0 (got $GE_RC)" $? + +echo "$GE_OUTPUT" | grep -q "$EXPECTED_POLICY" +check "get-endpoints contains $EXPECTED_POLICY" $? -# 2. FindServers returned the registered server -echo "$CLIENT_OUTPUT" | grep -q "urn:bobink.ServerRegister" -check "FindServers contains urn:bobink.ServerRegister" $? +# ── ReadTime ────────────────────────────────────────────────── +build/Client "$CONFIG_DIR/client.conf" read-time "opc.tcp://localhost:$SR_PORT" >"$TMPFILE" 2>&1 +RT_RC=$? +RT_OUTPUT=$(<"$TMPFILE") -# 3. Client read the current time -echo "$CLIENT_OUTPUT" | grep -q "date is:" -check "client read current time" $? +[ "$RT_RC" -eq 0 ] +check "read-time exit code is 0 (got $RT_RC)" $? -# 4. Endpoint lists expected security policy -echo "$CLIENT_OUTPUT" | grep -q "$EXPECTED_POLICY" -check "endpoint contains $EXPECTED_POLICY" $? +echo "$RT_OUTPUT" | grep -q "date is:" +check "read-time output contains 'date is:'" $? # ── result ───────────────────────────────────────────────────── if [ "$FAILURES" -ne 0 ]; then echo "" - echo "--- client output ---" - echo "$CLIENT_OUTPUT" + echo "--- find-servers output ---" + echo "$FS_OUTPUT" + echo "--- get-endpoints output ---" + echo "$GE_OUTPUT" + echo "--- read-time output ---" + echo "$RT_OUTPUT" echo "--- end ---" exit 1 fi |
