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