Skip to content

Commit bb84dd8

Browse files
beadonclaude
andcommitted
fix(set-u): initialize locals and guard network.sh calls in auto_detect_fqdn and detect_ipv6_prefix
network_find_wan/network_find_wan6 internally unset their dest variable before populating it via eval. Under set -u, the subsequent empty check crashes with "parameter not set". Fix: initialize all locals to "" and wrap network.sh calls with set +u / set -u using ${VAR:-} default expansion on the check. test(integration): add Suite 12 — auto-detect server settings (option 4), 95 tests passing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 82d4f43 commit bb84dd8

2 files changed

Lines changed: 48 additions & 22 deletions

File tree

openvpn_server_management.sh

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -665,26 +665,29 @@ check_ipv6_subnet_conflict() {
665665

666666
# Function to detect IPv6 prefix delegation from WAN
667667
detect_ipv6_prefix() {
668-
local WAN6_IF
669-
local wan6_addrs
670-
local prefix_delegation
671-
local prefix_size
672-
local lan_ipv6
673-
local lan_prefix
668+
local WAN6_IF=""
669+
local wan6_addrs=""
670+
local prefix_delegation=""
671+
local prefix_size=""
672+
local lan_ipv6=""
673+
local lan_prefix=""
674674

675675
echo "Detecting IPv6 configuration from WAN interface..."
676676
echo ""
677677

678-
# Get WAN interface name
678+
# Get WAN interface name — network.sh may unset the dest var if no route found,
679+
# so keep set +u active until after the empty check.
679680
. /lib/functions/network.sh
680681
network_flush_cache
682+
set +u
681683
network_find_wan6 WAN6_IF
682-
683-
if [ -z "$WAN6_IF" ]; then
684+
if [ -z "${WAN6_IF:-}" ]; then
685+
set -u
684686
echo " No WAN IPv6 interface found"
685687
echo " IPv6 may not be configured on this router"
686688
return 1
687689
fi
690+
set -u
688691

689692
echo " WAN IPv6 interface: $WAN6_IF"
690693

@@ -759,17 +762,17 @@ detect_ipv6_prefix() {
759762

760763
# Auto-Detect DDNS configured name, Fetch server address configured elsewhere
761764
auto_detect_fqdn() {
762-
local DETECTED_PORT
763-
local DETECTED_PROTO
764-
local DETECTED_POOL
765-
local DETECTED_IPV6_POOL
766-
local rule_index
767-
local rule_name
768-
local rule_dest_port
769-
local rule_proto
770-
local NET_FQDN
771-
local NET_IF
772-
local NET_ADDR
765+
local DETECTED_PORT=""
766+
local DETECTED_PROTO=""
767+
local DETECTED_POOL=""
768+
local DETECTED_IPV6_POOL=""
769+
local rule_index=""
770+
local rule_name=""
771+
local rule_dest_port=""
772+
local rule_proto=""
773+
local NET_FQDN=""
774+
local NET_IF=""
775+
local NET_ADDR=""
773776

774777
echo ""
775778
echo "Script default settings (if no config found):"
@@ -877,12 +880,14 @@ auto_detect_fqdn() {
877880
# Update DNS based on detected pool
878881
OVPN_DNS="${OVPN_POOL%.* *}.1"
879882

880-
# Detect server FQDN/IP
883+
# Detect server FQDN/IP — network.sh may unset dest vars; keep set +u active
881884
NET_FQDN="$(uci -q get ddns.@service[0].lookup_host)"
882885
. /lib/functions/network.sh
883886
network_flush_cache
887+
set +u
884888
network_find_wan NET_IF
885-
network_get_ipaddr NET_ADDR "${NET_IF}"
889+
network_get_ipaddr NET_ADDR "${NET_IF:-}"
890+
set -u
886891
if [ -n "${NET_FQDN}" ]
887892
then
888893
OVPN_SERV="${NET_FQDN}"

tests/integration_test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,27 @@ check wait_for "testvpn" 5
607607
expect_send "Press Enter" "" 5
608608
check wait_for "Select an option:" 5
609609

610+
# ── Suite 12: Auto-detect Server Settings ────────────────────────────────────
611+
# option 4 is read-only: detects port/proto from server.conf and firewall rules,
612+
# WAN IP from UCI, and prints "Final Settings". No user prompts — returns
613+
# directly to the main menu after output.
614+
615+
printf "\n--- [%s] Suite 12: Auto-detect Server Settings (option 4) ---\n" "$(ts)"
616+
617+
it "option 4 detects settings from server.conf and prints final summary"
618+
select_option "4"
619+
wait_for "Detecting configuration" 5
620+
# server.conf exists from Suite 2 — port and protocol should be detected
621+
wait_for "Detected port" 10
622+
wait_for "Final Settings" 10
623+
# No Press Enter gate — returns directly to menu; allow time for network detection
624+
check wait_for "Select an option:" 20
625+
626+
it "option 4 reports a VPN server address"
627+
select_option "4"
628+
wait_for "Detected WAN IP\|Detected DDNS" 20
629+
check wait_for "Select an option:" 20
630+
610631
# ── Done ──────────────────────────────────────────────────────────────────────
611632

612633
quit_script

0 commit comments

Comments
 (0)