gistfile1.txt
· 2.6 KiB · Text
Ham
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
}
| 1 | function cmd::test::section_destructive() { |
| 2 | test::section "Destructive (modifying state)" |
| 3 | |
| 4 | # Cleanup from any previous failed run |
| 5 | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true |
| 6 | "$WGCTL_BINARY" group remove --name testgroup --force > /dev/null 2>&1 || true |
| 7 | |
| 8 | # Add test peer |
| 9 | cmd::test::run_cmd "add phone peer" "added successfully" \ |
| 10 | add --name testunit --type phone |
| 11 | # Block/unblock |
| 12 | cmd::test::run_cmd "block peer" "blocked" \ |
| 13 | block --name phone-testunit |
| 14 | cmd::test::run_cmd "list shows blocked" "blocked" \ |
| 15 | list --blocked |
| 16 | cmd::test::run_cmd "unblock peer" "unblocked" \ |
| 17 | unblock --name phone-testunit |
| 18 | |
| 19 | # Rule assign/unassign |
| 20 | cmd::test::run_cmd "rule assign" "Assigned" \ |
| 21 | rule assign --name user --peer phone-testunit |
| 22 | cmd::test::run_cmd "rule unassign" "Unassigned" \ |
| 23 | rule unassign --peer phone-testunit |
| 24 | # Re-assign user rule (default) for cleanup |
| 25 | /usr/local/bin/wgctl rule assign --name user --peer phone-testunit \ |
| 26 | > /dev/null 2>&1 || true |
| 27 | |
| 28 | # Group operations |
| 29 | cmd::test::run_cmd "group add" "created" \ |
| 30 | group add --name testgroup --desc "Test group" |
| 31 | cmd::test::run_cmd "group peer add" "Added" \ |
| 32 | group peer add --name testgroup --peer phone-testunit |
| 33 | cmd::test::run_cmd "group block" "have been blocked" \ |
| 34 | group block --name testgroup |
| 35 | cmd::test::run_cmd "group unblock" "have been unblocked" \ |
| 36 | group unblock --name testgroup |
| 37 | cmd::test::run_cmd "group remove" "removed" \ |
| 38 | group remove --name testgroup --force |
| 39 | |
| 40 | # Block/unblock with group tracking |
| 41 | cmd::test::run_cmd "group block tracks groups" "" \ |
| 42 | group block --name testgroup |
| 43 | |
| 44 | # Verify peer stays blocked after partial unblock |
| 45 | "$WGCTL_BINARY" group add --name testgroup2 > /dev/null 2>&1 |
| 46 | "$WGCTL_BINARY" group peer add --name testgroup2 \ |
| 47 | --peer phone-testunit > /dev/null 2>&1 |
| 48 | "$WGCTL_BINARY" group block --name testgroup2 > /dev/null 2>&1 |
| 49 | "$WGCTL_BINARY" group unblock --name testgroup > /dev/null 2>&1 |
| 50 | |
| 51 | # Peer should STILL be blocked (testgroup2 is still blocking) |
| 52 | cmd::test::run_cmd "peer stays blocked after partial unblock" \ |
| 53 | "blocked" list --blocked |
| 54 | |
| 55 | # Full unblock |
| 56 | cmd::test::run_cmd "group unblock removes all" "" \ |
| 57 | group unblock --name testgroup2 |
| 58 | |
| 59 | "$WGCTL_BINARY" group remove --name testgroup --force > /dev/null 2>&1 || true |
| 60 | "$WGCTL_BINARY" group remove --name testgroup2 --force > /dev/null 2>&1 |
| 61 | |
| 62 | # Remove test peer |
| 63 | cmd::test::run_cmd "remove phone peer" "removed" \ |
| 64 | remove --name phone-testunit --force |
| 65 | } |