Skip to content

Commit

Permalink
Error early if no destination address is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
rwstauner committed Oct 4, 2019
1 parent 290d3a6 commit 761f19e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"bytes"
"fmt"
"io"
"net"
"os/exec"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion test/errors.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 761f19e

Please sign in to comment.