blob: 5173fa35331488ba93d7ba8ef2437c4747608e89 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#!/usr/bin/env bash
# ---------------------------------------------------------------
# Integration-test helper for OPC UA discovery.
#
# Usage: tests/run_test.sh <config_dir> <expected_policy>
#
# config_dir — directory containing server_lds.conf,
# server_register.conf, client_find_servers.conf
# expected_policy — security-policy string that must appear in
# the client's endpoint listing (e.g.
# "Basic256Sha256", "Aes128_Sha256_RsaOaep",
# or "None")
#
# Exit: 0 when all checks pass, 1 on any failure.
# ---------------------------------------------------------------
set -uo pipefail
# NOTE: we intentionally omit "set -e" so that every check runs
# even if the client itself returns non-zero.
CONFIG_DIR="${1:?Usage: $0 <config_dir> <expected_policy>}"
EXPECTED_POLICY="${2:?Usage: $0 <config_dir> <expected_policy>}"
LDS_PORT=14840
SR_PORT=14841
LDS_PID=""
SR_PID=""
TMPFILE=""
FAILURES=0
# ── cleanup ────────────────────────────────────────────────────
cleanup() {
[ -n "$LDS_PID" ] && kill "$LDS_PID" 2>/dev/null && wait "$LDS_PID" 2>/dev/null
[ -n "$SR_PID" ] && kill "$SR_PID" 2>/dev/null && wait "$SR_PID" 2>/dev/null
[ -n "$TMPFILE" ] && rm -f "$TMPFILE"
}
trap cleanup EXIT
# ── port check ─────────────────────────────────────────────────
for port in $LDS_PORT $SR_PORT; do
if ss -tlnp 2>/dev/null | grep -q ":${port} "; then
echo "FAIL: port $port is already in use"
exit 1
fi
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
# ── start ServerRegister ───────────────────────────────────────
build/ServerRegister "$CONFIG_DIR/server_register.conf" >/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
# ── 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 ─────────────────────────────────────────
check() {
local label="$1" result="$2"
if [ "$result" -eq 0 ]; then
echo "PASS: $label"
else
echo "FAIL: $label"
FAILURES=$((FAILURES + 1))
fi
}
# 1. Exit code
[ "$CLIENT_RC" -eq 0 ]
check "client exit code is 0 (got $CLIENT_RC)" $?
# 2. FindServers returned the registered server
echo "$CLIENT_OUTPUT" | grep -q "urn:bobink.ServerRegister"
check "FindServers contains urn:bobink.ServerRegister" $?
# 3. Client read the current time
echo "$CLIENT_OUTPUT" | grep -q "date is:"
check "client read current time" $?
# 4. Endpoint lists expected security policy
echo "$CLIENT_OUTPUT" | grep -q "$EXPECTED_POLICY"
check "endpoint contains $EXPECTED_POLICY" $?
# ── result ─────────────────────────────────────────────────────
if [ "$FAILURES" -ne 0 ]; then
echo ""
echo "--- client output ---"
echo "$CLIENT_OUTPUT"
echo "--- end ---"
exit 1
fi
exit 0
|