nuno zrewidował ten Gist 1 month ago. Przejdź do rewizji
1 file changed, 127 insertions
destructive.sh(stworzono plik)
| @@ -0,0 +1,127 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | # test/destructive.sh — tests that modify system state | |
| 3 | + | # Sourced by test.command.sh — do not execute directly. | |
| 4 | + | # Requires run_cmd / run_cmd_fails from integration.sh to be sourced first. | |
| 5 | + | ||
| 6 | + | function cmd::test::section_destructive() { | |
| 7 | + | test::section "Destructive (modifying state)" | |
| 8 | + | ||
| 9 | + | # Cleanup from any previous failed run | |
| 10 | + | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true | |
| 11 | + | "$WGCTL_BINARY" remove --name laptop-testunit2 --force > /dev/null 2>&1 || true | |
| 12 | + | "$WGCTL_BINARY" remove --name laptop-testunit2b --force > /dev/null 2>&1 || true | |
| 13 | + | "$WGCTL_BINARY" group remove --name testgroup --force > /dev/null 2>&1 || true | |
| 14 | + | "$WGCTL_BINARY" group remove --name testgroup2 --force > /dev/null 2>&1 || true | |
| 15 | + | "$WGCTL_BINARY" net rm --name test-block-svc --force > /dev/null 2>&1 || true | |
| 16 | + | "$WGCTL_BINARY" unblock --name phone-testunit > /dev/null 2>&1 || true | |
| 17 | + | ||
| 18 | + | cmd::test::_destructive_peer | |
| 19 | + | cmd::test::_destructive_block_unblock | |
| 20 | + | cmd::test::_destructive_service_block | |
| 21 | + | cmd::test::_destructive_rule | |
| 22 | + | cmd::test::_destructive_groups | |
| 23 | + | cmd::test::_destructive_identity | |
| 24 | + | cmd::test::_destructive_cleanup | |
| 25 | + | } | |
| 26 | + | ||
| 27 | + | function cmd::test::_destructive_peer() { | |
| 28 | + | cmd::test::run_cmd "add phone peer" "added" \ | |
| 29 | + | add --name testunit --type phone | |
| 30 | + | } | |
| 31 | + | ||
| 32 | + | function cmd::test::_destructive_block_unblock() { | |
| 33 | + | cmd::test::run_cmd "block peer" "blocked" block --name phone-testunit | |
| 34 | + | cmd::test::run_cmd "list shows blocked" "phone-testunit" list --blocked | |
| 35 | + | cmd::test::run_cmd "unblock peer" "unblocked" unblock --name phone-testunit | |
| 36 | + | ||
| 37 | + | cmd::test::run_cmd "block peer --ip" "blocked for" \ | |
| 38 | + | block --name phone-testunit --ip 10.0.0.99 | |
| 39 | + | cmd::test::run_cmd "list shows restricted" "restricted" \ | |
| 40 | + | list --name phone-testunit | |
| 41 | + | cmd::test::run_cmd "unblock peer --ip" "unblocked" \ | |
| 42 | + | unblock --name phone-testunit --ip 10.0.0.99 | |
| 43 | + | } | |
| 44 | + | ||
| 45 | + | function cmd::test::_destructive_service_block() { | |
| 46 | + | "$WGCTL_BINARY" net add --name test-block-svc \ | |
| 47 | + | --ip 10.0.0.99 > /dev/null 2>&1 | |
| 48 | + | "$WGCTL_BINARY" net add --name test-block-svc:web \ | |
| 49 | + | --port 9999:tcp > /dev/null 2>&1 | |
| 50 | + | ||
| 51 | + | cmd::test::run_cmd "block peer --service (ip)" "blocked" block --name phone-testunit --service test-block-svc | |
| 52 | + | cmd::test::run_cmd "block already blocked service" "already" block --name phone-testunit --service test-block-svc | |
| 53 | + | cmd::test::run_cmd "unblock peer --service (ip)" "unblocked" unblock --name phone-testunit --service test-block-svc | |
| 54 | + | cmd::test::run_cmd "unblock not blocked service" "not blocked" unblock --name phone-testunit --service test-block-svc | |
| 55 | + | cmd::test::run_cmd "block peer --service (port)" "blocked" block --name phone-testunit --service test-block-svc:web | |
| 56 | + | cmd::test::run_cmd "unblock peer --service (port)" "unblocked" unblock --name phone-testunit --service test-block-svc:web | |
| 57 | + | ||
| 58 | + | "$WGCTL_BINARY" net rm --name test-block-svc --force > /dev/null 2>&1 || true | |
| 59 | + | } | |
| 60 | + | ||
| 61 | + | function cmd::test::_destructive_rule() { | |
| 62 | + | cmd::test::run_cmd "rule assign" "Assigned" rule assign --name user --peer phone-testunit | |
| 63 | + | cmd::test::run_cmd "rule unassign" "Unassigned" rule unassign --peer phone-testunit | |
| 64 | + | "$WGCTL_BINARY" rule assign --name user --peer phone-testunit > /dev/null 2>&1 || true | |
| 65 | + | } | |
| 66 | + | ||
| 67 | + | function cmd::test::_destructive_groups() { | |
| 68 | + | cmd::test::run_cmd "group add" "created" group add --name testgroup --desc "Test group" | |
| 69 | + | cmd::test::run_cmd "group peer add" "Added" group peer add --name testgroup --peer phone-testunit | |
| 70 | + | cmd::test::run_cmd "group block" "blocked" group block --name testgroup | |
| 71 | + | cmd::test::run_cmd "group unblock" "unblocked" group unblock --name testgroup | |
| 72 | + | ||
| 73 | + | "$WGCTL_BINARY" group add --name testgroup2 --desc "Test group 2" > /dev/null 2>&1 | |
| 74 | + | "$WGCTL_BINARY" group peer add --name testgroup2 --peer phone-testunit > /dev/null 2>&1 | |
| 75 | + | ||
| 76 | + | cmd::test::run_cmd "group block first" "blocked" group block --name testgroup | |
| 77 | + | cmd::test::run_cmd "group block second" "blocked" group block --name testgroup2 | |
| 78 | + | ||
| 79 | + | "$WGCTL_BINARY" group unblock --name testgroup > /dev/null 2>&1 | |
| 80 | + | cmd::test::run_cmd "peer stays blocked after partial unblock" "phone-testunit" list --blocked | |
| 81 | + | ||
| 82 | + | "$WGCTL_BINARY" group unblock --name testgroup2 > /dev/null 2>&1 | |
| 83 | + | cmd::test::run_cmd "peer unblocked after all groups unblock" "phone-testunit" list --allowed | |
| 84 | + | ||
| 85 | + | "$WGCTL_BINARY" group block --name testgroup > /dev/null 2>&1 | |
| 86 | + | cmd::test::run_cmd "direct unblock overrides group block" "unblocked" unblock --name phone-testunit | |
| 87 | + | ||
| 88 | + | cmd::test::run_cmd "group remove" "removed" group remove --name testgroup --force | |
| 89 | + | "$WGCTL_BINARY" group remove --name testgroup2 --force > /dev/null 2>&1 || true | |
| 90 | + | } | |
| 91 | + | ||
| 92 | + | function cmd::test::_destructive_identity() { | |
| 93 | + | test::section "Destructive: identity auto-attach/detach" | |
| 94 | + | ||
| 95 | + | # Cleanup from any previous failed run | |
| 96 | + | "$WGCTL_BINARY" remove --name laptop-testunit2 --force > /dev/null 2>&1 || true | |
| 97 | + | "$WGCTL_BINARY" remove --name laptop-testunit2b --force > /dev/null 2>&1 || true | |
| 98 | + | ||
| 99 | + | # Add — verify auto-attach to identity "testunit2" | |
| 100 | + | cmd::test::run_cmd "add attaches to identity" "added" \ | |
| 101 | + | add --name testunit2 --type laptop | |
| 102 | + | ||
| 103 | + | cmd::test::run_cmd "identity created for testunit2" "laptop-testunit2" \ | |
| 104 | + | identity show --name testunit2 | |
| 105 | + | ||
| 106 | + | # Rename — verify identity::rename_peer moves peer to new identity "testunit2b" | |
| 107 | + | cmd::test::run_cmd "rename peer" "renamed" \ | |
| 108 | + | rename --name laptop-testunit2 --new-name laptop-testunit2b | |
| 109 | + | ||
| 110 | + | cmd::test::run_cmd "identity reflects rename (new identity)" "laptop-testunit2b" \ | |
| 111 | + | identity show --name testunit2b | |
| 112 | + | ||
| 113 | + | cmd::test::run_cmd_fails "old identity gone after rename" \ | |
| 114 | + | identity show --name testunit2 | |
| 115 | + | ||
| 116 | + | # Remove — verify auto-detach cleans up identity file | |
| 117 | + | cmd::test::run_cmd "remove detaches from identity" "removed" \ | |
| 118 | + | remove --name laptop-testunit2b --force | |
| 119 | + | ||
| 120 | + | cmd::test::run_cmd_fails "identity cleaned up after remove" \ | |
| 121 | + | identity show --name testunit2b | |
| 122 | + | } | |
| 123 | + | ||
| 124 | + | function cmd::test::_destructive_cleanup() { | |
| 125 | + | cmd::test::run_cmd "remove phone peer" "removed" \ | |
| 126 | + | remove --name phone-testunit --force | |
| 127 | + | } | |
Nowsze
Starsze