X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6feefc59c459d778046a83cb29178afc04acdf1c..6d95130da47af9fd0290d3c8f80a0364faf74957:/services/arv-git-httpd/git_handler_test.go diff --git a/services/arv-git-httpd/git_handler_test.go b/services/arv-git-httpd/git_handler_test.go index e24679f579..c14030f95d 100644 --- a/services/arv-git-httpd/git_handler_test.go +++ b/services/arv-git-httpd/git_handler_test.go @@ -1,55 +1,73 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + package main import ( "net/http" "net/http/httptest" "net/url" - "os" "regexp" + "git.arvados.org/arvados.git/lib/config" + "git.arvados.org/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/sdk/go/ctxlog" check "gopkg.in/check.v1" ) var _ = check.Suite(&GitHandlerSuite{}) -type GitHandlerSuite struct {} +type GitHandlerSuite struct { + cluster *arvados.Cluster +} + +func (s *GitHandlerSuite) SetUpTest(c *check.C) { + cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load() + c.Assert(err, check.Equals, nil) + s.cluster, err = cfg.GetCluster("") + c.Assert(err, check.Equals, nil) + + s.cluster.Services.GitHTTP.InternalURLs = map[arvados.URL]arvados.ServiceInstance{arvados.URL{Host: "localhost:80"}: arvados.ServiceInstance{}} + s.cluster.Git.GitoliteHome = "/test/ghh" + s.cluster.Git.Repositories = "/" +} func (s *GitHandlerSuite) TestEnvVars(c *check.C) { u, err := url.Parse("git.zzzzz.arvadosapi.com/test") c.Check(err, check.Equals, nil) resp := httptest.NewRecorder() req := &http.Request{ - Method: "GET", - URL: u, + Method: "GET", + URL: u, RemoteAddr: "[::1]:12345", } - h := newGitHandler() + h := newGitHandler(s.cluster) h.(*gitHandler).Path = "/bin/sh" - h.(*gitHandler).Args = []string{"-c", "echo HTTP/1.1 200 OK; echo Content-Type: text/plain; echo; env"} - os.Setenv("GITOLITE_HTTP_HOME", "/test/ghh") - os.Setenv("GL_BYPASS_ACCESS_CHECKS", "yesplease") + h.(*gitHandler).Args = []string{"-c", "printf 'Content-Type: text/plain\r\n\r\n'; env"} h.ServeHTTP(resp, req) c.Check(resp.Code, check.Equals, http.StatusOK) body := resp.Body.String() + c.Check(body, check.Matches, `(?ms).*^PATH=.*:/test/ghh/bin$.*`) c.Check(body, check.Matches, `(?ms).*^GITOLITE_HTTP_HOME=/test/ghh$.*`) - c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=yesplease$.*`) + c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=1$.*`) c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`) c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`) - c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=` + regexp.QuoteMeta(theConfig.Addr) + `$.*`) + c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta("localhost:80")+`$.*`) } -func (s *GitHandlerSuite) TestCGIError(c *check.C) { +func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) { u, err := url.Parse("git.zzzzz.arvadosapi.com/test") c.Check(err, check.Equals, nil) resp := httptest.NewRecorder() req := &http.Request{ - Method: "GET", - URL: u, - RemoteAddr: "bogus", + Method: "GET", + URL: u, + RemoteAddr: "test.bad.address.missing.port", } - h := newGitHandler() + h := newGitHandler(s.cluster) h.ServeHTTP(resp, req) c.Check(resp.Code, check.Equals, http.StatusInternalServerError) c.Check(resp.Body.String(), check.Equals, "")