diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-06-09 09:26:44 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-07-06 02:27:25 +0300 |
commit | 4c7d7872868361d79796e87cca2d4cf5d0e95824 (patch) | |
tree | d23736d4b9dd741e69ccd59b1ffad232995a1656 /internal/domain | |
parent | 2a23f2fb9bca74302dcdc40def50c748da4a5e06 (diff) |
Address MR feedback
use correct reference
Diffstat (limited to 'internal/domain')
-rw-r--r-- | internal/domain/domain.go | 13 | ||||
-rw-r--r-- | internal/domain/domain_test.go | 7 |
2 files changed, 11 insertions, 9 deletions
diff --git a/internal/domain/domain.go b/internal/domain/domain.go index 9fa843a3..7c1639a3 100644 --- a/internal/domain/domain.go +++ b/internal/domain/domain.go @@ -1,6 +1,7 @@ package domain import ( + "context" "crypto/tls" "errors" "net/http" @@ -173,16 +174,18 @@ func (d *Domain) ServeNotFoundHTTP(w http.ResponseWriter, r *http.Request) { // that failed authentication so that we serve the custom namespace error page for // public namespace domains func (d *Domain) serveNamespaceNotFound(w http.ResponseWriter, r *http.Request) { - // override the path and try to resolve the domain name - r.URL.Path = "/" - namespaceDomain, err := d.Resolver.Resolve(r) + // clone r and override the path and try to resolve the domain name + clonedReq := r.Clone(context.Background()) + clonedReq.URL.Path = "/" + + namespaceDomain, err := d.Resolver.Resolve(clonedReq) if err != nil || namespaceDomain.LookupPath == nil { httperrors.Serve404(w) return } // for namespace domains that have no access control enabled - if namespaceDomain.LookupPath.IsNamespaceProject && !namespaceDomain.LookupPath.HasAccessControl { + if !namespaceDomain.LookupPath.HasAccessControl { namespaceDomain.ServeNotFoundHTTP(w, r) return } @@ -197,7 +200,7 @@ func (d *Domain) ServeNotFoundAuthFailed(w http.ResponseWriter, r *http.Request) httperrors.Serve404(w) return } - if d.IsNamespaceProject(r) { + if d.IsNamespaceProject(r) && !d.GetLookupPath(r).HasAccessControl { d.ServeNotFoundHTTP(w, r) return } diff --git a/internal/domain/domain_test.go b/internal/domain/domain_test.go index 9e89f0e5..fc5611ba 100644 --- a/internal/domain/domain_test.go +++ b/internal/domain/domain_test.go @@ -157,10 +157,7 @@ func chdirInPath(t require.TestingT, path string) func() { } } -func TestDomain_ServeNamespaceNotFound(t *testing.T) { - // defaultNotFound := "The page you're looking for could not be found." - // customNotFound := "Custom error page" - +func TestServeNamespaceNotFound(t *testing.T) { tests := []struct { name string domain string @@ -231,6 +228,8 @@ func TestDomain_ServeNamespaceNotFound(t *testing.T) { d.serveNamespaceNotFound(w, r) resp := w.Result() + defer resp.Body.Close() + require.Equal(t, http.StatusNotFound, resp.StatusCode) body, err := ioutil.ReadAll(resp.Body) require.NoError(t, err) |