mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-21 02:17:36 +00:00
tsnet: be stricter about arguments to Server.Listen
Fixes #6201 Change-Id: I14b2b8ce9bee838344a3fad4f305c78ab775f72e Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
08e110ebc5
commit
cbc89830c4
@@ -4,7 +4,10 @@
|
||||
|
||||
package tsnet
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestListener_Server ensures that the listener type always keeps the Server
|
||||
// method, which is used by some external applications to identify a tsnet.Listener
|
||||
@@ -16,3 +19,29 @@ func TestListener_Server(t *testing.T) {
|
||||
t.Errorf("listener.Server() returned %v, want %v", ln.Server(), s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListenerPort(t *testing.T) {
|
||||
errNone := errors.New("sentinel start error")
|
||||
|
||||
tests := []struct {
|
||||
network string
|
||||
addr string
|
||||
wantErr bool
|
||||
}{
|
||||
{"tcp", ":80", false},
|
||||
{"foo", ":80", true},
|
||||
{"tcp", ":http", false}, // built-in name to Go; doesn't require cgo, /etc/services
|
||||
{"tcp", ":https", false}, // built-in name to Go; doesn't require cgo, /etc/services
|
||||
{"tcp", ":gibberishsdlkfj", true},
|
||||
{"tcp", ":%!d(string=80)", true}, // issue 6201
|
||||
}
|
||||
for _, tt := range tests {
|
||||
s := &Server{}
|
||||
s.initOnce.Do(func() { s.initErr = errNone })
|
||||
_, err := s.Listen(tt.network, tt.addr)
|
||||
gotErr := err != nil && err != errNone
|
||||
if gotErr != tt.wantErr {
|
||||
t.Errorf("Listen(%q, %q) error = %v, want %v", tt.network, tt.addr, gotErr, tt.wantErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user