[ARVADOS] created: 2.1.0-2309-g954f3e357

Git user git at public.arvados.org
Thu Apr 14 14:59:50 UTC 2022


        at  954f3e357128f884409e52658933d120ce0127ea (commit)


commit 954f3e357128f884409e52658933d120ce0127ea
Author: Tom Clegg <tom at curii.com>
Date:   Thu Apr 14 10:59:14 2022 -0400

    18995: Un-stub addrIsLocal, make it work for in-use ports.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/boot/supervisor.go b/lib/boot/supervisor.go
index 7daceccb9..26b3fceee 100644
--- a/lib/boot/supervisor.go
+++ b/lib/boot/supervisor.go
@@ -809,7 +809,11 @@ func (super *Supervisor) autofillConfig(cfg *arvados.Config) error {
 }
 
 func addrIsLocal(addr string) (bool, error) {
-	return true, nil
+	if h, _, err := net.SplitHostPort(addr); err != nil {
+		return false, err
+	} else {
+		addr = net.JoinHostPort(h, "0")
+	}
 	listener, err := net.Listen("tcp", addr)
 	if err == nil {
 		listener.Close()
diff --git a/lib/boot/supervisor_test.go b/lib/boot/supervisor_test.go
new file mode 100644
index 000000000..b80fe1ed4
--- /dev/null
+++ b/lib/boot/supervisor_test.go
@@ -0,0 +1,57 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package boot
+
+import (
+	"net"
+	"testing"
+
+	check "gopkg.in/check.v1"
+)
+
+func Test(t *testing.T) {
+	check.TestingT(t)
+}
+
+type supervisorSuite struct{}
+
+var _ = check.Suite(&supervisorSuite{})
+
+func (s *supervisorSuite) TestAddrIsLocal(c *check.C) {
+	is, err := addrIsLocal("0.0.0.0:0")
+	c.Check(err, check.IsNil)
+	c.Check(is, check.Equals, true)
+
+	is, err = addrIsLocal("127.0.0.1:9")
+	c.Check(err, check.IsNil)
+	c.Check(is, check.Equals, true)
+
+	is, err = addrIsLocal("127.0.0.127:32767")
+	c.Check(err, check.IsNil)
+	c.Check(is, check.Equals, true)
+
+	is, err = addrIsLocal("[::1]:32767")
+	c.Check(err, check.IsNil)
+	c.Check(is, check.Equals, true)
+
+	is, err = addrIsLocal("8.8.8.8:32767")
+	c.Check(err, check.IsNil)
+	c.Check(is, check.Equals, false)
+
+	is, err = addrIsLocal("example.com:32767")
+	c.Check(err, check.IsNil)
+	c.Check(is, check.Equals, false)
+
+	is, err = addrIsLocal("1.2.3.4.5:32767")
+	c.Check(err, check.NotNil)
+
+	ln, err := net.Listen("tcp", ":")
+	c.Assert(err, check.IsNil)
+	defer ln.Close()
+	is, err = addrIsLocal(ln.Addr().String())
+	c.Check(err, check.IsNil)
+	c.Check(is, check.Equals, true)
+
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list