16561: Handle implicit port number in ws:// and wss:// urls.
authorTom Clegg <tom@curii.com>
Tue, 28 Jun 2022 19:40:26 +0000 (15:40 -0400)
committerTom Clegg <tom@curii.com>
Tue, 28 Jun 2022 19:40:26 +0000 (15:40 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/service/cmd.go
lib/service/cmd_test.go

index 9e45e0f7e828a340d5eee6d024eb9f8da21cf948..04c3e170ec6e093bac2e701e51e06894aa42009c 100644 (file)
@@ -279,7 +279,11 @@ func getListenAddr(svcs arvados.Services, prog arvados.ServiceName, log logrus.F
                        // explicit port name/number) means listen on
                        // the well-known port for the specified
                        // protocol, "foo.example:https".
                        // explicit port name/number) means listen on
                        // the well-known port for the specified
                        // protocol, "foo.example:https".
-                       listenAddr = net.JoinHostPort(listenAddr, listenURL.Scheme)
+                       port := listenURL.Scheme
+                       if port == "ws" || port == "wss" {
+                               port = "http" + port[2:]
+                       }
+                       listenAddr = net.JoinHostPort(listenAddr, port)
                }
                listener, err := net.Listen("tcp", listenAddr)
                if err == nil {
                }
                listener, err := net.Listen("tcp", listenAddr)
                if err == nil {
index 7a1f98a8f0af2c3ac188fe15be171f6ca1e26f6b..7db91092745e2e4886f0b1b35a3015da0f0387fc 100644 (file)
@@ -64,8 +64,6 @@ func (*Suite) TestGetListenAddress(c *check.C) {
                },
                { // implicit port 80 in InternalURLs
                        internalURLs:     map[string]string{"http://localhost/": ""},
                },
                { // implicit port 80 in InternalURLs
                        internalURLs:     map[string]string{"http://localhost/": ""},
-                       expectListen:     "http://localhost/",
-                       expectInternal:   "http://localhost/",
                        expectErrorMatch: `.*:80: bind: permission denied`,
                },
                { // implicit port 443 in InternalURLs
                        expectErrorMatch: `.*:80: bind: permission denied`,
                },
                { // implicit port 443 in InternalURLs
@@ -73,6 +71,10 @@ func (*Suite) TestGetListenAddress(c *check.C) {
                        expectListen:   "http://localhost:" + unusedPort + "/",
                        expectInternal: "https://host.example/",
                },
                        expectListen:   "http://localhost:" + unusedPort + "/",
                        expectInternal: "https://host.example/",
                },
+               { // implicit port 443 in ListenURL
+                       internalURLs:     map[string]string{"wss://host.example/": "wss://localhost/"},
+                       expectErrorMatch: `.*:443: bind: permission denied`,
+               },
                {
                        internalURLs:   map[string]string{"https://hostname.example/": "http://localhost:8000/"},
                        expectListen:   "http://localhost:8000/",
                {
                        internalURLs:   map[string]string{"https://hostname.example/": "http://localhost:8000/"},
                        expectListen:   "http://localhost:8000/",