9 check "gopkg.in/check.v1"
12 var _ = check.Suite(&GitHandlerSuite{})
14 type GitHandlerSuite struct{}
16 func (s *GitHandlerSuite) TestEnvVars(c *check.C) {
17 theConfig = defaultConfig()
18 theConfig.RepoRoot = "/"
19 theConfig.GitoliteHome = "/test/ghh"
21 u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
22 c.Check(err, check.Equals, nil)
23 resp := httptest.NewRecorder()
27 RemoteAddr: "[::1]:12345",
30 h.(*gitHandler).Path = "/bin/sh"
31 h.(*gitHandler).Args = []string{"-c", "printf 'Content-Type: text/plain\r\n\r\n'; env"}
33 h.ServeHTTP(resp, req)
35 c.Check(resp.Code, check.Equals, http.StatusOK)
36 body := resp.Body.String()
37 c.Check(body, check.Matches, `(?ms).*^PATH=.*:/test/ghh/bin$.*`)
38 c.Check(body, check.Matches, `(?ms).*^GITOLITE_HTTP_HOME=/test/ghh$.*`)
39 c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=1$.*`)
40 c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`)
41 c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`)
42 c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta(theConfig.Listen)+`$.*`)
45 func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) {
46 u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
47 c.Check(err, check.Equals, nil)
48 resp := httptest.NewRecorder()
52 RemoteAddr: "test.bad.address.missing.port",
55 h.ServeHTTP(resp, req)
56 c.Check(resp.Code, check.Equals, http.StatusInternalServerError)
57 c.Check(resp.Body.String(), check.Equals, "")