17598: Also use lowercase for URL host comparison
authorPeter Amstutz <peter.amstutz@curii.com>
Mon, 3 May 2021 18:31:21 +0000 (14:31 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Mon, 3 May 2021 18:31:21 +0000 (14:31 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

services/keep-web/handler.go
services/keep-web/handler_test.go

index 754aefe44bbb03eda7c6816c1c7b24154d087e15..81925421dc53b322fc9eb731422f85907e245fd5 100644 (file)
@@ -189,9 +189,9 @@ func stripDefaultPort(host string) string {
        // Will consider port 80 and port 443 to be the same vhost.  I think that's fine.
        u := &url.URL{Host: host}
        if p := u.Port(); p == "80" || p == "443" {
-               return u.Hostname()
+               return strings.ToLower(u.Hostname())
        } else {
-               return host
+               return strings.ToLower(host)
        }
 }
 
index 4560adc68c0c89a1561a165dfb078cc3f88174a3..3ff7cb1926b69d36ccd8f683ec544ec977fd7aef 100644 (file)
@@ -327,23 +327,25 @@ func (s *IntegrationSuite) doVhostRequestsWithHostPath(c *check.C, authz authori
 }
 
 func (s *IntegrationSuite) TestVhostPortMatch(c *check.C) {
-       for _, port := range []string{"80", "443", "8000"} {
-               s.testServer.Config.cluster.Services.WebDAVDownload.ExternalURL.Host = fmt.Sprintf("download.example.com:%v", port)
-               u := mustParseURL(fmt.Sprintf("http://download.example.com/by_id/%v/foo", arvadostest.FooCollection))
-               req := &http.Request{
-                       Method:     "GET",
-                       Host:       u.Host,
-                       URL:        u,
-                       RequestURI: u.RequestURI(),
-                       Header:     http.Header{"Authorization": []string{"Bearer " + arvadostest.ActiveToken}},
-               }
-               req, resp := s.doReq(req)
-               code, _ := resp.Code, resp.Body.String()
+       for _, host := range []string{"download.example.com", "DOWNLOAD.EXAMPLE.COM"} {
+               for _, port := range []string{"80", "443", "8000"} {
+                       s.testServer.Config.cluster.Services.WebDAVDownload.ExternalURL.Host = fmt.Sprintf("download.example.com:%v", port)
+                       u := mustParseURL(fmt.Sprintf("http://%v/by_id/%v/foo", host, arvadostest.FooCollection))
+                       req := &http.Request{
+                               Method:     "GET",
+                               Host:       u.Host,
+                               URL:        u,
+                               RequestURI: u.RequestURI(),
+                               Header:     http.Header{"Authorization": []string{"Bearer " + arvadostest.ActiveToken}},
+                       }
+                       req, resp := s.doReq(req)
+                       code, _ := resp.Code, resp.Body.String()
 
-               if port == "8000" {
-                       c.Check(code, check.Equals, 401)
-               } else {
-                       c.Check(code, check.Equals, 200)
+                       if port == "8000" {
+                               c.Check(code, check.Equals, 401)
+                       } else {
+                               c.Check(code, check.Equals, 200)
+                       }
                }
        }
 }