function cmd::test::section_destructive() { test::section "Destructive (modifying state)" # Cleanup from any previous failed run "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true "$WGCTL_BINARY" group remove --name testgroup --force > /dev/null 2>&1 || true # Add test peer cmd::test::run_cmd "add phone peer" "added successfully" \ add --name testunit --type phone # Block/unblock cmd::test::run_cmd "block peer" "blocked" \ block --name phone-testunit cmd::test::run_cmd "list shows blocked" "blocked" \ list --blocked cmd::test::run_cmd "unblock peer" "unblocked" \ unblock --name phone-testunit # Rule assign/unassign cmd::test::run_cmd "rule assign" "Assigned" \ rule assign --name user --peer phone-testunit cmd::test::run_cmd "rule unassign" "Unassigned" \ rule unassign --peer phone-testunit # Re-assign user rule (default) for cleanup /usr/local/bin/wgctl rule assign --name user --peer phone-testunit \ > /dev/null 2>&1 || true # Group operations cmd::test::run_cmd "group add" "created" \ group add --name testgroup --desc "Test group" cmd::test::run_cmd "group peer add" "Added" \ group peer add --name testgroup --peer phone-testunit cmd::test::run_cmd "group block" "have been blocked" \ group block --name testgroup cmd::test::run_cmd "group unblock" "have been unblocked" \ group unblock --name testgroup cmd::test::run_cmd "group remove" "removed" \ group remove --name testgroup --force # Block/unblock with group tracking cmd::test::run_cmd "group block tracks groups" "" \ group block --name testgroup # Verify peer stays blocked after partial unblock "$WGCTL_BINARY" group add --name testgroup2 > /dev/null 2>&1 "$WGCTL_BINARY" group peer add --name testgroup2 \ --peer phone-testunit > /dev/null 2>&1 "$WGCTL_BINARY" group block --name testgroup2 > /dev/null 2>&1 "$WGCTL_BINARY" group unblock --name testgroup > /dev/null 2>&1 # Peer should STILL be blocked (testgroup2 is still blocking) cmd::test::run_cmd "peer stays blocked after partial unblock" \ "blocked" list --blocked # Full unblock cmd::test::run_cmd "group unblock removes all" "" \ group unblock --name testgroup2 "$WGCTL_BINARY" group remove --name testgroup --force > /dev/null 2>&1 || true "$WGCTL_BINARY" group remove --name testgroup2 --force > /dev/null 2>&1 # Remove test peer cmd::test::run_cmd "remove phone peer" "removed" \ remove --name phone-testunit --force }