socks_config_test.go 1.0 KB

1234567891011121314151617181920212223242526
  1. package amneziawgnet
  2. import "testing"
  3. // An inbound id past the slot count used to be refused outright, which capped a
  4. // database at 435 AmneziaWG inbounds for its whole life (#6537).
  5. func TestSOCKSPortForInboundKeepsEverySlotInsideTheWindow(t *testing.T) {
  6. t.Run("no id derives a port outside the window", func(t *testing.T) {
  7. for _, id := range []int{1, 2, 434, 435, 436, 437, 870, 871, 6537, 70350, 1_000_000} {
  8. port := SOCKSPortForInbound(id)
  9. if port < SOCKSBasePort+1 || port > 65535 {
  10. t.Errorf("id %d derives relay port %d, outside %d..65535", id, port, SOCKSBasePort+1)
  11. }
  12. }
  13. })
  14. // Every id the old formula reached must keep its exact port, or upgrading
  15. // moves a running relay. Ids 1..435 also leave SOCKSBasePort itself unused.
  16. t.Run("ids up to the slot count keep the port they always had", func(t *testing.T) {
  17. for id := 1; id <= 435; id++ {
  18. if got, want := SOCKSPortForInbound(id), SOCKSBasePort+id; got != want {
  19. t.Errorf("id %d moved from relay port %d to %d", id, want, got)
  20. }
  21. }
  22. })
  23. }