10 check "gopkg.in/check.v1"
13 var _ = check.Suite(&GitHandlerSuite{})
15 type GitHandlerSuite struct{}
17 func (s *GitHandlerSuite) TestEnvVars(c *check.C) {
18 theConfig = defaultConfig()
19 theConfig.RepoRoot = "/"
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"}
32 os.Setenv("GITOLITE_HTTP_HOME", "/test/ghh")
33 os.Setenv("GL_BYPASS_ACCESS_CHECKS", "yesplease")
35 h.ServeHTTP(resp, req)
37 c.Check(resp.Code, check.Equals, http.StatusOK)
38 body := resp.Body.String()
39 c.Check(body, check.Matches, `(?ms).*^GITOLITE_HTTP_HOME=/test/ghh$.*`)
40 c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=yesplease$.*`)
41 c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`)
42 c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`)
43 c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta(theConfig.Listen)+`$.*`)
46 func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) {
47 u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
48 c.Check(err, check.Equals, nil)
49 resp := httptest.NewRecorder()
53 RemoteAddr: "test.bad.address.missing.port",
56 h.ServeHTTP(resp, req)
57 c.Check(resp.Code, check.Equals, http.StatusInternalServerError)
58 c.Check(resp.Body.String(), check.Equals, "")