Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions qvpn
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,19 @@ load_config() {

load_meta() {
if [[ -f "$QVPN_META" ]]; then
# shellcheck source=/dev/null
source "$QVPN_META"
# Older metadata files persisted QVPN_VERSION, which is readonly in
# the running script. Filter it out so existing installs keep working.
local meta_content
meta_content=$(sed '/^[[:space:]]*QVPN_VERSION[[:space:]]*=/d' "$QVPN_META")
# shellcheck source=/dev/stdin
source /dev/stdin <<< "$meta_content"
debug "loaded state: $QVPN_META"
fi
}

save_meta() {
cat > "$QVPN_META" <<EOF
# qvpn state — written by qvpn ${QVPN_VERSION}. Safe to delete (will be regenerated).
QVPN_VERSION="${QVPN_VERSION}"
SERVER_IP="${SERVER_IP}"
VPN_SUBNET="${VPN_SUBNET}"
SERVER_VPN_IP="${SERVER_VPN_IP}"
Expand Down
28 changes: 28 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,34 @@ test_config_defaults_applied_when_no_file() {
assert_eq "$VPN_SUBNET" "$DEFAULT_VPN_SUBNET" "default VPN_SUBNET"
}

test_load_meta_ignores_legacy_version_field() {
local tmp; tmp=$(make_tmp)
QVPN_META="$tmp/.qvpn-meta"
cat > "$QVPN_META" <<'EOF'
QVPN_VERSION="0.9.0"
SERVER_IP="203.0.113.10"
VPN_SUBNET="10.77.0.0/24"
SERVER_VPN_IP="10.77.0.1"
LISTEN_PORT="42820"
DNS_SERVERS="9.9.9.9"
NETWORK_INTERFACE="ens3"
EOF

SERVER_IP=""; VPN_SUBNET=""; SERVER_VPN_IP=""
LISTEN_PORT=""; DNS_SERVERS=""; NETWORK_INTERFACE=""

load_meta

assert_eq "$QVPN_VERSION" "1.0.0" "runtime QVPN_VERSION should remain unchanged"
assert_eq "$SERVER_IP" "203.0.113.10" "SERVER_IP meta"
assert_eq "$VPN_SUBNET" "10.77.0.0/24" "VPN_SUBNET meta"
assert_eq "$SERVER_VPN_IP" "10.77.0.1" "SERVER_VPN_IP meta"
assert_eq "$LISTEN_PORT" "42820" "LISTEN_PORT meta"
assert_eq "$DNS_SERVERS" "9.9.9.9" "DNS_SERVERS meta"
assert_eq "$NETWORK_INTERFACE" "ens3" "NETWORK_INTERFACE meta"
rm -rf "$tmp"
}

# ============================================================================
# BLACK-BOX TESTS — invoke ./qvpn as a subprocess
# ============================================================================
Expand Down