diff --git a/service/service.go b/service/service.go index bc5037a..0ca7066 100644 --- a/service/service.go +++ b/service/service.go @@ -2,6 +2,7 @@ package service import ( "bytes" + "fmt" "io" "net" "os/exec" @@ -104,6 +105,10 @@ func (s *Service) shouldStop() bool { } func (s *Service) proxy(src string, dst string) error { + if dst == "" { + return fmt.Errorf("destination address is required") + } + ln, err := net.Listen("tcp", src) if err != nil { return err diff --git a/test/errors.bats b/test/errors.bats index bfb8088..36184a1 100755 --- a/test/errors.bats +++ b/test/errors.bats @@ -6,7 +6,14 @@ load helpers "$YNETD" | grep -q 'no services configured' } -@test "bad destination address" { +@test "no address" { + ynetd -proxy ":$LISTEN_PORT " + knock + # Should be instant, rather than timing out. + ylog | grep -qF -- "error starting listener: destination address is required" +} + +@test "no port" { ynetd -proxy ":$LISTEN_PORT foobar" knock # Should be instant, rather than timing out.