#!/bin/sh # vpn-switch Ownership Reconciliation Unit Tests # # Deterministic, function-level tests for the interface-ownership logic added to # prevent and repair "ownership drift" (session/latest-$interface pointing at a # session whose config is not the one actually loaded on the interface). # # Why a dedicated file (not the black-box vpn-switch-unit-test.sh suite): # The core of this logic compares the LIVE peer set (`wg show `) against # a session's stored config. The black-box suite cannot stub that live output - # EXAMINE_* variables are re-sourced from the platform file at startup # (overriding setenv), and PATH injection does not reach the examination # subshell. So here we extract the two functions under test from source and # drive them directly with a stubbed examiner and a temp database, which is # fully deterministic and needs no real WireGuard interface. # # Functions under test: # session_peer_matches_interface (include/session.sh) - used by is_session_alive() # _session_refresh0 (include/session.sh) - 'session refresh' # # POSIX shell compliant. set -u PASS=0 FAIL=0 ok() { PASS=$((PASS + 1)); printf ' \033[1;32mok\033[0m %s\n' "$1"; } bad() { FAIL=$((FAIL + 1)); printf ' \033[1;31mFAIL\033[0m %s\n' "$1"; } check(){ # check "