1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.arvados.org/arvados.git/lib/config"
15 "git.arvados.org/arvados.git/sdk/go/arvados"
16 "git.arvados.org/arvados.git/sdk/go/ctxlog"
17 check "gopkg.in/check.v1"
20 var _ = check.Suite(&GitHandlerSuite{})
22 type GitHandlerSuite struct {
23 cluster *arvados.Cluster
26 func (s *GitHandlerSuite) SetUpTest(c *check.C) {
27 cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
28 c.Assert(err, check.Equals, nil)
29 s.cluster, err = cfg.GetCluster("")
30 c.Assert(err, check.Equals, nil)
32 s.cluster.Services.GitHTTP.InternalURLs = map[arvados.URL]arvados.ServiceInstance{{Host: "localhost:80"}: {}}
33 s.cluster.Git.GitoliteHome = "/test/ghh"
34 s.cluster.Git.Repositories = "/"
37 func (s *GitHandlerSuite) TestEnvVars(c *check.C) {
38 u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
39 c.Check(err, check.Equals, nil)
40 resp := httptest.NewRecorder()
44 RemoteAddr: "[::1]:12345",
46 h := newGitHandler(context.Background(), s.cluster)
47 h.(*gitHandler).Path = "/bin/sh"
48 h.(*gitHandler).Args = []string{"-c", "printf 'Content-Type: text/plain\r\n\r\n'; env"}
50 h.ServeHTTP(resp, req)
52 c.Check(resp.Code, check.Equals, http.StatusOK)
53 body := resp.Body.String()
54 c.Check(body, check.Matches, `(?ms).*^PATH=.*:/test/ghh/bin$.*`)
55 c.Check(body, check.Matches, `(?ms).*^GITOLITE_HTTP_HOME=/test/ghh$.*`)
56 c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=1$.*`)
57 c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`)
58 c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`)
59 c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta("localhost:80")+`$.*`)
62 func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) {
63 u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
64 c.Check(err, check.Equals, nil)
65 resp := httptest.NewRecorder()
69 RemoteAddr: "test.bad.address.missing.port",
71 h := newGitHandler(context.Background(), s.cluster)
72 h.ServeHTTP(resp, req)
73 c.Check(resp.Code, check.Equals, http.StatusInternalServerError)
74 c.Check(resp.Body.String(), check.Equals, "")