1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 check "gopkg.in/check.v1"
16 var _ = check.Suite(&GitHandlerSuite{})
18 type GitHandlerSuite struct{}
20 func (s *GitHandlerSuite) TestEnvVars(c *check.C) {
21 theConfig = defaultConfig()
22 theConfig.RepoRoot = "/"
23 theConfig.GitoliteHome = "/test/ghh"
25 u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
26 c.Check(err, check.Equals, nil)
27 resp := httptest.NewRecorder()
31 RemoteAddr: "[::1]:12345",
34 h.(*gitHandler).Path = "/bin/sh"
35 h.(*gitHandler).Args = []string{"-c", "printf 'Content-Type: text/plain\r\n\r\n'; env"}
37 h.ServeHTTP(resp, req)
39 c.Check(resp.Code, check.Equals, http.StatusOK)
40 body := resp.Body.String()
41 c.Check(body, check.Matches, `(?ms).*^PATH=.*:/test/ghh/bin$.*`)
42 c.Check(body, check.Matches, `(?ms).*^GITOLITE_HTTP_HOME=/test/ghh$.*`)
43 c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=1$.*`)
44 c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`)
45 c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`)
46 c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta(theConfig.Listen)+`$.*`)
49 func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) {
50 u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
51 c.Check(err, check.Equals, nil)
52 resp := httptest.NewRecorder()
56 RemoteAddr: "test.bad.address.missing.port",
59 h.ServeHTTP(resp, req)
60 c.Check(resp.Code, check.Equals, http.StatusInternalServerError)
61 c.Check(resp.Body.String(), check.Equals, "")