10 check "gopkg.in/check.v1"
13 var _ = check.Suite(&GitHandlerSuite{})
15 type GitHandlerSuite struct{}
17 func (s *GitHandlerSuite) TestEnvVars(c *check.C) {
18 u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
19 c.Check(err, check.Equals, nil)
20 resp := httptest.NewRecorder()
24 RemoteAddr: "[::1]:12345",
27 h.(*gitHandler).Path = "/bin/sh"
28 h.(*gitHandler).Args = []string{"-c", "printf 'Content-Type: text/plain\r\n\r\n'; env"}
29 os.Setenv("GITOLITE_HTTP_HOME", "/test/ghh")
30 os.Setenv("GL_BYPASS_ACCESS_CHECKS", "yesplease")
32 h.ServeHTTP(resp, req)
34 c.Check(resp.Code, check.Equals, http.StatusOK)
35 body := resp.Body.String()
36 c.Check(body, check.Matches, `(?ms).*^GITOLITE_HTTP_HOME=/test/ghh$.*`)
37 c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=yesplease$.*`)
38 c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`)
39 c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`)
40 c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta(theConfig.Addr)+`$.*`)
43 func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) {
44 u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
45 c.Check(err, check.Equals, nil)
46 resp := httptest.NewRecorder()
50 RemoteAddr: "test.bad.address.missing.port",
53 h.ServeHTTP(resp, req)
54 c.Check(resp.Code, check.Equals, http.StatusInternalServerError)
55 c.Check(resp.Body.String(), check.Equals, "")