Skip to content

Commit 555db26

Browse files
authored
Use loopback address for local communication (#46)
Use loopback address for local communication to avoid exposing ports externally. This has the side effect of not triggering OS X dialogs prompting users to deny/allow access to incoming traffic, in tests and `Local` system usage.
1 parent 2830c67 commit 555db26

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

ec2system/ec2machine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestMutualHTTPS(t *testing.T) {
7676

7777
var listenAndServeError errors.Once
7878
go func() {
79-
listenAndServeError.Set(sys.ListenAndServe(fmt.Sprintf(":%d", port), mux))
79+
listenAndServeError.Set(sys.ListenAndServe(fmt.Sprintf("localhost:%d", port), mux))
8080
}()
8181
time.Sleep(time.Second)
8282

@@ -97,7 +97,7 @@ func TestMutualHTTPS(t *testing.T) {
9797
}
9898

9999
func getFreeTCPPort() (int, error) {
100-
addr, err := net.ResolveTCPAddr("tcp", ":0")
100+
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
101101
if err != nil {
102102
return 0, err
103103
}

local.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (s *localSystem) Start(ctx context.Context, count int) ([]*Machine, error)
9393
muxer := new(tee.Writer)
9494
cmd.Stdout = iofmt.PrefixWriter(muxer, prefix)
9595
cmd.Stderr = iofmt.PrefixWriter(muxer, prefix)
96-
cmd.Env = append(cmd.Env, fmt.Sprintf("BIGMACHINE_ADDR=:%d", port))
96+
cmd.Env = append(cmd.Env, fmt.Sprintf("BIGMACHINE_ADDR=localhost:%d", port))
9797
cmd.Env = append(cmd.Env, fmt.Sprintf("BIGMACHINE_AUTHORITY=%s", s.authorityFilename))
9898

9999
m := new(Machine)
@@ -176,7 +176,6 @@ func (s *localSystem) HTTPClient() *http.Client {
176176
http2.ConfigureTransport(transport)
177177
return &http.Client{Transport: transport}
178178
}
179-
180179
func (*localSystem) Exit(code int) {
181180
os.Exit(code)
182181
}
@@ -220,7 +219,7 @@ func (s *localSystem) Read(ctx context.Context, m *Machine, filename string) (io
220219
}
221220

222221
func getFreeTCPPort() (int, error) {
223-
addr, err := net.ResolveTCPAddr("tcp", ":0")
222+
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
224223
if err != nil {
225224
return 0, err
226225
}

regress/tests/teststream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type service struct{}
3131

3232
func (service) Empty(ctx context.Context, howlong time.Duration, reply *io.ReadCloser) error {
3333
http2.VerboseLogs = true
34-
go http.ListenAndServe(":9090", nil)
34+
go http.ListenAndServe("localhost:9090", nil)
3535
*reply = ioutil.NopCloser(bytes.NewReader(nil))
3636
return nil
3737
}

0 commit comments

Comments
 (0)